WindowMouseButton()
WindowMouseButton()
Hi,
I'm just programming something where I need a small stripe of a screen window insode a normal window.
Inside this stripe are sprites which are working as buttons.
WindowMouseX() and Y() are working to get the position.
But I have no chance to get the state of the buttons.
For that I need InitMouse(), ExamineMouse() and MouseButton()
Unfortunately if I use InitMouse(), the mouse cursor is off when the first call of ExamineMouse()
happens.
So a WindowMouseButton() procedure would be very nice.
Bernd
I'm just programming something where I need a small stripe of a screen window insode a normal window.
Inside this stripe are sprites which are working as buttons.
WindowMouseX() and Y() are working to get the position.
But I have no chance to get the state of the buttons.
For that I need InitMouse(), ExamineMouse() and MouseButton()
Unfortunately if I use InitMouse(), the mouse cursor is off when the first call of ExamineMouse()
happens.
So a WindowMouseButton() procedure would be very nice.
Bernd
Re: WindowMouseButton()
> the mouse cursor is off when the first call of ExamineMouse() happens
Why not do a single dummy call to ExamineMouse() to prime it?
Why not do a single dummy call to ExamineMouse() to prime it?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: WindowMouseButton()
Why not use the canvas? I'm an avid fan of screen(), but sometimes there's a better way.
Perhaps something like this? Then you got all the eventtypes available from the canvasgadget too.
Edit: added the selected state to code
Perhaps something like this? Then you got all the eventtypes available from the canvasgadget too.
Edit: added the selected state to code
Code: Select all
Structure my_buttons
x.i
y.i
im.i[3]
selected.i
EndStructure
Global Dim bt.my_buttons(8)
Global bw.i = 638/8
Procedure.i buttoncanvas()
Protected newnum.i, et.i
newnum = GetGadgetAttribute(0, #PB_Canvas_MouseX)
et = EventType()
Select et
Case #PB_EventType_MouseMove
StartDrawing(CanvasOutput(0))
For x = 0 To 7
If newnum > bt(x)\x And newnum < bt(x)\x+bw
If bt(x)\selected = 1
DrawImage(ImageID(bt(x)\im[2]),bt(x)\x,0)
Else
DrawImage(ImageID(bt(x)\im[1]),bt(x)\x,0)
EndIf
Else
If bt(x)\selected = 1
DrawImage(ImageID(bt(x)\im[2]),bt(x)\x,0)
Else
DrawImage(ImageID(bt(x)\im[0]),bt(x)\x,0)
EndIf
EndIf
Next x
StopDrawing()
Case #PB_EventType_LeftClick
StartDrawing(CanvasOutput(0))
For x = 0 To 7
If newnum > bt(x)\x And newnum < bt(x)\x+bw
If et = #PB_EventType_LeftClick And bt(x)\selected = 0
bt(x)\selected = 1
DrawImage(ImageID(bt(x)\im[2]),bt(x)\x,0)
Else
DrawImage(ImageID(bt(x)\im[1]),bt(x)\x,0)
EndIf
Else
DrawImage(ImageID(bt(x)\im[0]),bt(x)\x,0)
bt(x)\selected = 0
EndIf
Next x
StopDrawing()
EndSelect
EndProcedure
Procedure.i ButtonEvents()
If EventType() = #PB_EventType_LeftClick
For x = 0 To 7
If bt(x)\selected = 1
Debug "Button " + Str(x)
EndIf
Next x
EndIf
EndProcedure
Procedure.i CreateButtons()
For x = 0 To 7
With bt(x)
\im[0] = CreateImage(#PB_Any, bw, 20) ;Normal
\im[1] = CreateImage(#PB_Any, bw, 20) ;Hovered
\im[2] = CreateImage(#PB_Any, bw, 20) ;Selected---Not used in example
StartDrawing(ImageOutput(\im[0]))
Box(0, 0, bw, 20, $777777)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText((bw/2)-(TextWidth("Button X")/2), 10-(TextHeight("XXXX")/2),"Button " + Str(x), $0)
LineXY(1, 1, bw-2, 1, $AAAAAA)
LineXY(1, 1, 1, 18, $AAAAAA)
LineXY(1,18, bw-2, 18, $555555)
LineXY(bw-2, 1, bw-2, 18, $555555)
StopDrawing()
StartDrawing(ImageOutput(\im[1]))
Box(0, 0, bw, 20, $999999)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText((bw/2)-(TextWidth("Button X")/2), 10-(TextHeight("XXXX")/2),"Button " + Str(x), $0)
LineXY(1, 1, bw-1, 1, $AAAAAA)
LineXY(1, 1, 1, 18, $AAAAAA)
LineXY(1,18, bw-1, 18, $555555)
LineXY(bw-2, 1, bw-2, 18, $555555)
StopDrawing()
bt(x)\x = x*bw
StartDrawing(ImageOutput(\im[2]))
Box(0, 0, bw, 20, $CCCCCC)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText((bw/2)-(TextWidth("Button X")/2), 10-(TextHeight("XXXX")/2),"Button " + Str(x), $333333)
LineXY(1, 1, bw-2, 0, $AAAAAA)
LineXY(1, 1, 0, 18, $AAAAAA)
LineXY(1,18, bw-2, 18, $555555)
LineXY(bw-2, 1, bw-2, 18, $555555)
StopDrawing()
bt(x)\x = x*bw
EndWith
Next x
EndProcedure
CreateButtons()
OpenWindow(0, 0, 0, 640, 480, "Small buttons", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CanvasGadget(0, 2, 2,638,20)
BindGadgetEvent(0,@buttoncanvas())
buttoncanvas()
ButtonGadget(1, 40, 40, 150, 20, "Check selected button")
BindGadgetEvent(1, @ButtonEvents())
Repeat
ev = WaitWindowEvent()
Until ev = #PB_Event_CloseWindow
Last edited by DK_PETER on Tue Sep 09, 2014 5:59 pm, edited 2 times in total.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Re: WindowMouseButton()
whats about the normal window events ?
But to create his own Gadgets, better use CanvasGadget().
Code: Select all
...
Event = WaitWindowEvent()
If Event = #PB_Event_LeftClick
mx = WindowMouseX(Window)
my = WindowMouseY(Window)
If mx > Bx And mx < Bx + Bw
....
Re: WindowMouseButton()
A single call to ExamineMouse() switches off the mouse cursor.
Bernd
Bernd
Re: WindowMouseButton()
> A single call to ExamineMouse() switches off the mouse cursor
Ah... when I read "mouse cursor is off" in your original post,
I thought you meant the mouse cursor's POSITION was off.
LOL! Now I understand what you mean.
Ah... when I read "mouse cursor is off" in your original post,
I thought you meant the mouse cursor's POSITION was off.
LOL! Now I understand what you mean.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: WindowMouseButton()
...I thought that too
Certainly, owner-drawn buttons etc on a CanvasGadget is the way to go - it's much easier.

Certainly, owner-drawn buttons etc on a CanvasGadget is the way to go - it's much easier.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: WindowMouseButton()
Your request is a good one, for sure. In the meantime though, is this any help?
http://purebasic.fr/english/viewtopic.p ... 68#p187468
http://purebasic.fr/english/viewtopic.p ... 68#p187468
BERESHEIT
Re: WindowMouseButton()
@netmaestro
There's always been the option to use ReleaseMouse().
Using mouseX() and mouseY() - you could simply release the mouse from screen, when the coords
are greater or lesser than - and simply grab the mouse again when coords (using WindowMouseX() and WindowMouseY())
are within screen coordinate area.
But how would you create a mouse function, which works on screen and window at the same time?
The Screen and Window are two completely different things.
There's always been the option to use ReleaseMouse().
Using mouseX() and mouseY() - you could simply release the mouse from screen, when the coords
are greater or lesser than - and simply grab the mouse again when coords (using WindowMouseX() and WindowMouseY())
are within screen coordinate area.
But how would you create a mouse function, which works on screen and window at the same time?
The Screen and Window are two completely different things.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: WindowMouseButton()
I'd gird up my loins, call on everything I've learned over the years, do a lot of research, consult with experts in the area, then I'd sit down, focus in and let Fred do it.But how would you create a mouse function, which works on screen and window at the same time?
BERESHEIT
Re: WindowMouseButton()
You got off easy there.Not quite the answer I expected, but an answer nevertheless.netmaestro wrote:I'd gird up my loins, call on everything I've learned over the years, do a lot of research, consult with experts in the area, then I'd sit down, focus in and let Fred do it.But how would you create a mouse function, which works on screen and window at the same time?


Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.