widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #08544
[Merge] lp:~widelands-dev/widelands/zoom_ui into lp:widelands
SirVer has proposed merging lp:~widelands-dev/widelands/zoom_ui into lp:widelands.
Commit message:
- Adds UI elements and keyboard shortcuts for zoom.
- Removes ctrl+0 from being a landmark shortcut. Only CTRL 1 - 9 now work.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/zoom_ui/+merge/309177
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/zoom_ui into lp:widelands.
=== added file 'data/images/wui/menus/menu_reset_zoom.png'
Binary files data/images/wui/menus/menu_reset_zoom.png 1970-01-01 00:00:00 +0000 and data/images/wui/menus/menu_reset_zoom.png 2016-10-24 21:25:40 +0000 differ
=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc 2016-10-22 18:19:22 +0000
+++ src/editor/editorinteractive.cc 2016-10-24 21:25:40 +0000
@@ -118,6 +118,9 @@
toggle_buildhelp_(INIT_BUTTON("images/wui/menus/menu_toggle_buildhelp.png",
"buildhelp",
_("Show Building Spaces (on/off)"))),
+ reset_zoom_(INIT_BUTTON("images/wui/menus/menu_reset_zoom.png",
+ "reset_zoom",
+ _("Reset zoom to 1"))),
toggle_player_menu_(
INIT_BUTTON("images/wui/editor/editor_menu_player_menu.png", "players", _("Players"))),
undo_(INIT_BUTTON("images/wui/editor/editor_undo.png", "undo", _("Undo"))),
@@ -129,6 +132,8 @@
boost::bind(&EditorInteractive::toolsize_menu_btn, this));
toggle_minimap_.sigclicked.connect(boost::bind(&EditorInteractive::toggle_minimap, this));
toggle_buildhelp_.sigclicked.connect(boost::bind(&EditorInteractive::toggle_buildhelp, this));
+ reset_zoom_.sigclicked.connect(
+ [this] { zoom_around(1.f, Vector2f(get_w() / 2.f, get_h() / 2.f)); });
toggle_player_menu_.sigclicked.connect(boost::bind(&EditorInteractive::toggle_playermenu, this));
undo_.sigclicked.connect([this] { history_->undo_action(egbase().world()); });
redo_.sigclicked.connect([this] { history_->redo_action(egbase().world()); });
@@ -138,11 +143,15 @@
toolbar_.add(&toggle_main_menu_, UI::Align::kLeft);
toolbar_.add(&toggle_tool_menu_, UI::Align::kLeft);
toolbar_.add(&toggle_toolsize_menu_, UI::Align::kLeft);
+ toolbar_.add(&toggle_player_menu_, UI::Align::kLeft);
+ toolbar_.add_space(15);
toolbar_.add(&toggle_minimap_, UI::Align::kLeft);
toolbar_.add(&toggle_buildhelp_, UI::Align::kLeft);
- toolbar_.add(&toggle_player_menu_, UI::Align::kLeft);
+ toolbar_.add(&reset_zoom_, UI::Align::kLeft);
+ toolbar_.add_space(15);
toolbar_.add(&undo_, UI::Align::kLeft);
toolbar_.add(&redo_, UI::Align::kLeft);
+ toolbar_.add_space(15);
toolbar_.add(&toggle_help_, UI::Align::kLeft);
adjust_toolbar_position();
=== modified file 'src/editor/editorinteractive.h'
--- src/editor/editorinteractive.h 2016-09-25 18:46:29 +0000
+++ src/editor/editorinteractive.h 2016-10-24 21:25:40 +0000
@@ -189,6 +189,7 @@
UI::Button toggle_toolsize_menu_;
UI::Button toggle_minimap_;
UI::Button toggle_buildhelp_;
+ UI::Button reset_zoom_;
UI::Button toggle_player_menu_;
UI::Button undo_;
UI::Button redo_;
=== modified file 'src/wui/interactive_gamebase.cc'
--- src/wui/interactive_gamebase.cc 2016-10-24 14:04:00 +0000
+++ src/wui/interactive_gamebase.cc 2016-10-24 21:25:40 +0000
@@ -62,8 +62,11 @@
TOOLBAR_BUTTON_COMMON_PARAMETERS(name), g_gr->images().get("images/" picture ".png"), tooltip
toggle_buildhelp_(INIT_BTN(
- "wui/menus/menu_toggle_buildhelp", "buildhelp", _("Show Building Spaces (on/off)"))) {
+ "wui/menus/menu_toggle_buildhelp", "buildhelp", _("Show Building Spaces (on/off)"))),
+ reset_zoom_(INIT_BTN("wui/menus/menu_reset_zoom", "reset_zoom", _("Reset zoom to 1"))) {
toggle_buildhelp_.sigclicked.connect(boost::bind(&InteractiveGameBase::toggle_buildhelp, this));
+ reset_zoom_.sigclicked.connect(
+ [this] { zoom_around(1.f, Vector2f(get_w() / 2.f, get_h() / 2.f)); });
}
/// \return a pointer to the running \ref Game instance.
=== modified file 'src/wui/interactive_gamebase.h'
--- src/wui/interactive_gamebase.h 2016-09-30 18:15:11 +0000
+++ src/wui/interactive_gamebase.h 2016-10-24 21:25:40 +0000
@@ -93,6 +93,7 @@
UI::UniqueWindow::Registry game_summary_;
UI::Button toggle_buildhelp_;
+ UI::Button reset_zoom_;
private:
void on_buildhelp_changed(const bool value) override;
=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc 2016-10-24 14:04:00 +0000
+++ src/wui/interactive_player.cc 2016-10-24 21:25:40 +0000
@@ -104,12 +104,16 @@
// they should not at all be generated. -> implement more dynamic toolbar UI
toolbar_.add(&toggle_options_menu_, UI::Align::kLeft);
toolbar_.add(&toggle_statistics_menu_, UI::Align::kLeft);
+ toolbar_.add_space(15);
toolbar_.add(&toggle_minimap_, UI::Align::kLeft);
toolbar_.add(&toggle_buildhelp_, UI::Align::kLeft);
+ toolbar_.add(&reset_zoom_, UI::Align::kLeft);
+ toolbar_.add_space(15);
if (multiplayer) {
toolbar_.add(&toggle_chat_, UI::Align::kLeft);
toggle_chat_.set_visible(false);
toggle_chat_.set_enabled(false);
+ toolbar_.add_space(15);
}
toolbar_.add(&toggle_objectives_, UI::Align::kLeft);
=== modified file 'src/wui/mapview.cc'
--- src/wui/mapview.cc 2016-10-24 20:07:22 +0000
+++ src/wui/mapview.cc 2016-10-24 21:25:40 +0000
@@ -250,20 +250,22 @@
constexpr float kPercentPerMouseWheelTick = 0.02f;
float zoom = zoom_ * static_cast<float>(
std::pow(1.f - math::sign(y) * kPercentPerMouseWheelTick, std::abs(y)));
+ zoom_around(zoom, last_mouse_pos_.cast<float>());
+ return true;
+}
+void MapView::zoom_around(float new_zoom, const Vector2f& panel_pixel) {
// Somewhat arbitrarily we limit the zoom to a reasonable value. This is for
// performance and to avoid numeric glitches with more extreme values.
constexpr float kMaxZoom = 4.f;
- zoom = math::clamp(zoom, 1.f / kMaxZoom, kMaxZoom);
+ new_zoom = math::clamp(new_zoom, 1.f / kMaxZoom, kMaxZoom);
// Zoom around the current mouse position. See
// http://stackoverflow.com/questions/2916081/zoom-in-on-a-point-using-scale-and-translate
// for a good explanation of this math.
- const Vector2f offset = -last_mouse_pos_.cast<float>() * (zoom - zoom_);
-
- zoom_ = zoom;
+ const Vector2f offset = -panel_pixel * (new_zoom - zoom_);
+ zoom_ = new_zoom;
set_viewpoint(viewpoint_ + offset, false);
- return true;
}
/*
@@ -279,3 +281,29 @@
intbase_.set_sel_pos(MapviewPixelFunctions::calc_node_and_triangle(
intbase().egbase().map(), p_in_map.x, p_in_map.y));
}
+
+bool MapView::handle_key(bool down, SDL_Keysym code) {
+ if (!down) {
+ return false;
+ }
+ if (!code.mod & KMOD_CTRL) {
+ return false;
+ }
+
+ constexpr float kPercentPerKeyPress = 0.10f;
+ switch (code.sym) {
+ case SDLK_PLUS:
+ zoom_around(zoom_ - kPercentPerKeyPress, Vector2f(get_w() / 2.f, get_h() / 2.f));
+ return true;
+ case SDLK_MINUS:
+ zoom_around(zoom_ + kPercentPerKeyPress, Vector2f(get_w() / 2.f, get_h() / 2.f));
+ return true;
+ case SDLK_0:
+ zoom_around(1.f, Vector2f(get_w() / 2.f, get_h() / 2.f));
+ return true;
+ default:
+ return false;
+ }
+ NEVER_HERE();
+}
+
=== modified file 'src/wui/mapview.h'
--- src/wui/mapview.h 2016-10-22 18:19:22 +0000
+++ src/wui/mapview.h 2016-10-24 21:25:40 +0000
@@ -67,6 +67,10 @@
// the view will perceivably jump.
void set_zoom(float zoom);
+ // Set the zoom to the 'new_zoom'. This keeps the map_pixel that is
+ // displayed at 'panel_pixel' unchanging, i.e. the center of the zoom.
+ void zoom_around(float new_zoom, const Vector2f& panel_pixel);
+
bool is_dragging() const {
return dragging_;
}
@@ -81,6 +85,7 @@
handle_mousemove(uint8_t state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff) override;
bool
handle_mousewheel(uint32_t which, int32_t x, int32_t y) override;
+ bool handle_key(bool down, SDL_Keysym code) override;
void track_sel(const Vector2f& m);
=== modified file 'src/wui/quicknavigation.cc'
--- src/wui/quicknavigation.cc 2016-10-22 18:19:22 +0000
+++ src/wui/quicknavigation.cc 2016-10-24 21:25:40 +0000
@@ -85,7 +85,7 @@
if (!down)
return false;
- if (key.sym >= SDLK_0 && key.sym <= SDLK_9) {
+ if (key.sym >= SDLK_1 && key.sym <= SDLK_9) {
unsigned int which = key.sym - SDLK_0;
assert(which < 10);
Follow ups