The Battle for Wesnoth  1.15.0-dev
floating_label.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://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 "color.hpp"
18 #include "sdl/surface.hpp"
19 #include <string>
20 
21 namespace font {
22 
23 /// structure which will hide all current floating labels, and cause floating labels
24 /// instantiated after it is created to be displayed
26 {
29 };
30 
32 
34 
36 {
37 public:
38  floating_label(const std::string& text, const surface& surface = nullptr);
39 
40  void set_font_size(int font_size) {font_size_ = font_size;}
41 
42  // set the location on the screen to display the text.
43  void set_position(double xpos, double ypos){
44  xpos_ = xpos;
45  ypos_ = ypos;
46  }
47  // set the amount to move the text each frame
48  void set_move(double xmove, double ymove){
49  xmove_ = xmove;
50  ymove_ = ymove;
51  }
52  // set the number of frames to display the text for, or -1 to display until removed
53  void set_lifetime(int lifetime) {
54  lifetime_ = lifetime;
55  alpha_change_ = -255 / lifetime_;
56  }
57  void set_color(const color_t& color) {color_ = color;}
58  void set_bg_color(const color_t& bg_color) {
59  bgcolor_ = bg_color;
60  bgalpha_ = bg_color.a;
61  }
62  void set_border_size(int border) {border_ = border;}
63  // set width for word wrapping (use -1 to disable it)
64  void set_width(int w) {width_ = w;}
65  void set_height(int h) { height_ = h; }
66  void set_clip_rect(const SDL_Rect& r) {clip_rect_ = r;}
67  void set_alignment(ALIGN align) {align_ = align;}
68  void set_scroll_mode(LABEL_SCROLL_MODE scroll) {scroll_ = scroll;}
69  void use_markup(bool b) {use_markup_ = b;}
70 
71  void move(double xmove, double ymove);
72  void draw(surface screen);
73  void undraw(surface screen);
74 
75  surface create_surface();
76 
77  bool expired() const { return lifetime_ == 0; }
78 
79  void show(const bool value) { visible_ = value; }
80 
81  LABEL_SCROLL_MODE scroll() const { return scroll_; }
82 
83 private:
84 
85  int xpos(std::size_t width) const;
86  surface surf_, buf_;
87  std::string text_;
89  color_t color_, bgcolor_;
90  int bgalpha_;
91  double xpos_, ypos_, xmove_, ymove_;
92  int lifetime_;
93  int width_, height_;
94  SDL_Rect clip_rect_;
96  bool visible_;
98  int border_;
101 };
102 
103 
104 /// add a label floating on the screen above everything else.
105 /// @returns a handle to the label which can be used with other label functions
106 
107 int add_floating_label(const floating_label& flabel);
108 
109 
110 /// moves the floating label given by 'handle' by (xmove,ymove)
111 void move_floating_label(int handle, double xmove, double ymove);
112 
113 /// moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP
114 void scroll_floating_labels(double xmove, double ymove);
115 
116 /// removes the floating label given by 'handle' from the screen
117 void remove_floating_label(int handle);
118 
119 /// hides or shows a floating label
120 void show_floating_label(int handle, bool show);
121 
122 SDL_Rect get_floating_label_rect(int handle);
123 void draw_floating_labels(surface screen);
124 void undraw_floating_labels(surface screen);
125 
126 } // end namespace font
void set_move(double xmove, double ymove)
void set_clip_rect(const SDL_Rect &r)
Note: Specific to sdl_ttf.
void scroll_floating_labels(double xmove, double ymove)
moves all floating labels that have &#39;scroll_mode&#39; set to ANCHOR_LABEL_MAP
void show_floating_label(int handle, bool value)
hides or shows a floating label
void remove_floating_label(int handle)
removes the floating label given by &#39;handle&#39; from the screen
#define h
void set_font_size(int font_size)
void show(const bool value)
void move_floating_label(int handle, double xmove, double ymove)
moves the floating label given by &#39;handle&#39; by (xmove,ymove)
#define b
void set_alignment(ALIGN align)
LABEL_SCROLL_MODE scroll() const
void set_lifetime(int lifetime)
void set_bg_color(const color_t &bg_color)
uint8_t a
Alpha value.
Definition: color.hpp:186
void set_position(double xpos, double ypos)
void set_color(const color_t &color)
void set_scroll_mode(LABEL_SCROLL_MODE scroll)
structure which will hide all current floating labels, and cause floating labels instantiated after i...
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)
int w
void set_border_size(int border)
LABEL_SCROLL_MODE scroll_
const int font_size
Definition: button.cpp:40
std::shared_ptr< halo_record > handle
Definition: halo.hpp:31
void draw_floating_labels(surface screen)
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
Definition: tooltip.cpp:154