⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_gui.h

📁 基于SDL实现的GUI
💻 H
📖 第 1 页 / 共 2 页
字号:
#include "SDL.h"#include "SDL_image.h"#include "SDL_ttf.h"#ifndef SDL_GUI_H#define SDL_GUI_H#ifdef WIN32# ifdef BUILDING_SDLGUI_DLL#  define DLLIMPORT __declspec(dllexport)# else#  define DLLIMPORT /* __declspec (dllimport) */# endif#else# define DLLIMPORT#endif#ifdef __cplusplusclass DLLIMPORT GUI_Exception{	protected:		char *message;	public:		GUI_Exception(const char *fmt, ...);		GUI_Exception(const GUI_Exception &err);		virtual ~GUI_Exception(void);		const char *GetMessage(void);};class DLLIMPORT GUI_Object{	private:		int refcount;		char *name;	public:		GUI_Object(const char *aname);		virtual ~GUI_Object(void);				void SetName(const char *s);		const char *GetName(void);		int CheckName(const char *aname);				void IncRef(void);		int DecRef(void);};class DLLIMPORT GUI_Callback : public GUI_Object{	protected:	public:		GUI_Callback(const char *aname);		~GUI_Callback(void);				virtual void Call(GUI_Object *object)=0;};template <class T> class DLLIMPORT GUI_EventHandler : public GUI_Callback{	typedef void handler(GUI_Object *sender);	typedef handler (T::*method);	protected:		method f;		T *obj;	public:		GUI_EventHandler<T>(T *t, method m) : GUI_Callback("event")		{			// FIXME keeps a borrowed reference			obj = t;			f = m;		}		virtual void Call(GUI_Object *sender)		{			(obj->*f)(sender);		}};class DLLIMPORT GUI_Surface : public GUI_Object{	protected:		SDL_Surface *surface;	public:		GUI_Surface(const char *aname, SDL_Surface *image);		GUI_Surface(const char *aname, int f, int w, int h, int d, int rm, int gm, int bm, int am);		GUI_Surface(const char *fn);		virtual ~GUI_Surface(void);		void DisplayFormat(void);		void SetAlpha(Uint32 flag, Uint8 alpha);		void SetColorKey(Uint32 c);		void Blit(SDL_Rect *src_r, GUI_Surface *dst, SDL_Rect *dst_r);		void UpdateRects(int n, SDL_Rect *rects);		void UpdateRect(int x, int y, int w, int h);		void Fill(SDL_Rect *r, Uint32 c);		int GetWidth(void);		int GetHeight(void);		Uint32 MapRGB(int r, int g, int b);		int IsDoubleBuffered(void);		int IsHardware(void);		void Flip(void);		SDL_Surface *GetSurface(void);		void SaveBMP(const char *filename);};class DLLIMPORT GUI_Font : public GUI_Object{	public:		GUI_Font(const char *aname);		virtual ~GUI_Font(void);		// draw text onto a surface		virtual void DrawText(GUI_Surface *surface, const char *s, int x, int y);		// create a new surface with text on it using the fastest method		virtual GUI_Surface *RenderFast(const char *s, SDL_Color fg);		// create a new surface with text on it using the best quality		virtual GUI_Surface *RenderQuality(const char *s, SDL_Color fg);				// return the size of the text when using this font		virtual SDL_Rect GetTextSize(const char *s);};class DLLIMPORT GUI_FastFont : public GUI_Font{	protected:		GUI_Surface *image;		int char_width;		int char_height;	public:		GUI_FastFont(const char *fn);		virtual ~GUI_FastFont(void);		virtual void DrawText(GUI_Surface *surface, const char *s, int x, int y);		virtual GUI_Surface *RenderFast(const char *s, SDL_Color fg);		virtual GUI_Surface *RenderQuality(const char *s, SDL_Color fg);		virtual SDL_Rect GetTextSize(const char *s);		GUI_Surface *GetFontImage(void);};class DLLIMPORT GUI_TrueTypeFont : public GUI_Font{	protected:		TTF_Font *ttf;	public:		GUI_TrueTypeFont(const char *fn, int size);		virtual ~GUI_TrueTypeFont(void);		virtual GUI_Surface *RenderFast(const char *s, SDL_Color fg);		virtual GUI_Surface *RenderQuality(const char *s, SDL_Color fg);		virtual SDL_Rect GetTextSize(const char *s);};class DLLIMPORT GUI_Container;class DLLIMPORT GUI_Layout : public GUI_Object{	public:		GUI_Layout(const char *aname);		virtual ~GUI_Layout(void);				virtual void Layout(GUI_Container *container);};class DLLIMPORT GUI_VBoxLayout : public GUI_Layout{	public:		GUI_VBoxLayout(const char *aname);		virtual ~GUI_VBoxLayout(void);				virtual void Layout(GUI_Container *container);};class DLLIMPORT GUI_Widget;class DLLIMPORT GUI_Drawable : public GUI_Object{	protected:		// FIXME make these private		int flags;		int flag_delta;		SDL_Rect area;		GUI_Callback *status_callback;		void Keep(GUI_Widget **target, GUI_Widget *source);		SDL_Rect Adjust(const SDL_Rect *area);	public:		GUI_Drawable(const char *aname, int x, int y, int w, int h);		virtual ~GUI_Drawable(void);				void DoUpdate(int force);		virtual void Update(int force);		virtual void Draw(GUI_Surface *image, const SDL_Rect *sr, const SDL_Rect *dr);		virtual void Erase(const SDL_Rect *dr);		virtual void Fill(const SDL_Rect *dr, SDL_Color c);		virtual int Event(const SDL_Event *event, int xoffset, int yoffset);		virtual void Clicked(int x, int y);		virtual void RemoveWidget(GUI_Widget *widget);		virtual void Notify(int mask);		int GetWidth(void);		int GetHeight(void);		void TileImage(GUI_Surface *surface, const SDL_Rect *area, int x_offset, int y_offset);		void MarkChanged(void);		void WriteFlags(int andmask, int ormask);		void SetFlags(int mask);		void ClearFlags(int mask);		SDL_Rect GetArea(void);		void SetPosition(int x, int y);		void SetStatusCallback(GUI_Callback *callback);		int GetFlagDelta(void);		int GetFlags(void);};class DLLIMPORT GUI_Widget : public GUI_Drawable{	protected:		GUI_Drawable *parent;	public:		GUI_Widget(const char *name, int x, int y, int w, int h);		virtual ~GUI_Widget(void);				void SetAlign(int align);		void SetTransparent(int trans);		void SetEnabled(int flag);		void SetState(int state);		int GetState(void);		virtual void Draw(GUI_Surface *image, const SDL_Rect *sr, const SDL_Rect *dr);		virtual void Erase(const SDL_Rect *dr);		virtual void Fill(const SDL_Rect *dr, SDL_Color c);		void SetParent(GUI_Drawable *aparent);		GUI_Drawable *GetParent(void);};class DLLIMPORT GUI_TextEntry : public GUI_Widget{	protected:		GUI_Font *font;		SDL_Color textcolor;		GUI_Surface *normal_image;		GUI_Surface *highlight_image;		GUI_Surface *focus_image;		GUI_Callback *focus_callback;		GUI_Callback *unfocus_callback;		int align;		size_t buffer_size;		size_t buffer_index;		char *buffer;	public:		GUI_TextEntry(const char *name, int x, int y, int w, int h, GUI_Font *font, int size);		~GUI_TextEntry(void);		void SetFont(GUI_Font *afont);		void SetTextColor(int r, int g, int b);		void SetText(const char *text);		const char *GetText(void);		void SetNormalImage(GUI_Surface *surface);		void SetHighlightImage(GUI_Surface *surface);		void SetFocusImage(GUI_Surface *surface);		void SetFocusCallback(GUI_Callback *callback);		void SetUnfocusCallback(GUI_Callback *callback);		virtual void Update(int force);		virtual void Clicked(int x, int y);		virtual int Event(const SDL_Event *event, int xoffset, int yoffset);};class DLLIMPORT GUI_Label : public GUI_Widget{	protected:		GUI_Surface *text;		GUI_Font *font;		SDL_Color textcolor;	public:		GUI_Label(const char *aname, int x, int y, int w, int h, GUI_Font *afont, const char *s);		virtual ~GUI_Label(void);		void SetFont(GUI_Font *font);		void SetTextColor(int r, int g, int b);		void SetText(const char *s);		virtual void Update(int force);};class DLLIMPORT GUI_Picture : public GUI_Widget{	protected:		GUI_Surface *image;		GUI_Widget *caption;	public:		GUI_Picture(const char *aname, int x, int y, int w, int h, GUI_Surface *an_image);		virtual ~GUI_Picture(void);		void SetImage(GUI_Surface *an_image);		void SetCaption(GUI_Widget *a_caption);				virtual void Update(int force);		virtual void Erase(const SDL_Rect *area);		virtual int Event(const SDL_Event *event, int xoffset, int yoffset);};class DLLIMPORT GUI_AbstractButton : public GUI_Widget{	protected:		GUI_Widget *caption;		GUI_Callback *click;		virtual GUI_Surface *GetCurrentImage(void);	public:		GUI_AbstractButton(const char *aname, int x, int y, int w, int h);		virtual ~GUI_AbstractButton(void);		virtual void RemoveWidget(GUI_Widget *widget);		void SetCaption(GUI_Widget *widget);		void SetClick(GUI_Callback *handler);				virtual void Erase(const SDL_Rect *dr);		virtual void Fill(const SDL_Rect *dr, SDL_Color c);		virtual void Update(int force);		virtual void Notify(int mask);		virtual void Clicked(int x, int y);};class DLLIMPORT GUI_Button : public GUI_AbstractButton{	protected:		GUI_Surface *normal;		GUI_Surface *highlight;		GUI_Surface *pressed;		GUI_Surface *disabled;		virtual GUI_Surface *GetCurrentImage(void);	public:		GUI_Button(const char *aname, int x, int y, int w, int h);		virtual ~GUI_Button(void);		void SetNormalImage(GUI_Surface *surface);		void SetHighlightImage(GUI_Surface *surface);		void SetPressedImage(GUI_Surface *surface);		void SetDisabledImage(GUI_Surface *surface);};class DLLIMPORT GUI_ToggleButton : public GUI_AbstractButton{	protected:		GUI_Surface *off_normal;		GUI_Surface *off_highlight;		GUI_Surface *on_normal;		GUI_Surface *on_highlight;		virtual GUI_Surface *GetCurrentImage(void);	public:		GUI_ToggleButton(const char *aname, int x, int y, int w, int h);		virtual ~GUI_ToggleButton(void);		virtual void Clicked(int x, int y);		void SetOnNormalImage(GUI_Surface *surface);		void SetOffNormalImage(GUI_Surface *surface);		void SetOnHighlightImage(GUI_Surface *surface);		void SetOffHighlightImage(GUI_Surface *surface);};class DLLIMPORT GUI_ProgressBar : public GUI_Widget{	protected:		GUI_Surface *image1;		GUI_Surface *image2;		double value;	public:		GUI_ProgressBar(const char *aname, int x, int y, int w, int h);		virtual ~GUI_ProgressBar(void);				void SetImage1(GUI_Surface *surface);		void SetImage2(GUI_Surface *surface);		void SetPosition(double value);		virtual void Update(int force);};class DLLIMPORT GUI_ScrollBar : public GUI_Widget

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -