Skip to content

Commit

Permalink
Added PHYSICAL_SCREEN_WIDTH global variable, little ugly, but should …
Browse files Browse the repository at this point in the history
…do for now, still needs to be updated properly on window resize
  • Loading branch information
Grumbel committed Jul 31, 2014
1 parent 417c6a1 commit 1c68be3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
12 changes: 4 additions & 8 deletions src/gui/menu.cpp
Expand Up @@ -770,9 +770,8 @@ Menu::event(const SDL_Event& event)
case SDL_MOUSEBUTTONDOWN:
if(event.button.button == SDL_BUTTON_LEFT)
{
#ifdef OLD_SDL1
int x = int(event.motion.x * float(SCREEN_WIDTH)/g_screen->w);
int y = int(event.motion.y * float(SCREEN_HEIGHT)/g_screen->h);
int x = int(event.motion.x * float(SCREEN_WIDTH) / PHYSICAL_SCREEN_WIDTH);
int y = int(event.motion.y * float(SCREEN_HEIGHT) / PHYSICAL_SCREEN_WIDTH);

if(x > pos.x - get_width()/2 &&
x < pos.x + get_width()/2 &&
Expand All @@ -781,15 +780,13 @@ Menu::event(const SDL_Event& event)
{
menuaction = MENU_ACTION_HIT;
}
#endif
}
break;

case SDL_MOUSEMOTION:
{
#ifdef OLD_SDL1
float x = event.motion.x * SCREEN_WIDTH/g_screen->w;
float y = event.motion.y * SCREEN_HEIGHT/g_screen->h;
float x = event.motion.x * SCREEN_WIDTH / PHYSICAL_SCREEN_WIDTH;
float y = event.motion.y * SCREEN_HEIGHT / PHYSICAL_SCREEN_HEIGHT;

if(x > pos.x - get_width()/2 &&
x < pos.x + get_width()/2 &&
Expand All @@ -813,7 +810,6 @@ Menu::event(const SDL_Event& event)
if(MouseCursor::current())
MouseCursor::current()->set_state(MC_NORMAL);
}
#endif
}
break;

Expand Down
6 changes: 2 additions & 4 deletions src/gui/mousecursor.cpp
Expand Up @@ -57,15 +57,14 @@ void MouseCursor::set_mid(int x, int y)

void MouseCursor::draw(DrawingContext& context)
{
#ifdef OLD_SDL1
if(cur_state == MC_HIDE)
return;

int x,y,w,h;
Uint8 ispressed = SDL_GetMouseState(&x,&y);

x = int(x * float(SCREEN_WIDTH)/g_screen->w);
y = int(y * float(SCREEN_HEIGHT)/g_screen->h);
x = int(x * float(SCREEN_WIDTH) / PHYSICAL_SCREEN_WIDTH);
y = int(y * float(SCREEN_HEIGHT) / PHYSICAL_SCREEN_HEIGHT);

w = (int) cursor->get_width();
h = (int) (cursor->get_height() / MC_STATES_NB);
Expand All @@ -81,7 +80,6 @@ void MouseCursor::draw(DrawingContext& context)

context.draw_surface_part(cursor, Vector(0, h*cur_state),
Vector(w, h), Vector(x-mid_x, y-mid_y), LAYER_GUI+100);
#endif
}

/* EOF */
3 changes: 3 additions & 0 deletions src/supertux/globals.cpp
Expand Up @@ -23,6 +23,9 @@ tinygettext::DictionaryManager* dictionary_manager = 0;
int SCREEN_WIDTH;
int SCREEN_HEIGHT;

int PHYSICAL_SCREEN_WIDTH;
int PHYSICAL_SCREEN_HEIGHT;

ScreenManager* g_screen_manager = 0;

TextureManager* texture_manager = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/supertux/globals.hpp
Expand Up @@ -39,6 +39,9 @@ extern int SCREEN_WIDTH;
shrink or scale things) */
extern int SCREEN_HEIGHT;

extern int PHYSICAL_SCREEN_WIDTH;
extern int PHYSICAL_SCREEN_HEIGHT;

// global variables
extern JoystickKeyboardController* g_jk_controller;

Expand Down
5 changes: 4 additions & 1 deletion src/supertux/main.cpp
Expand Up @@ -466,7 +466,10 @@ Main::init_video()
// FIXME: Add something here
SCREEN_WIDTH = 800;
SCREEN_HEIGHT = 600;


PHYSICAL_SCREEN_WIDTH = SCREEN_WIDTH;
PHYSICAL_SCREEN_HEIGHT = SCREEN_HEIGHT;

context_pointer->init_renderer();

#ifdef OLD_SDL1
Expand Down

0 comments on commit 1c68be3

Please sign in to comment.