简体   繁体   English

在Allegro5中启用鼠标

[英]Enabling mouse in Allegro5

I am starting using Allegro in my program in C, but I'm having difficulties creating the buttons. 我开始在C语言程序中使用Allegro,但是创建按钮时遇到困难。 I am using this kind of logic: 我正在使用这种逻辑:

if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
{
      if ((event.mouse.x >= 442) &&(event.mouse.x <= 471) &&(event.mouse.y >= 202) &&(event.mouse.y <= 238))
            {
                dig = '1';
                entr = 1;
            }

But this spaces defined by the axis are non 'clickable'.Somebody here has some tip about the typo of command I should use? 但是这个由轴定义的空间是不可点击的。这里有人提示我应该使用命令的错字吗?

I can only guess what was wrong, but there is no answer yet, so I will provide some tips about the possible problem. 我只能猜测出什么问题了,但是还没有答案,因此,我将提供一些有关可能出现问题的提示。 Your thread is titled enabling the mouse in allegro 5, so I can only assume you're not getting mouse input. 您的线程标题为在allegro 5中启用鼠标,因此我只能假设您没有鼠标输入。

1) You need to install the mouse driver before you will get any mouse input : 1)您需要先安装鼠标驱动程序,然后才能获得任何鼠标输入:

if (!al_install_mouse()) {Fail();}

2) The mouse needs to be registered with your event queue. 2)鼠标需要在事件队列中注册。

al_register_event_source(event_queue , al_get_mouse_event_source());

In a typical GUI, most buttons are only considered 'pressed' if they receive both a mouse button down event over their click area, AND a mouse button up event over the same area. 在典型的GUI中,大多数按钮只有在其单击区域上收到鼠标按下事件以及在同一区域上收到鼠标按下事件时,才被视为“按下”。 This way you don't get a button press when you click on something else, move the mouse over your button and release it. 这样,当您单击其他按钮时,不会使按钮按动,而是将鼠标移到按钮上并释放按钮。 You also prevent button events from pressing the mouse, moving it off the click area and releasing it. 您还可以防止按钮事件按下鼠标,将鼠标移离单击区域并释放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM