Thread: GUI structure in C

  1. #31
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > Is it better to create wrappers for all of the base struct functions which will be used by the child struct
    Wrappers IMO. That way if anything internally changes then the user is really none-the-wiser.

  2. #32
    Registered User officedog's Avatar
    Join Date
    Oct 2008
    Posts
    77
    Thanks zacs7. Definitely makes sense.

  3. #33
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    I also noticed you're using glut, which is mostly dead. You may want to look into gflw.

    I use it, and it is VERY nice.

  4. #34
    Registered User officedog's Avatar
    Join Date
    Oct 2008
    Posts
    77
    Thanks for the link. I'll see if I can get it to load up on my system and give it a spin....

  5. #35
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    It'll probably mean you'll have to program your own fonts though :-). No more using the glut ones!

    If you still want bitmap fonts, perhaps use http://www.angelcode.com/products/bmfont/ . Of course this is all work in the opposite direction of what you're trying to get done really...

  6. #36
    Registered User officedog's Avatar
    Join Date
    Oct 2008
    Posts
    77
    officedog is resourceful and already has a wonky home-made bitmap alphabet! So assuming glfw can withstand a few officedog characters and an officedog rectangle, all should be well. However we'll investigate angelfonts, just in case. Thanks for all these links, really helpful.

    The direction is evolving as these posts go by. We've decided to go back to the drawing board, re-engineer the structs, wrap all functions and develop a programme which will bake the GUI. Shouldn't take more than a couple of days.

  7. #37
    Registered User officedog's Avatar
    Join Date
    Oct 2008
    Posts
    77
    I am trying to build a screen manager now. It will detect which object the user clicked with the mouse and work out which function to call. I've returned to C_ntua's earlier post (page 1, no.14) on this. Just wondering whether I'm getting the ideas right.

    Here's what I have so far:

    Included in the struct for each GUI object is another struct called "objectScreenData". The purpose is to serve as a set of data for use by the screen manager - to check which object has been clicked on and know where to go to call the relevant function.

    Here's the struct
    Code:
    typedef struct objectScreenData {
        ScreenBounds objectBounds;
        ScreenBounds resizeBounds;
        ScreenBounds textBounds;
        int type;
        int tag;
        char name[20];
        void * address; //stores address of struct - key issue. Intend to put a cast on it with
    		// relevant struct when function is called.
    }ObjectScreenData;
    Each time an object is drawn or redrawn, it sends a pointer to this information to the ScreenManager struct. Here's the screen manager:
    Code:
    typedef struct screenManager {
        ObjectScreenData * objects[20];
        int nObjects;
        int selectedObject;
        
        //Function pointers
        void (*init)(struct screenManager *sm);
        void (*destroy)(struct screenManager **sm);
        int (*add)(struct screenManager *sm, ObjectScreenData *obj);
        void (*checkWhichObject)(struct screenManager *sm, int x, int y);
        int (*checkWhichFunction)(struct screenManager *sm, int x, int y);
        void (*callFunction)(struct screenManager *sm, int tag);
    }ScreenManager;
    This is the add function for the screen manager:

    Code:
    int  screenManagerAdd(ScreenManager *sm, ObjectScreenData *obj) {
        if (sm->nObjects < 19) {
            if ((obj->tag) < 0) 
            {
                printf("\n\n+++ Adding %s to screen manager database", obj->name);
                sm->objects[sm->nObjects] = obj;
                sm->nObjects += 1;
                obj->tag = sm->nObjects;
                printf("\nObject added, tag = %d", obj->tag);
                return sm->nObjects;
            }
            else{
                printf("\nObject >>%s, ID = %d already registered", obj->name, obj->tag);
                return obj->tag;
            }
        }
        else{
            printf("\nObject: %s could not be added to the Screen Manager", obj->name);
            return -1;
        }
    }
    And this is the checkWhichObject function. Still work n progress - it's a bit of a building site at the moment, but just to give an idea of where it is (or isn't?) going.

    Code:
    void screenManagerCheckWhichObject(ScreenManager *sm, int x, int y) {
        for (int i = 0; i < sm->nObjects; i++) {
    	//get the objects screen boundaries
            int minX = (sm->objects[i])->objectBounds.minX;
            int minY = (sm->objects[i])->objectBounds.minY;
            
            int maxX = (sm->objects[i])->objectBounds.maxX;
            int maxY = (sm->objects[i])->objectBounds.maxY;
            
            if ( x> minX && x < maxX && y > minY && y < maxY) {
                sm->selectedObject = i;
                printf("\nObject ID = %d, name = %s", i, (sm->objects[i])->name);
                sm->checkWhichFunction(sm, x, y);
            }
        }
    }
    Comments are very welcome. The general question is - am I on the right lines, are there any glaring errors in the way I'm doing this?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem referencing structure elements by pointer
    By trillianjedi in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 05:46 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Window priority handling for a GUI - data structure
    By rmullen3 in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2003, 07:06 PM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 05:48 PM