moved help_string stuff from display to video

This commit is contained in:
Yann Dirson 2005-03-16 20:50:12 +00:00
parent 8e160681bc
commit 3d60db811d
6 changed files with 53 additions and 53 deletions

View file

@ -79,7 +79,7 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
theme_(theme_cfg,screen_area()), builder_(cfg, level, map),
first_turn_(true), in_game_(false), map_labels_(*this,map),
tod_hex_mask1(NULL), tod_hex_mask2(NULL), diagnostic_label_(0),
help_string_(0), fps_handle_(0)
fps_handle_(0)
{
if(non_interactive())
updatesLocked_++;
@ -2156,41 +2156,6 @@ void display::begin_game()
create_buttons();
}
int display::set_help_string(const std::string& str)
{
font::remove_floating_label(help_string_);
const SDL_Color colour = {0x0,0x00,0x00,0x77};
int size = font::SIZE_LARGE;
while(size > 0) {
if(font::line_width(str, size) > x()) {
size--;
} else {
break;
}
}
help_string_ = font::add_floating_label(str,size,font::NORMAL_COLOUR,x()/2,y(),0.0,0.0,-1,screen_area(),font::CENTER_ALIGN,&colour,5);
const SDL_Rect& rect = font::get_floating_label_rect(help_string_);
font::move_floating_label(help_string_,0.0,-double(rect.h));
return help_string_;
}
void display::clear_help_string(int handle)
{
if(handle == help_string_) {
font::remove_floating_label(handle);
help_string_ = 0;
}
}
void display::clear_all_help_strings()
{
clear_help_string(help_string_);
}
void display::create_buttons()
{
buttons_.clear();

View file

@ -352,13 +352,6 @@ public:
bool in_game() const { return in_game_; }
//functions to set and clear 'help strings'. A 'help string' is like a tooltip, but it appears
//at the bottom of the screen, so as to not be intrusive. Setting a help string sets what
//is currently displayed there.
int set_help_string(const std::string& str);
void clear_help_string(int handle);
void clear_all_help_strings();
private:
display(const display&);
void operator=(const display&);
@ -503,9 +496,6 @@ private:
int diagnostic_label_;
//variables for help strings
int help_string_;
//animated flags for each team
std::vector<animated<image::locator> > flags_;

View file

@ -202,7 +202,7 @@ void update_whole_screen()
{
update_all = true;
}
CVideo::CVideo() : bpp(0), fake_screen(false)
CVideo::CVideo() : bpp(0), fake_screen(false), help_string_(0)
{
const int res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
@ -213,7 +213,7 @@ CVideo::CVideo() : bpp(0), fake_screen(false)
}
CVideo::CVideo( int x, int y, int bits_per_pixel, int flags)
: bpp(0), fake_screen(false)
: bpp(0), fake_screen(false), help_string_(0)
{
const int res = SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
if(res < 0) {
@ -385,3 +385,38 @@ int CVideo::getBpp( void )
{
return bpp;
}
int CVideo::set_help_string(const std::string& str)
{
font::remove_floating_label(help_string_);
const SDL_Color colour = {0x0,0x00,0x00,0x77};
int size = font::SIZE_LARGE;
while(size > 0) {
if(font::line_width(str, size) > getx()) {
size--;
} else {
break;
}
}
help_string_ = font::add_floating_label(str,size,font::NORMAL_COLOUR,getx()/2,gety(),0.0,0.0,-1,screen_area(),font::CENTER_ALIGN,&colour,5);
const SDL_Rect& rect = font::get_floating_label_rect(help_string_);
font::move_floating_label(help_string_,0.0,-double(rect.h));
return help_string_;
}
void CVideo::clear_help_string(int handle)
{
if(handle == help_string_) {
font::remove_floating_label(handle);
help_string_ = 0;
}
}
void CVideo::clear_all_help_strings()
{
clear_help_string(help_string_);
}

View file

@ -78,6 +78,13 @@ class CVideo {
void make_fake();
//functions to set and clear 'help strings'. A 'help string' is like a tooltip, but it appears
//at the bottom of the screen, so as to not be intrusive. Setting a help string sets what
//is currently displayed there.
int set_help_string(const std::string& str);
void clear_help_string(int handle);
void clear_all_help_strings();
private:
bool mode_changed_;
@ -86,6 +93,9 @@ private:
//if there is no display at all, but we 'fake' it for clients
bool fake_screen;
//variables for help strings
int help_string_;
};
#endif

View file

@ -568,11 +568,11 @@ void menu::process_help_string(int mousex, int mousey)
if(loc == cur_help_) {
return;
} else if(loc.first == -1) {
disp().clear_help_string(help_string_);
video().clear_help_string(help_string_);
help_string_ = -1;
} else {
if(help_string_ != -1) {
disp().clear_help_string(help_string_);
video().clear_help_string(help_string_);
help_string_ = -1;
}
@ -582,7 +582,7 @@ void menu::process_help_string(int mousex, int mousey)
const std::string& help = row[loc.second];
if(help.empty() == false) {
//std::cerr << "setting help string from menu to '" << help << "'\n";
help_string_ = disp().set_help_string(help);
help_string_ = video().set_help_string(help);
}
}
}

View file

@ -243,10 +243,10 @@ void widget::process_help_string(int mousex, int mousey)
if (!hidden() && point_in_rect(mousex, mousey, rect_)) {
if(help_string_ == 0 && help_text_ != "") {
//std::cerr << "setting help string to '" << help_text_ << "'\n";
help_string_ = disp().set_help_string(help_text_);
help_string_ = video().set_help_string(help_text_);
}
} else if(help_string_ > 0) {
disp().clear_help_string(help_string_);
video().clear_help_string(help_string_);
help_string_ = 0;
}
}