Skip to content

Commit

Permalink
Remove SDL2-specific parts from loadscreen.
Browse files Browse the repository at this point in the history
  • Loading branch information
lipk committed Jul 1, 2014
1 parent c2d7265 commit fe1aae7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 110 deletions.
102 changes: 0 additions & 102 deletions src/loadscreen.cpp
Expand Up @@ -71,24 +71,15 @@ void loadscreen::global_loadscreen_manager::reset()
loadscreen::loadscreen(CVideo &screen, const int percent):
screen_(screen),
textarea_(),
#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),
prcnt_(percent)
{
#if SDL_VERSION_ATLEAST(2,0,0)
if (logo_texture_.null()) {
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);
Expand All @@ -99,7 +90,6 @@ loadscreen::loadscreen(CVideo &screen, const int percent):
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;
}
Expand Down Expand Up @@ -131,93 +121,6 @@ void loadscreen::draw_screen(const std::string &text)
// Height of the lighting line.
int lightning_thickness = 2;

#if SDL_VERSION_ATLEAST(2,0,0)
sdl::twindow *wnd = CVideo::get_window();
SDL_Renderer *rnd = SDL_GetRenderer(*wnd);

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_WINDOWEVENT
&& (ev.window.event == SDL_WINDOWEVENT_RESIZED
|| ev.window.event == SDL_WINDOWEVENT_EXPOSED))
{
logo_drawn_ = false;
}
}

// Draw logo if it was successfully loaded.
if (!logo_texture_.null() && !logo_drawn_) {
int x = (screen_.getx () - logo_texture_.width()) / 2;
int y = ((scry - logo_texture_.height()) / 2) - pbh;

// Check if we have enough pixels to display it.
if (x > 0 && y > 0) {
pby_offset_ = (pbh + logo_texture_.height())/2;
wnd->draw(logo_texture_, x, y);
} else {
if (!screen_.faked()) { // Avoid error if --nogui is used.
ERR_DP << "loadscreen: Logo image is too big." << std::endl;
}
}
logo_drawn_ = true;
}
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(rnd,&area,bcr,bcg,bcb,255);
// 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(rnd,&area,bcr,bcg,bcb,255);
// Draw left border.
area.x = pbx; area.y = pby + bw;
area.w = bw; area.h = pbh + 2*bispw;
sdl::fill_rect(rnd,&area,bcr,bcg,bcb,255);
// 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(rnd,&area,bcr,bcg,bcb,255);
// 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(rnd,&area,fcr,fcg,fcb,255);

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(rnd,&lightning,(fcr*3+255)/4,(fcg*3+255)/4,(fcb*3+255)/4,255);
lightning.y = area.y+area.h-lightning.h;
//remove 50% of color to simulate a shadow effect
sdl::fill_rect(rnd,&lightning,fcr/2,fcg/2,fcb/2,255);

// 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(rnd, &area, lcr, lcg, lcb, 255);

// Clear the last text and draw new if text is provided.
if (!text.empty())
{
sdl::fill_rect(rnd, &textarea_, 0, 0, 0, 255);

font::ttext txt;
txt.set_text(text, false);
// A text-ure... haha, get it?
sdl::ttexture texture = txt.render_as_texture();
textarea_.h = texture.height();
textarea_.w = texture.width();
textarea_.x = scrx/2 + bw + bispw - textarea_.w / 2;
textarea_.y = pby + pbh + 4*(bw + bispw);
wnd->draw(texture, textarea_.x, textarea_.y);
}
CVideo::get_window()->render();
#else
#ifdef SDL_GPU
int x1, y1, x2, y2;

Expand Down Expand Up @@ -412,14 +315,10 @@ void loadscreen::draw_screen(const std::string &text)
update_rect(pbx, pby, pbw + 2*(bw + bispw), pbh + 2*(bw + bispw));
screen_.flip();
#endif
#endif
}

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
Expand All @@ -432,7 +331,6 @@ void loadscreen::clear_screen()
update_whole_screen();
screen_.flip();
#endif
#endif
}

loadscreen *loadscreen::global_loadscreen = 0;
Expand Down
8 changes: 0 additions & 8 deletions src/loadscreen.hpp
Expand Up @@ -22,10 +22,6 @@ class CVideo;
#include "sdl/utils.hpp"
#include "sdl/gpu.hpp"

#if SDL_VERSION_ATLEAST(2,0,0)
#include "sdl/texture.hpp"
#endif

class loadscreen {
public:
// Preferred constructor
Expand Down Expand Up @@ -79,14 +75,10 @@ class loadscreen {
// Data members
CVideo &screen_;
SDL_Rect textarea_;
#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_;
Expand Down

0 comments on commit fe1aae7

Please sign in to comment.