The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
floating_label.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "font.hpp"
18 
19 #include "sdl/utils.hpp"
20 #include <string>
21 
22 namespace font {
23 
24 /// structure which will hide all current floating labels, and cause floating labels
25 /// instantiated after it is created to be displayed
27 {
30 };
31 
33 
35 
37 {
38 public:
39  floating_label(const std::string& text, const surface& surface = nullptr);
40 
42 
43  // set the location on the screen to display the text.
44  void set_position(double xpos, double ypos){
45  xpos_ = xpos;
46  ypos_ = ypos;
47  }
48  // set the amount to move the text each frame
49  void set_move(double xmove, double ymove){
50  xmove_ = xmove;
51  ymove_ = ymove;
52  }
53  // set the number of frames to display the text for, or -1 to display until removed
54  void set_lifetime(int lifetime) {
55  lifetime_ = lifetime;
56  alpha_change_ = -255 / lifetime_;
57  }
58  void set_color(const SDL_Color& color) {color_ = color;}
59  void set_bg_color(const SDL_Color& bg_color) {
60  bgcolor_ = bg_color;
61  bgalpha_ = bg_color.a;
62  }
64  // set width for word wrapping (use -1 to disable it)
65  void set_width(int w) {width_ = w;}
66  void set_height(int h) { height_ = h; }
67  void set_clip_rect(const SDL_Rect& r) {clip_rect_ = r;}
68  void set_alignment(ALIGN align) {align_ = align;}
70  void use_markup(bool b) {use_markup_ = b;}
71 
72  void move(double xmove, double ymove);
73 #ifdef SDL_GPU
74  void draw(CVideo &video);
75  void undraw(CVideo &video);
76 #else
77  void draw(surface screen);
78  void undraw(surface screen);
79 #endif
80 
81 #if 0
82  sdl::timage create_image();
83 #else
85 #endif
86 
87  bool expired() const { return lifetime_ == 0; }
88 
89  void show(const bool value) { visible_ = value; }
90 
91  LABEL_SCROLL_MODE scroll() const { return scroll_; }
92 
93 private:
94 
95  int xpos(size_t width) const;
96 #if 0
97  sdl::timage img_;
98 #else
100 #endif
103  SDL_Color color_, bgcolor_;
104  int bgalpha_;
108  SDL_Rect clip_rect_;
110  bool visible_;
112  int border_;
115 };
116 
117 
118 /// add a label floating on the screen above everything else.
119 /// @returns a handle to the label which can be used with other label functions
120 
121 int add_floating_label(const floating_label& flabel);
122 
123 
124 /// moves the floating label given by 'handle' by (xmove,ymove)
125 void move_floating_label(int handle, double xmove, double ymove);
126 
127 /// moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP
128 void scroll_floating_labels(double xmove, double ymove);
129 
130 /// removes the floating label given by 'handle' from the screen
131 void remove_floating_label(int handle);
132 
133 /// hides or shows a floating label
134 void show_floating_label(int handle, bool show);
135 
136 SDL_Rect get_floating_label_rect(int handle);
137 #ifdef SDL_GPU
138 void draw_floating_labels(CVideo &video);
139 void undraw_floating_labels(CVideo &video);
140 #else
143 #endif
144 
145 } // end namespace font
floating_label(const std::string &text, const surface &surface=nullptr)
void set_move(double xmove, double ymove)
void set_clip_rect(const SDL_Rect &r)
Graphical text output.
void set_bg_color(const SDL_Color &bg_color)
void scroll_floating_labels(double xmove, double ymove)
moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP
void show_floating_label(int handle, bool value)
hides or shows a floating label
Definition: video.hpp:58
game_display * screen
Definition: resources.cpp:27
void remove_floating_label(int handle)
removes the floating label given by 'handle' from the screen
#define h
void set_font_size(int font_size)
void move(double xmove, double ymove)
void show(const bool value)
void move_floating_label(int handle, double xmove, double ymove)
moves the floating label given by 'handle' by (xmove,ymove)
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
void set_alignment(ALIGN align)
void set_lifetime(int lifetime)
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
LABEL_SCROLL_MODE scroll() const
GLsizei const GLfloat * value
Definition: glew.h:1817
void set_color(const SDL_Color &color)
void set_position(double xpos, double ypos)
GLuint color
Definition: glew.h:5801
void show(CVideo &video, const std::string &window_id, const t_string &message, const tpoint &mouse)
Shows a tip.
Definition: tip.cpp:133
void set_scroll_mode(LABEL_SCROLL_MODE scroll)
int xpos(size_t width) const
structure which will hide all current floating labels, and cause floating labels instantiated after i...
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:5910
void undraw_floating_labels(surface screen)
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
SDL_Rect get_floating_label_rect(int handle)
GLdouble GLdouble GLdouble r
Definition: glew.h:1374
void set_border_size(int border)
void undraw(surface screen)
GLint GLint GLsizei GLsizei GLsizei GLint border
Definition: glew.h:1222
void draw(surface screen)
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1220
LABEL_SCROLL_MODE scroll_
const int font_size
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void draw_floating_labels(surface screen)
boost::shared_ptr< halo_record > handle
Definition: halo.hpp:34