Made pango font rendering use color_t

This commit is contained in:
Charles Dang 2016-11-30 16:58:34 +11:00
parent cd90652bec
commit a8517a234d
6 changed files with 15 additions and 20 deletions

View file

@ -2887,7 +2887,7 @@ void display::refresh_report(const std::string& report_name, const config * new_
// font_rgb() has no alpha channel and uses a 0x00RRGGBB
// layout instead of 0xRRGGBBAA which is what pango_text expects,
// so shift the value to the left and add fully-opaque alpha.
text.set_foreground_color((item->font_rgb() << 8) + 0xFF);
text.set_foreground_color(color_t::from_rgba_bytes((item->font_rgb() << 8) + 0xFF));
}
bool eol = false;
if (t[t.size() - 1] == '\n') {

View file

@ -81,7 +81,7 @@ surface floating_label::create_surface()
{
if (surf_.null()) {
font::pango_text text;
text.set_foreground_color((color_.r << 24) | (color_.g << 16) | (color_.b << 8) | 255);
text.set_foreground_color(color_t(color_));
text.set_font_size(font_size_);
text.set_maximum_width(width_ < 0 ? clip_rect_.w : width_);
text.set_maximum_height(height_ < 0 ? clip_rect_.h : height_, true);

View file

@ -56,7 +56,7 @@ pango_text::pango_text()
, font_class_(font::FONT_SANS_SERIF)
, font_size_(14)
, font_style_(STYLE_NORMAL)
, foreground_color_(0xFFFFFFFF) // solid white
, foreground_color_() // solid white
, maximum_width_(-1)
, characters_per_line_(0)
, maximum_height_(-1)
@ -357,7 +357,7 @@ pango_text& pango_text::set_font_style(const pango_text::FONT_STYLE font_style)
return *this;
}
pango_text& pango_text::set_foreground_color(const Uint32 color)
pango_text& pango_text::set_foreground_color(const color_t& color)
{
if(color != foreground_color_) {
foreground_color_ = color;
@ -367,11 +367,6 @@ pango_text& pango_text::set_foreground_color(const Uint32 color)
return *this;
}
pango_text &pango_text::set_foreground_color(const SDL_Color color)
{
return this->set_foreground_color((color.r << 24) + (color.g << 16) + (color.b << 8) + color.a);
}
pango_text& pango_text::set_maximum_width(int width)
{
if(width <= 0) {
@ -671,10 +666,11 @@ void pango_text::rerender(const bool force) const
/* set color (used for foreground). */
cairo_set_source_rgba(cr,
(foreground_color_ >> 24) / 256.0,
((foreground_color_ >> 16) & 0xFF) / 256.0,
((foreground_color_ >> 8) & 0xFF) / 256.0,
(foreground_color_ & 0xFF) / 256.0);
foreground_color_.r / 256.0,
foreground_color_.g / 256.0,
foreground_color_.b / 256.0,
foreground_color_.a / 256.0
);
pango_cairo_show_layout(cr, layout_);

View file

@ -16,6 +16,7 @@
#define TEXT_HPP_INCLUDED
#include "font/font_options.hpp"
#include "sdl/color.hpp"
#include "sdl/utils.hpp"
#include "serialization/unicode_types.hpp"
@ -224,9 +225,7 @@ public:
pango_text& set_font_style(const FONT_STYLE font_style);
pango_text& set_foreground_color(const Uint32 color);
pango_text& set_foreground_color(const SDL_Color color);
pango_text& set_foreground_color(const color_t& color);
pango_text& set_maximum_width(int width);
@ -284,7 +283,7 @@ private:
FONT_STYLE font_style_;
/** The foreground color. */
Uint32 foreground_color_;
color_t foreground_color_;
/**
* The maximum width of the text.

View file

@ -1335,7 +1335,7 @@ void text_shape::draw(surface& canvas,
.set_font_size(font_size_)
.set_font_style(font_style_)
.set_alignment(text_alignment_(variables))
.set_foreground_color(color_.to_sdl())
.set_foreground_color(color_)
.set_maximum_width(maximum_width_(variables))
.set_maximum_height(maximum_height_(variables), true)
.set_ellipse_mode(

View file

@ -297,7 +297,7 @@ void part_ui::render_title_box()
t.set_font_style(font::pango_text::STYLE_NORMAL)
.set_font_size(titlebox_font_size)
.set_foreground_color(titlebox_font_color)
.set_foreground_color(color_t::from_rgba_bytes(titlebox_font_color))
.set_maximum_width(titlebox_max_w)
.set_maximum_height(titlebox_max_h, true);
surface txtsurf = t.render();
@ -476,7 +476,7 @@ void part_ui::render_story_box()
t.set_font_style(font::pango_text::STYLE_NORMAL)
.set_alignment(story_text_alignment)
.set_font_size(storybox_font_size)
.set_foreground_color(storybox_font_color)
.set_foreground_color(color_t::from_rgba_bytes(storybox_font_color))
.set_maximum_width(max_width)
.set_maximum_height(max_height, true);