how do i read mousex and y when operating max gui..

Started by Hardcoal, January 24, 2018, 05:55:55

Previous topic - Next topic

Hardcoal

iv being trying for hours to get info from mousex and mousey
under maxgui.. but nothing..
and i find nothing written anywhere about it..
how can i get that info?

thanks..
Code

Hardcoal

#1
i think i just found this little bastard .. its called EnablePolledInput() .. erm

but it reads only from the canvas area.. what if i want to read from the whole window area?

Im new to MaxGui.. so here is another question..
How can i tell if my mouse is above a gadget or outside of it?

cheers
Code

col

Hiya,

I think

SetGadgetSensitivity( gadget, SENSITIZE_MOUSE )

may be what you need?

If you check out the docs for the command you can use specific flags to get just the 'mouse enter', 'mouse leave' and 'mouse move' events. Each one also gives you the coordinates of the mouse relative to the gadget itself - for a screen position you would iterate up the hierarchy of 'parents' doing the math to calculate where the mouse actually is by using the offset plus the gadgets position.
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Hardcoal

#3
everything seems more complicated with maxgui..
I'm doing my own commands to simplify it..
But i'll get over it

I need to know when I click my mouse outside of a Gadget..
Code

col

More complicated compared to?

To be honest I used to feel the same way, but the OS is event driven from the core and there's no use trying to fight it if you want to use what it offers. Its easier in the long run to learn how it works and integrate with it, if you want to use it.

EDIT:-
QuoteI need to know when I click my mouse outside of a Gadget
After clicking the gadget once?
If so, then I would have a variable that is 'last gadget clicked', any further clicks do a comparison to the gadget that has the new click, if it's not the same gadget then the user has clicked outside of the one of interest.
If not then I don't understand what you mean and some more information would be needed.
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Hardcoal

more complicated compared to any other GUI Ive tried..
like Albalynx and others..

i always find my self making additional commands to a gui to make it clearer
its a shame someone needs to waste lots of time reading simple stuff like mouse coords and mouse clicks..

Its dumb.. but i have to face it ..
and its hard to fine solutions this days besides asking..
Code

Derron

#6
Alphalynx = ingame gui
MaxGUI = OS gui


As col described: the OS is event driven. It informs the application about things happening ("onresize", "onclose" ..). Why? If every app constantly checks "mousehit? mousedown? keydown?" then it would take a lot of cpu cycles for "nothing". So the OS is watching for many things. Applications can announce their interest (register for events). If an interesting thing happens, the apps which announced get the information they need (or better: they can "extract" it from a passed event - or skip it if they are not interested now).

BlitzMax (and other game-languages) fetches many of these events and prepares stuff for you. They "hide" it for convenience.
MaxGUI is also event driven: not all widgets need to know if somewhere a mouse button was pressed/hit. They by default should always only care for itself + children + parent. widget changes size? informs children, informs parent - so all of them could eg. resize too, or paint the content again.

When drawing your normal BlitzMax-stuff together with MaxGUI-stuff then you are drawing on a kind of "canvas" - this canvas allows easy retrieval of mouse positions _within_ this canvas (sensitivity was already proposed). Of course you could use "MouseX()" there as you want - because BlitzMax already fetches that for you.

When using Albalynx instead of MaxGUI the "canvas" is the whole application canvas.


If above makes any sense at all, ok (phew ;p). If not: Excuse my fud and read about event driven programming - and remember that "ingame gui" and "OS gui" are different beasts.


bye
Ron

Hardcoal

Thanks for the description Derron..

I actually feel like giving up on a project due to this nonsense..
I understand what you Say..
But it still doesnt change the Facts.. it became horribly hard to do anything Useful without breaking my mind
on simple stuff..

For Example:

* MouseOverGadget..
* Getting General Coords of The Mouse..
* Choosing a TreeItem
* Getting GadgetParent
* Select TreeItem by Mouse RightClick..

Any many other annoying things..

wasting hours on the GUI instead of dealing with my actually project content is frustrating.

Ill see If ill continue using It..  (I may overcome to obstacles.. eventually)
I already miss ALbaLynx.. and Feel sorry I even tried using MaxGui. What a waste



Code

Henri

Hi,

way to go is to create a base panel where you attach all your other gadgets. Panel emits mouse-events for you to read.


Example:
Code (blitzmax) Select


Import MaxGui.Drivers

Strict

Local window:TGadget = CreateWindow("My Window",50, 50, 440, 440, Null, WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS|WINDOW_CENTER)
Local panel:Tgadget = CreatePanel(0, 0, ClientWidth(window), ClientHeight(window), window )
SetGadgetColor(panel, 200, 200, 200)
Local treeview:TGadget = CreateTreeView(5, 5, ClientWidth(window)/2-10, ClientHeight(window)-10, panel)

SetGadgetLayout treeview, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED
SetGadgetSensitivity treeview, SENSITIZE_MOUSE
SetGadgetSensitivity panel, SENSITIZE_MOUSE

Local root:TGadget=TreeViewRoot(treeview)

Local help:TGadget=AddTreeViewNode("Help",root)
AddTreeViewNode "Topic 1",help
AddTreeViewNode "Topic 2",help
AddTreeViewNode "Topic 3",help

Local projects:TGadget=AddTreeViewNode("Projects",root)
AddTreeViewNode("Sub Project",AddTreeViewNode("Project 1",projects))
AddTreeViewNode("Project 2",projects)
AddTreeViewNode("Project 3",projects)

While WaitEvent()
Print CurrentEvent.ToString()
Select EventID()

Case EVENT_MOUSEMOVE
Select EventSource()
Case treeview
Local tmpNode:TGadget = GetNodeUnderMouse( treeview, EventX(), EventY())
If tmpNode Then SetGadgetText window, GadgetText(tmpNode)
EndSelect

Case EVENT_MOUSELEAVE
Select EventSource()
Case panel
SetGadgetColor(panel, Rand(100, 255), Rand(100, 255), Rand(100, 255) )
EndSelect

Case EVENT_MOUSEENTER
Select EventSource()
Case panel
SetGadgetColor(panel, Rand(100, 255), Rand(100, 255), Rand(100, 255) )
EndSelect

Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
End
End Select
Wend

'Windows way of getting treeviewnode under mouse pointer. See apptitle change
Function GetNodeUnderMouse:TGadget( treeview:TGadget, pX, pY ) "win32"

?Win32
Local hwnd:Int = QueryGadget(treeview, QUERY_HWND)
Local item:Int[10], hittestinfo:Int[] = [pX, pY, 0, 0]
If SendMessageW( hwnd, TVM_HITTEST, 0, Int Byte Ptr hittestinfo )
item[0] = TVIF_PARAM
item[1] = hittestinfo[3]
SendMessageW hwnd, TVM_GETITEMW, 0, Int Byte Ptr item
Return TWindowsTreeNode(HandleToObject(item[9]))
EndIf
?

EndFunction


-Henri
- Got 01100011 problems, but the bit ain't 00000001

Hardcoal

#9
Thanks henri..
what i really wanted is to know is whether i click on a gadget or outside of it..
this is good when you want a window to be closed when you press outside of it..
Instead of pressing the [X] button each time to close the window
That's why I wanted to coords of the mouse X and Y
Code

Henri

Well, why didn't you say that in the beginning :-)

When you click outside your window, the window emits EVENT_APPSUSPEND event. You can catch this and do things like close the window etc.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Hardcoal

Do you mean any gadget.. not only the main window?

Also i needed mouse coords in general.. so this was not in vain

;D
Code