Jump to content
  • Advertisement
Sign in to follow this  
Mybowlcut

GUI Framework

This topic is 3902 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
{
public:
	Screen();
	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);
protected:
	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
{
public:
	typedef enum OBSERVABLE_EVENT
	{
		LMB_CLICK,
		RMB_CLICK,
		MOUSE_OVER
	};

	Base_XImage();
	Base_XImage(
		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;
protected:
	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;
	AE.Initialise();

	Screen test_screen("Screens/Screen_Test_Screen/");

	SDL_Event event_;
	bool exit = false;

	while(!exit)
	{
		while(SDL_PollEvent(&event_))
		{
			if(event_.type == SDL_QUIT)
			{
				exit = true;
				break;
			}

			// Update screen elements.
			test_screen.Update(event_);
			// Draw(blit) elements to screen.
			test_screen.Draw(DE.Get_Screen());
			// Draw screen.
			DE.Draw_Screen();
		}
	}

	DE.Clean_Up();
	AE.Clean_Up();

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:
Quote:
< 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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!