October 26, 2020, 01:42:50 AM

Author Topic: how do i read mousex and y when operating max gui..  (Read 2260 times)

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
how do i read mousex and y when operating max gui..
« on: January 24, 2018, 05:55:55 AM »
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..
Go with the Flow

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: how do i read mousex and y when operating max gui..
« Reply #1 on: January 24, 2018, 05:58:43 AM »
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
Go with the Flow

Offline col

  • Sr. Member
  • ****
  • Posts: 464
Re: how do i read mousex and y when operating max gui..
« Reply #2 on: January 24, 2018, 09:24:59 AM »
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.
To be is to be perceived.

https://github.com/davecamp

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: how do i read mousex and y when operating max gui..
« Reply #3 on: January 24, 2018, 07:21:11 PM »
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..
Go with the Flow

Offline col

  • Sr. Member
  • ****
  • Posts: 464
Re: how do i read mousex and y when operating max gui..
« Reply #4 on: January 24, 2018, 08:38:35 PM »
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:-
Quote
I 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.
To be is to be perceived.

https://github.com/davecamp

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: how do i read mousex and y when operating max gui..
« Reply #5 on: January 29, 2018, 09:37:21 PM »
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..
Go with the Flow

Offline Derron

  • Hero Member
  • *****
  • Posts: 3234
Re: how do i read mousex and y when operating max gui..
« Reply #6 on: January 29, 2018, 10:13:50 PM »
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

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: how do i read mousex and y when operating max gui..
« Reply #7 on: January 29, 2018, 11:08:12 PM »
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



Go with the Flow

Offline Henri

  • Sr. Member
  • ****
  • Posts: 263
Re: how do i read mousex and y when operating max gui..
« Reply #8 on: February 11, 2018, 12:17:09 PM »
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
  1.  
  2. Import MaxGui.Drivers
  3.  
  4. Strict
  5.  
  6. Local window:TGadget = CreateWindow("My Window",50, 50, 440, 440, Null, WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS|WINDOW_CENTER)
  7. Local panel:Tgadget = CreatePanel(0, 0, ClientWidth(window), ClientHeight(window), window )
  8.         SetGadgetColor(panel, 200, 200, 200)
  9. Local treeview:TGadget = CreateTreeView(5, 5, ClientWidth(window)/2-10, ClientHeight(window)-10, panel)
  10.  
  11. SetGadgetLayout treeview, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED
  12. SetGadgetSensitivity treeview, SENSITIZE_MOUSE
  13. SetGadgetSensitivity panel, SENSITIZE_MOUSE
  14.  
  15. Local root:TGadget=TreeViewRoot(treeview)
  16.  
  17. Local help:TGadget=AddTreeViewNode("Help",root)
  18. AddTreeViewNode "Topic 1",help
  19. AddTreeViewNode "Topic 2",help
  20. AddTreeViewNode "Topic 3",help
  21.  
  22. Local projects:TGadget=AddTreeViewNode("Projects",root)
  23. AddTreeViewNode("Sub Project",AddTreeViewNode("Project 1",projects))
  24. AddTreeViewNode("Project 2",projects)
  25. AddTreeViewNode("Project 3",projects)
  26.  
  27. While WaitEvent()
  28.         Print CurrentEvent.ToString()
  29.         Select EventID()
  30.        
  31.                 Case EVENT_MOUSEMOVE
  32.                         Select EventSource()
  33.                                 Case treeview
  34.                                         Local tmpNode:TGadget = GetNodeUnderMouse( treeview, EventX(), EventY())
  35.                                         If tmpNode Then SetGadgetText window, GadgetText(tmpNode)
  36.                         EndSelect
  37.                        
  38.                 Case EVENT_MOUSELEAVE
  39.                         Select EventSource()
  40.                                 Case panel
  41.                                         SetGadgetColor(panel, Rand(100, 255), Rand(100, 255), Rand(100, 255) )
  42.                         EndSelect
  43.        
  44.                 Case EVENT_MOUSEENTER
  45.                         Select EventSource()
  46.                                 Case panel
  47.                                         SetGadgetColor(panel, Rand(100, 255), Rand(100, 255), Rand(100, 255) )
  48.                         EndSelect
  49.                        
  50.                 Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
  51.                         End
  52.         End Select
  53. Wend
  54.  
  55. 'Windows way of getting treeviewnode under mouse pointer. See apptitle change
  56. Function GetNodeUnderMouse:TGadget( treeview:TGadget, pX, pY ) "win32"
  57.        
  58.         ?Win32
  59.         Local hwnd:Int = QueryGadget(treeview, QUERY_HWND)
  60.         Local item:Int[10], hittestinfo:Int[] = [pX, pY, 0, 0]
  61.         If SendMessageW( hwnd, TVM_HITTEST, 0, Int Byte Ptr hittestinfo )
  62.                 item[0] = TVIF_PARAM
  63.                 item[1] = hittestinfo[3]
  64.                 SendMessageW hwnd, TVM_GETITEMW, 0, Int Byte Ptr item
  65.                 Return TWindowsTreeNode(HandleToObject(item[9]))
  66.         EndIf
  67.         ?
  68.  
  69. EndFunction
  70.  
  71.  
  72. -Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: how do i read mousex and y when operating max gui..
« Reply #9 on: February 11, 2018, 03:38:47 PM »
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
Go with the Flow

Offline Henri

  • Sr. Member
  • ****
  • Posts: 263
Re: how do i read mousex and y when operating max gui..
« Reply #10 on: February 11, 2018, 04:07:51 PM »
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

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: how do i read mousex and y when operating max gui..
« Reply #11 on: February 11, 2018, 04:20:13 PM »
Do you mean any gadget.. not only the main window?

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

 ;D
Go with the Flow

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal