#include "util/gettext.hpp"
#include "video/drawing_context.hpp"
#include "video/font.hpp"
+#include "video/renderer.hpp"
static const float MENU_REPEAT_INITIAL = 0.4f;
static const float MENU_REPEAT_RATE = 0.1f;
case SDL_MOUSEBUTTONDOWN:
if(event.button.button == SDL_BUTTON_LEFT)
{
- int x = int(event.motion.x * float(SCREEN_WIDTH) / PHYSICAL_SCREEN_WIDTH);
- int y = int(event.motion.y * float(SCREEN_HEIGHT) / PHYSICAL_SCREEN_HEIGHT);
+ Vector mouse_pos = Renderer::instance()->to_logical(event.motion.x, event.motion.y);
+ int x = int(mouse_pos.x);
+ int y = int(mouse_pos.y);
if(x > pos.x - get_width()/2 &&
x < pos.x + get_width()/2 &&
case SDL_MOUSEMOTION:
{
- float x = event.motion.x * SCREEN_WIDTH / PHYSICAL_SCREEN_WIDTH;
- float y = event.motion.y * SCREEN_HEIGHT / PHYSICAL_SCREEN_HEIGHT;
+ Vector mouse_pos = Renderer::instance()->to_logical(event.motion.x, event.motion.y);
+ float x = mouse_pos.x;
+ float y = mouse_pos.y;
if(x > pos.x - get_width()/2 &&
x < pos.x + get_width()/2 &&
#include "supertux/globals.hpp"
#include "video/drawing_context.hpp"
+#include "video/renderer.hpp"
+#include "video/sdl/sdl_renderer.hpp"
MouseCursor* MouseCursor::current_ = 0;
int x,y,w,h;
Uint8 ispressed = SDL_GetMouseState(&x,&y);
- x = int(x * float(SCREEN_WIDTH) / PHYSICAL_SCREEN_WIDTH);
- y = int(y * float(SCREEN_HEIGHT) / PHYSICAL_SCREEN_HEIGHT);
+ Vector mouse_pos = Renderer::instance()->to_logical(x, y, true);
+
+ x = int(mouse_pos.x);
+ y = int(mouse_pos.y);
w = (int) cursor->get_width();
h = (int) (cursor->get_height() / MC_STATES_NB);
}
}
+Vector
+GLRenderer::to_logical(int physical_x, int physical_y, bool foobar)
+{
+ return Vector(physical_x * float(SCREEN_WIDTH) / PHYSICAL_SCREEN_WIDTH,
+ physical_y * float(SCREEN_HEIGHT) / PHYSICAL_SCREEN_HEIGHT);
+}
+
void
GLRenderer::set_gamma(float gamma)
{
void resize(int w, int h);
void apply_config();
void apply_video_mode(const Size& size, bool fullscreen);
+ Vector to_logical(int physical_x, int physical_y, bool foobar);
void set_gamma(float gamma);
SDL_Window* get_window() const { return window; }
};
virtual void flip() = 0;
virtual void resize(int w, int h) = 0;
virtual void apply_config() = 0;
+ virtual Vector to_logical(int physical_x, int physical_y, bool foobar = false) = 0;
virtual void set_gamma(float gamma) = 0;
virtual SDL_Window* get_window() const = 0;
if(texture_manager == 0)
texture_manager = new TextureManager();
+
+ apply_config();
}
SDLRenderer::~SDLRenderer()
SCREEN_WIDTH = static_cast<int>(SCREEN_WIDTH * scale);
SCREEN_HEIGHT = static_cast<int>(SCREEN_HEIGHT * scale);
}
-
- SDL_Rect viewport;
- viewport.x = 0;
- viewport.y = 0;
- viewport.w = screen_size.width;
- viewport.h = screen_size.height;
- SDL_RenderSetViewport(renderer, &viewport);
}
else
{
new_size.height = static_cast<int>((float) new_size.height * float(max_size.height)/SCREEN_HEIGHT);
SCREEN_HEIGHT = static_cast<int>(max_size.height);
}
-
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
- SDL_RenderClear(renderer);
- SDL_RenderPresent(renderer);
- SDL_RenderClear(renderer);
-
- SDL_Rect viewport;
- viewport.x = std::max(0, (screen_size.width - new_size.width) / 2);
- viewport.y = std::max(0, (screen_size.height - new_size.height) / 2);
- viewport.w = std::min(new_size.width, screen_size.width);
- viewport.h = std::min(new_size.height, screen_size.height);
- SDL_RenderSetViewport(renderer, &viewport);
}
-
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
}
+Vector
+SDLRenderer::to_logical(int physical_x, int physical_y, bool foobar)
+{
+ if (foobar)
+ {
+ // SDL translates coordinates automatically, except for SDL_GetMouseState(), thus foobar
+ return Vector(physical_x * float(SCREEN_WIDTH) / (PHYSICAL_SCREEN_WIDTH),
+ physical_y * float(SCREEN_HEIGHT) / (PHYSICAL_SCREEN_HEIGHT));
+ }
+ else
+ {
+ // SDL is doing the translation internally, so we have nothing to do
+ return Vector(physical_x, physical_y);
+ }
+}
+
void
SDLRenderer::set_gamma(float gamma)
{
void flip();
void resize(int w, int h);
void apply_config();
+ Vector to_logical(int physical_x, int physical_y, bool foobar);
void set_gamma(float gamma);
SDL_Window* get_window() const { return window; }