Although I understand OOP may be a better way to go with my GUI project, I decided to stick it out in understanding how to implement this in C. The basic building blocks are:
a) A rectangle
b) A button
c) A textbox
This is an edited (to keep the post shorter) version of my struct for the rectangle:
Code:typedef struct{
float convertToPixel, convertToOrtho;
float x1, y1, x2, y2; //bottom left, top right coordinates
float centreXOrtho, centreYOrtho, length, height;
//Label
int labelLengthChars;
float labelLengthOrtho, labelHeightOrtho;
//Final data for drawing functions
float vertices[4][2];
float colour[3];
char label[MAX_LABEL_LENGTH];
float rasterStartPos[2];
}Rectangle;
//.... a series of functions to initialise struct, setters, getters etc
My question is about which route would other people go in creating say a textbox from here. Would it be better to:
a) Copy the Rectangle struct into another header file, relabel the typedef "textbox", copy and paste existing functions (renaming and editing the functions), and add additional functions as necessary
b) Leave the struct as it is (perhaps adding additional contents to it though), but have a separate set of functions which initialise and use the struct, e.g.:Code:typedef struct {
//....pretty much same or identical contents to Rectangle
}Textbox;
void textboxNew(Textbox *r, float coords[4]);
void textboxGetText(Textbox *r, char *buffer);
Thanks for any thoughts on thisCode:typedef struct {
//....
}Rectangle;
void buttonNew(Rectangle *r, float coords[4], char *label); // initialise button
void textboxNew(Rectangle *r, float coords[4]); //initialise textbox
void textboxGetText(Rectangle *r, char * buffer);