|
Radio.. Yes same ol' problem. |
julian_boolean
Member #8,201
January 2007
|
I'm STILL trying to finish this one function for a radio button class I've been working on for the past 4 months called is_selected() but since I'm an idiot, it's slightly difficult for me. Basically I want the function to do this: 1) Check to see if the object that's stored in the vector is in fact of the radio button class by checking it's type. (type = radio) All my GUI objects are stored in the same vector. 2) Check to see what the group ID is. 3) Check to see if your mouse is hovered over the object. The function for this is already done (is_hovered()) 4) Check to see if you clicked on the object. If so, that object will become selected and all other objects within that group will become unselected. This will also return true. If nothing is clicked, then return false. So outside the class it would be used something like this: if(myRadioButtonInstance->is_selected()) { // do some stuff }
|
ixilom
Member #7,167
April 2006
|
What exactly is the problem? ___________________________________________ |
julian_boolean
Member #8,201
January 2007
|
That I have no clue how to make the function.. Suppose I could've mentioned that. |
ixilom
Member #7,167
April 2006
|
Not really sure if I follow, but I'll try to write some sort of simplified code of what I think you're asking for
I'm sure that could be optimized in like 10 ways, but I'm too lazy [Edit] ___________________________________________ |
julian_boolean
Member #8,201
January 2007
|
Thanks going to take a closer look at that. I made another post about this before, well similar to it and this was one of the examples given:
The problem was I couldn't seem to alter it the way I wanted.. Like where would I stick in that is_hovered function, or to check to see if the object was clicked on? The whole int selection part sorta confused me too. |
ixilom
Member #7,167
April 2006
|
As I see it, that function needs to be called when you have found the RadioButton that has been clicked (and hovering above it). so, somewhere in your logic you would do something like unsigned int RadioIndex = 0; while(RadioIndex < radios.size()) { if(radios.at(RadioIndex)->is_hovered() && bMouse & 1) { changeSelection(RadioIndex); break; } RadioIndex++; }
___________________________________________ |
julian_boolean
Member #8,201
January 2007
|
There's no way to combine all that together in one function that will return a true once an object within the group is selected/clicked? |
ixilom
Member #7,167
April 2006
|
Not really sure what you mean, but here goes
___________________________________________ |
julian_boolean
Member #8,201
January 2007
|
That looks promising! I still don't know what getGroup() was suppose to be, though. |
ixilom
Member #7,167
April 2006
|
I'm guessing it is a "getter function", which basically just return an int that identifies that group (GroupID) ___________________________________________ |
julian_boolean
Member #8,201
January 2007
|
Hmm okay then. Thank you again! |
bamccaig
Member #7,536
July 2006
|
I haven't done any GUI programming yet so I'll just spit my opinion, whatever it's worth. It sounds like the is_selected() method is supposed to do too much work. There should be events for mouse clicks or activation/deactivation, and there should be numerous methods for many of the things you want done with this one function. A GUI doesn't work well as a single thread. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
ImLeftFooted
Member #3,935
October 2003
|
Quote: A GUI doesn't work well as a single thread. Funny, I would have said the opposite...:-X |
julian_boolean
Member #8,201
January 2007
|
Quote: It sounds like the is_selected() method is supposed to do too much work. I've been looking this over again and I think your probably right. I might just put the for statement in a seperate function called updater() or something, which should look something like this: void radioButton::updater() { for (curRadio = radios.begin(); curRadio != radios.end(); curRadio++) { if(this->is_hovered && mouse_b &1) { this->selected = true; group->selected = false; // everything that has the same group_id is made false } } } I just don't understand the whole, tracking-the-group-and-switching-its-bool-to-false, part. |
|