Quote:Original post by Zahlman
0) What is a framework?
1) You don't need classes to make code modules. Classes are to define *types*. If you have a FontModule and a GraphicsModule that are both Modules... well, what is the common interface of a Module? What do you *do* with a Module? Can you instantiate several of them? Can they be serialized in any meaningful way?
A Font, for example, makes sense as a class type. You can have an instance of it, which represents a combination of a typeface, leading, kerning, point size and emphasis flags. You can associate a Font with a fragment of Text. But what is a FontModule? Is it, for example, a thing that accepts Text with a Font and renders it to the screen? Would you benefit from having more than one? Why not make rendering be something that the Font can do? That's a reasonable interface for a Font: You give it some string, and say "draw it here according to how you make text look". Reasonable, for something that represents an appearance-of-text.
0 + 1) The framework is the name I gave to the structure that just stores all the different modules. They've all got instances in the framework and due to the pointers to and from the two structures they can all use the different features of the other modules. Thus, the FontModule, which is responsible for loading, storing, and rendering text to an SDL_Surface (which is what this GUI is using for graphics) can use the GraphicsModule to blit the surface to the target render surface (which isn't necessarily the screen, hence necessitating the graphics module which deals with this among other related responsibilities).
Modules aren't just used to wrap function calls - the font module, for example, can load a certain font from a file, and generate new font files at different sizes when needed. The control module stores the controls (push button etc) used by the GUI, and manages their memory and their updates.
Now, I think you have a point in terms of whether this makes sense or not, especially in the case of the fonts. It would make sense for the individual font to be able to render text itself - the way I'm doing it, the control tells the font module that it wants to render this text, here, in this color, with this font. The font module retrieves the font of the appropriate size, and renders the text in the appropriate location. It also performs formatting if necessary, to manage rendering multiple lines of text. Most of this seems like something the font could do. In fact, this seems, upon reflection, to be procedural programming wrapped up in an ugly pseudo-OOP structure. I'm starting to sound like you, Zahlman!
So how does this sound instead: all fonts, graphics used by the GUI (like a close button) and other such flotsam are stored in one structure, which controls have access to. These graphics are responsible for rendering themselves. Controls have access to this encompassing structure and can retrieve the objects they need from it. The flow might look a bit like this:
A text field needs to render its caption, so it accesses its stored instance of what we'll call the "Graphics System". It tells it to render some text, with certain attributes. The Graphics System finds the appropriate font, and tells the font to render the requested text to a certain position. The font takes the text, formats it appropriately, and blits it to the appropriate position.
The original looked like this, and diverges about halfway through from the above:
A text field needs to render its caption, so it accesses its stored framework object, and retrieves the font module. It then tells the font module to render some text, with certain attributes. Then, the font module retrieves the requested font object of the appropriate size, uses the data stored there to render the text, and then returns the text texture to the control. The control then gets access to the graphics module from the framework, and tells it to render the texture in the appropriate spot.
Well, I think I have some reworking to do, but thanks for the intense questioning, Zahlman - it made me rethink the design, and I think that this way makes a lot more sense.