![]() |
|
#1
|
||||
|
||||
Fluid, classes and callbacksI post this here in the hopes of finding someone who has done this in fluid and can expain show it a little better than the docs do.
After fighting with this long enough to qualify as foolish I must "Ask the Experts" in hopes of ending my pain. To start: FLTK 1.1.6 (built from cvs) and running under cygwin What I am trying to figure out is how to have access to a class's members from a callback. After reading through the docs about the callbacks and the CubeViewUI section of the fluid chapter I can't seem to get at my class members. I will give a stripped down example below. If I can do it for one I can do it for many after all. The GIM project has some rules defined to make long term growth a learning experience as well as a way to show people how to do things they didn't think they could do with fluid. Having a fluid project file will make it easier for someone with only a small amount of hand coding from scratch in FLTK experience (like myself) have the abiltiy to customize an application to their own needs. I can define the class and it's members by building everything in fluid I am just hung up on the callbacks. Perhaps someone can give me a basis to work from. Code:
Now, I am just learning to use this wondrous toolkit and would like to know (in a basic form) what I need to do to get over this hump. I have worked through the related fluid posts in the newsgroups (Greg was describing how to inherit values by using a dummy group in a window in main() that calls the class constructor and the info seems closely related. If what I am looking for is not clear (I know it makes my head spin) ask for specific info. As I said, this is a learning experience for me. Quite frankly I am astounded at how little you actually need to learn (especially with fluid picking up the slack) to get at the power of FLTK. Makes it fun to learn as long as you have the tenacity of a pit bull. Mark A nice and simple example in a fluid project is really what I am after. The callbacks need to read and/or modify the base members and if I can't get closer I will have two choices. 1. Go back to my non-class version and straighten out the spagetti. 2. Admit defeat and create a non-fluid generated version of Contacts. 3. (hmm. this is more than 2) Take up knitting and change my name to Mary. __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#2
|
||||
|
||||
|
I got a response from the newsgroups by the big gun and yet I seem no closer to my goal.
Quote:
Maybe it will help someone help me get past this problem. I sure hope so. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#3
|
|||
|
|||
|
Quote:
OK, well, the problem is that you cannot call a 'normal' method of a class, because C++ was missing the syntax to do that (you can't store the pointer to a member function in C++ ; err, well, you can, but the syntax to actually call that address is so horrendously horrible, that we simply don't do it). In FLTK, you must either call a 'regular' C function that is not a member of a class, or you must mark a member function as 'static'. This has the drawback though, that stati functions have no access to the 'this' variable. FLTK helps you here by providing the 'user_data' field, which you can use to store 'this'. FLUID will try to write those static functions for you if you only put a function name into the callback field. If you add braces 'my_func(a, b)', it'll generate direct call code. So this is how that can look: CPP / C++ / C Code:
Last edited by cable_guy_67 : 02-Jul-2006 at 07:04.
Reason: Added [c++] ... [/c++] code tag
|
|
#4
|
||||
|
||||
|
Quote:
I followed up to this point in the docs (there used to be a warning about this in the docs) Quote:
Quote:
Quote:
I will give this a go and see if I can't get this working. I left the last bit in with your code to show you our markup tags in action. [c] to [/c] or [c++] to [/c++] or a plain old [code] to [/code] This sheds some light on some things that have been causing me great trouble. Thanks again. I more than likely should not even be attempting this at such an early stage in my learning but if learning is not like hanging out with Louis and Clark what fun is it. :-P Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#5
|
||||
|
||||
|
Ok, thanks to the help of the community I have managed to get this silly little problem to work (at least I think so, moving back with GIMcontacts will tell the tale) as it has been explained to me.
Here is the FLUID project file: CPP / C++ / C Code:
I have to thank MatthiasWM and Bill Spitzak for the responses that got me moving in the right direction. Hopefully this will help someone else out. I think I can explain what is going on now in case anyone has any (basic) questions. At the very least this should keep me from having to scrap my Class version and go back to my mess. Back to GIMcontacts. I have been working on it quite a bit and this should be the last hump. It surely isn't because the backend isn't ready, gim.h seems from my testing to work quite well. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs Last edited by cable_guy_67 : 30-Jan-2005 at 20:42.
|
|
#6
|
||||
|
||||
|
By using the simple example here I have made wonderful progress with GIMcontacts. I do have one issue with this method though. Since the callbacks are set in main() I have to make any of the callback functions and their related widget public. If anyone has a suggestion on how to get around this I would appreciate hearing it. I'm sure it must be a simple "put this here in fluid" kind of answer, I just haven't found it yet.
Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#7
|
||||
|
||||
|
Quote:
The FAQ finally sunk in. The fluid way is to put the code in the constructor. My class constructor is where the window lives so when I create the GUI elements I set the defaults (some groups hidden) and then call CPP / C++ / C Code:
I also call the main window ->show from here as well. Now all the widgets can remain private and main() is reduced to : CPP / C++ / C Code:
Note: fluid will add the return(Fl::run()); at the end of your main if it is built in fluid so the code will have the above routine past the return(0). It won't hurt anything but your sense of aesthetics. Code:
Thanks to dsmith for that last little sanity saver. Now the includes in the project files are #include <filename.h> variety instead of the #include "filename.h" type. __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#8
|
|||
|
|||
|
Quote:
<grin> I like to either make a class for every dialog in fluid. Then I create a method 'create_ui()' which, um, creates the UI. I then try to keep everything inside this class private and provide some access functions for the main app. Another way is to create a 'partner class' to an existing class that reflects the settings of the class in a UI, something like this: CPP / C++ / C Code:
The same thing works even for the main application window. Just seperate everything into coveniently small parts. |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The