Skip to content

Commit

Permalink
Support spacebar in accelerator
Browse files Browse the repository at this point in the history
Name EnableVSync consistently
Enforce renderers implement required functions
Look for skin in executable location rather than current directory
  • Loading branch information
matt-attack committed Jun 23, 2024
1 parent 1fc397a commit bdca631
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gwen/Renderers/OpenGL/OpenGL_Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ namespace Gwen
return true;
}

void OpenGL_Base::EnableVsync(bool yn)
void OpenGL_Base::EnableVSync(bool yn)
{
#ifdef WIN32
auto wglSwapIntervalEXT = (bool(*)(int))wglGetProcAddress("wglSwapIntervalEXT");
Expand Down
29 changes: 25 additions & 4 deletions gwen/include/Gwen/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Application: public BaseApplication
{
std::wstring default_font_ = L"Segoe UI";
double default_font_size_ = 10.0;
std::string skin_ = "DefaultSkin.png";
std::string skin_ = "";

std::vector<Gwen::Controls::WindowCanvas*> canvases_;

Expand Down Expand Up @@ -177,20 +177,41 @@ class Application: public BaseApplication
Gwen::Controls::WindowCanvas* window_canvas = new Gwen::Controls::WindowCanvas(x, y, w, h, skin, title, is_menu);
window_canvas->SetSizable(!is_menu);

if (FILE* f = fopen(skin_.c_str(), "rb"))
// fall back to default if not set
std::string skin_file = skin_;
if (skin_file.length() == 0)
{
char buf[500];
#ifdef _WIN32
GetModuleFileName(NULL, buf, 500);
#else
readlink("/proc/self/exe", buf, 500);
#endif
skin_file = buf;
auto index = skin_file.find_last_of("/");
if (index != std::string::npos)
skin_file = skin_file.substr(0, index);
index = skin_file.find_last_of("\\");
if (index != std::string::npos)
skin_file = skin_file.substr(0, index);
skin_file += "/DefaultSkin.png";
}

printf("Loading skin %s\n", skin_file.c_str());
if (FILE* f = fopen(skin_file.c_str(), "rb"))
{
fclose(f);
}
else
{
// create the skin from default
f = fopen(skin_.c_str(), "wb");
f = fopen(skin_file.c_str(), "wb");
fwrite(DefaultSkin_png, 1, DefaultSkin_png_size, f);
fclose(f);
printf("Skin doesnt exist. Creating from default.\n");
}

skin->Init(skin_);
skin->Init(skin_file);
skin->SetDefaultFont(default_font_, default_font_size_);

canvases_.push_back(window_canvas);
Expand Down
18 changes: 9 additions & 9 deletions gwen/include/Gwen/BaseRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ namespace Gwen
Base();
virtual ~Base();

virtual void Init() {};
virtual void Init() = 0;

virtual void Begin() {};
virtual void End() {};
virtual void Begin() = 0;
virtual void End() = 0;

virtual void EnableVsync(bool yn) {};
virtual void EnableVSync(bool yn) {};

virtual void SetDrawColor( Color color ) {};
virtual void SetDrawColor( Color color ) = 0;

virtual void DrawFilledRect( Gwen::Rect rect ) {};;
virtual void DrawFilledRect( Gwen::Rect rect ) = 0;

virtual void StartClip() {};
virtual void EndClip() {};
virtual void StartClip() = 0;
virtual void EndClip() = 0;

virtual void LoadTexture( Gwen::Texture* pTexture ) {};
virtual void FreeTexture( Gwen::Texture* pTexture ) {};
virtual void DrawTexturedRect( Gwen::Texture* pTexture, Gwen::Rect pTargetRect, float u1 = 0.0f, float v1 = 0.0f, float u2 = 1.0f, float v2 = 1.0f ) {};
virtual void DrawTexturedRect( Gwen::Texture* pTexture, Gwen::Rect pTargetRect, float u1 = 0.0f, float v1 = 0.0f, float u2 = 1.0f, float v2 = 1.0f ) = 0;
virtual void DrawMissingImage( Gwen::Rect pTargetRect );
virtual Gwen::Color PixelColour( Gwen::Texture* pTexture, unsigned int x, unsigned int y, const Gwen::Color & col_default = Gwen::Color( 255, 255, 255, 255 ) ) { return col_default; }

Expand Down
2 changes: 1 addition & 1 deletion gwen/include/Gwen/Renderers/OpenGL_Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Gwen
virtual void SetDrawColor( Gwen::Color color );
virtual void DrawFilledRect( Gwen::Rect rect );

virtual void EnableVsync(bool yn);
virtual void EnableVSync(bool yn);

void StartClip();
void EndClip();
Expand Down
9 changes: 8 additions & 1 deletion gwen/src/inputhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,14 @@ bool Gwen::Input::HandleAccelerator( Gwen::UnicodeChar chr )
else
{
chr = towupper(chr);
accelString += chr;
if (chr == ' ')
{
accelString += L"SPACE";
}
else
{
accelString += chr;
}
}

//Debug::Msg("Accelerator string :%S\n", accelString.c_str());
Expand Down

0 comments on commit bdca631

Please sign in to comment.