Add the font style parameter.

Add a new label type for the window title.

Use the new window title label in the addon connect dialog.
This commit is contained in:
Mark de Wever 2008-04-12 10:10:36 +00:00
parent d9bd18057c
commit 7369f27443
11 changed files with 148 additions and 14 deletions

View File

@ -559,6 +559,7 @@ libwesnoth_sources = [
"src/gui/widgets/label.cpp",
"src/gui/widgets/settings.cpp",
"src/gui/widgets/text_box.cpp",
"src/gui/widgets/utils.cpp",
"src/gui/widgets/widget.cpp",
"src/gui/widgets/window.cpp",
"src/gui/widgets/window_builder.cpp",

View File

@ -9,6 +9,8 @@
#
#
# normal colour "221, 221, 221, 255"
# label colour "107, 140, 255, 255"
#define FONT_COLOUR_ENABLED
"221, 221, 221, 255"
#enddef
@ -63,6 +65,19 @@
14
#enddef
# font used for the titles
#define FONT_SIZE_NORMAL__TITLE
18
#enddef
#define FONT_STYLE_NORMAL__TITLE
"bold"
#enddef
#define FONT_COLOUR_TITLE
"188, 176, 136, 255"
#enddef
#define FONT_SIZE_NORMAL__BIG
18
#enddef

View File

@ -2,9 +2,11 @@
### Definition of a label.
###
#define LABEL_DEFINITION ID DESCRIPTION FONT_SIZE FONT_COLOUR FONT_STYLE
[label_definition]
id = "default"
description = "Default label"
id = {ID}
description = {DESCRIPTION}
[resolution]
min_width = 0
@ -16,7 +18,8 @@
max_width = 0
max_height = 0
text_font_size = {FONT_SIZE_NORMAL__NORMAL}
text_font_size = {FONT_SIZE}
text_font_style = {FONT_STYLE}
[state_enabled]
@ -29,8 +32,9 @@
y = {TEXT_V_CENTRE}
w = "(text_width)"
h = "(text_height)"
font_size = {FONT_SIZE_NORMAL__NORMAL}
colour = {FONT_COLOUR_ENABLED}
font_size = {FONT_SIZE}
font_style = {FONT_STYLE}
colour = {FONT_COLOUR}
text = "(text)"
[/text]
@ -49,8 +53,9 @@
y = {TEXT_V_CENTRE}
w = "(text_width)"
h = "(text_height)"
font_size = {FONT_SIZE_NORMAL__NORMAL}
colour = {FONT_COLOUR_DISABLED}
font_size = {FONT_SIZE}
font_style = {FONT_STYLE}
colour = {FONT_COLOUR}
text = "(text)"
[/text]
@ -61,4 +66,7 @@
[/resolution]
[/label_definition]
#enddef
{LABEL_DEFINITION "default" "default label" 16 {FONT_COLOUR_ENABLED} "normal"}
{LABEL_DEFINITION "title" "label used for titles" {FONT_SIZE_NORMAL__TITLE} {FONT_COLOUR_TITLE} "bold"}

View File

@ -12,7 +12,7 @@
left = "center"
width = 600
height = 200
height = 250
definition = "default"
@ -29,7 +29,7 @@
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
definition = "title"
label = _ "Connect to Server"
[/label]

View File

@ -74,6 +74,7 @@ wesnoth_source = \
gui/widgets/label.cpp \
gui/widgets/settings.cpp \
gui/widgets/text_box.cpp \
gui/widgets/helper.cpp \
gui/widgets/widget.cpp \
gui/widgets/window.cpp \
gui/widgets/window_builder.cpp \
@ -305,6 +306,7 @@ noinst_HEADERS = \
gui/widgets/label.hpp \
gui/widgets/settings.hpp \
gui/widgets/text_box.hpp \
gui/widgets/helper.hpp \
gui/widgets/widget.hpp \
gui/widgets/window.hpp \
gui/widgets/window_builder.hpp \

View File

@ -22,6 +22,7 @@
#include "formula.hpp"
#include "image.hpp"
#include "gettext.hpp"
#include "gui/widgets/helper.hpp"
#include "log.hpp"
#include "serialization/parser.hpp"
#include "wml_exception.hpp"
@ -300,6 +301,18 @@ tline::tline(const config& cfg) :
* available. An alpha of 0 is fully
* transparent. Ommitted values are set to 0.
*
* font_style A string which contains the style of the
* font:
* * normal normal font
* * bold bold font
* * italic italic font
* * underline underlined font
* Since SDL has problems combining these
* styles only one can be picked. Once SDL
* will allow multiple options, this type
* will be transformed to a comma separated
* list. If empty we default to the normal
* style.
*
* Formulas are a funtion between brackets, that way the engine can see whether
* there is standing a plain number or a formula eg:
@ -645,6 +658,7 @@ private:
h_;
unsigned font_size_;
int font_style_;
Uint32 colour_;
tformula<t_string> text_;
@ -656,6 +670,7 @@ ttext::ttext(const config& cfg) :
w_(cfg["w"]),
h_(cfg["h"]),
font_size_(lexical_cast_default<unsigned>(cfg["font_size"])),
font_style_(decode_font_style(cfg["font_style"])),
colour_(decode_colour(cfg["colour"])),
text_(cfg["text"])
{
@ -669,13 +684,13 @@ ttext::ttext(const config& cfg) :
* w (f_unsigned = 0) The width of the rectangle.
* h (f_unsigned = 0) The height of the rectangle.
* font_size (unsigned = 0) The size of the font to draw in.
* font_style (font_style = "") The style of the text.
* colour (colour = "") The colour of the text.
* text (tstring = "") The text to draw (translatable).
* debug = (string = "") Debug message to show upon creation
* this message is not stored.
*
* NOTE there's no option of font style yet, alignment can be done with the
* forumulas.
* NOTE alignment can be done with the forumulas.
*
* Variables:
* text_width unsigned The width of the rendered text.
@ -708,7 +723,7 @@ void ttext::draw(surface& canvas,
}
SDL_Color col = { (colour_ >> 24), (colour_ >> 16), (colour_ >> 8), colour_ };
surface surf(font::get_rendered_text(text, font_size_, col, TTF_STYLE_NORMAL));
surface surf(font::get_rendered_text(text, font_size_, col, font_style_));
assert(surf);
game_logic::map_formula_callable local_variables(variables);

View File

@ -105,7 +105,7 @@ tpoint tcontrol::get_minimum_size() const
return min_size;
}
SDL_Rect rect = font::line_size(label_, config_->text_font_size);
SDL_Rect rect = font::line_size(label_, config_->text_font_size, config_->text_font_style);
const tpoint text_size(rect.w + config_->text_extra_width, rect.h + config_->text_extra_height);
return maximum(min_size, text_size);
}
@ -119,7 +119,7 @@ tpoint tcontrol::get_best_size() const
return default_size;
}
SDL_Rect rect = font::line_size(label_, config_->text_font_size);
SDL_Rect rect = font::line_size(label_, config_->text_font_size, config_->text_font_style);
const tpoint text_size(rect.w + config_->text_extra_width, rect.h + config_->text_extra_height);
return maximum(default_size, text_size);
}

View File

@ -0,0 +1,61 @@
/* $Id$ */
/*
copyright (c) 2008 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 version 2
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 "gui/widgets/helper.hpp"
#include "log.hpp"
#include "SDL_ttf.h"
#define DBG_G LOG_STREAM_INDENT(debug, gui)
#define LOG_G LOG_STREAM_INDENT(info, gui)
#define WRN_G LOG_STREAM_INDENT(warn, gui)
#define ERR_G LOG_STREAM_INDENT(err, gui)
#define DBG_G_D LOG_STREAM_INDENT(debug, gui_draw)
#define LOG_G_D LOG_STREAM_INDENT(info, gui_draw)
#define WRN_G_D LOG_STREAM_INDENT(warn, gui_draw)
#define ERR_G_D LOG_STREAM_INDENT(err, gui_draw)
#define DBG_G_E LOG_STREAM_INDENT(debug, gui_event)
#define LOG_G_E LOG_STREAM_INDENT(info, gui_event)
#define WRN_G_E LOG_STREAM_INDENT(warn, gui_event)
#define ERR_G_E LOG_STREAM_INDENT(err, gui_event)
#define DBG_G_P LOG_STREAM_INDENT(debug, gui_parse)
#define LOG_G_P LOG_STREAM_INDENT(info, gui_parse)
#define WRN_G_P LOG_STREAM_INDENT(warn, gui_parse)
#define ERR_G_P LOG_STREAM_INDENT(err, gui_parse)
namespace gui2 {
int decode_font_style(const std::string& style)
{
if(style == "bold") {
return TTF_STYLE_BOLD;
} else if(style == "italic") {
return TTF_STYLE_ITALIC;
} else if(style == "underline") {
return TTF_STYLE_UNDERLINE;
} else if(style.empty() || style == "normal") {
return TTF_STYLE_NORMAL;
}
ERR_G << "Unknown style '" << style << "' using 'normal' instead.\n";
return TTF_STYLE_NORMAL;
}
} // namespace gui2

View File

@ -0,0 +1,26 @@
/* $Id$ */
/*
copyright (c) 2008 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 version 2
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.
*/
#ifndef __GUI_WIDGETS_HELPER_HPP_INCLUDED__
#define __GUI_WIDGETS_HELPER_HPP_INCLUDED__
#include <string>
namespace gui2 {
int decode_font_style(const std::string& style);
} // namespace gui2
#endif

View File

@ -21,6 +21,7 @@
#include "filesystem.hpp"
#include "gettext.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/helper.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/widget.hpp"
#include "gui/widgets/window_builder.hpp"
@ -333,6 +334,7 @@ tresolution_definition_::tresolution_definition_(const config& cfg) :
text_extra_width(lexical_cast_default<unsigned>(cfg["text_extra_width"])),
text_extra_height(lexical_cast_default<unsigned>(cfg["text_extra_height"])),
text_font_size(lexical_cast_default<unsigned>(cfg["text_font_size"])),
text_font_style(decode_font_style(cfg["text_font_style"])),
state()
{
/*WIKI
@ -371,6 +373,9 @@ tresolution_definition_::tresolution_definition_(const config& cfg) :
* minimal size for the text.
* text_font_size = (unsigned) The font size, which needs to be used to
* determine the minimal size for the text.
* text_font_style (font_style = "")
* The font style, which needs to be used to
* determine the minimal size for the text.
*
* [/resolution]
*/

View File

@ -79,6 +79,7 @@ public:
unsigned text_extra_width;
unsigned text_extra_height;
unsigned text_font_size;
int text_font_style;
std::vector<tstate_definition> state;