📄 gui.h
字号:
// ********************************************************// This is demo code. You may derive from, use, modify, and// distribute it without limitation for any purpose.// Obviously you don't get a warranty or an assurance of// fitness for a particular purpose with this code. Your// welcome to remove this header and claim original// authorship. I really don't care.// ********************************************************#ifndef __GUI_H__#define __GUI_H__#include <SDL/SDL.h>#include "../GClasses/GWidgets.h"class ControllerBase;inline Uint32* getPixMem32(SDL_Surface *surface, int x, int y){ return (Uint32*)((Uint8*)surface->pixels + y * surface->pitch + (x << 2));}inline Uint16* getPixMem16(SDL_Surface *pScreen, int x, int y){ return (Uint16*)pScreen->pixels + y * pScreen->pitch / 2 + x;}class ViewBase{protected: SDL_Surface* m_pScreen; GRect m_screenRect;public: ViewBase(); virtual ~ViewBase(); void Update(); virtual void OnChar(char c) = 0; virtual void OnMouseDown(int x, int y) = 0; virtual void OnMouseUp(int x, int y) = 0; virtual bool OnMousePos(int x, int y) = 0;protected: static void BlitImage(SDL_Surface* pScreen, int x, int y, GImage* pImage); static void StretchClipAndBlitImage(SDL_Surface* pScreen, GRect* pDestRect, GRect* pClipRect, GImage* pImage); virtual void Draw(SDL_Surface* pScreen) = 0; void DrawDot(SDL_Surface *pScreen, int x, int y, GColor col, int nSize); void SetScreenSize(int x, int y);};class ControllerBase{protected: enum KeyState { Normal, Holding, Repeating, }; static char* s_szAppPath; bool m_bKeepRunning; int m_keyboard[SDLK_LAST]; int m_mouse[4]; int m_mouseX; int m_mouseY; bool m_bMouseDown; KeyState m_eKeyState; SDLKey m_lastPressedKey; double m_dKeyRepeatTimer; ViewBase* m_pView;public: ControllerBase(); virtual ~ControllerBase(); static void SetAppPath(char* szAppPath) { s_szAppPath = szAppPath; } static const char* GetAppPath() { return s_szAppPath; } bool HandleEvents(double dTimeDelta); void Quit() { m_bKeepRunning = false; }protected: void HandleKeyPress(SDLKey eKey, SDLMod mod); void HandleMouseClick();};
void OpenFile(const char* szFilename);
#endif // __GUI_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -