Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Getting Mouse position in GUI
No permission to create posts
December 16, 2015
9:31 am
Avatar
Frodson
Member
Members
Forum Posts: 38
Member Since:
September 7, 2015
sp_UserOfflineSmall Offline

Hi,
I'm looking for a way to get the mouse position in the GUI. I came across this function in the VSTGUI documentation: getCurrentMouseLocation ( CPoint & where)
for the class CFrame. I need to call this function on the main view, ( The main view is a CFrame, right?) and I don't know how to refer to the main view in my code. Do I need to cache a pointer out like with the ViewContainers?
Thanks in advance,
Fred

December 16, 2015
8:59 pm
Avatar
W Pirkle
Admin
Forum Posts: 143
Member Since:
January 28, 2017
sp_UserOfflineSmall Offline

Hi Fred

You certainly can get a pointer to the frame! Each GUI control carries a pointer to the parent frame. You can get the CFrame* from a control but only after the GUI opens. You will need to create a custom view (you could even use an invisible/transparent view controller). The CFrame* will NOT be valid until after the GUI opens. So, you could place the code inside of GUI_DID_OPEN here:

switch(info->message)
{
case GUI_DID_OPEN:

You can place the code elsewhere as well, as long as you check your view pointers to make sure they are non-NULL.

You need to convert the frame coordinates into local versions for them to make any sense.

Here, I am using a custom view COptionMenu to grab the frame and printing the coordinates to the status window (this code is inside of userInterfaceChange() for the option menu):

if(m_pOptionMenu)
{
CFrame* pFrame = m_pOptionMenu->getFrame();
if(pFrame)
{
CPoint point;
pFrame->getCurrentMouseLocation(point);
pFrame->frameToLocal(point);

char* pX = intToString(point.x);
char* pY = intToString(point.y);
char* pMessage = addStrings("X: ", pX);
sendStatusWndText(pMessage);
char* pMessage2 = addStrings("Y: ", pY);
sendStatusWndText(pMessage2);

delete[] pX;
delete[] pY;
delete[] pMessage;
delete[] pMessage2;
}
}

If you are trying to track mouse positions as the user moves the mouse, then you could place code inside of

case GUI_TIMER_PING:

Which is called every 50 mSec. If you do place code here, be careful not to do anything that requires a lot of processing, and do not use new/delete or malloc/free as this could slow down the GUI significantly.

- Will

December 18, 2015
2:36 am
Avatar
Frodson
Member
Members
Forum Posts: 38
Member Since:
September 7, 2015
sp_UserOfflineSmall Offline

Hi Will,
Cool it works this way! Smile I'm using it to move a CTextLabel around the GUI to show the value of the parameter being edited.
Anyway, thanks for the fast response!
Fred

December 18, 2015
6:01 pm
Avatar
W Pirkle
Admin
Forum Posts: 143
Member Since:
January 28, 2017
sp_UserOfflineSmall Offline

Hi Fred

I can't wait to see/hear the final product! When it is ready I'd like to do a short video about it, showing your use of the GUI Designer.

- Will

December 19, 2015
1:28 am
Avatar
Frodson
Member
Members
Forum Posts: 38
Member Since:
September 7, 2015
sp_UserOfflineSmall Offline

Hi Will,
Wow, I'd be more than honored if you did! Laugh I expect the synth to be finished in about a month.
Enjoy the holidays,
Fred

Forum Timezone: America/New_York

Most Users Ever Online: 36

Currently Online:
7 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Skyler: 47

Peter: 41

Derek: 41

clau_ste: 39

Frodson: 38

Gwen: 32

EZB: 24

lppier: 23

Msaldaña: 18

Jorge: 17

Member Stats:

Guest Posters: 1

Members: 476

Moderators: 1

Admins: 4

Forum Stats:

Groups: 11

Forums: 30

Topics: 482

Posts: 1876

Newest Members:

sam, annaharris, Marie Weaver, kev, Steven, Mr Anderson, mguy, omelc

Moderators: W Pirkle: 143

Administrators: Tom: 65, JD Young: 80, Will Pirkle: 0, W Pirkle: 143