mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-16 18:31:32 +00:00
Store link colour as color_t
Currently, formulas treat a colour as an array of components. This could be improved.
This commit is contained in:
parent
76f725415d
commit
3f0485aaa4
@ -478,7 +478,7 @@ pango_text& pango_text::set_link_aware(bool b)
|
||||
return *this;
|
||||
}
|
||||
|
||||
pango_text& pango_text::set_link_color(const std::string & color)
|
||||
pango_text& pango_text::set_link_color(const color_t& color)
|
||||
{
|
||||
if(color != link_color_) {
|
||||
link_color_ = color;
|
||||
@ -733,7 +733,7 @@ std::string pango_text::format_link_tokens(const std::string & text) const {
|
||||
std::string pango_text::handle_token(const std::string & token) const
|
||||
{
|
||||
if (looks_like_url(token)) {
|
||||
return format_as_link(token, link_color_);
|
||||
return format_as_link(token, link_color_.to_hex_string());
|
||||
} else {
|
||||
return token;
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ public:
|
||||
|
||||
pango_text& set_link_aware(bool b);
|
||||
|
||||
pango_text& set_link_color(const std::string & color);
|
||||
pango_text& set_link_color(const color_t& color);
|
||||
private:
|
||||
|
||||
/***** ***** ***** ***** Pango variables ***** ***** ***** *****/
|
||||
@ -271,7 +271,7 @@ private:
|
||||
*
|
||||
* "<span underline=\'single\' color=\'" + link_color_ + "\'>"
|
||||
*/
|
||||
std::string link_color_;
|
||||
color_t link_color_;
|
||||
|
||||
/** The font family class used. */
|
||||
font::family_class font_class_;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "lexical_cast.hpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
#include "tstring.hpp"
|
||||
#include "color.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@ -225,6 +226,16 @@ inline PangoAlignment typed_formula<PangoAlignment>::execute(
|
||||
.as_string());
|
||||
}
|
||||
|
||||
template<>
|
||||
inline color_t typed_formula<color_t>::execute(
|
||||
const game_logic::map_formula_callable& variables,
|
||||
game_logic::function_symbol_table* functions) const
|
||||
{
|
||||
const auto& result = game_logic::formula(formula_, functions).evaluate(variables).as_list();
|
||||
int alpha = result.size() == 4 ? result[3].as_int() : ALPHA_OPAQUE;
|
||||
return color_t(result.at(0).as_int(), result.at(1).as_int(), result.at(2).as_int(), alpha);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T
|
||||
typed_formula<T>::execute(const game_logic::map_formula_callable& /*variables*/
|
||||
@ -261,6 +272,12 @@ inline void typed_formula<PangoAlignment>::convert(const std::string& str)
|
||||
value_ = decode_text_alignment(str);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void typed_formula<color_t>::convert(const std::string& str)
|
||||
{
|
||||
value_ = color_t::from_rgba_string(str);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void typed_formula<T>::convert(const std::string& str)
|
||||
{
|
||||
|
@ -1218,7 +1218,7 @@ private:
|
||||
typed_formula<bool> link_aware_;
|
||||
|
||||
/** The link color of the text. */
|
||||
typed_formula<std::string> link_color_;
|
||||
typed_formula<color_t> link_color_;
|
||||
|
||||
/** The maximum width for the text. */
|
||||
typed_formula<int> maximum_width_;
|
||||
@ -1295,7 +1295,7 @@ text_shape::text_shape(const config& cfg)
|
||||
, text_(cfg["text"])
|
||||
, text_markup_(cfg["text_markup"], false)
|
||||
, link_aware_(cfg["text_link_aware"], false)
|
||||
, link_color_(cfg["text_link_color"], "#ffff00")
|
||||
, link_color_(cfg["text_link_color"], color_t::from_hex_string("ffff00"))
|
||||
, maximum_width_(cfg["maximum_width"], -1)
|
||||
, characters_per_line_(cfg["text_characters_per_line"])
|
||||
, maximum_height_(cfg["maximum_height"], -1)
|
||||
|
@ -46,7 +46,7 @@ label::label()
|
||||
, can_wrap_(false)
|
||||
, characters_per_line_(0)
|
||||
, link_aware_(false)
|
||||
, link_color_("#ffff00")
|
||||
, link_color_(color_t::from_hex_string("ffff00"))
|
||||
{
|
||||
connect_signal<event::LEFT_BUTTON_CLICK>(std::bind(&label::signal_handler_left_button_click, this, _2, _3));
|
||||
connect_signal<event::RIGHT_BUTTON_CLICK>(std::bind(&label::signal_handler_right_button_click, this, _2, _3));
|
||||
@ -67,7 +67,7 @@ bool label::get_link_aware() const
|
||||
return link_aware_;
|
||||
}
|
||||
|
||||
std::string label::get_link_color() const
|
||||
color_t label::get_link_color() const
|
||||
{
|
||||
return link_color_;
|
||||
}
|
||||
@ -110,7 +110,7 @@ void label::set_link_aware(bool link_aware)
|
||||
set_is_dirty(true);
|
||||
}
|
||||
|
||||
void label::set_link_color(const std::string & color)
|
||||
void label::set_link_color(const color_t& color)
|
||||
{
|
||||
if(color == link_color_) {
|
||||
return;
|
||||
@ -264,8 +264,7 @@ label_definition::label_definition(const config& cfg)
|
||||
label_definition::resolution::resolution(const config& cfg)
|
||||
: resolution_definition(cfg)
|
||||
, link_aware(cfg["link_aware"].to_bool(false))
|
||||
// TODO: link_color should probably be stored as color_t internally, not as a string
|
||||
, link_color(cfg["link_color"].empty() ? "#ffff00" : color_t::from_rgb_string(cfg["link_color"].str()).to_hex_string())
|
||||
, link_color(cfg["link_color"].empty() ? color_t::from_hex_string("ffff00") : color_t::from_rgba_string(cfg["link_color"].str()))
|
||||
{
|
||||
// Note the order should be the same as the enum state_t is label.hpp.
|
||||
state.push_back(state_definition(cfg.child("state_enabled")));
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
virtual bool get_link_aware() const override;
|
||||
|
||||
/** See @ref styled_widget::get_link_aware. */
|
||||
virtual std::string get_link_color() const override;
|
||||
virtual color_t get_link_color() const override;
|
||||
|
||||
/** See @ref styled_widget::set_active. */
|
||||
virtual void set_active(const bool active) override;
|
||||
@ -66,7 +66,7 @@ public:
|
||||
|
||||
void set_link_aware(bool l);
|
||||
|
||||
void set_link_color(const std::string & color);
|
||||
void set_link_color(const color_t& color);
|
||||
|
||||
virtual bool can_mouse_focus() const override { return !tooltip().empty(); }
|
||||
private:
|
||||
@ -110,7 +110,7 @@ private:
|
||||
/**
|
||||
* What color links will be rendered in.
|
||||
*/
|
||||
std::string link_color_;
|
||||
color_t link_color_;
|
||||
|
||||
/** See @ref styled_widget::get_control_type. */
|
||||
virtual const std::string& get_control_type() const override;
|
||||
@ -143,7 +143,7 @@ struct label_definition : public styled_widget_definition
|
||||
explicit resolution(const config& cfg);
|
||||
|
||||
bool link_aware;
|
||||
std::string link_color;
|
||||
color_t link_color;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -185,9 +185,9 @@ bool styled_widget::get_link_aware() const
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string styled_widget::get_link_color() const
|
||||
color_t styled_widget::get_link_color() const
|
||||
{
|
||||
return "#ffff00";
|
||||
return color_t::from_hex_string("ffff00");
|
||||
}
|
||||
|
||||
void styled_widget::layout_initialise(const bool full_initialisation)
|
||||
@ -370,7 +370,10 @@ void styled_widget::update_canvas()
|
||||
canvas.set_variable("text", variant(label_));
|
||||
canvas.set_variable("text_markup", variant(use_markup_));
|
||||
canvas.set_variable("text_link_aware", variant(get_link_aware()));
|
||||
canvas.set_variable("text_link_color", variant(get_link_color()));
|
||||
// Possible TODO: Consider making a formula_callable for colours
|
||||
color_t link_color = get_link_color();
|
||||
std::vector<variant> link_color_as_list{variant(link_color.r), variant(link_color.g), variant(link_color.b), variant(link_color.a)};
|
||||
canvas.set_variable("text_link_color", variant(&link_color_as_list));
|
||||
canvas.set_variable("text_alignment",
|
||||
variant(encode_text_alignment(text_alignment_)));
|
||||
canvas.set_variable("text_maximum_width", variant(max_width));
|
||||
|
@ -163,7 +163,7 @@ public:
|
||||
* @returns The link color string. This impl returns "#ffff00".
|
||||
*
|
||||
*/
|
||||
virtual std::string get_link_color() const;
|
||||
virtual color_t get_link_color() const;
|
||||
|
||||
/**
|
||||
* See @ref widget::layout_initialise.
|
||||
|
Loading…
x
Reference in New Issue
Block a user