exporting c functions and variables

Member
Posts: 194
Joined: 2009.02
Post: #1
I'm writing a opengl gui and I want to write a program similar to ib or resedit which allows you to create interface elements and save them to a file for use in an application.

I'd also like the project using the gui editor, to be able to import its own functions and variables into the editor, just like with ibactions/outlets.

Any suggestions on the best way to go about this?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
yeah, don't bother, it's not worth the pain Wink
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #3
To expand on OSC's response, that would be a very large project that would probably take years to complete on your own. Unless this is something you wanted to use for years or wanted to create to distribute or sell, the time saved will be negligible compared to the time to create the system. In fact, unless you are a top-notch programmer with years of experience, you will likely run into too many problems to complete the project due to the fact that without a solid design, a project that large will collapse in on itself. That's assuming you have the tenacity to stick with it for that long in the first place.

Of course, you could do something like an XML layout that you write by hand fairly easily. You could then look up objects by name and hook up the connections manually in code. That kind of thing wouldn't take too long to complete, and would allow you to make small changes to the UI without having to recompile and save you a lot of setup code.
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #4
Thanks for the responses. This is only a small short-term project so I'd rather not spend years of my like on it.

Admittedly I have no idea how ib works in linking data and functions to objects, but what you guys seem to be saying is it's an incredibly complex(or at least time-consuming) process. I'd still be curious to know how it goes about this and also where the difficulty would lie in trying to implement such a thing.

Thanks akb for the xml suggestion I'm going to look into it.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
IB parses the header file looking for IBOutlets, and Cocoa uses the reflection facilities of the ObjC runtime to set the ivars when you load the nib.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #6
IB gets a lot of help from Objective C since it has dynamic dispatch. You can look up a message by name to get a selector, which can then be called on any object. It will do a runtime check to see if that message exists, then call it if it does.

In other languages, such as C and C++, there is no such support. QT has this kind of functionality in C++, but in order to obtain it you have to run the moc (Meta Object Compiler) utility on your classes that derive from QObject. You must declare your signals (to send messages) and slots (to receive messages), and the moc utility will parse the file to build tables that must be compiled into your program that allow those functions to be called by name. This isn't a simple problem to get right, because you must have a simple method to declare your signals and slots, figure out how to correctly look into your table and call the correct function on the correct object, and get the arguments to the function. The fact that they require a pre-compiler also shows that the tools available in C++ aren't enough to get it working. It may be possible to speed up the process somewhat by reverse-engineering what an existing library like QT does, but you will still have to write a parser that accepts general C++ files and extracts the necessary information, and C++ isn't an incredibly parseable language.

Once you have the backend in place, the issue of the GUI comes into play. In order to be useable, it requires a very dynamic GUI. You need to be able to place and manipulate every widget type you want to support. Each element must be rendered exactly as the widget you wish to place, but it must behave completely differently. You need to be able to show and edit unique properties for each object. Unless you want to finely resize pixel by pixel to get things looking right (and redoing it if you move a single item), you will have to implement grid snapping and/or edge snapping behavior for your widgets. If you want to be complete about things, you will also need to have both the backend for and a way to edit and show layout rules for resizing windows and elements and how that will affect other elements. Then you also need to have the UI in place to drag between objects, see what signals there are from the first object and what slots are compatible on the received object, and choose a connection. You will also need a way to view, edit, and delete existing connections.

Once you get the UI implemented, you will need to have a file format specified. When you read in the file and create the objects for the layout you specified, it must traverse the layout to make the connections. It needs to look up the correct objects by name, and then look up and store the connections specified for those objects. This file format must also be useable by both your widget library and your GUI editor.
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #7
Thanks akb for the great explanation. That sounds like a nightmare to program, I'll just have to do the connections manually which really isn't that bad anyways.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  virtual functions not working supersonic 2 4,988 Mar 10, 2011 06:22 AM
Last Post: compiler
  Weird problem passing integer variables.. quarus 6 5,004 Mar 15, 2009 12:47 PM
Last Post: quarus
  Haskell Data Types and Functions wyrmmage 1 3,438 Mar 4, 2008 05:25 PM
Last Post: OneSadCookie
  Adding Member Variables to Classes FlamingHairball 2 3,313 Jan 12, 2008 02:43 PM
Last Post: FlamingHairball
  Getting around Python's referencing of variables Nevada 2 3,256 Mar 10, 2007 01:07 PM
Last Post: Nevada