Storyscreen: store the text/title alignment as strings

This removes the need for a dedicated function in the viewer dialog to convert the enum to pango
alignments. Now the GUI2 helper function can be used directly instead.
This commit is contained in:
Charles Dang 2017-05-03 21:54:08 +11:00
parent 478fea46b6
commit 85b2aad5ba
3 changed files with 10 additions and 55 deletions

View file

@ -35,26 +35,6 @@ namespace gui2
namespace dialogs
{
// TODO: change the internal part handling to either use PangoAlignment or plain strings
// once the GUI1 screen is dropped.
static PangoAlignment storyscreen_alignment_to_pango(const storyscreen::part::TEXT_ALIGNMENT alignment)
{
PangoAlignment text_alignment = PANGO_ALIGN_LEFT;
switch(alignment) {
case storyscreen::part::TEXT_CENTERED:
text_alignment = PANGO_ALIGN_CENTER;
break;
case storyscreen::part::TEXT_RIGHT:
text_alignment = PANGO_ALIGN_RIGHT;
break;
default:
break; // already set before
}
return text_alignment;
}
// Helper function to get the canvas shape data for the shading under the title area until
// I can figure out how to ensure it always stays on top of the canvas stack.
static config get_title_area_decor_config()
@ -226,7 +206,7 @@ void story_viewer::display_part(window& window)
if(current_part_->show_title() && !title_text.empty()) {
showing_title = true;
PangoAlignment title_text_alignment = storyscreen_alignment_to_pango(current_part_->title_text_alignment());
PangoAlignment title_text_alignment = decode_text_alignment(current_part_->title_text_alignment());
title_label.set_visible(widget::visibility::visible);
title_label.set_text_alignment(title_text_alignment);
@ -279,7 +259,7 @@ void story_viewer::display_part(window& window)
}
// Convert the story part text alignment types into the Pango equivalents
PangoAlignment story_text_alignment = storyscreen_alignment_to_pango(current_part_->story_text_alignment());
PangoAlignment story_text_alignment = decode_text_alignment(current_part_->story_text_alignment());
scroll_label& text_label = find_widget<scroll_label>(&window, "part_text", false);

View file

@ -123,8 +123,8 @@ part::part(const vconfig& part_cfg)
, text_()
, text_title_()
, text_block_loc_(part::BLOCK_BOTTOM)
, text_alignment_(part::TEXT_LEFT)
, title_alignment_(part::TEXT_LEFT)
, text_alignment_("left")
, title_alignment_("left")
, music_()
, sound_()
, background_layers_()
@ -146,19 +146,6 @@ part::BLOCK_LOCATION part::string_tblock_loc(const std::string& s)
return part::BLOCK_BOTTOM;
}
part::TEXT_ALIGNMENT part::string_title_align(const std::string& s)
{
if(s.empty() != true) {
if(s == "right") {
return part::TEXT_RIGHT;
} else if(s == "center") {
return part::TEXT_CENTERED;
}
}
return part::TEXT_LEFT;
}
void part::resolve_wml(const vconfig& cfg)
{
if(cfg.null()) {
@ -224,11 +211,11 @@ void part::resolve_wml(const vconfig& cfg)
}
if(cfg.has_attribute("text_alignment")) {
text_alignment_ = string_title_align(cfg["text_alignment"]);
text_alignment_ = cfg["text_alignment"].str();
}
if(cfg.has_attribute("title_alignment")) {
title_alignment_ = string_title_align(cfg["title_alignment"]);
title_alignment_ = cfg["title_alignment"].str();
}
if(cfg.has_attribute("music")) {

View file

@ -236,17 +236,6 @@ public:
BLOCK_BOTTOM /**< Bottom of the screen. This is the default. */
};
/**
* Currently used to indicate where the page title should be placed.
* It always takes as little space (horizontally) as possible,
* and it is always placed at the top of the screen.
*/
enum TEXT_ALIGNMENT {
TEXT_LEFT, /**< Top-left corner. */
TEXT_CENTERED, /**< Center on the topmost edge of the screen. */
TEXT_RIGHT /**< Top-right corner. */
};
/**
* Used to signal user actions.
*/
@ -311,13 +300,13 @@ public:
}
/** Retrieves the alignment of the story text within the text area. */
TEXT_ALIGNMENT story_text_alignment() const
const std::string& story_text_alignment() const
{
return text_alignment_;
}
/** Retrieves the alignment of the title text against the screen. */
TEXT_ALIGNMENT title_text_alignment() const
const std::string& title_text_alignment() const
{
return title_alignment_;
}
@ -342,14 +331,13 @@ private:
virtual void resolve_wml_helper(const std::string& key, const vconfig& node) override;
static BLOCK_LOCATION string_tblock_loc(const std::string& s);
static TEXT_ALIGNMENT string_title_align(const std::string& s);
bool show_title_;
std::string text_;
std::string text_title_;
BLOCK_LOCATION text_block_loc_;
TEXT_ALIGNMENT text_alignment_;
TEXT_ALIGNMENT title_alignment_;
std::string text_alignment_;
std::string title_alignment_;
std::string music_;
std::string sound_;