• Advertisement
Sign in to follow this  

GUI Framework

This topic is 3662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got a design issue... it's more of a block than anything. I have created several classes that allow me to do draw things to the screen in a nice simple way. I've also made these classes compatible with the Observer pattern, but I can't think of a way to use these in unison. I'd like to learn how to translate a button being clicked to increasing volume... or exiting the program... etc. But I want it to be handled neatly, not in some giant switch case in main...
class Screen : public Drawable, public Updateable, public Uncopyable, public Observer
	Screen(const std::string& directory);
	virtual ~Screen();

	virtual void Draw(SDL_Surface* screen);
	virtual void Update(const SDL_Event& event_);
	virtual void Notify(Observable* observable, void* oe);
	virtual void Load(const std::string& directory);
	virtual void Load_Elements(const std::string& directory);
	virtual void Load_Observation(const std::string& directory);

	std::vector<Base_XImage*> elements;

class Base_XImage : public Drawable, public Updateable, public Cloneable, public Observable
	typedef enum OBSERVABLE_EVENT

		const std::string& name_,
		const std::string& file_name_,
		int position_x,
		int position_y,
		bool is_colour_key_,
		SDL_Colour colour_key_ = SDL_Wrappers::colour(0,0,0));
	Base_XImage(const Base_XImage& rhs);
	virtual ~Base_XImage();
	Base_XImage& operator=(const Base_XImage& rhs);

	const std::string& Get_Name() const;
	const std::string& Get_File_Name() const;
	const SDL_Rect& Get_Position() const;
	bool Is_Colour_Key() const;
	const SDL_Colour& Get_Colour_Key() const;
	virtual void Load();
	virtual void Draw(SDL_Surface* screen) = 0;
	virtual void Update(const SDL_Event& event_) = 0;
	virtual Base_XImage* Clone() const = 0;
	static void Check_Opening_Tag(const std::string& buffer);
	static void Check_Closing_Tag(const std::string& buffer);

	std::string name;
	std::string file_name;
	SDL_Rect position;
	bool is_colour_key;
	SDL_Colour colour_key;
	SDL_Surface* surface;

As you can see, I've only started to implement the Observer pattern. I don't know how I'm going to actually use it. This is a sample loop of a program using the Screen class:
Draw_Engine DE;
	DE.Initialise(640, 480, 24, "SDL Testing", "C:/WINDOWS/Fonts/Arial.ttf");
	Audio_Engine AE;

	Screen test_screen("Screens/Screen_Test_Screen/");

	SDL_Event event_;
	bool exit = false;

			if(event_.type == SDL_QUIT)
				exit = true;

			// Update screen elements.
			// Draw(blit) elements to screen.
			// Draw screen.


The string parameter passed to the Screen constructor is the directory where all the info for the elements are. For each class (Image, Button, Audible_Button, Draggable_Button, etc.) I create a new .txt file with all the elements of that type that I want to be drawn to the screen:
< test1 1.png 10 10 0 >
Should I just use something like wxWidgets instead of doing this all on my own? I guess you could say that I'm looking to create a GUI framework.. or use an existing one so I can get on with finishing my game. :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement