MouseEvents abfangen und erweitern (MaxGui,Canvas)
Übersicht BlitzMax, BlitzMax NG Codearchiv & Module
klepto2Betreff: MouseEvents abfangen und erweitern (MaxGui,Canvas) |
Do, Jan 18, 2007 11:43 Antworten mit Zitat |
|
---|---|---|
Hier mal ein kleiner Code (nix besonderes) den ich wegen meiner Codearea gerade gebraucht hatte und nix entsprechendes gefunden habe. Es handelt sich dabei um einen kleinen MouseHandler, der MouseEvents verwaltet und
folgende States zurückliefert: -LeftClick,RightClick -LeftDown,RightDown -DblLeftClick,DblRightClick -DblLeftDown,DblRightDown Ist noch erweiterbar auf den mittleren Button und auf die Daten des Scrollrades. Vielleicht braucht es wer. Code: [AUSKLAPPEN] ' createcanvas.bmx Strict Global GAME_WIDTH=320 Global GAME_HEIGHT=240 ' create a centered window with client size GAME_WIDTH,GAME_HEIGHT Local wx=(ClientWidth(Desktop())-GAME_WIDTH)/2 Local wy=(ClientHeight(Desktop())-GAME_HEIGHT)/2 Local window:TGadget=CreateWindow("My Canvas",wx,wy,GAME_WIDTH,GAME_HEIGHT,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS) ' create a canvas for our game Global canvas:TGadget=CreateCanvas(0,0,320,240,window) ' create an update timer CreateTimer 60 Local Handler:TMouseHandler = New TMouseHandler While WaitEvent() Select EventID() Case EVENT_TIMERTICK RedrawGadget canvas Case EVENT_GADGETPAINT SetGraphics CanvasGraphics(canvas) Cls Handler.UPdate() DrawText "Position : " + Handler.X+"\"+Handler.Y,20,20 DrawText "Status : " + Handler.GetState(),20,40 Flip Case EVENT_MOUSEMOVE Handler.UpdatePosition(CurrentEvent) Case EVENT_MOUSEDOWN Handler.UpdateButtons(CurrentEvent) Case EVENT_MOUSEUP Handler.UpdateButtons(CurrentEvent) Case EVENT_WINDOWCLOSE FreeGadget canvas End Case EVENT_APPTERMINATE End End Select Wend Type TMouseHandler Field State:String = "Idle" Field LastPress:Int = MilliSecs() Field Dbldelay:Int = 100 Field X:Int = 0 Field Y:Int = 0 Field LastButton:Int = 0 Field pressedbutton:Int Method UpdatePosition(ev:TEvent) X = ev.X Y = ev.Y End Method Method UpdateButtons(ev:TEvent) Print Ev.ToString() Select ev.id Case EVENT_MOUSEDOWN pressedButton:Int = ev.data If (MilliSecs()-lastpress) > DblDelay Then Lastbutton = 0 Select State Case "Idle" If pressedButton = Lastbutton Then If (MilliSecs()-lastpress) < DblDelay Then Select pressedbutton Case 1 State = "DblLeftClick" Case 2 State = "DblRightClick" End Select EndIf EndIf If pressedButton <> LastButton Then LastPress = MilliSecs() Select pressedbutton Case 1 State = "LeftClick" Case 2 State = "RightClick" End Select EndIf End Select LastButton = PressedButton Case EVENT_MOUSEUP State = "Idle" LastPress = MilliSecs() LastButton = PressedButton If (MilliSecs()-lastpress) > DblDelay Then Lastbutton = 0 End Select RedrawGadget Canvas End Method Method UPdate() Select State Case "Idle" Case "DblLeftClick" If MilliSecs()-LastPress > DblDelay+100 State = "DblLeftDown" EndIf Case "DblRightClick" If MilliSecs()-LastPress > DblDelay+100 State = "DblRightDown" EndIf Case "LeftClick" If MilliSecs()-LastPress > DblDelay State = "LeftDown" EndIf Case "RightClick" If MilliSecs()-LastPress > DblDelay State = "RightDown" EndIf End Select End Method Method GetState:String() Return State End Method End Type |
||
Matrix Screensaver
Console Modul für BlitzMax KLPacker Modul für BlitzMax HomePage : http://www.brsoftware.de.vu |
Übersicht BlitzMax, BlitzMax NG Codearchiv & Module
Powered by phpBB © 2001 - 2006, phpBB Group