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 "gui_main.h"
50#include "mapview.h"
51#include "qtg_cxxside.h"
52#include "sidebar.h"
53
54const char *get_timeout_label_text();
55static int mapview_frozen_level = 0;
56extern void destroy_city_dialog();
57extern struct canvas *canvas;
58
59#define MAX_DIRTY_RECTS 20
60static int num_dirty_rects = 0;
62
63extern int last_center_enemy;
64extern int last_center_capital;
66extern int last_center_enemy_city;
67
68/**********************************************************************/
71bool is_point_in_area(int x, int y, int px, int py, int pxe, int pye)
72{
73 if (x >= px && y >= py && x <= pxe && y <= pye) {
74 return true;
75 }
76 return false;
77}
78
79/**********************************************************************/
82void draw_calculated_trade_routes(QPainter *painter)
83{
84 int dx, dy;
85 float w, h;
86 float x1, y1, x2, y2;
87 qtiles qgilles;
88 struct city *pcity;
89 struct color *pcolor;
90 QPen pen;
91
93 || gui()->trade_gen.cities.empty()) {
94 return;
95 }
96 pcolor = get_color(tileset, COLOR_MAPVIEW_TRADE_ROUTES_NO_BUILT);
97 /* Draw calculated trade routes */
99
100 foreach (qgilles, gui()->trade_gen.lines) {
101 base_map_distance_vector(&dx, &dy, TILE_XY(qgilles.t1),
102 TILE_XY(qgilles.t2));
103 map_to_gui_vector(tileset, 1.0, &w, &h, dx, dy);
104
105 tile_to_canvas_pos(&x1, &y1, map_zoom, qgilles.t1);
106 tile_to_canvas_pos(&x2, &y2, map_zoom, qgilles.t2);
107
108 /* Dont draw if route was already established */
109 if (tile_city(qgilles.t1) && tile_city(qgilles.t2)
111 tile_city(qgilles.t2))) {
112 continue;
113 }
114
115 if (qgilles.autocaravan != nullptr) {
116 pcolor = get_color(tileset, COLOR_MAPVIEW_TRADE_ROUTES_SOME_BUILT);
117 }
118
119 pen.setColor(pcolor->qcolor);
120 pen.setStyle(Qt::DashLine);
121 pen.setDashOffset(4);
122 pen.setWidth(1);
123 painter->setPen(pen);
124 if (x2 - x1 == w && y2 - y1 == h) {
125 painter->drawLine(x1 + tileset_tile_width(tileset) / 2,
127 x1 + tileset_tile_width(tileset) / 2 + w,
128 y1 + tileset_tile_height(tileset) / 2 + h);
129 continue;
130 }
131 painter->drawLine(x2 + tileset_tile_width(tileset) / 2,
133 x2 + tileset_tile_width(tileset) / 2 - w,
134 y2 + tileset_tile_height(tileset) / 2 - h);
135 }
136 }
137 /* Draw virtual cities */
138 foreach (pcity, gui()->trade_gen.virtual_cities) {
139 float canvas_x, canvas_y;
140 if (pcity->tile != nullptr
142 painter->drawPixmap(static_cast<int>(canvas_x),
143 static_cast<int>(canvas_y),
145 }
146 }
147}
148
149/**********************************************************************/
153{
154 connect(&timer, &QTimer::timeout, this, &mr_idle::idling);
155 timer.start(5);
156}
157
158/**********************************************************************/
162{
163 call_me_back *cb;
164
165 while (!callback_list.isEmpty()) {
166 cb = callback_list.dequeue();
167 delete cb;
168 }
169}
170
171/**********************************************************************/
175{
176 call_me_back *cb;
177
178 while (!callback_list.isEmpty()) {
179 cb = callback_list.dequeue();
180 (cb->callback) (cb->data);
181 delete cb;
182 }
183}
184
185/**********************************************************************/
189{
190 callback_list.enqueue(cb);
191}
192
193/**********************************************************************/
197{
198 menu_click = false;
199 cursor = -1;
200 QTimer *timer = new QTimer(this);
201 setAttribute(Qt::WA_OpaquePaintEvent, true);
202 connect(timer, &QTimer::timeout, this, &map_view::timer_event);
203 timer->start(200);
204 resize(0, 0);
205 setMouseTracking(true);
207 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
208}
209
210/**********************************************************************/
214{
215 int i;
216
217 if (ct == CURSOR_DEFAULT) {
218 setCursor(Qt::ArrowCursor);
219 cursor = -1;
220 return;
221 }
222 cursor_frame = 0;
223 i = static_cast<int>(ct);
224 cursor = i;
225 setCursor(*(gui()->fc_cursors[i][0]));
226}
227
228/**********************************************************************/
232{
233 if (gui()->infotab->underMouse()
234 || gui()->minimapview_wdg->underMouse()
235 || gui()->sidebar_wdg->underMouse()) {
237 return;
238 }
239 if (cursor == -1) {
240 return;
241 }
242 cursor_frame++;
244 cursor_frame = 0;
245 }
246 setCursor(*(gui()->fc_cursors[cursor][cursor_frame]));
247}
248
249/**********************************************************************/
252void map_view::update_font(const QString &name, const QFont &font)
253{
257 }
258}
259
260/**********************************************************************/
267
268/**********************************************************************/
275
276/**********************************************************************/
279void map_view::paintEvent(QPaintEvent *event)
280{
281 QPainter painter;
282
283 painter.begin(this);
284 paint(&painter, event);
285 painter.end();
286}
287
288/**********************************************************************/
291void map_view::paint(QPainter *painter, QPaintEvent *event)
292{
293 painter->drawPixmap(event->rect(), mapview.store->map_pixmap,
294 event->rect());
296}
297
298/**********************************************************************/
301void map_view::resume_searching(int pos_x, int pos_y, int &w, int &h,
302 int wdth, int hght, int recursive_nr)
303{
304 int new_pos_x, new_pos_y;
305
306 recursive_nr++;
307 new_pos_x = pos_x;
308 new_pos_y = pos_y;
309
310 if (pos_y + hght + 4 < height() && pos_x > width() / 2) {
311 new_pos_y = pos_y + 5;
312 } else if (pos_x > 0 && pos_y > 10) {
313 new_pos_x = pos_x - 5;
314 } else if (pos_y > 0) {
315 new_pos_y = pos_y - 5;
316 } else if (pos_x + wdth + 4 < this->width()) {
317 new_pos_x = pos_x + 5;
318 }
319 find_place(new_pos_x, new_pos_y, w, h, wdth, hght, recursive_nr);
320}
321
322/**********************************************************************/
328void map_view::find_place(int pos_x, int pos_y, int &w, int &h, int wdth,
329 int hght, int recursive_nr)
330{
331 int i;
332 int x, y, xe, ye;
333 QList <fcwidget *>widgets = this->findChildren <fcwidget *>();
334 bool cont_searching = false;
335
336 if (recursive_nr >= 1000) {
340 return;
341 }
347 for (i = 0; i < widgets.count(); i++) {
348 if (!widgets[i]->isVisible()) {
349 continue;
350 }
351 x = widgets[i]->pos().x();
352 y = widgets[i]->pos().y();
353
354 if (x == 0 && y ==0) {
355 continue;
356 }
357 xe = widgets[i]->pos().x() + widgets[i]->width();
358 ye = widgets[i]->pos().y() + widgets[i]->height();
359
360 if (is_point_in_area(pos_x, pos_y, x, y, xe, ye)) {
361 cont_searching = true;
362 }
363 if (is_point_in_area(pos_x + wdth, pos_y, x, y, xe, ye)) {
364 cont_searching = true;
365 }
366 if (is_point_in_area(pos_x + wdth, pos_y + hght, x, y, xe, ye)) {
367 cont_searching = true;
368 }
369 if (is_point_in_area(pos_x, pos_y + hght, x, y, xe, ye)) {
370 cont_searching = true;
371 }
372 if (is_point_in_area(pos_x + wdth / 2, pos_y + hght / 2, x, y, xe, ye)) {
373 cont_searching = true;
374 }
375 }
376 w = pos_x;
377 h = pos_y;
378 if (cont_searching) {
379 resume_searching(pos_x, pos_y, w, h, wdth, hght, recursive_nr);
380 }
381}
382
383/**********************************************************************/
386move_widget::move_widget(QWidget *parent) : QLabel()
387{
388 QPixmap *pix;
389
390 setParent(parent);
391 setCursor(Qt::SizeAllCursor);
392 pix = fc_icons::instance()->get_pixmap("move");
393 setPixmap(*pix);
394 delete pix;
395 setFixedSize(16, 16);
396}
397
398/**********************************************************************/
402{
403 move(0, 0);
404}
405
406/**********************************************************************/
410{
411 if (!gui()->interface_locked) {
412 parentWidget()->move(mevent_gpos(event) - point);
413 }
414}
415
416/**********************************************************************/
420{
421 if (!gui()->interface_locked) {
422 point = mevent_gpos(event) - parentWidget()->geometry().topLeft();
423 }
424
425 update();
426}
427
428/**********************************************************************/
431resize_widget::resize_widget(QWidget *parent) : QLabel()
432{
433 QPixmap *pix;
434
435 setParent(parent);
436 setCursor(Qt::SizeFDiagCursor);
437 pix = fc_icons::instance()->get_pixmap("resize");
438 setPixmap(*pix);
439 delete pix;
440}
441
442/**********************************************************************/
446{
447 move(parentWidget()->width() - width(),
448 parentWidget()->height() - height());
449}
450
451/**********************************************************************/
455{
456 QPoint qp, np;
457
458 if (gui()->interface_locked) {
459 return;
460 }
461
462 qp = mevent_gpos(event);
463 np.setX(qp.x() - point.x());
464 np.setY(qp.y() - point.y());
465 np.setX(qMax(np.x(), 32));
466 np.setY(qMax(np.y(), 32));
467 parentWidget()->resize(np.x(), np.y());
468}
469
470/**********************************************************************/
474{
475 QPoint qp;
476
477 if (gui()->interface_locked) {
478 return;
479 }
480
481 qp = mevent_gpos(event);
482 point.setX(qp.x() - parentWidget()->width());
483 point.setY(qp.y() - parentWidget()->height());
484 update();
485}
486
487/**********************************************************************/
490close_widget::close_widget(QWidget *parent) : QLabel()
491{
492 QPixmap *pix;
493
494 setParent(parent);
495 setCursor(Qt::ArrowCursor);
496 pix = fc_icons::instance()->get_pixmap("close");
497 setPixmap(*pix);
498 delete pix;
499}
500
501/**********************************************************************/
505{
506 move(parentWidget()->width()-width(), 0);
507}
508
509/**********************************************************************/
513{
514 if (gui()->interface_locked) {
515 return;
516 }
517 if (event->button() == Qt::LeftButton) {
518 parentWidget()->hide();
520 }
521}
522
523/**********************************************************************/
527{
528 fcwidget *fcw;
529
530 fcw = reinterpret_cast<fcwidget *>(parentWidget());
531 fcw->update_menu();
532}
533
534/**********************************************************************/
538{
539 setParent(parent);
540 setAttribute(Qt::WA_OpaquePaintEvent, true);
541 w_ratio = 0.0;
542 h_ratio = 0.0;
543 // Dark magic: This call is required for the widget to work.
544 resize(0, 0);
545 background = QBrush(QColor (0, 0, 0));
546 setCursor(Qt::CrossCursor);
547 rw = new resize_widget(this);
548 rw->put_to_corner();
549 pix = new QPixmap;
550 scale_factor = 1.0;
553}
554
555/**********************************************************************/
559{
560 if (pix) {
561 delete pix;
562 }
563}
564
565/**********************************************************************/
569{
570 QPainter painter;
571
572 painter.begin(this);
573 paint(&painter, event);
574 painter.end();
575}
576
577/**********************************************************************/
580void minimap_view::scale(double factor)
581{
582 scale_factor *= factor;
583 if (scale_factor < 1) {
584 scale_factor = 1.0;
585 };
586 update_image();
587}
588
589/**********************************************************************/
592static void gui_to_overview(int *ovr_x, int *ovr_y, int gui_x, int gui_y)
593{
594 double ntl_x, ntl_y;
595 const double gui_xd = gui_x, gui_yd = gui_y;
596 const double W = tileset_tile_width(tileset);
597 const double H = tileset_tile_height(tileset);
598 double map_x, map_y;
599
601 map_x = (gui_xd * H + gui_yd * W) / (W * H);
602 map_y = (gui_yd * W - gui_xd * H) / (W * H);
603 } else {
604 map_x = gui_xd / W;
605 map_y = gui_yd / H;
606 }
607
608 if (MAP_IS_ISOMETRIC) {
609 ntl_y = map_x + map_y - wld.map.xsize;
610 ntl_x = 2 * map_x - ntl_y;
611 } else {
612 ntl_x = map_x;
613 ntl_y = map_y;
614 }
615
616 *ovr_x = floor((ntl_x - (double)gui_options.overview.map_x0)
618 *ovr_y = floor((ntl_y - (double)gui_options.overview.map_y0)
620
621 if (current_topo_has_flag(TF_WRAPX)) {
622 *ovr_x = FC_WRAP(*ovr_x, NATURAL_WIDTH * OVERVIEW_TILE_SIZE);
623 } else {
624 if (MAP_IS_ISOMETRIC) {
625 *ovr_x -= OVERVIEW_TILE_SIZE;
626 }
627 }
628 if (current_topo_has_flag(TF_WRAPY)) {
629 *ovr_y = FC_WRAP(*ovr_y, NATURAL_HEIGHT * OVERVIEW_TILE_SIZE);
630 }
631}
632
633/**********************************************************************/
637{
638 ::gui()->menu_bar->minimap_status->setChecked(false);
639}
640
641/**********************************************************************/
645{
646 position = event->pos();
647}
648
649/**********************************************************************/
653{
654 move(position);
655 event->setAccepted(true);
656}
657
658/**********************************************************************/
661void minimap_view::draw_viewport(QPainter *painter)
662{
663 int i, x[4], y[4];
664 int src_x, src_y, dst_x, dst_y;
665
666 if (!gui_options.overview.map) {
667 return;
668 }
669
675 gui_to_overview(&x[3], &y[3], mapview.gui_x0,
677 painter->setPen(QColor(Qt::white));
678
679 if (scale_factor > 1) {
680 for (i = 0; i < 4; i++) {
681 scale_point(x[i], y[i]);
682 }
683 }
684
685 for (i = 0; i < 4; i++) {
686 src_x = x[i] * w_ratio;
687 src_y = y[i] * h_ratio;
688 dst_x = x[(i + 1) % 4] * w_ratio;
689 dst_y = y[(i + 1) % 4] * h_ratio;
690 painter->drawLine(src_x, src_y, dst_x, dst_y);
691 }
692}
693
694/**********************************************************************/
697void minimap_view::scale_point(int &x, int &y)
698{
699 int ax, bx;
700 int dx, dy;
701
704 x = qRound(x * scale_factor);
705 y = qRound(y * scale_factor);
706 dx = qRound(ax * scale_factor - gui_options.overview.width / 2);
707 dy = qRound(bx * scale_factor - gui_options.overview.height / 2);
708 x = x - dx;
709 y = y - dy;
710}
711
712/**********************************************************************/
715void unscale_point(double scale_factor, int &x, int &y)
716{
717 int ax, bx;
718 int dx, dy;
719
722 dx = qRound(ax * scale_factor - gui_options.overview.width / 2);
723 dy = qRound(bx * scale_factor - gui_options.overview.height / 2);
724 x = x + dx;
725 y = y + dy;
726 x = qRound(x / scale_factor);
727 y = qRound(y / scale_factor);
728}
729
730/**********************************************************************/
734{
735 scale_factor = 1;
736}
737
738/**********************************************************************/
741void minimap_view::update_pixmap(const QImage &image)
742{
743 *pix = QPixmap::fromImage(image);
744 update();
745}
746
747/**********************************************************************/
750minimap_thread::minimap_thread(QObject *parent) : QThread(parent)
751{
752}
753
754/**********************************************************************/
758{
759 wait();
760}
761
762/**********************************************************************/
765void minimap_thread::render(double scale_factor, int width, int height)
766{
767 QMutexLocker locker(&mutex);
770 scale = scale_factor;
771 start(LowPriority);
772}
773
774/**********************************************************************/
778{
779 QImage tpix;
780 QImage gpix;
781 QImage image(QSize(mini_width, mini_height), QImage::Format_RGB32);
782 QImage bigger_pix(gui_options.overview.width * 2,
783 gui_options.overview.height * 2, QImage::Format_RGB32);
784 int delta_x, delta_y;
785 int x, y, ix, iy;
786 float wf, hf;
787 QPixmap *src, *dst;
788
789 mutex.lock();
790 if (gui_options.overview.map != nullptr) {
791 if (scale > 1) {
792 /* move minimap now,
793 scale later and draw without looking for origin */
798 ix = gui_options.overview.width - x;
799 iy = gui_options.overview.height - y;
800 pixmap_copy(dst, src, 0, 0, ix, iy, x, y);
801 pixmap_copy(dst, src, 0, y, ix, 0, x, iy);
802 pixmap_copy(dst, src, x, 0, 0, iy, ix, y);
803 pixmap_copy(dst, src, x, y, 0, 0, ix, iy);
804 tpix = gui_options.overview.window->map_pixmap.toImage();
805 wf = static_cast <float>(gui_options.overview.width) / scale;
806 hf = static_cast <float>(gui_options.overview.height) / scale;
807 x = 0;
808 y = 0;
809 unscale_point(scale, x, y);
810 bigger_pix.fill(Qt::black);
811 delta_x = gui_options.overview.width / 2;
812 delta_y = gui_options.overview.height / 2;
813 image_copy(&bigger_pix, &tpix, 0, 0, delta_x, delta_y,
815 gpix = bigger_pix.copy(delta_x + x, delta_y + y, wf, hf);
816 image = gpix.scaled(mini_width, mini_height,
817 Qt::IgnoreAspectRatio, Qt::FastTransformation);
818 } else {
819 tpix = gui_options.overview.map->map_pixmap.toImage();
820 image = tpix.scaled(mini_width, mini_height,
821 Qt::IgnoreAspectRatio, Qt::FastTransformation);
822 }
823 }
824 emit rendered_image(image);
825 mutex.unlock();
826}
827
828/**********************************************************************/
832{
833 if (isHidden()) {
834 return;
835 }
837}
838
839/**********************************************************************/
842void minimap_view::paint(QPainter * painter, QPaintEvent * event)
843{
844 int x, y, ix, iy;
845
848 ix = pix->width() - x;
849 iy = pix->height() - y;
850
851 if (scale_factor > 1) {
852 painter->drawPixmap(0, 0, *pix, 0, 0, pix->width(), pix->height());
853 } else {
854 painter->drawPixmap(ix, iy, *pix, 0, 0, x, y);
855 painter->drawPixmap(ix, 0, *pix, 0, y, x, iy);
856 painter->drawPixmap(0, iy, *pix, x, 0, ix, y);
857 painter->drawPixmap(0, 0, *pix, x, y, ix, iy);
858 }
859 painter->setPen(QColor(palette().color(QPalette::Highlight)));
860 painter->drawRect(0, 0, width() - 1, height() - 1);
861 draw_viewport(painter);
862 rw->put_to_corner();
863}
864
865/**********************************************************************/
869{
870 QSize size;
871 size = event->size();
872
873 if (C_S_RUNNING <= client_state() && size.width() > 0
874 && size.height() > 0) {
875 w_ratio = static_cast<float>(width()) / gui_options.overview.width;
876 h_ratio = static_cast<float>(height()) / gui_options.overview.height;
877 gui()->qt_settings.minimap_width = static_cast<float>(size.width())
878 / mapview.width;
879 gui()->qt_settings.minimap_height = static_cast<float>(size.height())
880 / mapview.height;
881 }
882 update_image();
883}
884
885/**********************************************************************/
889{
890 if (event->angleDelta().y() > 0) {
891 zoom_in();
892 } else {
893 zoom_out();
894 }
895 event->accept();
896}
897
898/**********************************************************************/
902{
904 scale(1.2);
905 }
906}
907
908/**********************************************************************/
912{
913 scale(0.833);
914}
915
916/**********************************************************************/
923{
924 int fx, fy;
925 int x, y;
926
927 if (event->button() == Qt::LeftButton) {
928 if (gui()->interface_locked) {
929 return;
930 }
931 cursor = mevent_gpos(event) - geometry().topLeft();
932 }
933
934 if (event->button() == Qt::RightButton) {
935 cursor = event->pos();
936 fx = event->pos().x();
937 fy = event->pos().y();
938 fx = qRound(fx / w_ratio);
939 fy = qRound(fy / h_ratio);
940 if (scale_factor > 1) {
942 }
943 fx = qMax(fx, 1);
944 fy = qMax(fy, 1);
945 fx = qMin(fx, gui_options.overview.width - 1);
946 fy = qMin(fy, gui_options.overview.height - 1);
947 overview_to_map_pos(&x, &y, fx, fy);
949 update_image();
950 }
951
952 event->setAccepted(true);
953}
954
955/**********************************************************************/
959{
960 if (gui()->interface_locked) {
961 return;
962 }
963
964 if (event->buttons() & Qt::LeftButton) {
965 QPoint p, r;
966
967 p = event->pos();
968 r = mapTo(gui()->mapview_wdg, p);
969 p = r - p;
971 setCursor(Qt::SizeAllCursor);
972 gui()->qt_settings.minimap_x = static_cast<float>(p.x()) / mapview.width;
973 gui()->qt_settings.minimap_y = static_cast<float>(p.y())
974 / mapview.height;
975 }
976}
977
978/**********************************************************************/
982{
983 setCursor(Qt::CrossCursor);
984}
985
986
987/**********************************************************************/
993{
994 gui()->update_info_label();
995}
996
997
998/**********************************************************************/
1002{
1003 QString s, eco_info;
1004
1005 if (current_page() != PAGE_GAME) {
1006 return;
1007 }
1008 if (update_info_timer == nullptr) {
1009 update_info_timer = new QTimer();
1010 update_info_timer->setSingleShot(true);
1011 connect(update_info_timer, &QTimer::timeout,
1013 update_info_timer->start(300);
1014 return;
1015 }
1016
1017 if (update_info_timer->remainingTime() > 0) {
1018 return;
1019 }
1021 if (head_of_units_in_focus() != nullptr) {
1023 }
1024 /* TRANS: T is shortcut from Turn */
1025 s = QString(_("%1 \nT:%2")).arg(calendar_text(),
1026 QString::number(game.info.turn));
1027
1030
1034
1035 if (client.conn.playing != NULL) {
1037 eco_info = QString(_("%1 (+%2)"))
1038 .arg(QString::number(client.conn.playing->economic.gold),
1039 QString::number(player_get_expected_income(client.conn.playing)));
1040 } else {
1041 eco_info = QString(_("%1 (%2)"))
1042 .arg(QString::number(client.conn.playing->economic.gold),
1043 QString::number(player_get_expected_income(client.conn.playing)));
1044 }
1045 sw_economy->set_custom_labels(eco_info);
1046 } else {
1048 }
1051 delete update_info_timer;
1052 update_info_timer = nullptr;
1053}
1054
1055
1056/**********************************************************************/
1068void update_unit_info_label(struct unit_list *punitlist)
1069{
1070 if (gui()->unitinfo_wdg->isVisible()) {
1071 gui()->unitinfo_wdg->update_actions(nullptr);
1072 }
1073}
1074
1075/**********************************************************************/
1079void update_mouse_cursor(enum cursor_type new_cursor_type)
1080{
1081 gui()->mapview_wdg->update_cursor(new_cursor_type);
1082}
1083
1084/**********************************************************************/
1089{
1090 gui()->sw_endturn->set_custom_labels(QString(get_timeout_label_text()));
1091 gui()->sw_endturn->update_final_pixmap();
1092}
1093
1094/**********************************************************************/
1100void update_turn_done_button(bool do_restore)
1101{
1103 return;
1104 }
1105 side_blink_endturn(do_restore);
1106}
1107
1108
1109/**********************************************************************/
1114void set_indicator_icons(struct sprite *bulb, struct sprite *sol,
1115 struct sprite *flake, struct sprite *gov)
1116{
1117 gui()->sw_indicators->update_final_pixmap();
1118}
1119
1120/**********************************************************************/
1124{
1125 gui()->minimapview_wdg->update_image();
1126 return NULL;
1127}
1128
1129/**********************************************************************/
1133static void flush_mapcanvas(int canvas_x, int canvas_y,
1134 int pixel_width, int pixel_height)
1135{
1136 gui()->mapview_wdg->repaint(canvas_x, canvas_y, pixel_width, pixel_height);
1137}
1138
1139/**********************************************************************/
1144 int pixel_width, int pixel_height)
1145{
1146 if (mapview_is_frozen()) {
1147 return;
1148 }
1153 dirty_rects[num_dirty_rects].setHeight(pixel_height);
1155 }
1156}
1157
1158/**********************************************************************/
1161void dirty_all(void)
1162{
1163 if (mapview_is_frozen()) {
1164 return;
1165 }
1167}
1168
1169/**********************************************************************/
1174void flush_dirty(void)
1175{
1176 if (mapview_is_frozen()) {
1177 return;
1178 }
1180 flush_mapcanvas(0, 0, gui()->mapview_wdg->width(),
1181 gui()->mapview_wdg->height());
1182 } else {
1183 int i;
1184
1185 for (i = 0; i < num_dirty_rects; i++) {
1187 dirty_rects[i].width(), dirty_rects[i].height());
1188 }
1189 }
1190 num_dirty_rects = 0;
1191}
1192
1193/**********************************************************************/
1198void gui_flush(void)
1199{
1200 gui()->mapview_wdg->update();
1201}
1202
1203/**********************************************************************/
1208{
1209 gui()->mapview_wdg->update();
1210}
1211
1212/**********************************************************************/
1216{
1217 /* PORTME */
1218}
1219
1220/**********************************************************************/
1227
1228/**********************************************************************/
1232 struct sprite *ssprite)
1233{
1234 if (!ssprite) {
1235 return;
1236 }
1237
1238 /* PORTME */
1239}
1240
1241/**********************************************************************/
1244void put_cross_overlay_tile(struct tile *ptile)
1245{
1246 float canvas_x, canvas_y;
1247
1248 if (tile_to_canvas_pos(&canvas_x, &canvas_y, map_zoom, ptile)) {
1251 }
1252
1253}
1254
1255/**********************************************************************/
1258void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
1259{
1260 /* PORTME */
1261}
1262
1263/**********************************************************************/
1267{
1268 int i;
1269 science_report *sci_rep;
1270 QWidget *w;
1271
1274 /* Update science report if open */
1275 if (gui()->is_repo_dlg_open("SCI")) {
1276 i = gui()->gimme_index_of("SCI");
1277 fc_assert(i != -1);
1278 w = gui()->game_tab_widget->widget(i);
1279 sci_rep = reinterpret_cast<science_report*>(w);
1280 sci_rep->reset_tree();
1281 sci_rep->update_report();
1282 sci_rep->repaint();
1283 }
1284}
1285
1286/**********************************************************************/
1291{
1292 *width = 0;
1293 *height = 0;
1294}
1295
1296/**********************************************************************/
1305{
1306 gui()->minimapview_wdg->resize(0, 0);
1307 gui()->minimapview_wdg->move(gui()->qt_settings.minimap_x
1308 * mapview.width,
1309 gui()->qt_settings.minimap_y
1310 * mapview.height);
1311 gui()->minimapview_wdg->resize(gui()->qt_settings.minimap_width
1312 * mapview.width,
1313 gui()->qt_settings.minimap_height
1314 * mapview.height);
1315}
1316
1317/**********************************************************************/
1321{
1322 /* TODO: PORTME. */
1323}
1324
1325/**********************************************************************/
1329{
1330 return (0 < mapview_frozen_level);
1331}
1332
1333/**********************************************************************/
1337{
1339}
1340
1341/**********************************************************************/
1345{
1346 if (1 < mapview_frozen_level) {
1348 } else {
1351 dirty_all();
1352 }
1353}
1354
1355/**********************************************************************/
1358info_tile::info_tile(struct tile *ptile, QWidget *parent): QLabel(parent)
1359{
1360 setParent(parent);
1362 itile = ptile;
1363 calc_size();
1364}
1365
1366/**********************************************************************/
1370{
1371 QFontMetrics fm(info_font);
1372 QString str;
1373 float x, y;
1374 int w = 0;
1375
1377 str_list = str.split("\n");
1378
1379 foreach(str, str_list) {
1380 w = qMax(w, fm.horizontalAdvance(str));
1381 }
1382 setFixedHeight(str_list.count() * (fm.height() + 5));
1383 setFixedWidth(w + 10);
1384
1385 if (tile_to_canvas_pos(&x, &y, map_zoom, itile)) {
1386 int fin_x;
1387 int fin_y;
1388 int wh = height();
1389 int ww = width();
1390 int pw = parentWidget()->width();
1391
1392 fin_x = x;
1393 if (y - wh > 0) {
1394 fin_y = y - wh;
1395 } else {
1396 fin_y = y + tileset_tile_height(tileset);
1397 }
1398 if (x + ww > pw) {
1399 fin_x = pw - ww;
1400 }
1401 move(fin_x, fin_y);
1402 }
1403}
1404
1405/**********************************************************************/
1408void info_tile::paint(QPainter *painter, QPaintEvent *event)
1409{
1410 QFontMetrics fm(info_font);
1411 int pos, h;
1412
1413 h = fm.height();
1414 pos = h;
1415 painter->setFont(info_font);
1416 for (int i = 0; i < str_list.count(); i++) {
1417 painter->drawText(5, pos, str_list.at(i));
1418 pos = pos + 5 + h;
1419 }
1420}
1421
1422/**********************************************************************/
1426{
1427 QPainter painter;
1428
1429 painter.begin(this);
1430 paint(&painter, event);
1431 painter.end();
1432}
1433
1434/**********************************************************************/
1437void info_tile::update_font(const QString &name, const QFont &font)
1438{
1439 if (name == fonts::notify_label) {
1440 info_font = font;
1441 calc_size();
1442 update();
1443 }
1444}
1445
1446/**********************************************************************/
1457
1458/**********************************************************************/
1462{
1463 /* Needed only with full screen zoom mode.
1464 * Not needed, nor implemented, in this client. */
1465 fc_assert(false);
1466}
#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:504
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:512
close_widget(QWidget *parent)
Definition mapview.cpp:490
void notify_parent()
Definition mapview.cpp:526
fc_sidewidget * sw_tax
Definition fc_client.h:222
void update_sidebar_tooltips()
Definition pages.cpp:2137
fc_sidewidget * sw_economy
Definition fc_client.h:223
enum client_pages current_page()
void update_info_label()
Definition mapview.cpp:1001
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:1437
void calc_size()
Definition mapview.cpp:1369
struct tile * itile
Definition mapview.h:122
info_tile(struct tile *ptile, QWidget *parent=0)
Definition mapview.cpp:1358
void paintEvent(QPaintEvent *event)
Definition mapview.cpp:1425
QStringList str_list
Definition mapview.h:127
QFont info_font
Definition mapview.h:119
void paint(QPainter *painter, QPaintEvent *event)
Definition mapview.cpp:1408
void leaveEvent(QEvent *event)
Definition mapview.cpp:271
void paintEvent(QPaintEvent *event)
Definition mapview.cpp:279
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:328
void timer_event()
Definition mapview.cpp:231
void update_cursor(enum cursor_type)
Definition mapview.cpp:213
void update_font(const QString &name, const QFont &font)
Definition mapview.cpp:252
void resume_searching(int pos_x, int pos_y, int &w, int &h, int wdth, int hght, int recursive_nr)
Definition mapview.cpp:301
void paint(QPainter *painter, QPaintEvent *event)
Definition mapview.cpp:291
void focusOutEvent(QFocusEvent *event)
Definition mapview.cpp:263
void rendered_image(const QImage &image)
minimap_thread(QObject *parent=0)
Definition mapview.cpp:750
void render(double scale_factor, int width, int height)
Definition mapview.cpp:765
double scale
Definition mapview.h:211
void run() Q_DECL_OVERRIDE
Definition mapview.cpp:777
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:741
void paintEvent(QPaintEvent *event)
Definition mapview.cpp:568
void mouseMoveEvent(QMouseEvent *event)
Definition mapview.cpp:958
float w_ratio
Definition mapview.h:249
void paint(QPainter *painter, QPaintEvent *event)
Definition mapview.cpp:842
void showEvent(QShowEvent *event)
Definition mapview.cpp:652
void mouseReleaseEvent(QMouseEvent *event)
Definition mapview.cpp:981
float h_ratio
Definition mapview.h:249
void resizeEvent(QResizeEvent *event)
Definition mapview.cpp:868
minimap_view(QWidget *parent)
Definition mapview.cpp:537
double scale_factor
Definition mapview.h:248
void zoom_out()
Definition mapview.cpp:911
QPixmap * pix
Definition mapview.h:252
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:922
void zoom_in()
Definition mapview.cpp:901
resize_widget * rw
Definition mapview.h:255
void scale_point(int &x, int &y)
Definition mapview.cpp:697
void wheelEvent(QWheelEvent *event)
Definition mapview.cpp:888
virtual void update_menu()
Definition mapview.cpp:636
void moveEvent(QMoveEvent *event)
Definition mapview.cpp:644
QBrush background
Definition mapview.h:251
void reset()
Definition mapview.cpp:733
minimap_thread thread
Definition mapview.h:250
void draw_viewport(QPainter *painter)
Definition mapview.cpp:661
void update_image()
Definition mapview.cpp:831
void scale(double factor)
Definition mapview.cpp:580
void put_to_corner()
Definition mapview.cpp:401
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:419
QPoint point
Definition mapview.h:164
void mouseMoveEvent(QMouseEvent *event)
Definition mapview.cpp:409
move_widget(QWidget *parent)
Definition mapview.cpp:386
void idling()
Definition mapview.cpp:174
QQueue< call_me_back * > callback_list
Definition mapview.h:72
void add_callback(call_me_back *cb)
Definition mapview.cpp:188
void put_to_corner()
Definition mapview.cpp:445
resize_widget(QWidget *parent)
Definition mapview.cpp:431
QPoint point
Definition mapview.h:146
void mouseMoveEvent(QMouseEvent *event)
Definition mapview.cpp:454
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:473
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:411
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
#define mevent_gpos(__ev__)
Definition gui_main.h:29
void unscale_point(double scale_factor, int &x, int &y)
Definition mapview.cpp:715
bool is_point_in_area(int x, int y, int px, int py, int pxe, int pye)
Definition mapview.cpp:71
void draw_calculated_trade_routes(QPainter *painter)
Definition mapview.cpp:82
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:1174
void update_info_label(void)
Definition mapview.cpp:992
void update_turn_done_button(bool do_restore)
Definition mapview.cpp:1100
int last_center_capital
Definition pages.cpp:66
void dirty_all(void)
Definition mapview.cpp:1161
int last_center_enemy
Definition pages.cpp:79
void tileset_changed(void)
Definition mapview.cpp:1266
void put_cross_overlay_tile(struct tile *ptile)
Definition mapview.cpp:1244
void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
Definition mapview.cpp:1258
static void flush_mapcanvas(int canvas_x, int canvas_y, int pixel_width, int pixel_height)
Definition mapview.cpp:1133
void update_map_canvas_scrollbars_size(void)
Definition mapview.cpp:1215
void get_overview_area_dimensions(int *width, int *height)
Definition mapview.cpp:1290
void mapview_freeze(void)
Definition mapview.cpp:1336
#define MAX_DIRTY_RECTS
Definition mapview.cpp:59
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:1320
void update_city_descriptions(void)
Definition mapview.cpp:1223
void unscale_point(double scale_factor, int &x, int &y)
Definition mapview.cpp:715
void pixmap_put_overlay_tile(int canvas_x, int canvas_y, struct sprite *ssprite)
Definition mapview.cpp:1231
void gui_flush(void)
Definition mapview.cpp:1198
void qtg_update_timeout_label(void)
Definition mapview.cpp:1088
void update_map_canvas_scrollbars(void)
Definition mapview.cpp:1207
bool mapview_is_frozen(void)
Definition mapview.cpp:1328
int last_center_enemy_city
Definition pages.cpp:68
void overview_size_changed(void)
Definition mapview.cpp:1304
void qtg_start_turn()
Definition mapview.cpp:1449
void qtg_map_canvas_size_refresh(void)
Definition mapview.cpp:1461
bool is_point_in_area(int x, int y, int px, int py, int pxe, int pye)
Definition mapview.cpp:71
void draw_calculated_trade_routes(QPainter *painter)
Definition mapview.cpp:82
void update_unit_info_label(struct unit_list *punitlist)
Definition mapview.cpp:1068
static int mapview_frozen_level
Definition mapview.cpp:55
void mapview_thaw(void)
Definition mapview.cpp:1344
struct canvas * get_overview_window(void)
Definition mapview.cpp:1123
static int num_dirty_rects
Definition mapview.cpp:60
const char * get_timeout_label_text()
Definition text.c:1590
static QRect dirty_rects[MAX_DIRTY_RECTS]
Definition mapview.cpp:61
void update_mouse_cursor(enum cursor_type new_cursor_type)
Definition mapview.cpp:1079
void set_indicator_icons(struct sprite *bulb, struct sprite *sol, struct sprite *flake, struct sprite *gov)
Definition mapview.cpp:1114
void destroy_city_dialog()
Definition citydlg.cpp:3736
static void gui_to_overview(int *ovr_x, int *ovr_y, int gui_x, int gui_y)
Definition mapview.cpp:592
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:959
void reset_tree()
Definition repodlgs.cpp:947
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:6685
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