Floating Label: header formatting updates
This commit is contained in:
parent
8647ff63c0
commit
3bf6768685
2 changed files with 123 additions and 59 deletions
|
@ -47,23 +47,23 @@ namespace font
|
|||
floating_label::floating_label(const std::string& text)
|
||||
: texture_(nullptr)
|
||||
, text_(text)
|
||||
, font_size_(SIZE_NORMAL)
|
||||
, color_(NORMAL_COLOR)
|
||||
, bgcolor_()
|
||||
, current_alpha_(255)
|
||||
, xpos_(0)
|
||||
, ypos_(0)
|
||||
, xmove_(0)
|
||||
, ymove_(0)
|
||||
, lifetime_(-1)
|
||||
, width_(-1)
|
||||
, height_(-1)
|
||||
, clip_rect_(screen_area())
|
||||
, alpha_change_(0)
|
||||
, visible_(true)
|
||||
, align_(CENTER_ALIGN)
|
||||
, font_size_(SIZE_NORMAL)
|
||||
, lifetime_(-1)
|
||||
, border_(0)
|
||||
, alpha_change_(0)
|
||||
, current_alpha_(255)
|
||||
, clip_rect_(screen_area())
|
||||
, align_(CENTER_ALIGN)
|
||||
, scroll_(ANCHOR_LABEL_SCREEN)
|
||||
, visible_(true)
|
||||
, use_markup_(true)
|
||||
, fill_background_(false)
|
||||
{
|
||||
|
|
|
@ -19,10 +19,12 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
namespace font {
|
||||
|
||||
/// structure which will hide all current floating labels, and cause floating labels
|
||||
/// instantiated after it is created to be displayed
|
||||
namespace font
|
||||
{
|
||||
/**
|
||||
* Struct which will hide all current floating labels, and cause floating labels
|
||||
* instantiated after it is created to be displayed.
|
||||
*/
|
||||
struct floating_label_context
|
||||
{
|
||||
floating_label_context();
|
||||
|
@ -38,91 +40,153 @@ class floating_label
|
|||
public:
|
||||
explicit floating_label(const std::string& text);
|
||||
|
||||
void set_font_size(int font_size) {font_size_ = font_size;}
|
||||
void set_font_size(int font_size)
|
||||
{
|
||||
font_size_ = font_size;
|
||||
}
|
||||
|
||||
// set the location on the screen to display the text.
|
||||
void set_position(double xpos, double ypos){
|
||||
/** Set the location on the screen to display the text. */
|
||||
void set_position(double xpos, double ypos)
|
||||
{
|
||||
xpos_ = xpos;
|
||||
ypos_ = ypos;
|
||||
}
|
||||
// set the amount to move the text each frame
|
||||
void set_move(double xmove, double ymove){
|
||||
|
||||
/** Set the amount to move the text each frame. */
|
||||
void set_move(double xmove, double ymove)
|
||||
{
|
||||
xmove_ = xmove;
|
||||
ymove_ = ymove;
|
||||
}
|
||||
// set the number of frames to display the text for, or -1 to display until removed
|
||||
void set_lifetime(int lifetime) {
|
||||
|
||||
/** Set the number of frames to display the text for, or -1 to display until removed. */
|
||||
void set_lifetime(int lifetime)
|
||||
{
|
||||
lifetime_ = lifetime;
|
||||
alpha_change_ = -255 / lifetime_;
|
||||
}
|
||||
void set_color(const color_t& color) {color_ = color;}
|
||||
void set_bg_color(const color_t& bg_color) {
|
||||
|
||||
void set_color(const color_t& color)
|
||||
{
|
||||
color_ = color;
|
||||
}
|
||||
|
||||
void set_bg_color(const color_t& bg_color)
|
||||
{
|
||||
bgcolor_ = bg_color;
|
||||
fill_background_ = bgcolor_.a != 255;
|
||||
}
|
||||
void set_border_size(int border) {border_ = border;}
|
||||
// set width for word wrapping (use -1 to disable it)
|
||||
void set_width(int w) {width_ = w;}
|
||||
void set_height(int h) { height_ = h; }
|
||||
void set_clip_rect(const SDL_Rect& r) {clip_rect_ = r;}
|
||||
void set_alignment(ALIGN align) {align_ = align;}
|
||||
void set_scroll_mode(LABEL_SCROLL_MODE scroll) {scroll_ = scroll;}
|
||||
void use_markup(bool b) {use_markup_ = b;}
|
||||
|
||||
void set_border_size(int border)
|
||||
{
|
||||
border_ = border;
|
||||
}
|
||||
|
||||
/** Set width for word wrapping (use -1 to disable it). */
|
||||
void set_width(int w)
|
||||
{
|
||||
width_ = w;
|
||||
}
|
||||
|
||||
void set_height(int h)
|
||||
{
|
||||
height_ = h;
|
||||
}
|
||||
|
||||
void set_clip_rect(const SDL_Rect& r)
|
||||
{
|
||||
clip_rect_ = r;
|
||||
}
|
||||
|
||||
void set_alignment(ALIGN align)
|
||||
{
|
||||
align_ = align;
|
||||
}
|
||||
|
||||
void set_scroll_mode(LABEL_SCROLL_MODE scroll)
|
||||
{
|
||||
scroll_ = scroll;
|
||||
}
|
||||
|
||||
void use_markup(bool b)
|
||||
{
|
||||
use_markup_ = b;
|
||||
}
|
||||
|
||||
bool expired() const
|
||||
{
|
||||
return lifetime_ == 0;
|
||||
}
|
||||
|
||||
void show(const bool value)
|
||||
{
|
||||
visible_ = value;
|
||||
}
|
||||
|
||||
LABEL_SCROLL_MODE scroll() const
|
||||
{
|
||||
return scroll_;
|
||||
}
|
||||
|
||||
void move(double xmove, double ymove);
|
||||
|
||||
/** Draws this label. */
|
||||
void draw();
|
||||
|
||||
/** Creates a texture of the label's text. */
|
||||
texture create_texture();
|
||||
|
||||
bool expired() const { return lifetime_ == 0; }
|
||||
|
||||
void show(const bool value) { visible_ = value; }
|
||||
|
||||
LABEL_SCROLL_MODE scroll() const { return scroll_; }
|
||||
|
||||
private:
|
||||
|
||||
int xpos(size_t width) const;
|
||||
|
||||
texture texture_;
|
||||
std::string text_;
|
||||
int font_size_;
|
||||
color_t color_, bgcolor_;
|
||||
unsigned int current_alpha_;
|
||||
double xpos_, ypos_, xmove_, ymove_;
|
||||
int lifetime_;
|
||||
int width_, height_;
|
||||
SDL_Rect clip_rect_;
|
||||
int alpha_change_;
|
||||
bool visible_;
|
||||
font::ALIGN align_;
|
||||
int border_;
|
||||
LABEL_SCROLL_MODE scroll_;
|
||||
bool use_markup_;
|
||||
|
||||
std::string text_;
|
||||
|
||||
color_t color_, bgcolor_;
|
||||
|
||||
double xpos_, ypos_, xmove_, ymove_;
|
||||
|
||||
int width_, height_;
|
||||
int font_size_;
|
||||
int lifetime_;
|
||||
int border_;
|
||||
int alpha_change_;
|
||||
|
||||
unsigned int current_alpha_;
|
||||
|
||||
SDL_Rect clip_rect_;
|
||||
|
||||
font::ALIGN align_;
|
||||
|
||||
LABEL_SCROLL_MODE scroll_;
|
||||
|
||||
bool visible_;
|
||||
bool use_markup_;
|
||||
bool fill_background_;
|
||||
};
|
||||
|
||||
|
||||
/// add a label floating on the screen above everything else.
|
||||
/// @returns a handle to the label which can be used with other label functions
|
||||
|
||||
/**
|
||||
* Add a label floating on the screen above everything else.
|
||||
* @returns a handle to the label which can be used with other label functions
|
||||
*/
|
||||
int add_floating_label(const floating_label& flabel);
|
||||
|
||||
|
||||
/// moves the floating label given by 'handle' by (xmove,ymove)
|
||||
/** Moves the floating label given by 'handle' by (xmove, ymove). */
|
||||
void move_floating_label(int handle, double xmove, double ymove);
|
||||
|
||||
/// moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP
|
||||
/** Moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP. */
|
||||
void scroll_floating_labels(double xmove, double ymove);
|
||||
|
||||
/// removes the floating label given by 'handle' from the screen
|
||||
/** Removes the floating label given by 'handle' from the screen. */
|
||||
void remove_floating_label(int handle);
|
||||
|
||||
/// hides or shows a floating label
|
||||
/** Hides or shows a floating label. */
|
||||
void show_floating_label(int handle, bool show);
|
||||
|
||||
SDL_Rect get_floating_label_rect(int handle);
|
||||
/** Renders all floating labels. */
|
||||
void draw_floating_labels();
|
||||
|
||||
SDL_Rect get_floating_label_rect(int handle);
|
||||
|
||||
} // end namespace font
|
||||
|
|
Loading…
Add table
Reference in a new issue