41 #define LOG_DP LOG_STREAM(info, log_display)
42 #define ERR_DP LOG_STREAM(err, log_display)
56 flags |= SDL_OPENGLBLIT;
59 flags |= SDL_WINDOW_RESIZABLE;
68 bool fake_interactive =
false;
76 sdl_handler(auto_join)
78 draw_layers.push_back(
this);
83 draw_layers.remove(
this);
90 event.type = SDL_WINDOWEVENT;
91 event.window.event = SDL_WINDOWEVENT_RESIZED;
92 event.window.data1 = (*frameBuffer).h;
93 event.window.data2 = (*frameBuffer).w;
96 (*it)->handle_window_event(event);
104 data.data1 =
nullptr;
105 data.data2 =
nullptr;
108 drawEvent.user =
data;
110 SDL_PushEvent(&drawEvent);
117 if (fake_interactive)
126 return render_target_;
148 SDL_Rect rect = rect_value;
153 if(rect.x*-1 >=
int(rect.w))
161 if(rect.y*-1 >=
int(rect.h))
168 if(rect.x + rect.w > fb->w) {
169 rect.w = fb->w - rect.x;
172 if(rect.y + rect.h > fb->h) {
173 rect.h = fb->h - rect.y;
176 if(rect.x >= fb->w) {
180 if(rect.y >= fb->h) {
188 if (event.type == SDL_WINDOWEVENT) {
189 switch (event.window.event) {
190 case SDL_WINDOWEVENT_RESIZED:
191 case SDL_WINDOWEVENT_RESTORED:
192 case SDL_WINDOWEVENT_SHOWN:
193 case SDL_WINDOWEVENT_EXPOSED:
201 data.data1 =
nullptr;
202 data.data2 =
nullptr;
205 drawEvent.user =
data;
208 SDL_PushEvent(&drawEvent);
247 if(render_target_ ==
nullptr) {
248 ERR_DP <<
"Could not initialize window: " << SDL_GetError() << std::endl;
254 shader_ = sdl::shader_program(vertex_src, frag_src);
257 const int res = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
260 ERR_DP <<
"Could not initialize SDL_video: " << SDL_GetError() << std::endl;
267 void CVideo::update_overlay(SDL_Rect *rect)
269 sdl::timage
img(overlay_);
270 shader_.set_overlay(
img);
273 static sdl::timage empty(image::get_texture(
"images/misc/blank.png"));
275 SDL_Rect *
r = rect ==
nullptr ? &whole : rect;
276 empty.set_scale(
float(r->w) / empty.base_width(), float(r->h) / empty.base_height());
277 draw_texture(empty, r->x, r->y);
283 LOG_DP <<
"calling SDL_Quit()\n";
287 LOG_DP <<
"called SDL_Quit()\n";
295 const clip_rect_setter clip_setter(target, clip_rect, clip_rect !=
nullptr);
302 return render_target_;
305 void CVideo::draw_texture(sdl::timage &
texture,
int x,
int y)
307 texture.draw(*
this, x, y);
310 void CVideo::set_texture_color_modulation(
int r,
int g,
int b,
int a)
312 shader_.set_color_mod(r, g, b, a);
315 void CVideo::set_texture_submerge(
float f)
317 shader_.set_submerge(f);
320 void CVideo::set_texture_effects(
int effects)
322 shader_.set_effects(effects);
325 void CVideo::blit_to_overlay(
surface surf,
int x,
int y)
327 if (x < 0 ||
y < 0 || x > overlay_->w || y > overlay_->h) {
331 SDL_BlitSurface(surf,
nullptr, overlay_, &r);
335 void CVideo::clear_overlay_area(SDL_Rect area)
337 const Uint32
color = SDL_MapRGBA(overlay_->format, 0, 0, 0, 0);
338 Uint32 *
pixels =
static_cast<Uint32*
>(overlay_->pixels);
339 for (
int x = area.x; x<area.x + area.w; ++x) {
340 for (
int y = area.y; y<area.y +area.h; ++y) {
341 const int index = y * (area.w + overlay_->pitch) + x;
345 update_overlay(&area);
348 void CVideo::clear_overlay()
358 frameBuffer = SDL_CreateRGBSurface(SDL_SWSURFACE,16,16,24,0xFF0000,0xFF00,0xFF,0);
363 const unsigned height,
const unsigned bpp)
365 frameBuffer = SDL_CreateRGBSurface(SDL_SWSURFACE,
366 width, height, bpp, 0xFF0000, 0xFF00, 0xFF, 0);
369 fake_interactive =
true;
406 video_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
408 video_flags |= SDL_WINDOW_MAXIMIZED;
414 std::cerr <<
"Setting mode to " << w <<
"x" << h << std::endl;
477 return frameBuffer->w;
486 return frameBuffer->h;
493 SDL_Delay(milliseconds);
501 assert(render_target_);
531 flags = SDL_GetWindowFlags(*
window);
532 if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
535 if (flags & SDL_WINDOW_INPUT_FOCUS) {
538 if (flags & SDL_WINDOW_MOUSE_FOCUS) {
541 if (flags & SDL_WINDOW_MAXIMIZED) {
542 state |= SDL_WINDOW_MAXIMIZED;
544 if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) {
545 state |= SDL_WINDOW_FULLSCREEN_DESKTOP;
571 return SDL_GetWindowDisplayIndex(*window);
578 std::vector<std::pair<int, int> >
result;
582 std::cerr <<
"No modes supported\n";
588 SDL_DisplayMode
mode;
589 for (
int i = 0;
i < modes; ++
i) {
590 if(SDL_GetDisplayMode(0,
i, &mode) == 0) {
591 if (mode.w >= min_res.first && mode.h >= min_res.second)
592 result.push_back(std::make_pair(mode.w, mode.h));
596 if (
std::find(result.begin(), result.end(), min_res) == result.end()) {
597 result.push_back(min_res);
600 if(include_current) {
605 result.erase(std::unique(result.begin(), result.end()), result.end());
621 return (
window->get_flags() & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
629 const SDL_Color color = { 0, 0, 0, 0xbb };
685 setMode(res.first, res.second, mode);
void set_window_icon(surface &icon)
Sets the icon of the main window.
surface & get_video_surface()
void _set_fullscreen(bool ison)
std::list< events::sdl_handler * > draw_layers
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
draw_layering(const bool auto_join=true)
void _set_resolution(const std::pair< int, int > &res)
static display * get_singleton()
Returns the display object if a display object exists.
void set_pixel_format(SDL_PixelFormat *format)
sets the pixel format used by the images.
void _set_maximized(bool ison)
static unsigned int get_flags(unsigned int flags)
std::pair< int, int > current_resolution()
void set_resolution(const std::pair< int, int > &res)
Set the resolution.
void set_bg_color(const SDL_Color &bg_color)
GLuint GLuint GLsizei GLenum type
static l_noret error(LoadState *S, const char *why)
static int sdl_display_index(sdl::twindow *window)
void lock_updates(bool value)
GPU_Target * GPU_Init(Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags)
void remove_floating_label(int handle)
removes the floating label given by 'handle' from the screen
void redraw_everything()
Invalidates entire screen, including all tiles and sidebar.
GPU_Target * GPU_GetContextTarget(void)
static CVideo * singleton_
std::vector< std::pair< int, int > > get_available_resolutions(const bool include_current=false)
Returns the list of available screen resolutions.
GLenum GLenum GLuint texture
GLint GLint GLint GLint GLint GLint y
void set_font_size(int font_size)
void blit_surface(int x, int y, surface surf, SDL_Rect *srcrect=nullptr, SDL_Rect *clip_rect=nullptr)
sdl::twindow * get_window()
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
#define GPU_DEFAULT_INIT_FLAGS
void move_floating_label(int handle, double xmove, double ymove)
moves the floating label given by 'handle' by (xmove,ymove)
GLdouble GLdouble GLdouble b
void setMode(int x, int y, const MODE_EVENT mode)
void set_window_title(const std::string &title)
Sets the title of the main window.
boost::scoped_ptr< sdl::twindow > window
The wrapper class for the SDL_Window class.
#define SDL_APPINPUTFOCUS
The app has input focus.
Uint8 window_state()
Wrapper for SDL_GetAppState.
void GPU_Flip(GPU_Target *target)
bool isFullScreen() const
GLubyte GLubyte GLubyte GLubyte w
GLsizei const GLfloat * value
static lg::log_domain log_display("display")
bool init_window()
Initializes a new window, taking into account any preiously saved states.
GLboolean GLboolean GLboolean GLboolean a
std::pair< int, int > resolution()
void set_position(double xpos, double ypos)
map_display and display: classes which take care of displaying the map and game-data on the screen...
cl_event GLbitfield flags
#define SDL_APPMOUSEFOCUS
The app has mouse coverage.
#define SDL_APPACTIVE
The application is active.
virtual void handle_window_event(const SDL_Event &event)
bool update_locked() const
GLfloat GLfloat GLfloat GLfloat h
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
GLint GLint GLint GLint GLint x
void set_fullscreen(bool ison)
SDL_Rect get_floating_label_rect(int handle)
GLdouble GLdouble GLdouble r
CVideo(FAKE_TYPES type=NO_FAKE)
static int sort(lua_State *L)
void set_border_size(int border)
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
int set_help_string(const std::string &str)
GLint GLint GLsizei GLsizei GLsizei GLint border
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
Contains the SDL_Rect helper code.
bool find(E event, F functor)
Tests whether an event handler is available.
void trigger_full_redraw()
Standard logging facilities (interface).
video_event_handler event_handler_
void assign(const surface &o)
surface create_compatible_surface(const surface &surf, int width, int height)
void make_test_fake(const unsigned width=1024, const unsigned height=768, const unsigned bpp=DefaultBpp)
Creates a fake frame buffer for the unit tests.
void clear_all_help_strings()
static void delay(unsigned int milliseconds)
Contains a wrapper class for the SDL_Window class.
GLint GLint GLint GLint GLint GLint GLsizei width
void update_framebuffer()
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
GLsizei const GLcharARB ** string
virtual void join_global()
int line_width(const std::string &line, int font_size, int style)
Determine the width of a line of text given a certain font size.
void clear_help_string(int handle)
boost::shared_ptr< halo_record > handle
void update_rect(size_t x, size_t y, size_t w, size_t h)