mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-27 06:19:30 +00:00
Move set_help_string to editor-only code
No behavior changes, this is just separating it into the editor directory. This corresponds to 1.16's 76306d3fb61da9a046087fc862d960a6ac5d4cad, but has additional cleanup outside the editor directory, including removing the unused code from floating_label.cpp. Even within the editor, there are differences because of the graphics refactor.
This commit is contained in:
parent
5a3a1b69ba
commit
abfb33ebf6
@ -1098,7 +1098,7 @@ void editor_controller::show_menu(const std::vector<config>& items_arg, int xloc
|
||||
|
||||
void editor_controller::preferences()
|
||||
{
|
||||
font::clear_help_string();
|
||||
gui_->clear_help_string();
|
||||
gui2::dialogs::preferences_dialog::display();
|
||||
|
||||
gui_->queue_rerender();
|
||||
|
@ -18,12 +18,15 @@
|
||||
#include "draw.hpp"
|
||||
#include "editor/controller/editor_controller.hpp"
|
||||
#include "editor/editor_display.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "font/sdl_ttf_compat.hpp" // for pango_line_width
|
||||
#include "lexical_cast.hpp"
|
||||
#include "overlay.hpp"
|
||||
#include "reports.hpp"
|
||||
#include "team.hpp"
|
||||
#include "terrain/builder.hpp"
|
||||
#include "units/map.hpp"
|
||||
#include "video.hpp"
|
||||
|
||||
namespace wb {
|
||||
class manager;
|
||||
@ -139,4 +142,41 @@ display::overlay_map& editor_display::get_overlays()
|
||||
return controller_.get_current_map_context().get_overlays();
|
||||
}
|
||||
|
||||
void editor_display::clear_help_string()
|
||||
{
|
||||
font::remove_floating_label(help_handle_);
|
||||
help_handle_ = 0;
|
||||
}
|
||||
|
||||
void editor_display::set_help_string(const std::string& str)
|
||||
{
|
||||
clear_help_string();
|
||||
|
||||
const color_t color{0, 0, 0, 0xbb};
|
||||
|
||||
int size = font::SIZE_LARGE;
|
||||
point canvas_size = video::game_canvas_size();
|
||||
|
||||
while(size > 0) {
|
||||
if(font::pango_line_width(str, size) > canvas_size.x) {
|
||||
size--;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const int border = 5;
|
||||
|
||||
font::floating_label flabel(str);
|
||||
flabel.set_font_size(size);
|
||||
flabel.set_position(canvas_size.x / 2, canvas_size.y);
|
||||
flabel.set_bg_color(color);
|
||||
flabel.set_border_size(border);
|
||||
|
||||
help_handle_ = font::add_floating_label(flabel);
|
||||
|
||||
const auto& r = font::get_floating_label_rect(help_handle_);
|
||||
font::move_floating_label(help_handle_, 0.0, -double(r.h));
|
||||
}
|
||||
|
||||
} //end namespace editor
|
||||
|
@ -61,6 +61,17 @@ public:
|
||||
mouseover_hex_overlay_.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a help string with the given text. A 'help string' is like a tooltip,
|
||||
* but appears at the bottom of the screen so as to not be intrusive.
|
||||
*
|
||||
* @param str The text to display.
|
||||
*/
|
||||
void set_help_string(const std::string& str);
|
||||
|
||||
/** Removes the help string. */
|
||||
void clear_help_string();
|
||||
|
||||
protected:
|
||||
void draw_hex(const map_location& loc) override;
|
||||
|
||||
@ -75,6 +86,10 @@ protected:
|
||||
editor_controller& controller_;
|
||||
|
||||
texture mouseover_hex_overlay_;
|
||||
|
||||
private:
|
||||
/** ID of the floating label that's controlled by set_help_string() / clear_help_string(). */
|
||||
int help_handle_ = 0;
|
||||
};
|
||||
|
||||
} //end namespace editor
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include "gettext.hpp"
|
||||
#include "font/text_formatting.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "tooltips.hpp"
|
||||
#include "overlay.hpp"
|
||||
#include "filesystem.hpp"
|
||||
@ -191,8 +190,7 @@ void editor_palette<Item>::adjust_size(const SDL_Rect& target)
|
||||
|
||||
set_location(target);
|
||||
set_dirty(true);
|
||||
font::clear_help_string();
|
||||
font::set_help_string(get_help_string());
|
||||
gui_.set_help_string(get_help_string());
|
||||
}
|
||||
|
||||
template<class Item>
|
||||
@ -202,8 +200,7 @@ void editor_palette<Item>::select_fg_item(const std::string& item_id)
|
||||
selected_fg_item_ = item_id;
|
||||
set_dirty();
|
||||
}
|
||||
font::clear_help_string();
|
||||
font::set_help_string(get_help_string());
|
||||
gui_.set_help_string(get_help_string());
|
||||
}
|
||||
|
||||
template<class Item>
|
||||
@ -213,8 +210,7 @@ void editor_palette<Item>::select_bg_item(const std::string& item_id)
|
||||
selected_bg_item_ = item_id;
|
||||
set_dirty();
|
||||
}
|
||||
font::clear_help_string();
|
||||
font::set_help_string(get_help_string());
|
||||
gui_.set_help_string(get_help_string());
|
||||
}
|
||||
|
||||
template<class Item>
|
||||
@ -239,9 +235,9 @@ void editor_palette<Item>::hide(bool hidden)
|
||||
widget::hide(hidden);
|
||||
|
||||
if (!hidden) {
|
||||
font::set_help_string(get_help_string());
|
||||
gui_.set_help_string(get_help_string());
|
||||
} else {
|
||||
font::clear_help_string();
|
||||
gui_.clear_help_string();
|
||||
}
|
||||
|
||||
for (gui::widget& w : buttons_) {
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "draw.hpp"
|
||||
#include "editor/editor_common.hpp"
|
||||
#include "editor/toolkit/editor_toolkit.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "font/sdl_ttf_compat.hpp"
|
||||
#include "font/standard_colors.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
@ -197,7 +196,7 @@ void location_palette::hide(bool hidden)
|
||||
{
|
||||
widget::hide(hidden);
|
||||
|
||||
font::clear_help_string();
|
||||
disp_.clear_help_string();
|
||||
|
||||
std::shared_ptr<gui::button> palette_menu_button = disp_.find_menu_button("menu-editor-terrain");
|
||||
palette_menu_button->set_overlay("");
|
||||
@ -308,8 +307,7 @@ void location_palette::adjust_size(const SDL_Rect& target)
|
||||
|
||||
set_location(target);
|
||||
set_dirty(true);
|
||||
font::clear_help_string();
|
||||
font::set_help_string(get_help_string());
|
||||
disp_.set_help_string(get_help_string());
|
||||
}
|
||||
|
||||
void location_palette::select_item(const std::string& item_id)
|
||||
@ -318,8 +316,7 @@ void location_palette::select_item(const std::string& item_id)
|
||||
selected_item_ = item_id;
|
||||
set_dirty();
|
||||
}
|
||||
font::clear_help_string();
|
||||
font::set_help_string(get_help_string());
|
||||
disp_.set_help_string(get_help_string());
|
||||
}
|
||||
|
||||
std::size_t location_palette::num_items()
|
||||
|
@ -15,10 +15,9 @@
|
||||
|
||||
#include "floating_label.hpp"
|
||||
|
||||
#include "display.hpp"
|
||||
#include "draw.hpp"
|
||||
#include "draw_manager.hpp"
|
||||
#include "font/sdl_ttf_compat.hpp" // pango_line_width
|
||||
#include "font/standard_colors.hpp"
|
||||
#include "font/text.hpp"
|
||||
#include "log.hpp"
|
||||
#include "sdl/utils.hpp"
|
||||
@ -45,8 +44,6 @@ int label_id = 1;
|
||||
|
||||
std::stack<std::set<int>> label_contexts;
|
||||
|
||||
/** Curent ID of the help string. */
|
||||
int help_string_ = 0;
|
||||
}
|
||||
|
||||
namespace font
|
||||
@ -398,41 +395,4 @@ void update_floating_labels()
|
||||
}
|
||||
}
|
||||
|
||||
void set_help_string(const std::string& str)
|
||||
{
|
||||
remove_floating_label(help_string_);
|
||||
|
||||
const color_t color{0, 0, 0, 0xbb};
|
||||
|
||||
int size = font::SIZE_LARGE;
|
||||
point canvas_size = video::game_canvas_size();
|
||||
|
||||
while(size > 0) {
|
||||
if(pango_line_width(str, size) > canvas_size.x) {
|
||||
size--;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const int border = 5;
|
||||
|
||||
floating_label flabel(str);
|
||||
flabel.set_font_size(size);
|
||||
flabel.set_position(canvas_size.x / 2, canvas_size.y);
|
||||
flabel.set_bg_color(color);
|
||||
flabel.set_border_size(border);
|
||||
|
||||
help_string_ = add_floating_label(flabel);
|
||||
|
||||
const rect& r = get_floating_label_rect(help_string_);
|
||||
move_floating_label(help_string_, 0.0, -double(r.h));
|
||||
}
|
||||
|
||||
void clear_help_string()
|
||||
{
|
||||
remove_floating_label(help_string_);
|
||||
help_string_ = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -153,15 +153,4 @@ SDL_Rect get_floating_label_rect(int handle);
|
||||
void draw_floating_labels();
|
||||
void update_floating_labels();
|
||||
|
||||
/**
|
||||
* Displays a help string with the given text. A 'help string' is like a tooltip,
|
||||
* but appears at the bottom of the screen so as to not be intrusive.
|
||||
*
|
||||
* @param str The text to display.
|
||||
*/
|
||||
void set_help_string(const std::string& str);
|
||||
|
||||
/** Removes the help string. */
|
||||
void clear_help_string();
|
||||
|
||||
} // end namespace font
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "cursor.hpp"
|
||||
#include "draw.hpp"
|
||||
#include "events.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "formula/callable.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "gettext.hpp"
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
#include "actions/undo.hpp"
|
||||
#include "display_chat_manager.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "preferences/game.hpp"
|
||||
#include "game_data.hpp"
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include "display.hpp"
|
||||
#include "draw_manager.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "font/sdl_ttf_compat.hpp"
|
||||
#include "font/text.hpp"
|
||||
#include "log.hpp"
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "draw.hpp"
|
||||
#include "font/sdl_ttf_compat.hpp"
|
||||
#include "font/standard_colors.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "language.hpp"
|
||||
#include "lexical_cast.hpp"
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include "draw.hpp"
|
||||
#include "draw_manager.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "widgets/widget.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
#include "tooltips.hpp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user