Freeciv-3.1
Loading...
Searching...
No Matches
mapview.cpp
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18// Qt
19#include <QMouseEvent>
20#include <QPainter>
21#include <QPixmap>
22#include <QToolTip>
23#include <QWheelEvent>
24
25// utility
26#include "log.h"
27#include "support.h"
28
29// common
30#include "calendar.h"
31#include "game.h"
32#include "map.h"
33#include "research.h"
34
35// client
36#include "climisc.h"
37#include "mapctrl_common.h"
38#include "menu.h" // gov_menu
39#include "movement.h"
40#include "overview_common.h"
41#include "sprite.h"
42#include "repodlgs.h"
43#include "text.h"
44#include "zoom.h"
45
46// gui-qt
47#include "colors.h"
48#include "fc_client.h"
49#include "qtg_cxxside.h"
50#include "mapview.h"
51#include "sidebar.h"
52
53const char *get_timeout_label_text();
54static int mapview_frozen_level = 0;
55extern void destroy_city_dialog();
56extern struct canvas *canvas;
57
58#define MAX_DIRTY_RECTS 20
59static int num_dirty_rects = 0;
61
62extern int last_center_enemy;
63extern int last_center_capital;
65extern int last_center_enemy_city;
66
67/**********************************************************************/
70bool is_point_in_area(int x, int y, int px, int py, int pxe, int pye)
71{
72 if (x >= px && y >= py && x <= pxe && y <= pye) {
73 return true;
74 }
75 return false;
76}
77
78/**********************************************************************/
81void draw_calculated_trade_routes(QPainter *painter)
82{
83 int dx, dy;
84 float w, h;
85 float x1, y1, x2, y2;
86 qtiles qgilles;
87 struct city *pcity;
88 struct color *pcolor;
89 QPen pen;
90
92 || gui()->trade_gen.cities.empty()) {
93 return;
94 }
95 pcolor = get_color(tileset, COLOR_MAPVIEW_TRADE_ROUTES_NO_BUILT);
96 /* Draw calculated trade routes */
98
99 foreach (qgilles, gui()->trade_gen.lines) {
100 base_map_distance_vector(&dx, &dy, TILE_XY(qgilles.t1),
101 TILE_XY(qgilles.t2));
102 map_to_gui_vector(tileset, 1.0, &w, &h, dx, dy);
103
104 tile_to_canvas_pos(&x1, &y1, map_zoom, qgilles.t1);
105 tile_to_canvas_pos(&x2, &y2, map_zoom, qgilles.t2);
106
107 /* Dont draw if route was already established */
108 if (tile_city(qgilles.t1) && tile_city(qgilles.t2)
110 tile_city(qgilles.t2))) {
111 continue;
112 }
113
114 if (qgilles.autocaravan != nullptr) {
115 pcolor = get_color(tileset, COLOR_MAPVIEW_TRADE_ROUTES_SOME_BUILT);
116 }
117
118 pen.setColor(pcolor->qcolor);
119 pen.setStyle(Qt::DashLine);
120 pen.setDashOffset(4);
121 pen.setWidth(1);
122 painter->setPen(pen);
123 if (x2 - x1 == w && y2 - y1 == h) {
124 painter->drawLine(x1 + tileset_tile_width(tileset) / 2,
126 x1 + tileset_tile_width(tileset) / 2 + w,
127 y1 + tileset_tile_height(tileset) / 2 + h);
128 continue;
129 }
130 painter->drawLine(x2 + tileset_tile_width(tileset) / 2,
132 x2 + tileset_tile_width(tileset) / 2 - w,
133 y2 + tileset_tile_height(tileset) / 2 - h);
134 }
135 }
136 /* Draw virtual cities */
137 foreach (pcity, gui()->trade_gen.virtual_cities) {
138 float canvas_x, canvas_y;
139 if (pcity->tile != nullptr
141 painter->drawPixmap(static_cast<int>(canvas_x),
142 static_cast<int>(canvas_y),
144 }
145 }
146}
147
148/**********************************************************************/
152{
153 connect(&timer, &QTimer::timeout, this, &mr_idle::idling);
154 timer.start(5);
155}
156
157/**********************************************************************/
161{
162 call_me_back *cb;
163
164 while (!callback_list.isEmpty()) {
165 cb = callback_list.dequeue();
166 delete cb;
167 }
168}
169
170/**********************************************************************/
174{
175 call_me_back *cb;
176
177 while (!callback_list.isEmpty()) {
178 cb = callback_list.dequeue();
179 (cb->callback) (cb->data);
180 delete cb;
181 }
182}
183
184/**********************************************************************/
188{
189 callback_list.enqueue(cb);
190}
191
192/**********************************************************************/
196{
197 menu_click = false;
198 cursor = -1;
199 QTimer *timer = new QTimer(this);
200 setAttribute(Qt::WA_OpaquePaintEvent, true);
201 connect(timer, &QTimer::timeout, this, &map_view::timer_event);
202 timer->start(200);
203 resize(0, 0);
204 setMouseTracking(true);
206 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
207}
208
209/**********************************************************************/
213{
214 int i;
215
216 if (ct == CURSOR_DEFAULT) {
217 setCursor(Qt::ArrowCursor);
218 cursor = -1;
219 return;
220 }
221 cursor_frame = 0;
222 i = static_cast<int>(ct);
223 cursor = i;
224 setCursor(*(gui()->fc_cursors[i][0]));
225}
226
227/**********************************************************************/
231{
232 if (gui()->infotab->underMouse()
233 || gui()->minimapview_wdg->underMouse()
234 || gui()->sidebar_wdg->underMouse()) {
236 return;
237 }
238 if (cursor == -1) {
239 return;
240 }
241 cursor_frame++;
243 cursor_frame = 0;
244 }
245 setCursor(*(gui()->fc_cursors[cursor][cursor_frame]));
246}
247
248/**********************************************************************/
251void map_view::update_font(const QString &name, const QFont &font)
252{
256 }
257}
258
259/**********************************************************************/
266
267/**********************************************************************/
274
275/**********************************************************************/
278void map_view::paintEvent(QPaintEvent *event)
279{
280 QPainter painter;
281
282 painter.begin(this);
283 paint(&painter, event);
284 painter.end();
285}
286
287/**********************************************************************/
290void map_view::paint(QPainter *painter, QPaintEvent *event)
291{
292 painter->drawPixmap(event->rect(), mapview.store->map_pixmap,
293 event->rect());
295}
296
297/**********************************************************************/
300void map_view::resume_searching(int pos_x, int pos_y, int &w, int &h,
301 int wdth, int hght, int recursive_nr)
302{
303 int new_pos_x, new_pos_y;
304
305 recursive_nr++;
306 new_pos_x = pos_x;
307 new_pos_y = pos_y;
308
309 if (pos_y + hght + 4 < height() && pos_x > width() / 2) {
310 new_pos_y = pos_y + 5;
311 } else if (pos_x > 0 && pos_y > 10) {
312 new_pos_x = pos_x - 5;
313 } else if (pos_y > 0) {
314 new_pos_y = pos_y - 5;
315 } else if (pos_x + wdth + 4 < this->width()) {
316 new_pos_x = pos_x + 5;
317 }
318 find_place(new_pos_x, new_pos_y, w, h, wdth, hght, recursive_nr);
319}
320
321/**********************************************************************/
327void map_view::find_place(int pos_x, int pos_y, int &w, int &h, int wdth,
328 int hght, int recursive_nr)
329{
330 int i;
331 int x, y, xe, ye;
332 QList <fcwidget *>widgets = this->findChildren <fcwidget *>();
333 bool cont_searching = false;
334
335 if (recursive_nr >= 1000) {
339 return;
340 }
346 for (i = 0; i < widgets.count(); i++) {
347 if (!widgets[i]->isVisible()) {
348 continue;
349 }
350 x = widgets[i]->pos().x();
351 y = widgets[i]->pos().y();
352
353 if (x == 0 && y ==0) {
354 continue;
355 }
356 xe = widgets[i]->pos().x() + widgets[i]->width();
357 ye = widgets[i]->pos().y() + widgets[i]->height();
358
359 if (is_point_in_area(pos_x, pos_y, x, y, xe, ye)) {
360 cont_searching = true;
361 }
362 if (is_point_in_area(pos_x + wdth, pos_y, x, y, xe, ye)) {
363 cont_searching = true;
364 }
365 if (is_point_in_area(pos_x + wdth, pos_y + hght, x, y, xe, ye)) {
366 cont_searching = true;
367 }
368 if (is_point_in_area(pos_x, pos_y + hght, x, y, xe, ye)) {
369 cont_searching = true;
370 }
371 if (is_point_in_area(pos_x + wdth / 2, pos_y + hght / 2, x, y, xe, ye)) {
372 cont_searching = true;
373 }
374 }
375 w = pos_x;
376 h = pos_y;
377 if (cont_searching) {
378 resume_searching(pos_x, pos_y, w, h, wdth, hght, recursive_nr);
379 }
380}
381
382/**********************************************************************/
385move_widget::move_widget(QWidget *parent) : QLabel()
386{
387 QPixmap *pix;
388
389 setParent(parent);
390 setCursor(Qt::SizeAllCursor);
391 pix = fc_icons::instance()->get_pixmap("move");
392 setPixmap(*pix);
393 delete pix;
394 setFixedSize(16, 16);
395}
396
397/**********************************************************************/
401{
402 move(0, 0);
403}
404
405/**********************************************************************/
409{
410 if (!gui()->interface_locked) {
411 parentWidget()->move(event->globalPos() - point);
412 }
413}
414
415/**********************************************************************/
419{
420 if (!gui()->interface_locked) {
421 point = event->globalPos() - parentWidget()->geometry().topLeft();
422 }
423 update();
424}
425
426/**********************************************************************/
429resize_widget::resize_widget(QWidget *parent) : QLabel()
430{
431 QPixmap *pix;
432
433 setParent(parent);
434 setCursor(Qt::SizeFDiagCursor);
435 pix = fc_icons::instance()->get_pixmap("resize");
436 setPixmap(*pix);
437 delete pix;
438}
439
440/**********************************************************************/
444{
445 move(parentWidget()->width() - width(),
446 parentWidget()->height() - height());
447}
448
449/**********************************************************************/
453{
454 QPoint qp, np;
455
456 if (gui()->interface_locked) {
457 return;
458 }
459 qp = event->globalPos();
460 np.setX(qp.x() - point.x());
461 np.setY(qp.y() - point.y());
462 np.setX(qMax(np.x(), 32));
463 np.setY(qMax(np.y(), 32));
464 parentWidget()->resize(np.x(), np.y());
465}
466
467/**********************************************************************/
471{
472 QPoint qp;
473
474 if (gui()->interface_locked) {
475 return;
476 }
477 qp = event->globalPos();
478 point.setX(qp.x() - parentWidget()->width());
479 point.setY(qp.y() - parentWidget()->height());
480 update();
481}
482
483/**********************************************************************/
486close_widget::close_widget(QWidget *parent) : QLabel()
487{
488 QPixmap *pix;
489
490 setParent(parent);
491 setCursor(Qt::ArrowCursor);
492 pix = fc_icons::instance()->get_pixmap("close");
493 setPixmap(*pix);
494 delete pix;
495}
496
497/**********************************************************************/
501{
502 move(parentWidget()->width()-width(), 0);
503}
504
505/**********************************************************************/
509{
510 if (gui()->interface_locked) {
511 return;
512 }
513 if (event->button() == Qt::LeftButton) {
514 parentWidget()->hide();
516 }
517}
518
519/**********************************************************************/
523{
524 fcwidget *fcw;
525
526 fcw = reinterpret_cast<fcwidget *>(parentWidget());
527 fcw->update_menu();
528}
529
530/**********************************************************************/
534{
535 setParent(parent);
536 setAttribute(Qt::WA_OpaquePaintEvent, true);
537 w_ratio = 0.0;
538 h_ratio = 0.0;
539 // Dark magic: This call is required for the widget to work.
540 resize(0, 0);
541 background = QBrush(QColor (0, 0, 0));
542 setCursor(Qt::CrossCursor);
543 rw = new resize_widget(this);
544 rw->put_to_corner();
545 pix = new QPixmap;
546 scale_factor = 1.0;
549}
550
551/**********************************************************************/
555{
556 if (pix) {
557 delete pix;
558 }
559}
560
561/**********************************************************************/
565{
566 QPainter painter;
567
568 painter.begin(this);
569 paint(&painter, event);
570 painter.end();
571}
572
573/**********************************************************************/
576void minimap_view::scale(double factor)
577{
578 scale_factor *= factor;
579 if (scale_factor < 1) {
580 scale_factor = 1.0;
581 };
582 update_image();
583}
584
585/**********************************************************************/
588static void gui_to_overview(int *ovr_x, int *ovr_y, int gui_x, int gui_y)
589{
590 double ntl_x, ntl_y;
591 const double gui_xd = gui_x, gui_yd = gui_y;
592 const double W = tileset_tile_width(tileset);
593 const double H = tileset_tile_height(tileset);
594 double map_x, map_y;
595
597 map_x = (gui_xd * H + gui_yd * W) / (W * H);
598 map_y = (gui_yd * W - gui_xd * H) / (W * H);
599 } else {
600 map_x = gui_xd / W;
601 map_y = gui_yd / H;
602 }
603
604 if (MAP_IS_ISOMETRIC) {
605 ntl_y = map_x + map_y - wld.map.xsize;
606 ntl_x = 2 * map_x - ntl_y;
607 } else {
608 ntl_x = map_x;
609 ntl_y = map_y;
610 }
611
612 *ovr_x = floor((ntl_x - (double)gui_options.overview.map_x0)
614 *ovr_y = floor((ntl_y - (double)gui_options.overview.map_y0)
616
617 if (current_topo_has_flag(TF_WRAPX)) {
618 *ovr_x = FC_WRAP(*ovr_x, NATURAL_WIDTH * OVERVIEW_TILE_SIZE);
619 } else {
620 if (MAP_IS_ISOMETRIC) {
621 *ovr_x -= OVERVIEW_TILE_SIZE;
622 }
623 }
624 if (current_topo_has_flag(TF_WRAPY)) {
625 *ovr_y = FC_WRAP(*ovr_y, NATURAL_HEIGHT * OVERVIEW_TILE_SIZE);
626 }
627}
628
629/**********************************************************************/
633{
634 ::gui()->menu_bar->minimap_status->setChecked(false);
635}
636
637/**********************************************************************/
641{
642 position = event->pos();
643}
644
645/**********************************************************************/
649{
650 move(position);
651 event->setAccepted(true);
652}
653
654/**********************************************************************/
657void minimap_view::draw_viewport(QPainter *painter)
658{
659 int i, x[4], y[4];
660 int src_x, src_y, dst_x, dst_y;
661
662 if (!gui_options.overview.map) {
663 return;
664 }
665
671 gui_to_overview(&x[3], &y[3], mapview.gui_x0,
673 painter->setPen(QColor(Qt::white));
674
675 if (scale_factor > 1) {
676 for (i = 0; i < 4; i++) {
677 scale_point(x[i], y[i]);
678 }
679 }
680
681 for (i = 0; i < 4; i++) {
682 src_x = x[i] * w_ratio;
683 src_y = y[i] * h_ratio;
684 dst_x = x[(i + 1) % 4] * w_ratio;
685 dst_y = y[(i + 1) % 4] * h_ratio;
686 painter->drawLine(src_x, src_y, dst_x, dst_y);
687 }
688}
689
690/**********************************************************************/
693void minimap_view::scale_point(int &x, int &y)
694{
695 int ax, bx;
696 int dx, dy;
697
700 x = qRound(x * scale_factor);
701 y = qRound(y * scale_factor);
702 dx = qRound(ax * scale_factor - gui_options.overview.width / 2);
703 dy = qRound(bx * scale_factor - gui_options.overview.height / 2);
704 x = x - dx;
705 y = y - dy;
706}
707
708/**********************************************************************/
711void unscale_point(double scale_factor, int &x, int &y)
712{
713 int ax, bx;
714 int dx, dy;
715
718 dx = qRound(ax * scale_factor - gui_options.overview.width / 2);
719 dy = qRound(bx * scale_factor - gui_options.overview.height / 2);
720 x = x + dx;
721 y = y + dy;
722 x = qRound(x / scale_factor);
723 y = qRound(y / scale_factor);
724}
725
726/**********************************************************************/
730{
731 scale_factor = 1;
732}
733
734/**********************************************************************/
737void minimap_view::update_pixmap(const QImage &image)
738{
739 *pix = QPixmap::fromImage(image);
740 update();
741}
742
743/**********************************************************************/
746minimap_thread::minimap_thread(QObject *parent) : QThread(parent)
747{
748}
749
750/**********************************************************************/
754{
755 wait();
756}
757
758/**********************************************************************/
761void minimap_thread::render(double scale_factor, int width, int height)
762{
763 QMutexLocker locker(&mutex);
766 scale = scale_factor;
767 start(LowPriority);
768}
769
770/**********************************************************************/
774{
775 QImage tpix;
776 QImage gpix;
777 QImage image(QSize(mini_width, mini_height), QImage::Format_RGB32);
778 QImage bigger_pix(gui_options.overview.width * 2,
779 gui_options.overview.height * 2, QImage::Format_RGB32);
780 int delta_x, delta_y;
781 int x, y, ix, iy;
782 float wf, hf;
783 QPixmap *src, *dst;
784
785 mutex.lock();
786 if (gui_options.overview.map != nullptr) {
787 if (scale > 1) {
788 /* move minimap now,
789 scale later and draw without looking for origin */
794 ix = gui_options.overview.width - x;
795 iy = gui_options.overview.height - y;
796 pixmap_copy(dst, src, 0, 0, ix, iy, x, y);
797 pixmap_copy(dst, src, 0, y, ix, 0, x, iy);
798 pixmap_copy(dst, src, x, 0, 0, iy, ix, y);
799 pixmap_copy(dst, src, x, y, 0, 0, ix, iy);
800 tpix = gui_options.overview.window->map_pixmap.toImage();
801 wf = static_cast <float>(gui_options.overview.width) / scale;
802 hf = static_cast <float>(gui_options.overview.height) / scale;
803 x = 0;
804 y = 0;
805 unscale_point(scale, x, y);
806 bigger_pix.fill(Qt::black);
807 delta_x = gui_options.overview.width / 2;
808 delta_y = gui_options.overview.height / 2;
809 image_copy(&bigger_pix, &tpix, 0, 0, delta_x, delta_y,
811 gpix = bigger_pix.copy(delta_x + x, delta_y + y, wf, hf);
812 image = gpix.scaled(mini_width, mini_height,
813 Qt::IgnoreAspectRatio, Qt::FastTransformation);
814 } else {
815 tpix = gui_options.overview.map->map_pixmap.toImage();
816 image = tpix.scaled(mini_width, mini_height,
817 Qt::IgnoreAspectRatio, Qt::FastTransformation);
818 }
819 }
820 emit rendered_image(image);
821 mutex.unlock();
822}
823
824/**********************************************************************/
828{
829 if (isHidden()) {
830 return;
831 }
833}
834
835/**********************************************************************/
838void minimap_view::paint(QPainter * painter, QPaintEvent * event)
839{
840 int x, y, ix, iy;
841
844 ix = pix->width() - x;
845 iy = pix->height() - y;
846
847 if (scale_factor > 1) {
848 painter->drawPixmap(0, 0, *pix, 0, 0, pix->width(), pix->height());
849 } else {
850 painter->drawPixmap(ix, iy, *pix, 0, 0, x, y);
851 painter->drawPixmap(ix, 0, *pix, 0, y, x, iy);
852 painter->drawPixmap(0, iy, *pix, x, 0, ix, y);
853 painter->drawPixmap(0, 0, *pix, x, y, ix, iy);
854 }
855 painter->setPen(QColor(palette().color(QPalette::Highlight)));
856 painter->drawRect(0, 0, width() - 1, height() - 1);
857 draw_viewport(painter);
858 rw->put_to_corner();
859}
860
861/**********************************************************************/
865{
866 QSize size;
867 size = event->size();
868
869 if (C_S_RUNNING <= client_state() && size.width() > 0
870 && size.height() > 0) {
871 w_ratio = static_cast<float>(width()) / gui_options.overview.width;
872 h_ratio = static_cast<float>(height()) / gui_options.overview.height;
873 gui()->qt_settings.minimap_width = static_cast<float>(size.width())
874 / mapview.width;
875 gui()->qt_settings.minimap_height = static_cast<float>(size.height())
876 / mapview.height;
877 }
878 update_image();
879}
880
881/**********************************************************************/
885{
886 if (event->angleDelta().y() > 0) {
887 zoom_in();
888 } else {
889 zoom_out();
890 }
891 event->accept();
892}
893
894/**********************************************************************/
898{
900 scale(1.2);
901 }
902}
903
904/**********************************************************************/
908{
909 scale(0.833);
910}
911
912/**********************************************************************/
919{
920 int fx, fy;
921 int x, y;
922
923 if (event->button() == Qt::LeftButton) {
924 if (gui()->interface_locked) {
925 return;
926 }
927 cursor = event->globalPos() - geometry().topLeft();
928 }
929 if (event->button() == Qt::RightButton) {
930 cursor = event->pos();
931 fx = event->pos().x();
932 fy = event->pos().y();
933 fx = qRound(fx / w_ratio);
934 fy = qRound(fy / h_ratio);
935 if (scale_factor > 1) {
937 }
938 fx = qMax(fx, 1);
939 fy = qMax(fy, 1);
940 fx = qMin(fx, gui_options.overview.width - 1);
941 fy = qMin(fy, gui_options.overview.height - 1);
942 overview_to_map_pos(&x, &y, fx, fy);
944 update_image();
945 }
946 event->setAccepted(true);
947}
948
949/**********************************************************************/
953{
954 if (gui()->interface_locked) {
955 return;
956 }
957 if (event->buttons() & Qt::LeftButton) {
958 QPoint p, r;
959 p = event->pos();
960 r = mapTo(gui()->mapview_wdg, p);
961 p = r - p;
962 move(event->globalPos() - cursor);
963 setCursor(Qt::SizeAllCursor);
964 gui()->qt_settings.minimap_x = static_cast<float>(p.x()) / mapview.width;
965 gui()->qt_settings.minimap_y = static_cast<float>(p.y())
966 / mapview.height;
967 }
968}
969
970/**********************************************************************/
974{
975 setCursor(Qt::CrossCursor);
976}
977
978
979/**********************************************************************/
985{
986 gui()->update_info_label();
987}
988
989
990/**********************************************************************/
994{
995 QString s, eco_info;
996
997 if (current_page() != PAGE_GAME) {
998 return;
999 }
1000 if (update_info_timer == nullptr) {
1001 update_info_timer = new QTimer();
1002 update_info_timer->setSingleShot(true);
1003 connect(update_info_timer, &QTimer::timeout,
1005 update_info_timer->start(300);
1006 return;
1007 }
1008
1009 if (update_info_timer->remainingTime() > 0) {
1010 return;
1011 }
1013 if (head_of_units_in_focus() != nullptr) {
1015 }
1016 /* TRANS: T is shortcut from Turn */
1017 s = QString(_("%1 \nT:%2")).arg(calendar_text(),
1018 QString::number(game.info.turn));
1019
1022
1026
1027 if (client.conn.playing != NULL) {
1029 eco_info = QString(_("%1 (+%2)"))
1030 .arg(QString::number(client.conn.playing->economic.gold),
1031 QString::number(player_get_expected_income(client.conn.playing)));
1032 } else {
1033 eco_info = QString(_("%1 (%2)"))
1034 .arg(QString::number(client.conn.playing->economic.gold),
1035 QString::number(player_get_expected_income(client.conn.playing)));
1036 }
1037 sw_economy->set_custom_labels(eco_info);
1038 } else {
1040 }
1043 delete update_info_timer;
1044 update_info_timer = nullptr;
1045}
1046
1047
1048/**********************************************************************/
1060void update_unit_info_label(struct unit_list *punitlist)
1061{
1062 if (gui()->unitinfo_wdg->isVisible()) {
1063 gui()->unitinfo_wdg->update_actions(nullptr);
1064 }
1065}
1066
1067/**********************************************************************/
1071void update_mouse_cursor(enum cursor_type new_cursor_type)
1072{
1073 gui()->mapview_wdg->update_cursor(new_cursor_type);
1074}
1075
1076/**********************************************************************/
1081{
1082 gui()->sw_endturn->set_custom_labels(QString(get_timeout_label_text()));
1083 gui()->sw_endturn->update_final_pixmap();
1084}
1085
1086/**********************************************************************/
1092void update_turn_done_button(bool do_restore)
1093{
1095 return;
1096 }
1097 side_blink_endturn(do_restore);
1098}
1099
1100
1101/**********************************************************************/
1106void set_indicator_icons(struct sprite *bulb, struct sprite *sol,
1107 struct sprite *flake, struct sprite *gov)
1108{
1109 gui()->sw_indicators->update_final_pixmap();
1110}
1111
1112/**********************************************************************/
1116{
1117 gui()->minimapview_wdg->update_image();
1118 return NULL;
1119}
1120
1121/**********************************************************************/
1125static void flush_mapcanvas(int canvas_x, int canvas_y,
1126 int pixel_width, int pixel_height)
1127{
1128 gui()->mapview_wdg->repaint(canvas_x, canvas_y, pixel_width, pixel_height);
1129}
1130
1131/**********************************************************************/
1136 int pixel_width, int pixel_height)
1137{
1138 if (mapview_is_frozen()) {
1139 return;
1140 }
1145 dirty_rects[num_dirty_rects].setHeight(pixel_height);
1147 }
1148}
1149
1150/**********************************************************************/
1153void dirty_all(void)
1154{
1155 if (mapview_is_frozen()) {
1156 return;
1157 }
1159}
1160
1161/**********************************************************************/
1166void flush_dirty(void)
1167{
1168 if (mapview_is_frozen()) {
1169 return;
1170 }
1172 flush_mapcanvas(0, 0, gui()->mapview_wdg->width(),
1173 gui()->mapview_wdg->height());
1174 } else {
1175 int i;
1176
1177 for (i = 0; i < num_dirty_rects; i++) {
1179 dirty_rects[i].width(), dirty_rects[i].height());
1180 }
1181 }
1182 num_dirty_rects = 0;
1183}
1184
1185/**********************************************************************/
1190void gui_flush(void)
1191{
1192 gui()->mapview_wdg->update();
1193}
1194
1195/**********************************************************************/
1200{
1201 gui()->mapview_wdg->update();
1202}
1203
1204/**********************************************************************/
1208{
1209 /* PORTME */
1210}
1211
1212/**********************************************************************/
1219
1220/**********************************************************************/
1224 struct sprite *ssprite)
1225{
1226 if (!ssprite) {
1227 return;
1228 }
1229
1230 /* PORTME */
1231}
1232
1233/**********************************************************************/
1236void put_cross_overlay_tile(struct tile *ptile)
1237{
1238 float canvas_x, canvas_y;
1239
1240 if (tile_to_canvas_pos(&canvas_x, &canvas_y, map_zoom, ptile)) {
1243 }
1244
1245}
1246
1247/**********************************************************************/
1250void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
1251{
1252 /* PORTME */
1253}
1254
1255/**********************************************************************/
1259{
1260 int i;
1261 science_report *sci_rep;
1262 QWidget *w;
1263
1266 /* Update science report if open */
1267 if (gui()->is_repo_dlg_open("SCI")) {
1268 i = gui()->gimme_index_of("SCI");
1269 fc_assert(i != -1);
1270 w = gui()->game_tab_widget->widget(i);
1271 sci_rep = reinterpret_cast<science_report*>(w);
1272 sci_rep->reset_tree();
1273 sci_rep->update_report();
1274 sci_rep->repaint();
1275 }
1276}
1277
1278/**********************************************************************/
1283{
1284 *width = 0;
1285 *height = 0;
1286}
1287
1288/**********************************************************************/
1297{
1298 gui()->minimapview_wdg->resize(0, 0);
1299 gui()->minimapview_wdg->move(gui()->qt_settings.minimap_x
1300 * mapview.width,
1301 gui()->qt_settings.minimap_y
1302 * mapview.height);
1303 gui()->minimapview_wdg->resize(gui()->qt_settings.minimap_width
1304 * mapview.width,
1305 gui()->qt_settings.minimap_height
1306 * mapview.height);
1307}
1308
1309/**********************************************************************/
1313{
1314 /* TODO: PORTME. */
1315}
1316
1317/**********************************************************************/
1321{
1322 return (0 < mapview_frozen_level);
1323}
1324
1325/**********************************************************************/
1329{
1331}
1332
1333/**********************************************************************/
1337{
1338 if (1 < mapview_frozen_level) {
1340 } else {
1343 dirty_all();
1344 }
1345}
1346
1347/**********************************************************************/
1350info_tile::info_tile(struct tile *ptile, QWidget *parent): QLabel(parent)
1351{
1352 setParent(parent);
1354 itile = ptile;
1355 calc_size();
1356}
1357
1358/**********************************************************************/
1362{
1363 QFontMetrics fm(info_font);
1364 QString str;
1365 float x, y;
1366 int w = 0;
1367
1369 str_list = str.split("\n");
1370
1371 foreach(str, str_list) {
1372 w = qMax(w, fm.horizontalAdvance(str));
1373 }
1374 setFixedHeight(str_list.count() * (fm.height() + 5));
1375 setFixedWidth(w + 10);
1376
1377 if (tile_to_canvas_pos(&x, &y, map_zoom, itile)) {
1378 int fin_x;
1379 int fin_y;
1380 int wh = height();
1381 int ww = width();
1382 int pw = parentWidget()->width();
1383
1384 fin_x = x;
1385 if (y - wh > 0) {
1386 fin_y = y - wh;
1387 } else {
1388 fin_y = y + tileset_tile_height(tileset);
1389 }
1390 if (x + ww > pw) {
1391 fin_x = pw - ww;
1392 }
1393 move(fin_x, fin_y);
1394 }
1395}
1396
1397/**********************************************************************/
1400void info_tile::paint(QPainter *painter, QPaintEvent *event)
1401{
1402 QFontMetrics fm(info_font);
1403 int pos, h;
1404
1405 h = fm.height();
1406 pos = h;
1407 painter->setFont(info_font);
1408 for (int i = 0; i < str_list.count(); i++) {
1409 painter->drawText(5, pos, str_list.at(i));
1410 pos = pos + 5 + h;
1411 }
1412}
1413
1414/**********************************************************************/
1418{
1419 QPainter painter;
1420
1421 painter.begin(this);
1422 paint(&painter, event);
1423 painter.end();
1424}
1425
1426/**********************************************************************/
1429void info_tile::update_font(const QString &name, const QFont &font)
1430{
1431 if (name == fonts::notify_label) {
1432 info_font = font;
1433 calc_size();
1434 update();
1435 }
1436}
1437
1438/**********************************************************************/
1449
1450/**********************************************************************/
1454{
1455 /* Needed only with full screen zoom mode.
1456 * Not needed, nor implemented, in this client. */
1457 fc_assert(false);
1458}
#define str
Definition astring.c:76
const char * calendar_text(void)
Definition calendar.c:141
void image_copy(QImage *dest, QImage *src, int src_x, int src_y, int dest_x, int dest_y, int width, int height)
Definition canvas.cpp:119
void pixmap_copy(QPixmap *dest, QPixmap *src, int src_x, int src_y, int dest_x, int dest_y, int width, int height)
Definition canvas.cpp:100
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int struct sprite bool int int fog_y struct canvas struct sprite struct color * pcolor
Definition canvas_g.h:57
struct canvas int int canvas_y
Definition canvas_g.h:43
struct canvas int canvas_x
Definition canvas_g.h:43
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
void put_to_corner()
Definition mapview.cpp:500
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:508
close_widget(QWidget *parent)
Definition mapview.cpp:486
void notify_parent()
Definition mapview.cpp:522
fc_sidewidget * sw_tax
Definition fc_client.h:222
void update_sidebar_tooltips()
Definition pages.cpp:2125
fc_sidewidget * sw_economy
Definition fc_client.h:223
enum client_pages current_page()
void update_info_label()
Definition mapview.cpp:993
QTimer * update_info_timer
Definition fc_client.h:214
fc_sidewidget * sw_map
Definition fc_client.h:220
static fc_font * instance()
Definition fonts.cpp:41
QFont * get_font(QString name)
Definition fonts.cpp:63
QPixmap * get_pixmap(const QString &id)
static fc_icons * instance()
void set_custom_labels(QString l)
Definition sidebar.cpp:152
void update_final_pixmap()
Definition sidebar.cpp:393
virtual void update_menu()=0
void update_font(const QString &name, const QFont &font)
Definition mapview.cpp:1429
void calc_size()
Definition mapview.cpp:1361
struct tile * itile
Definition mapview.h:122
info_tile(struct tile *ptile, QWidget *parent=0)
Definition mapview.cpp:1350
void paintEvent(QPaintEvent *event)
Definition mapview.cpp:1417
QStringList str_list
Definition mapview.h:127
QFont info_font
Definition mapview.h:119
void paint(QPainter *painter, QPaintEvent *event)
Definition mapview.cpp:1400
void leaveEvent(QEvent *event)
Definition mapview.cpp:270
void paintEvent(QPaintEvent *event)
Definition mapview.cpp:278
bool menu_click
Definition mapview.h:92
bool stored_autocenter
Definition mapview.h:107
int cursor_frame
Definition mapview.h:108
int cursor
Definition mapview.h:109
void find_place(int pos_x, int pos_y, int &w, int &h, int wdth, int hght, int recursive_nr)
Definition mapview.cpp:327
void timer_event()
Definition mapview.cpp:230
void update_cursor(enum cursor_type)
Definition mapview.cpp:212
void update_font(const QString &name, const QFont &font)
Definition mapview.cpp:251
void resume_searching(int pos_x, int pos_y, int &w, int &h, int wdth, int hght, int recursive_nr)
Definition mapview.cpp:300
void paint(QPainter *painter, QPaintEvent *event)
Definition mapview.cpp:290
void focusOutEvent(QFocusEvent *event)
Definition mapview.cpp:262
void rendered_image(const QImage &image)
minimap_thread(QObject *parent=0)
Definition mapview.cpp:746
void render(double scale_factor, int width, int height)
Definition mapview.cpp:761
double scale
Definition mapview.h:211
void run() Q_DECL_OVERRIDE
Definition mapview.cpp:773
QMutex mutex
Definition mapview.h:212
QPoint position
Definition mapview.h:254
QPoint cursor
Definition mapview.h:253
void update_pixmap(const QImage &image)
Definition mapview.cpp:737
void paintEvent(QPaintEvent *event)
Definition mapview.cpp:564
void mouseMoveEvent(QMouseEvent *event)
Definition mapview.cpp:952
float w_ratio
Definition mapview.h:249
void paint(QPainter *painter, QPaintEvent *event)
Definition mapview.cpp:838
void showEvent(QShowEvent *event)
Definition mapview.cpp:648
void mouseReleaseEvent(QMouseEvent *event)
Definition mapview.cpp:973
float h_ratio
Definition mapview.h:249
void resizeEvent(QResizeEvent *event)
Definition mapview.cpp:864
minimap_view(QWidget *parent)
Definition mapview.cpp:533
double scale_factor
Definition mapview.h:248
void zoom_out()
Definition mapview.cpp:907
QPixmap * pix
Definition mapview.h:252
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:918
void zoom_in()
Definition mapview.cpp:897
resize_widget * rw
Definition mapview.h:255
void scale_point(int &x, int &y)
Definition mapview.cpp:693
void wheelEvent(QWheelEvent *event)
Definition mapview.cpp:884
virtual void update_menu()
Definition mapview.cpp:632
void moveEvent(QMoveEvent *event)
Definition mapview.cpp:640
QBrush background
Definition mapview.h:251
void reset()
Definition mapview.cpp:729
minimap_thread thread
Definition mapview.h:250
void draw_viewport(QPainter *painter)
Definition mapview.cpp:657
void update_image()
Definition mapview.cpp:827
void scale(double factor)
Definition mapview.cpp:576
void put_to_corner()
Definition mapview.cpp:400
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:418
QPoint point
Definition mapview.h:164
void mouseMoveEvent(QMouseEvent *event)
Definition mapview.cpp:408
move_widget(QWidget *parent)
Definition mapview.cpp:385
void idling()
Definition mapview.cpp:173
QQueue< call_me_back * > callback_list
Definition mapview.h:72
void add_callback(call_me_back *cb)
Definition mapview.cpp:187
void put_to_corner()
Definition mapview.cpp:443
resize_widget(QWidget *parent)
Definition mapview.cpp:429
QPoint point
Definition mapview.h:146
void mouseMoveEvent(QMouseEvent *event)
Definition mapview.cpp:452
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:470
bool can_client_control(void)
struct civclient client
enum client_states client_state(void)
@ C_S_RUNNING
Definition client_main.h:47
struct sprite * client_warming_sprite(void)
Definition climisc.c:371
struct sprite * client_cooling_sprite(void)
Definition climisc.c:388
struct sprite * client_research_sprite(void)
Definition climisc.c:348
struct sprite * client_government_sprite(void)
Definition climisc.c:406
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
struct unit_list * get_units_in_focus(void)
Definition control.c:177
struct unit * head_of_units_in_focus(void)
Definition control.c:406
enum event_type event
Definition events.c:81
bool get_turn_done_button_state()
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:57
struct world wld
Definition game.c:58
static struct tile * pos
Definition finddlg.c:53
GdkCursor * fc_cursors[CURSOR_LAST][NUM_CURSOR_FRAMES]
Definition graphics.c:48
void set_indicator_icons(struct sprite *bulb, struct sprite *sol, struct sprite *flake, struct sprite *gov)
Definition mapview.c:285
void real_menus_update(void)
Definition menu.c:2317
void unscale_point(double scale_factor, int &x, int &y)
Definition mapview.cpp:711
bool is_point_in_area(int x, int y, int px, int py, int pxe, int pye)
Definition mapview.cpp:70
void draw_calculated_trade_routes(QPainter *painter)
Definition mapview.cpp:81
void show_new_turn_info()
const char * name
Definition inputfile.c:127
#define fc_assert(condition)
Definition log.h:176
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:417
void base_map_distance_vector(int *dx, int *dy, int x0dv, int y0dv, int x1dv, int y1dv)
Definition map.c:1022
#define current_topo_has_flag(flag)
Definition map.h:45
#define NATURAL_HEIGHT
Definition map.h:221
#define MAP_IS_ISOMETRIC
Definition map.h:40
#define NATURAL_WIDTH
Definition map.h:220
void flush_dirty(void)
Definition mapview.cpp:1166
void update_info_label(void)
Definition mapview.cpp:984
void update_turn_done_button(bool do_restore)
Definition mapview.cpp:1092
int last_center_capital
Definition pages.cpp:66
void dirty_all(void)
Definition mapview.cpp:1153
int last_center_enemy
Definition pages.cpp:79
void tileset_changed(void)
Definition mapview.cpp:1258
void put_cross_overlay_tile(struct tile *ptile)
Definition mapview.cpp:1236
void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
Definition mapview.cpp:1250
static void flush_mapcanvas(int canvas_x, int canvas_y, int pixel_width, int pixel_height)
Definition mapview.cpp:1125
void update_map_canvas_scrollbars_size(void)
Definition mapview.cpp:1207
void get_overview_area_dimensions(int *width, int *height)
Definition mapview.cpp:1282
void mapview_freeze(void)
Definition mapview.cpp:1328
#define MAX_DIRTY_RECTS
Definition mapview.cpp:58
int last_center_player_city
Definition pages.cpp:67
struct canvas * canvas
void update_overview_scroll_window_pos(int x, int y)
Definition mapview.cpp:1312
void update_city_descriptions(void)
Definition mapview.cpp:1215
void unscale_point(double scale_factor, int &x, int &y)
Definition mapview.cpp:711
void pixmap_put_overlay_tile(int canvas_x, int canvas_y, struct sprite *ssprite)
Definition mapview.cpp:1223
void gui_flush(void)
Definition mapview.cpp:1190
void qtg_update_timeout_label(void)
Definition mapview.cpp:1080
void update_map_canvas_scrollbars(void)
Definition mapview.cpp:1199
bool mapview_is_frozen(void)
Definition mapview.cpp:1320
int last_center_enemy_city
Definition pages.cpp:68
void overview_size_changed(void)
Definition mapview.cpp:1296
void qtg_start_turn()
Definition mapview.cpp:1441
void qtg_map_canvas_size_refresh(void)
Definition mapview.cpp:1453
bool is_point_in_area(int x, int y, int px, int py, int pxe, int pye)
Definition mapview.cpp:70
void draw_calculated_trade_routes(QPainter *painter)
Definition mapview.cpp:81
void update_unit_info_label(struct unit_list *punitlist)
Definition mapview.cpp:1060
static int mapview_frozen_level
Definition mapview.cpp:54
void mapview_thaw(void)
Definition mapview.cpp:1336
struct canvas * get_overview_window(void)
Definition mapview.cpp:1115
static int num_dirty_rects
Definition mapview.cpp:59
const char * get_timeout_label_text()
Definition text.c:1590
static QRect dirty_rects[MAX_DIRTY_RECTS]
Definition mapview.cpp:60
void update_mouse_cursor(enum cursor_type new_cursor_type)
Definition mapview.cpp:1071
void set_indicator_icons(struct sprite *bulb, struct sprite *sol, struct sprite *flake, struct sprite *gov)
Definition mapview.cpp:1106
void destroy_city_dialog()
Definition citydlg.cpp:3721
static void gui_to_overview(int *ovr_x, int *ovr_y, int gui_x, int gui_y)
Definition mapview.cpp:588
void update_map_canvas_visible(void)
void map_to_gui_vector(const struct tileset *t, float zoom, float *gui_dx, float *gui_dy, int map_dx, int map_dy)
struct view mapview
void center_tile_mapcanvas(const struct tile *ptile)
bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, float zoom, const struct tile *ptile)
dirty_rect
Definition mapview_g.h:47
int int int pixel_width
Definition mapview_g.h:48
#define H(x, y, z)
Definition md5.c:92
static mpgui * gui
Definition mpgui_qt.cpp:52
const char *const city_productions
Definition fonts.h:33
const char *const notify_label
Definition fonts.h:28
const char *const city_names
Definition fonts.h:32
struct client_options gui_options
Definition options.c:71
void overview_to_map_pos(int *map_x, int *map_y, int overview_x, int overview_y)
int OVERVIEW_TILE_SIZE
int player_get_expected_income(const struct player *pplayer)
Definition player.c:1262
#define FC_WRAP(value, range)
Definition shared.h:65
void side_blink_endturn(bool do_restore)
Definition sidebar.cpp:690
size_t size
Definition specvec.h:72
void(* callback)(void *data)
Definition mapview.h:54
void * data
Definition mapview.h:55
QPixmap map_pixmap
Definition canvas.h:25
Definition city.h:309
struct tile * tile
Definition city.h:311
struct packet_game_info info
Definition game.h:89
int xsize
Definition map_types.h:77
struct connection conn
Definition client_main.h:96
bool draw_city_trade_routes
Definition options.h:192
struct overview overview
Definition options.h:402
bool auto_center_on_unit
Definition options.h:148
Definition colors.h:20
struct player * playing
Definition connection.h:156
double map_y0
Definition options.h:92
double map_x0
Definition options.h:92
struct canvas * map
Definition options.h:96
int width
Definition options.h:93
struct canvas * window
Definition options.h:99
int height
Definition options.h:93
struct player_economic economic
Definition player.h:284
Definition menu.h:159
struct tile * t1
Definition menu.h:160
struct tile * t2
Definition menu.h:161
struct unit * autocaravan
Definition menu.h:162
void update_report()
Definition repodlgs.cpp:958
void reset_tree()
Definition repodlgs.cpp:946
Definition tile.h:49
Definition timing.c:81
union timer::@11 start
int height
float gui_x0
struct canvas * store
float gui_y0
int width
struct civ_map map
const char * popup_info_text(struct tile *ptile)
Definition text.c:146
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define TILE_XY(ptile)
Definition tile.h:42
struct sprite * get_attention_crosshair_sprite(const struct tileset *t)
Definition tilespec.c:6689
bool tileset_is_isometric(const struct tileset *t)
Definition tilespec.c:675
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:728
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:716
#define NUM_CURSOR_FRAMES
Definition tilespec.h:300
cursor_type
Definition tilespec.h:285
@ CURSOR_DEFAULT
Definition tilespec.h:297
bool have_cities_trade_route(const struct city *pc1, const struct city *pc2)
float map_zoom
Definition zoom.c:25