Loadscreen Progressbar:

added inner spacing for border and changed colors to wesnoth theme as
requested by Eleazar

(http://www.wesnoth.org/forum/viewtopic.php?t=10971)

Also: Minor fix for compilation warning of template re-instantiation
This commit is contained in:
Patrick Parker 2006-04-23 22:45:33 +00:00
parent eefce86054
commit a7671a2adb
5 changed files with 82 additions and 49 deletions

View File

@ -283,8 +283,8 @@ int animated<T,T_void_value>::get_last_frame_time() const
// Force compilation of the following template instantiations
#include "unit_frame.hpp"
#include "image.hpp"
#include "unit_types.hpp"
template class animated< image::locator >;
template class animated< std::string >;

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2005 by Joeri Melis <joeri_melis@hotmail.com>
Copyright (C) 2005 by Joeri Melis <joeri_melis@hotmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
@ -25,13 +25,14 @@ void loadscreen::set_progress(const int percentage, const std::string &text, con
/* Saturate percentage. */
prcnt_ = percentage < MIN_PERCENTAGE ? MIN_PERCENTAGE: percentage > MAX_PERCENTAGE ? MAX_PERCENTAGE: percentage;
/* Set progress bar parameters. */
int fcr = 0, fcg = 0, fcb = 255; /* Finished piece. */
int lcr = 0, lcg = 0, lcb = 63; /* Leftover piece. */
int bcr = 255, bcg = 255, bcb = 255; /* Border color. */
int bw = 5; /* Border width. */
bw = 2*bw > screen_.getx() ? 0: 2*bw > screen_.gety() ? 0: bw;
int scrx = screen_.getx() - 2*bw; /* Available width. */
int scry = screen_.gety() - 2*bw; /* Available height. */
int fcr = 103, fcg = 11, fcb = 10; /* Finished piece. */
int lcr = 24, lcg = 22, lcb = 21; /* Leftover piece. */
int bcr = 188, bcg = 176, bcb = 136; /* Border color. */
int bw = 1; /* Border width. */
int bispw = 1; /* Border inner spacing width. */
bw = 2*(bw+bispw) > screen_.getx() ? 0: 2*(bw+bispw) > screen_.gety() ? 0: bw;
int scrx = screen_.getx() - 2*(bw+bispw); /* Available width. */
int scry = screen_.gety() - 2*(bw+bispw); /* Available height. */
int pbw = scrx/2; /* Used width. */
int pbh = scry/16; /* Used heigth. */
int pbx = (scrx - pbw)/2; /* Horizontal location. */
@ -40,26 +41,26 @@ void loadscreen::set_progress(const int percentage, const std::string &text, con
SDL_Rect area;
/* Draw top border. */
area.x = pbx; area.y = pby;
area.w = pbw + 2*bw; area.h = bw;
area.w = pbw + 2*(bw+bispw); area.h = bw;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
/* Draw bottom border. */
area.x = pbx; area.y = pby + pbh + bw;
area.w = pbw + 2*bw; area.h = bw;
area.x = pbx; area.y = pby + pbh + bw + 2*bispw;
area.w = pbw + 2*(bw+bispw); area.h = bw;
SDL_FillRect(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;
area.w = bw; area.h = pbh + 2*bispw;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
/* Draw right border. */
area.x = pbx + pbw + bw; area.y = pby + bw;
area.w = bw; area.h = pbh;
area.x = pbx + pbw + bw + 2*bispw; area.y = pby + bw;
area.w = bw; area.h = pbh + 2*bispw;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
/* Draw the finished bar area. */
area.x = pbx + bw; area.y = pby + bw;
area.x = pbx + bw + bispw; area.y = pby + bw + bispw;
area.w = (prcnt_ * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.h = pbh;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,fcr,fcg,fcb));
/* Draw the leftover bar area. */
area.x = pbx + bw + (prcnt_ * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.y = pby + bw;
area.x = pbx + bw + bispw + (prcnt_ * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.y = pby + bw + bispw;
area.w = ((MAX_PERCENTAGE - prcnt_) * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.h = pbh;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,lcr,lcg,lcb));
/* Clear the last text and draw new if text is provided. */
@ -67,8 +68,8 @@ void loadscreen::set_progress(const int percentage, const std::string &text, con
{
SDL_FillRect(gdis,&textarea_,SDL_MapRGB(gdis->format,0,0,0));
textarea_ = font::line_size(text, font::SIZE_NORMAL);
textarea_.x = scrx/2 + bw - textarea_.w / 2;
textarea_.y = pby + pbh + 4*bw;
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_COLOUR,text,textarea_.x,textarea_.y);
}
/* Flip the double buffering so the change becomes visible */

View File

@ -29,6 +29,9 @@
#include <vector>
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
# undef INADDR_ANY
# undef INADDR_BROADCAST
# undef INADDR_NONE
# include <windows.h>
# define USE_SELECT 1
#else

View File

@ -21,37 +21,9 @@
#include <string>
#include <vector>
#include "unit_frame.hpp"
//a class to describe a unit's animation sequence
struct unit_frame {
unit_frame() : xoffset(0), image(), image_diagonal(),halo(), sound(),
halo_x(0), halo_y(0), begin_time(0), end_time(0),
blend_with(0),blend_ratio(0),
highlight_ratio(ftofxp(1)){}
explicit unit_frame(const std::string& str, const std::string & diag ="",
int begin=0,int end = 0,
Uint32 blend_color = 0, double blend_rate = 0.0,
fixed_t highlight = ftofxp(1),
std::string in_halo = "",int halox = 0,int haloy = 0) :
xoffset(0), image(str),image_diagonal(diag),
halo_x(halox), halo_y(haloy),
begin_time(begin), end_time(end),
blend_with(blend_color), blend_ratio(blend_rate),
highlight_ratio(highlight) {halo = prepare_halo(in_halo,begin,end);};
explicit unit_frame(const config& cfg);
int xoffset;
std::string image;
std::string image_diagonal;
std::vector<std::pair<std::string,int> > halo;
std::string sound;
int halo_x, halo_y;
int begin_time, end_time;
Uint32 blend_with;
double blend_ratio;
fixed_t highlight_ratio;
static std::vector<std::pair<std::string,int> > prepare_halo(const std::string & halo,int begin, int end);
};
class unit_animation:public animated<unit_frame>
{
public:

57
src/unit_frame.hpp Normal file
View File

@ -0,0 +1,57 @@
/* $Id: unit_frame.hpp 9700 2006-01-15 12:00:53Z noyga $ */
/*
Copyright (C) 2006 by Jeremy Rosen <jeremy.rosen@enst-bretagne.fr>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef UNIT_FRAME_H_INCLUDED
#define UNIT_FRAME_H_INCLUDED
#include "animated.hpp"
#include "map.hpp"
#include "config.hpp"
#include "util.hpp"
#include "serialization/string_utils.hpp"
#include <string>
#include <vector>
//a class to describe a unit's animation sequence
struct unit_frame {
unit_frame() : xoffset(0), image(), image_diagonal(),halo(), sound(),
halo_x(0), halo_y(0), begin_time(0), end_time(0),
blend_with(0),blend_ratio(0),
highlight_ratio(ftofxp(1)){}
explicit unit_frame(const std::string& str, const std::string & diag ="",
int begin=0,int end = 0,
Uint32 blend_color = 0, double blend_rate = 0.0,
fixed_t highlight = ftofxp(1),
std::string in_halo = "",int halox = 0,int haloy = 0) :
xoffset(0), image(str),image_diagonal(diag),
halo_x(halox), halo_y(haloy),
begin_time(begin), end_time(end),
blend_with(blend_color), blend_ratio(blend_rate),
highlight_ratio(highlight) {halo = prepare_halo(in_halo,begin,end);};
explicit unit_frame(const config& cfg);
int xoffset;
std::string image;
std::string image_diagonal;
std::vector<std::pair<std::string,int> > halo;
std::string sound;
int halo_x, halo_y;
int begin_time, end_time;
Uint32 blend_with;
double blend_ratio;
fixed_t highlight_ratio;
static std::vector<std::pair<std::string,int> > prepare_halo(const std::string & halo,int begin, int end);
};
#endif