Prevent setting double scale on smaller screens. Fixes #166

This commit is contained in:
Simon Robertshaw 2012-09-05 17:31:49 +01:00
parent d379390d06
commit d61690bc09
6 changed files with 42 additions and 4 deletions

View File

@ -50,6 +50,8 @@ using namespace std;
extern "C" IMAGE_DOS_HEADER __ImageBase; extern "C" IMAGE_DOS_HEADER __ImageBase;
#endif #endif
int desktopWidth = 1280, desktopHeight = 1024;
SDL_Surface * sdl_scrn; SDL_Surface * sdl_scrn;
int scale = 1; int scale = 1;
bool fullscreen = false; bool fullscreen = false;
@ -173,6 +175,9 @@ int SDLOpen()
fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError()); fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError());
return 1; return 1;
} }
const SDL_VideoInfo * vidInfo = SDL_GetVideoInfo();
desktopWidth = vidInfo->current_w;
desktopHeight = vidInfo->current_h;
SDL_EnableUNICODE(1); SDL_EnableUNICODE(1);
#if defined(WIN) && defined(WINCONSOLE) #if defined(WIN) && defined(WINCONSOLE)
//On Windows, SDL redirects stdout to stdout.txt, which can be annoying when debugging, here we redirect back to the console //On Windows, SDL redirects stdout to stdout.txt, which can be annoying when debugging, here we redirect back to the console
@ -492,6 +497,7 @@ int main(int argc, char * argv[])
ui::Engine::Ref().Fullscreen = fullscreen; ui::Engine::Ref().Fullscreen = fullscreen;
engine = &ui::Engine::Ref(); engine = &ui::Engine::Ref();
engine->SetMaxSize(desktopWidth, desktopHeight);
engine->Begin(XRES+BARSIZE, YRES+MENUSIZE); engine->Begin(XRES+BARSIZE, YRES+MENUSIZE);
GameController * gameController = new GameController(); GameController * gameController = new GameController();

View File

@ -12,7 +12,7 @@
#include "PowderToy.h" #include "PowderToy.h"
ErrorMessage::ErrorMessage(std::string title, std::string message, ErrorMessageCallback * callback_): ErrorMessage::ErrorMessage(std::string title, std::string message, ErrorMessageCallback * callback_):
ui::Window(ui::Point(-1, -1), ui::Point(200, 75)), ui::Window(ui::Point(-1, -1), ui::Point(200, 35)),
callback(callback_) callback(callback_)
{ {
ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 16), title); ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 16), title);
@ -21,11 +21,15 @@ ErrorMessage::ErrorMessage(std::string title, std::string message, ErrorMessage
titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
AddComponent(titleLabel); AddComponent(titleLabel);
ui::Label * messageLabel = new ui::Label(ui::Point(4, 24), ui::Point(Size.X-8, 60), message); ui::Label * messageLabel = new ui::Label(ui::Point(4, 24), ui::Point(Size.X-8, -1), message);
messageLabel->SetMultiline(true);
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop; messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
AddComponent(messageLabel); AddComponent(messageLabel);
Size.Y += messageLabel->Size.Y+12;
Position.Y = (ui::Engine::Ref().GetHeight()-Size.Y)/2;
class DismissAction: public ui::ButtonAction class DismissAction: public ui::ButtonAction
{ {
ErrorMessage * message; ErrorMessage * message;

View File

@ -88,7 +88,7 @@ DropDown::DropDown(Point position, Point size):
void DropDown::OnMouseClick(int x, int y, unsigned int button) void DropDown::OnMouseClick(int x, int y, unsigned int button)
{ {
DropDownWindow * newWindow = new DropDownWindow(this); DropDownWindow * newWindow = new DropDownWindow(this);
ui::Engine().Ref().ShowWindow(newWindow); ui::Engine::Ref().ShowWindow(newWindow);
} }
void DropDown::Draw(const Point& screenPos) void DropDown::Draw(const Point& screenPos)

View File

@ -14,6 +14,8 @@ using namespace std;
Engine::Engine(): Engine::Engine():
state_(NULL), state_(NULL),
maxWidth(0),
maxHeight(0),
mousex_(0), mousex_(0),
mousey_(0), mousey_(0),
mousexp_(0), mousexp_(0),
@ -148,6 +150,12 @@ void Engine::SetSize(int width, int height)
height_ = height; height_ = height;
} }
void Engine::SetMaxSize(int width, int height)
{
maxWidth = width;
maxHeight = height;
}
void Engine::Tick() void Engine::Tick()
{ {
if(state_ != NULL) if(state_ != NULL)

View File

@ -57,6 +57,10 @@ namespace ui
inline int GetMouseY() { return mousey_; } inline int GetMouseY() { return mousey_; }
inline int GetWidth() { return width_; } inline int GetWidth() { return width_; }
inline int GetHeight() { return height_; } inline int GetHeight() { return height_; }
inline int GetMaxWidth() { return maxWidth; }
inline int GetMaxHeight() { return maxHeight; }
inline void SetMaxSize(int width, int height);
inline void SetSize(int width, int height); inline void SetSize(int width, int height);
@ -90,6 +94,9 @@ namespace ui
int mouseyp_; int mouseyp_;
int width_; int width_;
int height_; int height_;
int maxWidth;
int maxHeight;
}; };
} }

View File

@ -6,6 +6,7 @@
*/ */
#include "OptionsController.h" #include "OptionsController.h"
#include "dialogues/ErrorMessage.h"
OptionsController::OptionsController(Simulation * sim, ControllerCallback * callback_): OptionsController::OptionsController(Simulation * sim, ControllerCallback * callback_):
callback(callback_), callback(callback_),
@ -61,7 +62,19 @@ void OptionsController::SetFullscreen(bool fullscreen)
void OptionsController::SetScale(bool scale) void OptionsController::SetScale(bool scale)
{ {
if(scale)
{
if(ui::Engine::Ref().GetMaxWidth() >= ui::Engine::Ref().GetWidth() * 2 && ui::Engine::Ref().GetMaxHeight() >= ui::Engine::Ref().GetHeight() * 2)
model->SetScale(scale); model->SetScale(scale);
else
{
new ErrorMessage("Screen resolution error", "Your screen size is too small to use this scale mode.");
model->SetScale(false);
}
}
else
model->SetScale(scale);
} }
OptionsView * OptionsController::GetView() OptionsView * OptionsController::GetView()