move font constants to their own compilation unit
avoids including SDL_TTF unnecessarily
This commit is contained in:
parent
6b978a7411
commit
f82f996347
29 changed files with 119 additions and 65 deletions
|
@ -985,6 +985,7 @@ set(libwesnoth-game_STAT_SRC
|
|||
display_context.cpp
|
||||
events.cpp
|
||||
floating_label.cpp
|
||||
font/constants.cpp
|
||||
font/font_config.cpp
|
||||
font/sdl_ttf.cpp
|
||||
font/text.cpp
|
||||
|
|
|
@ -90,6 +90,7 @@ libwesnoth_sources = Split("""
|
|||
display.cpp
|
||||
events.cpp
|
||||
floating_label.cpp
|
||||
font/constants.cpp
|
||||
font/font_config.cpp
|
||||
font/sdl_ttf.cpp
|
||||
font/text.cpp
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "tristate_button.hpp"
|
||||
|
||||
#include "font/constants.hpp"
|
||||
#include "font/sdl_ttf.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "image.hpp"
|
||||
|
|
37
src/font/constants.cpp
Normal file
37
src/font/constants.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2016 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "constants.hpp"
|
||||
|
||||
#include "sdl/utils.hpp"
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
namespace font {
|
||||
|
||||
const SDL_Color NORMAL_COLOR = {0xDD,0xDD,0xDD,0},
|
||||
GRAY_COLOR = {0x77,0x77,0x77,0},
|
||||
LOBBY_COLOR = {0xBB,0xBB,0xBB,0},
|
||||
GOOD_COLOR = {0x00,0xFF,0x00,0},
|
||||
BAD_COLOR = {0xFF,0x00,0x00,0},
|
||||
BLACK_COLOR = {0x00,0x00,0x00,0},
|
||||
YELLOW_COLOR = {0xFF,0xFF,0x00,0},
|
||||
BUTTON_COLOR = {0xBC,0xB0,0x88,0},
|
||||
PETRIFIED_COLOR = {0xA0,0xA0,0xA0,0},
|
||||
TITLE_COLOR = {0xBC,0xB0,0x88,0},
|
||||
LABEL_COLOR = {0x6B,0x8C,0xFF,0},
|
||||
BIGMAP_COLOR = {0xFF,0xFF,0xFF,0};
|
||||
const SDL_Color DISABLED_COLOR = inverse(PETRIFIED_COLOR);
|
||||
|
||||
} // end namespace font
|
49
src/font/constants.hpp
Normal file
49
src/font/constants.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2016 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
namespace font {
|
||||
|
||||
//various standard colors
|
||||
extern const SDL_Color NORMAL_COLOR, GRAY_COLOR, LOBBY_COLOR, GOOD_COLOR, BAD_COLOR,
|
||||
BLACK_COLOR, YELLOW_COLOR, BUTTON_COLOR, BIGMAP_COLOR,
|
||||
PETRIFIED_COLOR, TITLE_COLOR, DISABLED_COLOR, LABEL_COLOR;
|
||||
|
||||
// font sizes, to be made theme parameters
|
||||
constexpr int SIZE_NORMAL = 14;
|
||||
// automatic computation of other font sizes, to be made a default for theme-provided values
|
||||
constexpr int
|
||||
SIZE_TINY = 10 * SIZE_NORMAL / 14,
|
||||
SIZE_SMALL = 12 * SIZE_NORMAL / 14,
|
||||
|
||||
SIZE_15 = 15 * SIZE_NORMAL / 14,
|
||||
SIZE_PLUS = 16 * SIZE_NORMAL / 14,
|
||||
SIZE_LARGE = 18 * SIZE_NORMAL / 14,
|
||||
SIZE_TITLE = 20 * SIZE_NORMAL / 14,
|
||||
SIZE_XLARGE = 24 * SIZE_NORMAL / 14
|
||||
;
|
||||
// For arbitrary scaling:
|
||||
// (Not used in defining the SIZE_* consts because of spurious compiler warnings.)
|
||||
constexpr inline int relative_size(int size)
|
||||
{
|
||||
return (SIZE_NORMAL * size / 14);
|
||||
}
|
||||
|
||||
// GUI1 built-in maximum
|
||||
constexpr size_t max_text_line_width = 4096;
|
||||
|
||||
} // end namespace font
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2016 by Chris Beck<render787@gmail.com>
|
||||
Copyright (C) 2015 - 2016 by Chris Beck<render787@gmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2016 by Mark de Wever <koraq@xs4all.nl>
|
||||
Copyright (C) 2015 - 2016 by Chris Beck<render787@gmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#ifndef FONT_SDL_TTF_HPP
|
||||
#define FONT_SDL_TTF_HPP
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "font_id.hpp"
|
||||
#include "font_description.hpp"
|
||||
|
||||
|
@ -26,31 +27,6 @@ class surface;
|
|||
|
||||
namespace font {
|
||||
|
||||
//various standard colors
|
||||
extern const SDL_Color NORMAL_COLOR, GRAY_COLOR, LOBBY_COLOR, GOOD_COLOR, BAD_COLOR,
|
||||
BLACK_COLOR, YELLOW_COLOR, BUTTON_COLOR, BIGMAP_COLOR,
|
||||
PETRIFIED_COLOR, TITLE_COLOR, DISABLED_COLOR, LABEL_COLOR;
|
||||
|
||||
// font sizes, to be made theme parameters
|
||||
constexpr int SIZE_NORMAL = 14;
|
||||
// automatic computation of other font sizes, to be made a default for theme-provided values
|
||||
constexpr int
|
||||
SIZE_TINY = 10 * SIZE_NORMAL / 14,
|
||||
SIZE_SMALL = 12 * SIZE_NORMAL / 14,
|
||||
|
||||
SIZE_15 = 15 * SIZE_NORMAL / 14,
|
||||
SIZE_PLUS = 16 * SIZE_NORMAL / 14,
|
||||
SIZE_LARGE = 18 * SIZE_NORMAL / 14,
|
||||
SIZE_TITLE = 20 * SIZE_NORMAL / 14,
|
||||
SIZE_XLARGE = 24 * SIZE_NORMAL / 14
|
||||
;
|
||||
// For arbitrary scaling:
|
||||
// (Not used in defining the SIZE_* consts because of spurious compiler warnings.)
|
||||
inline int relative_size(int size)
|
||||
{
|
||||
return (SIZE_NORMAL * size / 14);
|
||||
}
|
||||
|
||||
// Returns a SDL surface containing the text rendered in a given color.
|
||||
surface get_rendered_text(const std::string& text, int size, const SDL_Color& color, int style=0);
|
||||
|
||||
|
|
|
@ -30,22 +30,6 @@
|
|||
|
||||
namespace font {
|
||||
|
||||
const SDL_Color NORMAL_COLOR = {0xDD,0xDD,0xDD,0},
|
||||
GRAY_COLOR = {0x77,0x77,0x77,0},
|
||||
LOBBY_COLOR = {0xBB,0xBB,0xBB,0},
|
||||
GOOD_COLOR = {0x00,0xFF,0x00,0},
|
||||
BAD_COLOR = {0xFF,0x00,0x00,0},
|
||||
BLACK_COLOR = {0x00,0x00,0x00,0},
|
||||
YELLOW_COLOR = {0xFF,0xFF,0x00,0},
|
||||
BUTTON_COLOR = {0xBC,0xB0,0x88,0},
|
||||
PETRIFIED_COLOR = {0xA0,0xA0,0xA0,0},
|
||||
TITLE_COLOR = {0xBC,0xB0,0x88,0},
|
||||
LABEL_COLOR = {0x6B,0x8C,0xFF,0},
|
||||
BIGMAP_COLOR = {0xFF,0xFF,0xFF,0};
|
||||
const SDL_Color DISABLED_COLOR = inverse(PETRIFIED_COLOR);
|
||||
|
||||
static const size_t max_text_line_width = 4096;
|
||||
|
||||
class text_surface
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "addon/manager.hpp" // for get_installed_addons
|
||||
#include "config_assign.hpp"
|
||||
#include "font/sdl_ttf.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "generators/map_create.hpp"
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "addon/manager_ui.hpp"
|
||||
#include "construct_dialog.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "font/sdl_ttf.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "lobby_preferences.hpp"
|
||||
#include "map/exception.hpp"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "construct_dialog.hpp"
|
||||
#include "video.hpp"
|
||||
#include "font/sdl_ttf.hpp"
|
||||
#include "formatter.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "gettext.hpp"
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
#include "serialization/string_utils.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
// #include "font.hpp"
|
||||
#include "preferences.hpp"
|
||||
#include "strftime.hpp"
|
||||
#include "video.hpp"
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include "control.hpp"
|
||||
|
||||
// #include "font.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "gui/auxiliary/iterator/walker_widget.hpp"
|
||||
#include "gui/core/log.hpp"
|
||||
|
|
|
@ -250,6 +250,7 @@ void ttext_box::update_offsets()
|
|||
|
||||
assert(conf);
|
||||
|
||||
// FIXME: This should use pango-cairo code path instead of sdl_ttf code path
|
||||
text_height_ = font::get_max_height(conf->text_font_size);
|
||||
|
||||
game_logic::map_formula_callable variables;
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "events.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "formula/callable.hpp"
|
||||
//#include "font.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "log.hpp"
|
||||
#include "gui/auxiliary/formula.hpp"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "config.hpp" // for config, etc
|
||||
#include "events.hpp" // for raise_draw_event, pump, etc
|
||||
#include "font/sdl_ttf.hpp" // for relative_size
|
||||
#include "font/constants.hpp" // for relative_size
|
||||
#include "game_preferences.hpp"
|
||||
#include "gettext.hpp" // for _
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <iostream> // for operator<<, basic_ostream, etc
|
||||
#include <SDL_mouse.h> // for SDL_GetMouseState, etc
|
||||
#include "cursor.hpp" // for set, CURSOR_TYPE::HYPERLINK, etc
|
||||
#include "font/sdl_ttf.hpp" // for relative_size
|
||||
#include "font/constants.hpp" // for relative_size
|
||||
#include "gettext.hpp" // for _
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "help/help_text_area.hpp" // for help_text_area
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <deque> // for deque
|
||||
#include <string> // for string
|
||||
#include <SDL_events.h> // for SDL_Event
|
||||
#include "help_menu.hpp" // for help_menu
|
||||
#include "help_menu.hpp" // for help_menu
|
||||
#include "help_text_area.hpp" // for help_text_area
|
||||
#include "widgets/button.hpp" // for button
|
||||
#include "widgets/widget.hpp" // for widget
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <string> // for string
|
||||
#include <utility> // for pair
|
||||
#include <SDL_video.h> // for SDL_Color (ptr only), etc
|
||||
#include "font/sdl_ttf.hpp" // for NORMAL_COLOR
|
||||
#include "font/constants.hpp" // for NORMAL_COLOR
|
||||
#include "sdl/utils.hpp" // for surface
|
||||
#include "widgets/scrollarea.hpp" // for scrollarea
|
||||
class CVideo;
|
||||
|
|
|
@ -14,19 +14,20 @@
|
|||
|
||||
#include "help_topic_generators.hpp"
|
||||
|
||||
#include "font/sdl_ttf.hpp" // for line_width
|
||||
#include "game_config.hpp" // for debug, menu_contract, etc
|
||||
#include "game_preferences.hpp" // for encountered_terrains, etc
|
||||
#include "gettext.hpp" // for _, gettext, N_
|
||||
#include "language.hpp" // for string_table, symbol_table
|
||||
#include "log.hpp" // for LOG_STREAM, logger, etc
|
||||
#include "movetype.hpp" // for movetype, movetype::effects, etc
|
||||
#include "units/race.hpp" // for unit_race, etc
|
||||
#include "terrain/terrain.hpp" // for terrain_type
|
||||
#include "units/race.hpp" // for unit_race, etc
|
||||
#include "terrain/terrain.hpp" // for terrain_type
|
||||
#include "terrain/translation.hpp" // for operator==, t_list, etc
|
||||
#include "terrain/type_data.hpp" // for terrain_type_data, etc
|
||||
#include "tstring.hpp" // for t_string, operator<<
|
||||
#include "units/helper.hpp" // for resistance_color
|
||||
#include "units/types.hpp" // for unit_type, unit_type_data, etc
|
||||
#include "units/helper.hpp" // for resistance_color
|
||||
#include "units/types.hpp" // for unit_type, unit_type_data, etc
|
||||
#include "video.hpp" // fore current_resolution
|
||||
|
||||
#include <boost/optional.hpp> // for optional
|
||||
|
@ -786,4 +787,8 @@ std::string unit_topic_generator::operator()() const {
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
void unit_topic_generator::push_header(std::vector< item > &row, const std::string& name) const {
|
||||
row.push_back(item(bold(name), font::line_width(name, normal_font_size, TTF_STYLE_BOLD)));
|
||||
}
|
||||
|
||||
} // end namespace help
|
||||
|
|
|
@ -15,13 +15,11 @@
|
|||
#ifndef HELP_TOPIC_GENERATORS_HPP
|
||||
#define HELP_TOPIC_GENERATORS_HPP
|
||||
|
||||
#include "font/sdl_ttf.hpp" // for line_width
|
||||
#include "help_impl.hpp"
|
||||
|
||||
#include <string> // for string
|
||||
#include <utility> // for pair
|
||||
#include <vector> // for vector
|
||||
#include <SDL.h> // for TTF_STYLE_BOLD
|
||||
class terrain_type; // lines 20-20
|
||||
class unit_type;
|
||||
|
||||
|
@ -45,9 +43,7 @@ class unit_topic_generator: public topic_generator
|
|||
const unit_type& type_;
|
||||
const std::string variation_;
|
||||
typedef std::pair< std::string, unsigned > item;
|
||||
void push_header(std::vector< item > &row, const std::string& name) const {
|
||||
row.push_back(item(bold(name), font::line_width(name, normal_font_size, TTF_STYLE_BOLD)));
|
||||
}
|
||||
void push_header(std::vector< item > &row, const std::string& name) const;
|
||||
public:
|
||||
unit_topic_generator(const unit_type &t, std::string variation="") : type_(t), variation_(variation) {}
|
||||
virtual std::string operator()() const;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#ifndef MAP_LABEL_HPP_INCLUDED
|
||||
#define MAP_LABEL_HPP_INCLUDED
|
||||
|
||||
#include "font/sdl_ttf.hpp"
|
||||
#include "font/constants.hpp"
|
||||
#include "map/location.hpp"
|
||||
#include "tstring.hpp"
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "attack_prediction.hpp"
|
||||
//#include "editor/editor_controller.hpp"
|
||||
//#include "editor/palette/terrain_palettes.hpp"
|
||||
#include "font/sdl_ttf.hpp"
|
||||
#include "font/constants.hpp"
|
||||
#include "font/pango/escape.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "gettext.hpp"
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "construct_dialog.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "font/sdl_ttf.hpp"
|
||||
#include "image.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "gui/core/event/handler.hpp"
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace {
|
|||
|
||||
CVideo* video_ = nullptr;
|
||||
|
||||
static const int font_size = font::SIZE_NORMAL;
|
||||
static const int text_width = 400;
|
||||
static constexpr int font_size = font::SIZE_NORMAL;
|
||||
static constexpr int text_width = 400;
|
||||
|
||||
struct tooltip
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#ifndef LABEL_HPP_INCLUDED
|
||||
#define LABEL_HPP_INCLUDED
|
||||
|
||||
#include "font/sdl_ttf.hpp"
|
||||
#include "font/constants.hpp"
|
||||
#include "widget.hpp"
|
||||
#include <string>
|
||||
#include "sdl/image.hpp"
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
#include "global.hpp"
|
||||
|
||||
#include "widgets/textbox.hpp"
|
||||
|
||||
#include "desktop/clipboard.hpp"
|
||||
#include "font/sdl_ttf.hpp"
|
||||
#include "log.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define TEXTBOX_HPP_INCLUDED
|
||||
|
||||
#include "serialization/unicode.hpp"
|
||||
#include "font/sdl_ttf.hpp"
|
||||
#include "font/constants.hpp"
|
||||
|
||||
#include "scrollarea.hpp"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue