Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/wesnoth/wesnoth
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 17, 2014
2 parents 1cc51de + 050235c commit 8106be9
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 73 deletions.
25 changes: 20 additions & 5 deletions src/image.cpp
Expand Up @@ -128,7 +128,8 @@ image::image_cache images_,
#if SDL_VERSION_ATLEAST(2,0,0)
/** Rexture caches */
image::texture_cache txt_images_,
txt_hexed_images_;
txt_hexed_images_,
txt_brightened_images_;
#endif

// cache storing if each image fit in a hex
Expand Down Expand Up @@ -910,16 +911,31 @@ sdl::ttexture get_texture(const locator& loc, TYPE type)

texture_cache *cache;

if (type == UNSCALED || type == SCALED_TO_ZOOM) {
switch (type) {
case UNSCALED:
case SCALED_TO_ZOOM:
cache = &txt_images_;
} else {
break;
case BRIGHTENED:
cache = &txt_brightened_images_;
break;
case HEXED:
case SCALED_TO_HEX:
case TOD_COLORED:
cache = &txt_hexed_images_;
break;
default:
return sdl::ttexture();
}

if (!loc.in_cache(*cache)) {
if (type == UNSCALED || type == SCALED_TO_ZOOM) {
sdl::ttexture txt = load_texture(loc);
loc.add_to_cache(*cache, txt);
} else if (type == BRIGHTENED) {
surface surf = get_brightened(loc);
sdl::ttexture txt = CVideo::get_window()->create_texture(SDL_TEXTUREACCESS_STATIC, surf);
loc.add_to_cache(*cache, txt);
} else {
surface surf = get_hexed(loc);
sdl::ttexture txt = CVideo::get_window()->create_texture(SDL_TEXTUREACCESS_STATIC, surf);
Expand All @@ -932,9 +948,8 @@ sdl::ttexture get_texture(const locator& loc, TYPE type)
switch (type) {
case UNSCALED:
case HEXED:
break;
case BRIGHTENED:
//TODO: brighten
break;
case TOD_COLORED:
result.set_color_mod(red_adjust, green_adjust, blue_adjust);
case SCALED_TO_ZOOM:
Expand Down
89 changes: 76 additions & 13 deletions src/loadscreen.cpp
Expand Up @@ -28,6 +28,10 @@
#include "video.hpp"
#include "image.hpp"

#if SDL_VERSION_ATLEAST(2,0,0)
#include "text.hpp"
#endif

#include <SDL_events.h>
#include <SDL_image.h>

Expand Down Expand Up @@ -116,44 +120,106 @@ void loadscreen::draw_screen(const std::string &text)
// Height of the lighting line.
int lightning_thickness = 2;

surface gdis = screen_.getSurface();
#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 SDL_VERSION_ATLEAST(2, 0, 0)
if(ev.type == SDL_WINDOWEVENT
&& (ev.window.event == SDL_WINDOWEVENT_RESIZED
|| ev.window.event == SDL_WINDOWEVENT_EXPOSED))
#else
if(ev.type == SDL_VIDEORESIZE || ev.type == SDL_VIDEOEXPOSE)
#endif
{
logo_drawn_ = false;
}
}

// Draw logo if it was successfully loaded.
#if SDL_VERSION_ATLEAST(2,0,0)
static int angle = 0;
if (!logo_texture_.null() /*&& !logo_drawn_*/) {
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;
CVideo::get_window()->draw(logo_texture_, x, y);
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;
logo_texture_.set_rotation(angle+=3);
}
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
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;
Expand All @@ -171,7 +237,6 @@ void loadscreen::draw_screen(const std::string &text)
logo_drawn_ = true;
update_rect(area.x, area.y, area.w, area.h);
}
#endif
int pbx = (scrx - pbw)/2; // Horizontal location.
int pby = (scry - pbh)/2 + pby_offset_; // Vertical location.

Expand Down Expand Up @@ -224,8 +289,6 @@ void loadscreen::draw_screen(const std::string &text)
// Update the rectangle.
update_rect(pbx, pby, pbw + 2*(bw + bispw), pbh + 2*(bw + bispw));
screen_.flip();
#if SDL_VERSION_ATLEAST(2,0,0)
CVideo::get_window()->render();
#endif
}

Expand Down
8 changes: 4 additions & 4 deletions src/sdl/rect.cpp
Expand Up @@ -112,15 +112,15 @@ void draw_solid_tinted_rectangle(int x, int y, int w, int h,


#if SDL_VERSION_ATLEAST(2,0,0)
void fill_rect(SDL_Renderer *rnd, SDL_Rect *rect, Uint8 r, Uint8 g, Uint8 b,
Uint8 a)
void fill_rect(SDL_Renderer *rnd, const SDL_Rect *rect, Uint8 r, Uint8 g,
Uint8 b, Uint8 a)
{
SDL_SetRenderDrawColor(rnd, r, g, b, a);
SDL_RenderFillRect(rnd, rect);
}

void draw_rect(SDL_Renderer *rnd, SDL_Rect *rect, Uint8 r, Uint8 g, Uint8 b,
Uint8 a)
void draw_rect(SDL_Renderer *rnd, const SDL_Rect *rect, Uint8 r, Uint8 g,
Uint8 b, Uint8 a)
{
SDL_SetRenderDrawColor(rnd, r, g, b, a);
SDL_RenderDrawRect(rnd, rect);
Expand Down
4 changes: 2 additions & 2 deletions src/sdl/rect.hpp
Expand Up @@ -142,10 +142,10 @@ inline void fill_rect(surface& dst, SDL_Rect* dst_rect, const Uint32 color)
}

#if SDL_VERSION_ATLEAST(2,0,0)
void fill_rect(SDL_Renderer &rnd, const SDL_Rect *rect, Uint8 r, Uint8 g,
void fill_rect(SDL_Renderer *rnd, const SDL_Rect *rect, Uint8 r, Uint8 g,
Uint8 b, Uint8 a);

void draw_rect(SDL_Renderer &rnd, const SDL_Rect *rect, Uint8 r, Uint8 g,
void draw_rect(SDL_Renderer *rnd, const SDL_Rect *rect, Uint8 r, Uint8 g,
Uint8 b, Uint8 a);
#endif
} // namespace sdl
Expand Down
68 changes: 33 additions & 35 deletions src/sdl/texture.cpp
Expand Up @@ -40,11 +40,13 @@ ttexture::ttexture(SDL_Renderer& renderer,
, smooth_scaling_(false)
, flip_(SDL_FLIP_NONE)
, clip_(create_rect(0, 0, w, h))
, mod_r_(0)
, mod_g_(0)
, mod_b_(0)
, mod_r_(255)
, mod_g_(255)
, mod_b_(255)
, alpha_(255)
, source_surface_(NULL)
{
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
if(!texture_) {
throw texception("Failed to create a SDL_Texture object.", true);
}
Expand All @@ -61,9 +63,10 @@ ttexture::ttexture(SDL_Renderer& renderer,
, smooth_scaling_(false)
, flip_(SDL_FLIP_NONE)
, clip_()
, mod_r_(0)
, mod_g_(0)
, mod_b_(0)
, mod_r_(255)
, mod_g_(255)
, mod_b_(255)
, alpha_(255)
, source_surface_(IMG_Load(file.c_str()))
{
if(source_surface_ == NULL) {
Expand All @@ -83,9 +86,10 @@ ttexture::ttexture()
, smooth_scaling_(false)
, flip_(SDL_FLIP_NONE)
, clip_()
, mod_r_(0)
, mod_g_(0)
, mod_b_(0)
, mod_r_(255)
, mod_g_(255)
, mod_b_(255)
, alpha_(255)
, source_surface_(NULL)
{}

Expand Down Expand Up @@ -117,6 +121,7 @@ ttexture::ttexture(const ttexture& texture)
, mod_r_(texture.mod_r_)
, mod_g_(texture.mod_g_)
, mod_b_(texture.mod_b_)
, alpha_(texture.alpha_)
, source_surface_(texture.source_surface_)
{
assert(reference_count_);
Expand All @@ -137,9 +142,10 @@ ttexture::ttexture(SDL_Renderer& renderer,
, smooth_scaling_(false)
, flip_(SDL_FLIP_NONE)
, clip_()
, mod_r_(0)
, mod_g_(0)
, mod_b_(0)
, mod_r_(255)
, mod_g_(255)
, mod_b_(255)
, alpha_(255)
, source_surface_(source_surface__)
{
if(source_surface_ == NULL) {
Expand All @@ -162,9 +168,10 @@ ttexture::ttexture(SDL_Renderer& renderer,
, smooth_scaling_(false)
, flip_(SDL_FLIP_NONE)
, clip_()
, mod_r_(0)
, mod_g_(0)
, mod_b_(0)
, mod_r_(255)
, mod_g_(255)
, mod_b_(255)
, alpha_(255)
, source_surface_(
SDL_ConvertSurface(surface, surface->format, surface->flags))
{
Expand All @@ -191,6 +198,8 @@ void ttexture::draw(SDL_Renderer& renderer, const int x, const int y)
{
SDL_Rect dstrect = create_rect(x, y, clip_.w * hscale_, clip_.h * vscale_);

SDL_SetTextureAlphaMod(texture_, alpha_);
SDL_SetTextureColorMod(texture_, mod_r_, mod_g_, mod_b_);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, smooth_scaling_ ? "linear" : "nearest");
SDL_RenderCopyEx(&renderer, texture_, &clip_, &dstrect,
rotation_, NULL, flip_);
Expand Down Expand Up @@ -275,20 +284,20 @@ bool ttexture::flopped() const
return flip_ & SDL_FLIP_VERTICAL;
}

unsigned ttexture::width() const
int ttexture::width() const
{
int w;
SDL_QueryTexture(texture_,NULL, NULL, &w, NULL);

return w;
return w*hscale_;
}

unsigned ttexture::height() const
int ttexture::height() const
{
int h;
SDL_QueryTexture(texture_,NULL, NULL, NULL, &h);

return h;
return h*vscale_;
}

SDL_Rect ttexture::dimensions() const
Expand All @@ -298,6 +307,8 @@ SDL_Rect ttexture::dimensions() const
dim.y = 0;
SDL_QueryTexture(texture_, NULL, NULL, &dim.w, &dim.h);

dim.w *= hscale_;
dim.h *= vscale_;
return dim;
}

Expand All @@ -321,26 +332,12 @@ Uint32 ttexture::format() const

void ttexture::set_alpha(Uint8 alpha)
{
SDL_SetTextureAlphaMod(texture_, alpha);
alpha_ = alpha;
}

Uint8 ttexture::alpha() const
{
Uint8 res;
SDL_GetTextureAlphaMod(texture_, &res);
return res;
}

void ttexture::set_blend_mode(SDL_BlendMode mode)
{
SDL_SetTextureBlendMode(texture_, mode);
}

SDL_BlendMode ttexture::blend_mode() const
{
SDL_BlendMode res;
SDL_GetTextureBlendMode(texture_, &res);
return res;
return alpha_;
}

void ttexture::set_color_mod(Uint8 r, Uint8 g, Uint8 b)
Expand Down Expand Up @@ -424,6 +421,7 @@ void ttexture::initialise_from_surface(SDL_Renderer& renderer, const int access)
} else {
throw texception("Unknown texture access mode.", false);
}
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
}

} // namespace sdl
Expand Down

0 comments on commit 8106be9

Please sign in to comment.