add resizable window and original fullscreen options
This commit is contained in:
parent
58127f355b
commit
743ec98e3f
@ -61,6 +61,8 @@ SDL_Renderer * sdl_renderer;
|
||||
SDL_Texture * sdl_texture;
|
||||
int scale = 1;
|
||||
bool fullscreen = false;
|
||||
bool altFullscreen = false;
|
||||
bool resizable = false;
|
||||
|
||||
|
||||
void ClipboardPush(ByteString text)
|
||||
@ -120,7 +122,7 @@ void blit(pixel * vid)
|
||||
{
|
||||
SDL_UpdateTexture(sdl_texture, NULL, vid, WINDOWW * sizeof (Uint32));
|
||||
// need to clear the renderer if there are black edges (fullscreen, or resizable window)
|
||||
if (fullscreen)
|
||||
if (fullscreen || resizable)
|
||||
SDL_RenderClear(sdl_renderer);
|
||||
SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL);
|
||||
SDL_RenderPresent(sdl_renderer);
|
||||
@ -140,8 +142,13 @@ int SDLOpen()
|
||||
desktopWidth = SDLDisplayMode.w;
|
||||
desktopHeight = SDLDisplayMode.h;
|
||||
|
||||
unsigned int flags = 0;
|
||||
if (fullscreen)
|
||||
flags = altFullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
if (resizable)
|
||||
flags |= SDL_WINDOW_RESIZABLE;
|
||||
sdl_window = SDL_CreateWindow("The Powder Toy", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOWW * scale, WINDOWH * scale,
|
||||
fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
||||
flags);
|
||||
sdl_renderer = SDL_CreateRenderer(sdl_window, -1, 0);
|
||||
SDL_RenderSetLogicalSize(sdl_renderer, WINDOWW, WINDOWH);
|
||||
//Uncomment this to force fullscreen to an integer resolution
|
||||
@ -180,14 +187,20 @@ int SDLOpen()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SDLSetScreen(int newScale, bool newFullscreen)
|
||||
void SDLSetScreen(int scale_, bool resizable_, bool fullscreen_, bool altFullscreen_)
|
||||
{
|
||||
scale = newScale;
|
||||
fullscreen = newFullscreen;
|
||||
SDL_SetWindowSize(sdl_window, WINDOWW * newScale, WINDOWH * newScale);
|
||||
SDL_SetWindowFullscreen(sdl_window, newFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
||||
if (newFullscreen)
|
||||
scale = scale_;
|
||||
fullscreen = fullscreen_;
|
||||
altFullscreen = altFullscreen_;
|
||||
resizable = resizable_;
|
||||
SDL_SetWindowSize(sdl_window, WINDOWW * scale, WINDOWH * scale);
|
||||
unsigned int flags = 0;
|
||||
if (fullscreen)
|
||||
flags = altFullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
SDL_SetWindowFullscreen(sdl_window, flags);
|
||||
if (fullscreen)
|
||||
SDL_RaiseWindow(sdl_window);
|
||||
SDL_SetWindowResizable(sdl_window, resizable ? SDL_TRUE : SDL_FALSE);
|
||||
}
|
||||
|
||||
unsigned int GetTicks()
|
||||
@ -417,9 +430,10 @@ void EngineProcess()
|
||||
engine->Tick();
|
||||
engine->Draw();
|
||||
|
||||
if(scale != engine->Scale || fullscreen != engine->Fullscreen)
|
||||
if (scale != engine->Scale || fullscreen != engine->Fullscreen
|
||||
|| altFullscreen != engine->GetAltFullscreen() || resizable != engine->GetResizable())
|
||||
{
|
||||
SDLSetScreen(engine->Scale, engine->Fullscreen);
|
||||
SDLSetScreen(engine->Scale, engine->GetResizable(), engine->Fullscreen, engine->GetAltFullscreen());
|
||||
}
|
||||
|
||||
#ifdef OGLI
|
||||
@ -534,7 +548,9 @@ int main(int argc, char * argv[])
|
||||
#endif
|
||||
|
||||
scale = Client::Ref().GetPrefInteger("Scale", 1);
|
||||
resizable = Client::Ref().GetPrefBool("Resizable", false);
|
||||
fullscreen = Client::Ref().GetPrefBool("Fullscreen", false);
|
||||
altFullscreen = Client::Ref().GetPrefBool("AltFullscreen", false);
|
||||
|
||||
|
||||
if(arguments["kiosk"] == "true")
|
||||
@ -598,7 +614,9 @@ int main(int argc, char * argv[])
|
||||
#endif
|
||||
ui::Engine::Ref().g = new Graphics();
|
||||
ui::Engine::Ref().Scale = scale;
|
||||
ui::Engine::Ref().SetResizable(resizable);
|
||||
ui::Engine::Ref().Fullscreen = fullscreen;
|
||||
ui::Engine::Ref().SetAltFullscreen(altFullscreen);
|
||||
|
||||
engine = &ui::Engine::Ref();
|
||||
engine->SetMaxSize(desktopWidth, desktopHeight);
|
||||
|
@ -18,6 +18,8 @@ Engine::Engine():
|
||||
Scale(1),
|
||||
Fullscreen(false),
|
||||
FrameIndex(0),
|
||||
altFullscreen(false),
|
||||
resizable(false),
|
||||
lastBuffer(NULL),
|
||||
prevBuffers(stack<pixel*>()),
|
||||
windows(stack<Window*>()),
|
||||
|
@ -46,8 +46,12 @@ namespace ui
|
||||
|
||||
void SetFullscreen(bool fullscreen) { Fullscreen = fullscreen; }
|
||||
inline bool GetFullscreen() { return Fullscreen; }
|
||||
void SetAltFullscreen(bool altFullscreen) { this->altFullscreen = altFullscreen; }
|
||||
inline bool GetAltFullscreen() { return altFullscreen; }
|
||||
void SetScale(int scale) { Scale = scale; }
|
||||
inline int GetScale() { return Scale; }
|
||||
void SetResizable(bool resizable) { this->resizable = resizable; }
|
||||
inline bool GetResizable() { return resizable; }
|
||||
void SetFastQuit(bool fastquit) { FastQuit = fastquit; }
|
||||
inline bool GetFastQuit() {return FastQuit; }
|
||||
|
||||
@ -80,6 +84,9 @@ namespace ui
|
||||
|
||||
unsigned int FrameIndex;
|
||||
private:
|
||||
bool altFullscreen;
|
||||
bool resizable;
|
||||
|
||||
float dt;
|
||||
float fps;
|
||||
pixel * lastBuffer;
|
||||
|
@ -55,6 +55,11 @@ void OptionsController::SetFullscreen(bool fullscreen)
|
||||
model->SetFullscreen(fullscreen);
|
||||
}
|
||||
|
||||
void OptionsController::SetAltFullscreen(bool altFullscreen)
|
||||
{
|
||||
model->SetAltFullscreen(altFullscreen);
|
||||
}
|
||||
|
||||
void OptionsController::SetShowAvatars(bool showAvatars)
|
||||
{
|
||||
model->SetShowAvatars(showAvatars);
|
||||
@ -65,6 +70,11 @@ void OptionsController::SetScale(int scale)
|
||||
model->SetScale(scale);
|
||||
}
|
||||
|
||||
void OptionsController::SetResizable(bool resizable)
|
||||
{
|
||||
model->SetResizable(resizable);
|
||||
}
|
||||
|
||||
void OptionsController::SetFastQuit(bool fastquit)
|
||||
{
|
||||
model->SetFastQuit(fastquit);
|
||||
|
@ -25,7 +25,9 @@ public:
|
||||
void SetAirMode(int airMode);
|
||||
void SetEdgeMode(int edgeMode);
|
||||
void SetFullscreen(bool fullscreen);
|
||||
void SetAltFullscreen(bool altFullscreen);
|
||||
void SetScale(int scale);
|
||||
void SetResizable(bool resizable);
|
||||
void SetFastQuit(bool fastquit);
|
||||
void SetShowAvatars(bool showAvatars);
|
||||
void Exit();
|
||||
|
@ -102,6 +102,18 @@ void OptionsModel::SetScale(int scale)
|
||||
notifySettingsChanged();
|
||||
}
|
||||
|
||||
bool OptionsModel::GetResizable()
|
||||
{
|
||||
return ui::Engine::Ref().GetResizable();
|
||||
}
|
||||
|
||||
void OptionsModel::SetResizable(bool resizable)
|
||||
{
|
||||
ui::Engine::Ref().SetResizable(resizable);
|
||||
Client::Ref().SetPref("Resizable", resizable);
|
||||
notifySettingsChanged();
|
||||
}
|
||||
|
||||
bool OptionsModel::GetFullscreen()
|
||||
{
|
||||
return ui::Engine::Ref().GetFullscreen();
|
||||
@ -109,7 +121,19 @@ bool OptionsModel::GetFullscreen()
|
||||
void OptionsModel::SetFullscreen(bool fullscreen)
|
||||
{
|
||||
ui::Engine::Ref().SetFullscreen(fullscreen);
|
||||
Client::Ref().SetPref("Fullscreen", bool(fullscreen));
|
||||
Client::Ref().SetPref("Fullscreen", fullscreen);
|
||||
notifySettingsChanged();
|
||||
}
|
||||
|
||||
bool OptionsModel::GetAltFullscreen()
|
||||
{
|
||||
return ui::Engine::Ref().GetAltFullscreen();
|
||||
}
|
||||
|
||||
void OptionsModel::SetAltFullscreen(bool altFullscreen)
|
||||
{
|
||||
ui::Engine::Ref().SetAltFullscreen(altFullscreen);
|
||||
Client::Ref().SetPref("AltFullscreen", altFullscreen);
|
||||
notifySettingsChanged();
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,12 @@ public:
|
||||
void SetGravityMode(int gravityMode);
|
||||
int GetScale();
|
||||
void SetScale(int scale);
|
||||
bool GetResizable();
|
||||
void SetResizable(bool resizable);
|
||||
bool GetFullscreen();
|
||||
void SetFullscreen(bool fullscreen);
|
||||
bool GetAltFullscreen();
|
||||
void SetAltFullscreen(bool oldFullscreen);
|
||||
bool GetFastQuit();
|
||||
void SetFastQuit(bool fastquit);
|
||||
virtual ~OptionsModel();
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "gui/dialogues/ErrorMessage.h"
|
||||
|
||||
OptionsView::OptionsView():
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(300, 329)){
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(300, 369)){
|
||||
|
||||
ui::Label * tempLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Simulation Options");
|
||||
tempLabel->SetTextColour(style::Colour::InformationTitle);
|
||||
@ -173,6 +173,24 @@ OptionsView::OptionsView():
|
||||
AddComponent(tempLabel);
|
||||
|
||||
|
||||
class ResizableAction: public ui::CheckboxAction
|
||||
{
|
||||
OptionsView * v;
|
||||
public:
|
||||
ResizableAction(OptionsView * v_){ v = v_; }
|
||||
virtual void ActionCallback(ui::Checkbox * sender)
|
||||
{
|
||||
v->c->SetResizable(sender->GetChecked());
|
||||
}
|
||||
};
|
||||
|
||||
resizable = new ui::Checkbox(ui::Point(8, scale->Position.Y + 20), ui::Point(Size.X-6, 16), "Resizable", "");
|
||||
resizable->SetActionCallback(new ResizableAction(this));
|
||||
tempLabel = new ui::Label(ui::Point(resizable->Position.X+Graphics::textwidth(resizable->GetText().c_str())+20, resizable->Position.Y), ui::Point(Size.X-28, 16), "\bg- Allow resizing and maximizing window");
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
AddComponent(resizable);
|
||||
|
||||
class FullscreenAction: public ui::CheckboxAction
|
||||
{
|
||||
OptionsView * v;
|
||||
@ -184,13 +202,31 @@ OptionsView::OptionsView():
|
||||
}
|
||||
};
|
||||
|
||||
fullscreen = new ui::Checkbox(ui::Point(8, 230), ui::Point(Size.X-6, 16), "Fullscreen", "");
|
||||
fullscreen = new ui::Checkbox(ui::Point(8, resizable->Position.Y + 20), ui::Point(Size.X-6, 16), "Fullscreen", "");
|
||||
fullscreen->SetActionCallback(new FullscreenAction(this));
|
||||
tempLabel = new ui::Label(ui::Point(fullscreen->Position.X+Graphics::textwidth(fullscreen->GetText().c_str())+20, fullscreen->Position.Y), ui::Point(Size.X-28, 16), "\bg- Fill the entire screen");
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
AddComponent(fullscreen);
|
||||
|
||||
class AltFullscreenAction: public ui::CheckboxAction
|
||||
{
|
||||
OptionsView * v;
|
||||
public:
|
||||
AltFullscreenAction(OptionsView * v_){ v = v_; }
|
||||
virtual void ActionCallback(ui::Checkbox * sender)
|
||||
{
|
||||
v->c->SetAltFullscreen(sender->GetChecked());
|
||||
}
|
||||
};
|
||||
|
||||
altFullscreen = new ui::Checkbox(ui::Point(23, fullscreen->Position.Y + 20), ui::Point(Size.X-6, 16), "Change Resolution", "");
|
||||
altFullscreen->SetActionCallback(new AltFullscreenAction(this));
|
||||
tempLabel = new ui::Label(ui::Point(altFullscreen->Position.X+Graphics::textwidth(altFullscreen->GetText().c_str())+20, altFullscreen->Position.Y), ui::Point(Size.X-28, 16), "\bg- Set optimial screen resolution");
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
AddComponent(altFullscreen);
|
||||
|
||||
|
||||
class FastQuitAction: public ui::CheckboxAction
|
||||
{
|
||||
@ -200,7 +236,7 @@ OptionsView::OptionsView():
|
||||
virtual void ActionCallback(ui::Checkbox * sender){ v->c->SetFastQuit(sender->GetChecked()); }
|
||||
};
|
||||
|
||||
fastquit = new ui::Checkbox(ui::Point(8, 250), ui::Point(Size.X-6, 16), "Fast Quit", "");
|
||||
fastquit = new ui::Checkbox(ui::Point(8, altFullscreen->Position.Y + 20), ui::Point(Size.X-6, 16), "Fast Quit", "");
|
||||
fastquit->SetActionCallback(new FastQuitAction(this));
|
||||
tempLabel = new ui::Label(ui::Point(fastquit->Position.X+Graphics::textwidth(fastquit->GetText().c_str())+20, fastquit->Position.Y), ui::Point(Size.X-28, 16), "\bg- Always exit completely when hitting close");
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
@ -215,7 +251,7 @@ OptionsView::OptionsView():
|
||||
virtual void ActionCallback(ui::Checkbox * sender){ v->c->SetShowAvatars(sender->GetChecked()); }
|
||||
};
|
||||
|
||||
showAvatars = new ui::Checkbox(ui::Point(8, 270), ui::Point(Size.X-6, 16), "Show Avatars", "");
|
||||
showAvatars = new ui::Checkbox(ui::Point(8, fastquit->Position.Y + 20), ui::Point(Size.X-6, 16), "Show Avatars", "");
|
||||
showAvatars->SetActionCallback(new ShowAvatarsAction(this));
|
||||
tempLabel = new ui::Label(ui::Point(showAvatars->Position.X+Graphics::textwidth(showAvatars->GetText().c_str())+20, showAvatars->Position.Y), ui::Point(Size.X-28, 16), "\bg- Disable if you have a slow connection");
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
@ -279,7 +315,9 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
|
||||
gravityMode->SetOption(sender->GetGravityMode());
|
||||
edgeMode->SetOption(sender->GetEdgeMode());
|
||||
scale->SetOption(sender->GetScale());
|
||||
resizable->SetChecked(sender->GetResizable());
|
||||
fullscreen->SetChecked(sender->GetFullscreen());
|
||||
altFullscreen->SetChecked(sender->GetAltFullscreen());
|
||||
fastquit->SetChecked(sender->GetFastQuit());
|
||||
showAvatars->SetChecked(sender->GetShowAvatars());
|
||||
}
|
||||
|
@ -20,7 +20,9 @@ class OptionsView: public ui::Window {
|
||||
ui::DropDown * gravityMode;
|
||||
ui::DropDown * edgeMode;
|
||||
ui::DropDown * scale;
|
||||
ui::Checkbox * resizable;
|
||||
ui::Checkbox * fullscreen;
|
||||
ui::Checkbox * altFullscreen;
|
||||
ui::Checkbox * fastquit;
|
||||
ui::Checkbox * showAvatars;
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user