-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add state for active objects to GUI #201
base: master
Are you sure you want to change the base?
Conversation
Fixes #200 about sliders that only work when the mouse is over them. This commit adds two things; state variables (`*childpath`) with function that modifies it, and modifications to relevant GUI object (e.g. button, slider) functions so that they use that function to register as a unique object and find out whether they are active. The GUI code now keeps track of the "path" to each object. By "path" I mean e.g. go to the 3rd top-level child and then to it's 2nd child. This is similar to what it looks like they do in Red Eclipse 2. This is not a perfect solution because it's possible that these paths change when objects are added or removed but it is much better than just giving each object a simple number as ID because when something is changed inside one list it doesn't change the path to an object that is not a child of that list. The modifications to the GUI objects are usually done so that the mouse-up action only happens if the object is the active object (the mouse was pressed down on that object).
@@ -95,6 +95,44 @@ struct gui : guient | |||
static int curdepth, curlist, xsize, ysize, curx, cury, fontdepth, mergelist, mergedepth; | |||
static bool hitfx, skinfx, cursorfx; | |||
|
|||
// Example: {3, 2} means that the current object (button/slider/whatever) is the 2nd child of the 3rd top-level child. | |||
// The exact numbers don't matter as long as they are unique for each object. | |||
static vector<int> curchildpath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use std::vector
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because vector is used in other places. It could be confusing to mix the two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We wanna switch to using STL datatypes and functions instead of the custom implementation, IIRC the custom vector has severe memory problems, but also it's way easier to use the STL for everybody because everybody usually knows how it behaves, if you look at PRs that have been merged so far, they all use std::vector
instead of vector
unless it has a serious advantage to use vector
} | ||
|
||
int poplist() | ||
{ | ||
if(curchildpath.size()) curchildpath.pop_back(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please write if (int(curchildpath.size()) != 0)
instead of if (curchildpath.size())
functionality wise it looks pretty good so far |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works. But codestyle could be improved
Fixes #200 about sliders that only work when the mouse is over them.
This commit adds two things; state variables (
*childpath
) withfunction that modifies it, and modifications to relevant GUI object
(e.g. button, slider) functions so that they use that function to
register as a unique object and find out whether they are active.
The GUI code now keeps track of the "path" to each object. By "path" I
mean e.g. go to the 3rd top-level child and then to it's 2nd child.
This is similar to what it looks like they do in Red Eclipse 2. This is
not a perfect solution because it's possible that these paths change
when objects are added or removed but it is much better than just giving
each object a simple number as ID because when something is changed
inside one list it doesn't change the path to an object that is not a
child of that list.
The modifications to the GUI objects are usually done so that the
mouse-up action only happens if the object is the active object (the
mouse was pressed down on that object).