Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Animate zoom in and zoom out
Browse files Browse the repository at this point in the history
This is almost a joke because rendering is too slow to see more than a few
frames, but it's also a motivation to speed it up.
lmoureaux committed Feb 6, 2022
1 parent 35b299d commit 692471c
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 15 additions & 1 deletion client/gui-qt/mapview.cpp
Original file line number Diff line number Diff line change
@@ -138,7 +138,9 @@ void draw_calculated_trade_routes(QPainter *painter)
/**
Constructor for map
*/
map_view::map_view() : QWidget()
map_view::map_view()
: QWidget(),
m_scale_animation(std::make_unique<QPropertyAnimation>(this, "scale"))
{
menu_click = false;
cursor = -1;
@@ -199,6 +201,18 @@ void map_view::show_all_fcwidgets()
* Sets the map scale.
*/
void map_view::set_scale(double scale)
{
m_scale_animation->stop();
m_scale_animation->setDuration(100);
m_scale_animation->setEndValue(scale);
m_scale_animation->setCurrentTime(0);
m_scale_animation->start();
}

/**
* Sets the map scale immediately without doing any animation.
*/
void map_view::set_scale_now(double scale)
{
m_scale = scale;
// When zoomed in, we pretend that the canvas is smaller than it is. This
5 changes: 5 additions & 0 deletions client/gui-qt/mapview.h
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
#include <QFrame>
#include <QLabel>
#include <QPointer>
#include <QPropertyAnimation>
#include <QQueue>
#include <QThread>
#include <QTimer>
@@ -42,6 +43,7 @@ void draw_calculated_trade_routes(QPainter *painter);
**************************************************************************/
class map_view : public QWidget {
Q_OBJECT
Q_PROPERTY(double scale READ scale WRITE set_scale_now);

// Ought to be a private slot
friend void debug_tile(tile *tile);
@@ -81,7 +83,9 @@ public slots:
void mouseMoveEvent(QMouseEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
void leaveEvent(QEvent *event) override;

private slots:
void set_scale_now(double scale);
void timer_event();

private:
@@ -91,6 +95,7 @@ private slots:
int cursor_frame{0};
int cursor;
double m_scale = 1;
std::unique_ptr<QPropertyAnimation> m_scale_animation;
QPointer<freeciv::tileset_debugger> m_debugger = nullptr;
std::vector<fcwidget *> m_hidden_fcwidgets;
};

0 comments on commit 692471c

Please sign in to comment.