PureBasic - форум

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » PureBasic - форум » PureBasic для Windows » CanvasGadget и мыша


CanvasGadget и мыша

Сообщений 1 страница 2 из 2

1

Как на канвасе отловить #PB_EventType_LeftButtonDown и #PB_EventType_MouseMove одновременно, нужно по канвасу двигать мышь с зажатой левой кнопкой и читать координаты мыши.
По отдельности они ловятся, а как вместе?

0

2

Событие #PB_EventType_LeftButtonDown происходит только в момент нажатия кнопки, а не все время когда она нажата. Чтобы узнать нажата кнопка или нет, нужно вызвать функцию GetGadgetAttribute() с параметром #PB_Canvas_Buttons.

#PB_Canvas_Buttons
Returns the state of the mouse buttons for the event. The result is a combination (using bitwise or) of the following values:
  #PB_Canvas_LeftButton  : The left button is currently down.
  #PB_Canvas_RightButton : The right button is currently down.
  #PB_Canvas_MiddleButton: The middle button is currently down.

Пример из справки.

Код:
  If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 10, 10, 200, 200)
    
    Repeat
      Event = WaitWindowEvent()
          
      If Event = #PB_Event_Gadget And EventGadget() = 0 
        If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
          If StartDrawing(CanvasOutput(0))
            x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
            y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
            Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
            StopDrawing()
          EndIf
        EndIf
      EndIf    
      
    Until Event = #PB_Event_CloseWindow
  EndIf

0


Вы здесь » PureBasic - форум » PureBasic для Windows » CanvasGadget и мыша