Make SDL_gpu an optional dependency.

This commit is contained in:
Boldizsár Lipka 2014-06-29 14:48:25 +02:00
parent d5491b0611
commit c2d7265718
4 changed files with 116 additions and 2 deletions

View file

@ -84,6 +84,7 @@ option(ENABLE_NLS "Enable building of translations" ON)
option(ENABLE_LOW_MEM "Reduce memory usage by removing extra functionality" OFF)
option(ENABLE_OMP "Enables OpenMP, and has additional dependencies" OFF)
option(ENABLE_PANDORA "Add support for the OpenPandora by deactivating libvorbis support" OFF)
option(ENABLE_SDL_GPU "Enable building with SDL_gpu (experimental" OFF)
if(NOT DEFINED ENABLE_DISPLAY_REVISION)
# Test whether the code is used in a repository if not autorevision will

View file

@ -52,8 +52,11 @@ if(USE_ANA_NETWORK)
add_subdirectory(ana/src)
endif(USE_ANA_NETWORK)
message(STATUS "Configuring SDL_gpu...")
add_subdirectory(SDL_gpu)
if(ENABLE_SDL_GPU)
message(STATUS "Configuring SDL_gpu...")
add_definitions("-DSDL_GPU")
add_subdirectory(SDL_gpu)
endif(ENABLE_SDL_GPU)
# needed to get include paths in the subfolders correct
include_directories( ${CMAKE_SOURCE_DIR}/src/ )

View file

@ -74,7 +74,11 @@ loadscreen::loadscreen(CVideo &screen, const int percent):
#if SDL_VERSION_ATLEAST(2,0,0)
logo_texture_(image::get_texture("misc/logo.png")),
#else
#ifdef SDL_GPU
logo_image_(NULL),
#else
logo_surface_(image::get_image("misc/logo.png")),
#endif
#endif
logo_drawn_(false),
pby_offset_(0),
@ -85,11 +89,17 @@ loadscreen::loadscreen(CVideo &screen, const int percent):
ERR_DP << "loadscreen: Failed to load the logo" << std::endl;
}
#else
#ifdef SDL_GPU
surface surf = image::get_image("misc/logo.png");
logo_image_ = GPU_CopyImageFromSurface(surf);
if (logo_image_ == NULL) {
ERR_DP << "loadscreen: Failed to load the logo" << std::endl;
}
#else
if (logo_surface_.null()) {
ERR_DP << "loadscreen: Failed to load the logo" << std::endl;
}
#endif
#endif
textarea_.x = textarea_.y = textarea_.w = textarea_.h = 0;
}
@ -208,6 +218,7 @@ void loadscreen::draw_screen(const std::string &text)
}
CVideo::get_window()->render();
#else
#ifdef SDL_GPU
int x1, y1, x2, y2;
// Pump events and make sure to redraw the logo if there's a chance that it's been obscured
@ -317,6 +328,90 @@ void loadscreen::draw_screen(const std::string &text)
}
GPU_Flip(get_render_target());
#else
surface gdis = screen_.getSurface();
SDL_Rect area;
// Pump events and make sure to redraw the logo if there's a chance that it's been obscured
SDL_Event ev;
while(SDL_PollEvent(&ev)) {
if(ev.type == SDL_VIDEORESIZE || ev.type == SDL_VIDEOEXPOSE)
{
logo_drawn_ = false;
}
}
// Draw logo if it was successfully loaded.
if (logo_surface_ && !logo_drawn_) {
area.x = (screen_.getx () - logo_surface_->w) / 2;
area.y = ((scry - logo_surface_->h) / 2) - pbh;
area.w = logo_surface_->w;
area.h = logo_surface_->h;
// Check if we have enough pixels to display it.
if (area.x > 0 && area.y > 0) {
pby_offset_ = (pbh + area.h)/2;
sdl_blit(logo_surface_, 0, gdis, &area);
} else {
if (!screen_.faked()) { // Avoid error if --nogui is used.
ERR_DP << "loadscreen: Logo image is too big." << std::endl;
}
}
logo_drawn_ = true;
update_rect(area.x, area.y, area.w, area.h);
}
int pbx = (scrx - pbw)/2; // Horizontal location.
int pby = (scry - pbh)/2 + pby_offset_; // Vertical location.
// Draw top border.
area.x = pbx; area.y = pby;
area.w = pbw + 2*(bw+bispw); area.h = bw;
sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
// Draw bottom border.
area.x = pbx; area.y = pby + pbh + bw + 2*bispw;
area.w = pbw + 2*(bw+bispw); area.h = bw;
sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
// Draw left border.
area.x = pbx; area.y = pby + bw;
area.w = bw; area.h = pbh + 2*bispw;
sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
// Draw right border.
area.x = pbx + pbw + bw + 2*bispw; area.y = pby + bw;
area.w = bw; area.h = pbh + 2*bispw;
sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
// Draw the finished bar area.
area.x = pbx + bw + bispw; area.y = pby + bw + bispw;
area.w = (prcnt_ * pbw) / 100; area.h = pbh;
sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,fcr,fcg,fcb));
SDL_Rect lightning = area;
lightning.h = lightning_thickness;
//we add 25% of white to the color of the bar to simulate a light effect
sdl::fill_rect(gdis,&lightning,SDL_MapRGB(gdis->format,(fcr*3+255)/4,(fcg*3+255)/4,(fcb*3+255)/4));
lightning.y = area.y+area.h-lightning.h;
//remove 50% of color to simulate a shadow effect
sdl::fill_rect(gdis,&lightning,SDL_MapRGB(gdis->format,fcr/2,fcg/2,fcb/2));
// Draw the leftover bar area.
area.x = pbx + bw + bispw + (prcnt_ * pbw) / 100; area.y = pby + bw + bispw;
area.w = ((100 - prcnt_) * pbw) / 100; area.h = pbh;
sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,lcr,lcg,lcb));
// Clear the last text and draw new if text is provided.
if (!text.empty())
{
SDL_Rect oldarea = textarea_;
sdl::fill_rect(gdis,&textarea_,SDL_MapRGB(gdis->format,0,0,0));
textarea_ = font::line_size(text, font::SIZE_NORMAL);
textarea_.x = scrx/2 + bw + bispw - textarea_.w / 2;
textarea_.y = pby + pbh + 4*(bw + bispw);
textarea_ = font::draw_text(&screen_,textarea_,font::SIZE_NORMAL,font::NORMAL_COLOR,text,textarea_.x,textarea_.y);
SDL_Rect refresh = sdl::union_rects(oldarea, textarea_);
update_rect(refresh.x, refresh.y, refresh.w, refresh.h);
}
// Update the rectangle.
update_rect(pbx, pby, pbw + 2*(bw + bispw), pbh + 2*(bw + bispw));
screen_.flip();
#endif
#endif
}
@ -325,7 +420,18 @@ void loadscreen::clear_screen()
#if SDL_VERSION_ATLEAST(2,0,0)
CVideo::get_window()->fill(0,0,0);
#else
#ifdef SDL_GPU
GPU_Clear(get_render_target());
#else
int scrx = screen_.getx(); // Screen width.
int scry = screen_.gety(); // Screen height.
SDL_Rect area = sdl::create_rect(0, 0, scrx, scry); // Screen area.
surface disp(screen_.getSurface()); // Screen surface.
// Make everything black.
sdl::fill_rect(disp,&area,SDL_MapRGB(disp->format,0,0,0));
update_whole_screen();
screen_.flip();
#endif
#endif
}

View file

@ -82,7 +82,11 @@ private:
#if SDL_VERSION_ATLEAST(2,0,0)
sdl::ttexture logo_texture_;
#else
#ifdef SDL_GPU
GPU_Image *logo_image_;
#else
surface logo_surface_;
#endif
#endif
bool logo_drawn_;
int pby_offset_;