Freeciv-3.4
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/**********************************************************************/
83{
84 int dx, dy;
85 float w, h;
86 float x1, y1, x2, y2;
88 struct city *pcity;
89 struct color *pcolor;
90 QPen pen;
91
93 || gui()->trade_gen.cities.empty()) {
94 return;
95 }
97 // Draw calculated trade routes
99
100 foreach (qgilles, gui()->trade_gen.lines) {
102 TILE_XY(qgilles.t2));
103 map_to_gui_vector(tileset, 1.0, &w, &h, dx, dy);
104
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) {
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 }
247}
248
249/**********************************************************************/
252void map_view::update_font(const QString &name, const QFont &font)
253{
257 }
258}
259
260/**********************************************************************/
267
268/**********************************************************************/
275
276/**********************************************************************/
280{
282
283 painter.begin(this);
285 painter.end();
286}
287
288/**********************************************************************/
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 }
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;
334 bool cont_searching = false;
335
336 if (recursive_nr >= 1000) {
337 // Give up searching position
338 return;
339 }
345 for (i = 0; i < widgets.count(); i++) {
346 if (!widgets[i]->isVisible()) {
347 continue;
348 }
349 x = widgets[i]->pos().x();
350 y = widgets[i]->pos().y();
351
352 if (x == 0 && y ==0) {
353 continue;
354 }
355 xe = widgets[i]->pos().x() + widgets[i]->width();
356 ye = widgets[i]->pos().y() + widgets[i]->height();
357
358 if (is_point_in_area(pos_x, pos_y, x, y, xe, ye)) {
359 cont_searching = true;
360 }
361 if (is_point_in_area(pos_x + wdth, pos_y, x, y, xe, ye)) {
362 cont_searching = true;
363 }
364 if (is_point_in_area(pos_x + wdth, pos_y + hght, x, y, xe, ye)) {
365 cont_searching = true;
366 }
367 if (is_point_in_area(pos_x, pos_y + hght, x, y, xe, ye)) {
368 cont_searching = true;
369 }
370 if (is_point_in_area(pos_x + wdth / 2, pos_y + hght / 2, x, y, xe, ye)) {
371 cont_searching = true;
372 }
373 }
374 w = pos_x;
375 h = pos_y;
376 if (cont_searching) {
377 resume_searching(pos_x, pos_y, w, h, wdth, hght, recursive_nr);
378 }
379}
380
381/**********************************************************************/
385{
386 QPixmap *pix;
387
389 setCursor(Qt::SizeAllCursor);
390 pix = fc_icons::instance()->get_pixmap("move");
391 setPixmap(*pix);
392 delete pix;
393 setFixedSize(16, 16);
394}
395
396/**********************************************************************/
400{
401 move(0, 0);
402}
403
404/**********************************************************************/
408{
409 if (!gui()->interface_locked) {
410 parentWidget()->move(event->globalPosition().toPoint() - point);
411 }
412}
413
414/**********************************************************************/
418{
419 if (!gui()->interface_locked) {
420 point = event->globalPosition().toPoint()
421 - parentWidget()->geometry().topLeft();
422 }
423
424 update();
425}
426
427/**********************************************************************/
431{
432 QPixmap *pix;
433
435 setCursor(Qt::SizeFDiagCursor);
436 pix = fc_icons::instance()->get_pixmap("resize");
437 setPixmap(*pix);
438 delete pix;
439}
440
441/**********************************************************************/
449
450/**********************************************************************/
454{
455 QPoint qp, np;
456
457 if (gui()->interface_locked) {
458 return;
459 }
460
461 qp = event->globalPosition().toPoint();
462 np.setX(qp.x() - point.x());
463 np.setY(qp.y() - point.y());
464 np.setX(qMax(np.x(), 32));
465 np.setY(qMax(np.y(), 32));
466 parentWidget()->resize(np.x(), np.y());
467}
468
469/**********************************************************************/
473{
474 QPoint qp;
475
476 if (gui()->interface_locked) {
477 return;
478 }
479
480 qp = event->globalPosition().toPoint();
481 point.setX(qp.x() - parentWidget()->width());
482 point.setY(qp.y() - parentWidget()->height());
483 update();
484}
485
486/**********************************************************************/
490{
491 QPixmap *pix;
492
494 setCursor(Qt::ArrowCursor);
495 pix = fc_icons::instance()->get_pixmap("close");
496 setPixmap(*pix);
497 delete pix;
498}
499
500/**********************************************************************/
504{
505 move(parentWidget()->width()-width(), 0);
506}
507
508/**********************************************************************/
512{
513 if (gui()->interface_locked) {
514 return;
515 }
516 if (event->button() == Qt::LeftButton) {
517 parentWidget()->hide();
519 }
520}
521
522/**********************************************************************/
526{
527 fcwidget *fcw;
528
529 fcw = reinterpret_cast<fcwidget *>(parentWidget());
530 fcw->update_menu();
531}
532
533/**********************************************************************/
537{
539 setAttribute(Qt::WA_OpaquePaintEvent, true);
540 w_ratio = 0.0;
541 h_ratio = 0.0;
542 // Dark magic: This call is required for the widget to work.
543 resize(0, 0);
544 background = QBrush(QColor (0, 0, 0));
545 setCursor(Qt::CrossCursor);
546 rw = new resize_widget(this);
547 rw->put_to_corner();
548 pix = new QPixmap;
549 scale_factor = 1.0;
552}
553
554/**********************************************************************/
558{
559 if (pix) {
560 delete pix;
561 }
562}
563
564/**********************************************************************/
568{
570
571 painter.begin(this);
573 painter.end();
574}
575
576/**********************************************************************/
579void minimap_view::scale(double factor)
580{
581 scale_factor *= factor;
582 if (scale_factor < 1) {
583 scale_factor = 1.0;
584 };
585 update_image();
586}
587
588/**********************************************************************/
591static void gui_to_overview(int *ovr_x, int *ovr_y, int gui_x, int gui_y)
592{
593 double ntl_x, ntl_y;
594 const double gui_xd = gui_x, gui_yd = gui_y;
595 const double W = tileset_tile_width(tileset);
596 const double H = tileset_tile_height(tileset);
597 double map_x, map_y;
598
600 map_x = (gui_xd * H + gui_yd * W) / (W * H);
601 map_y = (gui_yd * W - gui_xd * H) / (W * H);
602 } else {
603 map_x = gui_xd / W;
604 map_y = gui_yd / H;
605 }
606
607 if (MAP_IS_ISOMETRIC) {
609 ntl_x = 2 * map_x - ntl_y;
610 } else {
611 ntl_x = map_x;
612 ntl_y = map_y;
613 }
614
619
622 } else {
623 if (MAP_IS_ISOMETRIC) {
625 }
626 }
629 }
630}
631
632/**********************************************************************/
636{
637 ::gui()->menu_bar->minimap_status->setChecked(false);
638}
639
640/**********************************************************************/
644{
645 position = event->pos();
646}
647
648/**********************************************************************/
652{
653 move(position);
654 event->setAccepted(true);
655}
656
657/**********************************************************************/
661{
662 int i, x[4], y[4];
663 int src_x, src_y, dst_x, dst_y;
664
665 if (!gui_options.overview.map) {
666 return;
667 }
668
674 gui_to_overview(&x[3], &y[3], mapview.gui_x0,
676 painter->setPen(QColor(Qt::white));
677
678 if (scale_factor > 1) {
679 for (i = 0; i < 4; i++) {
680 scale_point(x[i], y[i]);
681 }
682 }
683
684 for (i = 0; i < 4; i++) {
685 src_x = x[i] * w_ratio;
686 src_y = y[i] * h_ratio;
687 dst_x = x[(i + 1) % 4] * w_ratio;
688 dst_y = y[(i + 1) % 4] * h_ratio;
689 painter->drawLine(src_x, src_y, dst_x, dst_y);
690 }
691}
692
693/**********************************************************************/
697{
698 int ax, bx;
699 int dx, dy;
700
703 x = qRound(x * scale_factor);
704 y = qRound(y * scale_factor);
707 x = x - dx;
708 y = y - dy;
709}
710
711/**********************************************************************/
714void unscale_point(double scale_factor, int &x, int &y)
715{
716 int ax, bx;
717 int dx, dy;
718
721 dx = qRound(ax * scale_factor - gui_options.overview.width / 2);
722 dy = qRound(bx * scale_factor - gui_options.overview.height / 2);
723 x = x + dx;
724 y = y + dy;
725 x = qRound(x / scale_factor);
726 y = qRound(y / scale_factor);
727}
728
729/**********************************************************************/
733{
734 scale_factor = 1;
735}
736
737/**********************************************************************/
741{
742 *pix = QPixmap::fromImage(image);
743 update();
744}
745
746/**********************************************************************/
750{
751}
752
753/**********************************************************************/
757{
758 wait();
759}
760
761/**********************************************************************/
764void minimap_thread::render(double scale_factor, int width, int height)
765{
769 scale = scale_factor;
770 start(LowPriority);
771}
772
773/**********************************************************************/
777{
778 QImage tpix;
779 QImage gpix;
780 QImage image(QSize(mini_width, mini_height), QImage::Format_RGB32);
782 gui_options.overview.height * 2, QImage::Format_RGB32);
783 int delta_x, delta_y;
784 int x, y, ix, iy;
785 float wf, hf;
786 QPixmap *src, *dst;
787
788 mutex.lock();
789 if (gui_options.overview.map != nullptr) {
790 if (scale > 1) {
791 /* move minimap now,
792 scale later and draw without looking for origin */
799 pixmap_copy(dst, src, 0, 0, ix, iy, x, y);
800 pixmap_copy(dst, src, 0, y, ix, 0, x, iy);
801 pixmap_copy(dst, src, x, 0, 0, iy, ix, y);
802 pixmap_copy(dst, src, x, y, 0, 0, ix, iy);
804 wf = static_cast <float>(gui_options.overview.width) / scale;
805 hf = static_cast <float>(gui_options.overview.height) / scale;
806 x = 0;
807 y = 0;
809 bigger_pix.fill(Qt::black);
810 delta_x = gui_options.overview.width / 2;
811 delta_y = gui_options.overview.height / 2;
812 image_copy(&bigger_pix, &tpix, 0, 0, delta_x, delta_y,
814 gpix = bigger_pix.copy(delta_x + x, delta_y + y, wf, hf);
816 Qt::IgnoreAspectRatio, Qt::FastTransformation);
817 } else {
820 Qt::IgnoreAspectRatio, Qt::FastTransformation);
821 }
822 }
824 mutex.unlock();
825}
826
827/**********************************************************************/
831{
832 if (isHidden()) {
833 return;
834 }
836}
837
838/**********************************************************************/
842{
843 int x, y, ix, iy;
844
847 ix = pix->width() - x;
848 iy = pix->height() - y;
849
850 if (scale_factor > 1) {
851 painter->drawPixmap(0, 0, *pix, 0, 0, pix->width(), pix->height());
852 } else {
853 painter->drawPixmap(ix, iy, *pix, 0, 0, x, y);
854 painter->drawPixmap(ix, 0, *pix, 0, y, x, iy);
855 painter->drawPixmap(0, iy, *pix, x, 0, ix, y);
856 painter->drawPixmap(0, 0, *pix, x, y, ix, iy);
857 }
858 painter->setPen(QColor(palette().color(QPalette::Highlight)));
859 painter->drawRect(0, 0, width() - 1, height() - 1);
861 rw->put_to_corner();
862}
863
864/**********************************************************************/
868{
869 QSize size;
870 size = event->size();
871
872 if (C_S_RUNNING <= client_state() && size.width() > 0
873 && size.height() > 0) {
874 w_ratio = static_cast<float>(width()) / gui_options.overview.width;
875 h_ratio = static_cast<float>(height()) / gui_options.overview.height;
876 gui()->qt_settings.minimap_width = static_cast<float>(size.width())
877 / mapview.width;
878 gui()->qt_settings.minimap_height = static_cast<float>(size.height())
879 / mapview.height;
880 }
881 update_image();
882}
883
884/**********************************************************************/
888{
889 if (event->angleDelta().y() > 0) {
890 zoom_in();
891 } else {
892 zoom_out();
893 }
894 event->accept();
895}
896
897/**********************************************************************/
901{
903 scale(1.2);
904 }
905}
906
907/**********************************************************************/
911{
912 scale(0.833);
913}
914
915/**********************************************************************/
922{
923 int fx, fy;
924 int x, y;
925
926 if (event->button() == Qt::LeftButton) {
927 if (gui()->interface_locked) {
928 return;
929 }
930 cursor = event->globalPosition().toPoint() - geometry().topLeft();
931 }
932
933 if (event->button() == Qt::RightButton) {
934 cursor = event->pos();
935 fx = event->pos().x();
936 fy = event->pos().y();
937 fx = qRound(fx / w_ratio);
938 fy = qRound(fy / h_ratio);
939 if (scale_factor > 1) {
941 }
942 fx = qMax(fx, 1);
943 fy = qMax(fy, 1);
948 update_image();
949 }
950
951 event->setAccepted(true);
952}
953
954/**********************************************************************/
958{
959 if (gui()->interface_locked) {
960 return;
961 }
962
963 if (event->buttons() & Qt::LeftButton) {
964 QPoint p, r;
965
966 p = event->pos();
967 r = mapTo(gui()->mapview_wdg, p);
968 p = r - p;
969 move(event->globalPosition().toPoint() - cursor);
970 setCursor(Qt::SizeAllCursor);
971 gui()->qt_settings.minimap_x = static_cast<float>(p.x()) / mapview.width;
972 gui()->qt_settings.minimap_y = static_cast<float>(p.y())
973 / mapview.height;
974 }
975}
976
977/**********************************************************************/
981{
982 setCursor(Qt::CrossCursor);
983}
984
985
986/**********************************************************************/
992{
993 gui()->update_info_label();
994}
995
996
997/**********************************************************************/
1001{
1002 QString s, eco_info;
1003
1004 if (current_page() != PAGE_GAME) {
1005 return;
1006 }
1007 if (update_info_timer == nullptr) {
1008 update_info_timer = new QTimer();
1009 update_info_timer->setSingleShot(true);
1010 connect(update_info_timer, &QTimer::timeout,
1012 update_info_timer->start(300);
1013 return;
1014 }
1015
1016 if (update_info_timer->remainingTime() > 0) {
1017 return;
1018 }
1020 if (head_of_units_in_focus() != nullptr) {
1022 }
1023 /* TRANS: T is shortcut from Turn */
1024 s = QString(_("%1 \nT:%2")).arg(calendar_text(),
1025 QString::number(game.info.turn));
1026
1029
1033
1034 if (client.conn.playing != nullptr) {
1036 eco_info = QString(_("%1 (+%2)"))
1037 .arg(QString::number(client.conn.playing->economic.gold),
1038 QString::number(player_get_expected_income(client.conn.playing)));
1039 } else {
1040 eco_info = QString(_("%1 (%2)"))
1041 .arg(QString::number(client.conn.playing->economic.gold),
1042 QString::number(player_get_expected_income(client.conn.playing)));
1043 }
1045 } else {
1047 }
1050 delete update_info_timer;
1051 update_info_timer = nullptr;
1052}
1053
1054
1055/**********************************************************************/
1067void update_unit_info_label(struct unit_list *punitlist)
1068{
1069 if (gui()->unitinfo_wdg->isVisible()) {
1070 gui()->unitinfo_wdg->update_actions(nullptr);
1071 }
1072}
1073
1074/**********************************************************************/
1079{
1080 gui()->mapview_wdg->update_cursor(new_cursor_type);
1081}
1082
1083/**********************************************************************/
1088{
1089 gui()->sw_endturn->set_custom_labels(QString(get_timeout_label_text()));
1090 gui()->sw_endturn->update_final_pixmap();
1091}
1092
1093/**********************************************************************/
1100{
1102 return;
1103 }
1105}
1106
1107
1108/**********************************************************************/
1114 struct sprite *flake, struct sprite *gov)
1115{
1116 gui()->sw_indicators->update_final_pixmap();
1117}
1118
1119/**********************************************************************/
1123{
1124 gui()->minimapview_wdg->update_image();
1125 return nullptr;
1126}
1127
1128/**********************************************************************/
1132static void flush_mapcanvas(int canvas_x, int canvas_y,
1133 int pixel_width, int pixel_height)
1134{
1135 gui()->mapview_wdg->repaint(canvas_x, canvas_y, pixel_width, pixel_height);
1136}
1137
1138/**********************************************************************/
1143 int pixel_width, int pixel_height)
1144{
1145 if (mapview_is_frozen()) {
1146 return;
1147 }
1154 }
1155}
1156
1157/**********************************************************************/
1160void dirty_all(void)
1161{
1162 if (mapview_is_frozen()) {
1163 return;
1164 }
1166}
1167
1168/**********************************************************************/
1173void flush_dirty(void)
1174{
1175 if (mapview_is_frozen()) {
1176 return;
1177 }
1179 flush_mapcanvas(0, 0, gui()->mapview_wdg->width(),
1180 gui()->mapview_wdg->height());
1181 } else {
1182 int i;
1183
1184 for (i = 0; i < num_dirty_rects; i++) {
1187 }
1188 }
1189 num_dirty_rects = 0;
1190}
1191
1192/**********************************************************************/
1197void gui_flush(void)
1198{
1199 gui()->mapview_wdg->update();
1200}
1201
1202/**********************************************************************/
1207{
1208 gui()->mapview_wdg->update();
1209}
1210
1211/**********************************************************************/
1215{
1216 // PORTME
1217}
1218
1219/**********************************************************************/
1226
1227/**********************************************************************/
1231 struct sprite *ssprite)
1232{
1233 if (!ssprite) {
1234 return;
1235 }
1236
1237 // PORTME
1238}
1239
1240/**********************************************************************/
1243void put_cross_overlay_tile(struct tile *ptile)
1244{
1245 float canvas_x, canvas_y;
1246
1247 if (tile_to_canvas_pos(&canvas_x, &canvas_y, map_zoom, ptile)) {
1250 }
1251
1252}
1253
1254/**********************************************************************/
1257void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
1258{
1259 // PORTME
1260}
1261
1262/**********************************************************************/
1266{
1267 int i;
1269 QWidget *w;
1270
1273 // Update science report if open
1274 if (gui()->is_repo_dlg_open("SCI")) {
1275 i = gui()->gimme_index_of("SCI");
1276 fc_assert(i != -1);
1277 w = gui()->game_tab_widget->widget(i);
1278 sci_rep = reinterpret_cast<science_report*>(w);
1280 sci_rep->update_report();
1281 sci_rep->repaint();
1282 }
1283}
1284
1285/**********************************************************************/
1290{
1291 *width = 0;
1292 *height = 0;
1293}
1294
1295/**********************************************************************/
1304{
1305 gui()->minimapview_wdg->resize(0, 0);
1306 gui()->minimapview_wdg->move(gui()->qt_settings.minimap_x
1307 * mapview.width,
1308 gui()->qt_settings.minimap_y
1309 * mapview.height);
1310 gui()->minimapview_wdg->resize(gui()->qt_settings.minimap_width
1311 * mapview.width,
1312 gui()->qt_settings.minimap_height
1313 * mapview.height);
1314}
1315
1316/**********************************************************************/
1320{
1321 // TODO: PORTME.
1322}
1323
1324/**********************************************************************/
1328{
1329 return (0 < mapview_frozen_level);
1330}
1331
1332/**********************************************************************/
1336{
1338}
1339
1340/**********************************************************************/
1344{
1345 if (1 < mapview_frozen_level) {
1347 } else {
1350 dirty_all();
1351 }
1352}
1353
1354/**********************************************************************/
1357info_tile::info_tile(struct tile *ptile, QWidget *parent): QLabel(parent)
1358{
1361 itile = ptile;
1362 calc_size();
1363}
1364
1365/**********************************************************************/
1369{
1371 QString str;
1372 float x, y;
1373 int w = 0;
1374
1376 str_list = str.split("\n");
1377
1378 foreach(str, str_list) {
1379 w = qMax(w, fm.horizontalAdvance(str));
1380 }
1381 setFixedHeight(str_list.count() * (fm.height() + 5));
1382 setFixedWidth(w + 10);
1383
1384 if (tile_to_canvas_pos(&x, &y, map_zoom, itile)) {
1385 int fin_x;
1386 int fin_y;
1387 int wh = height();
1388 int ww = width();
1389 int pw = parentWidget()->width();
1390
1391 fin_x = x;
1392 if (y - wh > 0) {
1393 fin_y = y - wh;
1394 } else {
1396 }
1397 if (x + ww > pw) {
1398 fin_x = pw - ww;
1399 }
1400 move(fin_x, fin_y);
1401 }
1402}
1403
1404/**********************************************************************/
1408{
1410 int pos, h;
1411
1412 h = fm.height();
1413 pos = h;
1414 painter->setFont(info_font);
1415 for (int i = 0; i < str_list.count(); i++) {
1416 painter->drawText(5, pos, str_list.at(i));
1417 pos = pos + 5 + h;
1418 }
1419}
1420
1421/**********************************************************************/
1425{
1427
1428 painter.begin(this);
1429 paint(&painter, event);
1430 painter.end();
1431}
1432
1433/**********************************************************************/
1436void info_tile::update_font(const QString &name, const QFont &font)
1437{
1438 if (name == fonts::notify_label) {
1439 info_font = font;
1440 calc_size();
1441 update();
1442 }
1443}
1444
1445/**********************************************************************/
1456
1457/**********************************************************************/
1461{
1462 /* Needed only with full screen zoom mode.
1463 * Not needed, nor implemented, in this client. */
1464 fc_assert(false);
1465}
#define str
Definition astring.c:76
const char * calendar_text(void)
Definition calendar.c:142
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:120
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:101
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
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:503
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:511
close_widget(QWidget *parent)
Definition mapview.cpp:489
void notify_parent()
Definition mapview.cpp:525
fc_sidewidget * sw_tax
Definition fc_client.h:222
void update_sidebar_tooltips()
Definition pages.cpp:2153
fc_sidewidget * sw_economy
Definition fc_client.h:223
enum client_pages current_page()
void update_info_label()
Definition mapview.cpp:1000
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:389
virtual void update_menu()=0
void update_font(const QString &name, const QFont &font)
Definition mapview.cpp:1436
void calc_size()
Definition mapview.cpp:1368
struct tile * itile
Definition mapview.h:122
info_tile(struct tile *ptile, QWidget *parent=0)
Definition mapview.cpp:1357
void paintEvent(QPaintEvent *event)
Definition mapview.cpp:1424
QStringList str_list
Definition mapview.h:127
QFont info_font
Definition mapview.h:119
void paint(QPainter *painter, QPaintEvent *event)
Definition mapview.cpp:1407
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:749
void render(double scale_factor, int width, int height)
Definition mapview.cpp:764
double scale
Definition mapview.h:211
void run() Q_DECL_OVERRIDE
Definition mapview.cpp:776
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:740
void paintEvent(QPaintEvent *event)
Definition mapview.cpp:567
void mouseMoveEvent(QMouseEvent *event)
Definition mapview.cpp:957
float w_ratio
Definition mapview.h:249
void paint(QPainter *painter, QPaintEvent *event)
Definition mapview.cpp:841
void showEvent(QShowEvent *event)
Definition mapview.cpp:651
void mouseReleaseEvent(QMouseEvent *event)
Definition mapview.cpp:980
float h_ratio
Definition mapview.h:249
void resizeEvent(QResizeEvent *event)
Definition mapview.cpp:867
minimap_view(QWidget *parent)
Definition mapview.cpp:536
double scale_factor
Definition mapview.h:248
void zoom_out()
Definition mapview.cpp:910
QPixmap * pix
Definition mapview.h:252
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:921
void zoom_in()
Definition mapview.cpp:900
resize_widget * rw
Definition mapview.h:255
void scale_point(int &x, int &y)
Definition mapview.cpp:696
void wheelEvent(QWheelEvent *event)
Definition mapview.cpp:887
virtual void update_menu()
Definition mapview.cpp:635
void moveEvent(QMoveEvent *event)
Definition mapview.cpp:643
QBrush background
Definition mapview.h:251
void reset()
Definition mapview.cpp:732
minimap_thread thread
Definition mapview.h:250
void draw_viewport(QPainter *painter)
Definition mapview.cpp:660
void update_image()
Definition mapview.cpp:830
void scale(double factor)
Definition mapview.cpp:579
void put_to_corner()
Definition mapview.cpp:399
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:417
QPoint point
Definition mapview.h:164
void mouseMoveEvent(QMouseEvent *event)
Definition mapview.cpp:407
move_widget(QWidget *parent)
Definition mapview.cpp:384
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:444
resize_widget(QWidget *parent)
Definition mapview.cpp:430
QPoint point
Definition mapview.h:146
void mouseMoveEvent(QMouseEvent *event)
Definition mapview.cpp:453
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:472
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:377
struct sprite * client_cooling_sprite(void)
Definition climisc.c:394
struct sprite * client_research_sprite(void)
Definition climisc.c:354
struct sprite * client_government_sprite(void)
Definition climisc.c:412
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
char * incite_cost
Definition comments.c:76
struct unit_list * get_units_in_focus(void)
Definition control.c:177
struct unit * head_of_units_in_focus(void)
Definition control.c:410
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
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:62
struct world wld
Definition game.c:63
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:302
void real_menus_update(void)
Definition menu.c:2364
void unscale_point(double scale_factor, int &x, int &y)
Definition mapview.cpp:714
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:177
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:434
void base_map_distance_vector(int *dx, int *dy, int x0dv, int y0dv, int x1dv, int y1dv)
Definition map.c:1162
#define current_wrap_has_flag(flag)
Definition map.h:46
void flush_dirty(void)
Definition mapview.cpp:1173
void update_info_label(void)
Definition mapview.cpp:991
void update_turn_done_button(bool do_restore)
Definition mapview.cpp:1099
int last_center_capital
Definition pages.cpp:68
void dirty_all(void)
Definition mapview.cpp:1160
int last_center_enemy
Definition pages.cpp:81
void tileset_changed(void)
Definition mapview.cpp:1265
void put_cross_overlay_tile(struct tile *ptile)
Definition mapview.cpp:1243
void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
Definition mapview.cpp:1257
static void flush_mapcanvas(int canvas_x, int canvas_y, int pixel_width, int pixel_height)
Definition mapview.cpp:1132
void update_map_canvas_scrollbars_size(void)
Definition mapview.cpp:1214
void get_overview_area_dimensions(int *width, int *height)
Definition mapview.cpp:1289
void mapview_freeze(void)
Definition mapview.cpp:1335
#define MAX_DIRTY_RECTS
Definition mapview.cpp:59
int last_center_player_city
Definition pages.cpp:69
struct canvas * canvas
void update_overview_scroll_window_pos(int x, int y)
Definition mapview.cpp:1319
void update_city_descriptions(void)
Definition mapview.cpp:1222
void unscale_point(double scale_factor, int &x, int &y)
Definition mapview.cpp:714
void pixmap_put_overlay_tile(int canvas_x, int canvas_y, struct sprite *ssprite)
Definition mapview.cpp:1230
void gui_flush(void)
Definition mapview.cpp:1197
void qtg_update_timeout_label(void)
Definition mapview.cpp:1087
void update_map_canvas_scrollbars(void)
Definition mapview.cpp:1206
bool mapview_is_frozen(void)
Definition mapview.cpp:1327
int last_center_enemy_city
Definition pages.cpp:70
void overview_size_changed(void)
Definition mapview.cpp:1303
void qtg_start_turn()
Definition mapview.cpp:1448
void qtg_map_canvas_size_refresh(void)
Definition mapview.cpp:1460
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:1067
static int mapview_frozen_level
Definition mapview.cpp:55
void mapview_thaw(void)
Definition mapview.cpp:1343
struct canvas * get_overview_window(void)
Definition mapview.cpp:1122
static int num_dirty_rects
Definition mapview.cpp:60
const char * get_timeout_label_text()
Definition text.c:1610
static QRect dirty_rects[MAX_DIRTY_RECTS]
Definition mapview.cpp:61
void update_mouse_cursor(enum cursor_type new_cursor_type)
Definition mapview.cpp:1078
void set_indicator_icons(struct sprite *bulb, struct sprite *sol, struct sprite *flake, struct sprite *gov)
Definition mapview.cpp:1113
void destroy_city_dialog()
Definition citydlg.cpp:3845
static void gui_to_overview(int *ovr_x, int *ovr_y, int gui_x, int gui_y)
Definition mapview.cpp:591
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:53
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:1294
#define FC_WRAP(value, range)
Definition shared.h:65
void side_blink_endturn(bool do_restore)
Definition sidebar.cpp:685
size_t size
Definition specvec.h:72
struct sprite int int y
Definition sprite_g.h:31
struct sprite int int int int struct sprite int int float scale
Definition sprite_g.h:33
struct sprite int x
Definition sprite_g.h:31
void(* callback)(void *data)
Definition mapview.h:54
void * data
Definition mapview.h:55
QPixmap map_pixmap
Definition canvas.h:25
Definition city.h:318
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
bool draw_city_trade_routes
Definition options.h:201
struct overview overview
Definition options.h:474
bool auto_center_on_unit
Definition options.h:156
Definition colors.h:21
struct player * playing
Definition connection.h:151
double map_y0
Definition options.h:93
double map_x0
Definition options.h:93
struct canvas * map
Definition options.h:97
int width
Definition options.h:94
struct canvas * window
Definition options.h:100
int height
Definition options.h:94
struct player_economic economic
Definition player.h:284
Definition menu.h:160
void reset_tree()
Definition repodlgs.cpp:950
Definition tile.h:50
Definition timing.c:81
union timer::@11 start
struct tile * tile
Definition unit.h:142
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:147
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define TILE_XY(ptile)
Definition tile.h:43
struct sprite * get_attention_crosshair_sprite(const struct tileset *t)
Definition tilespec.c:7238
bool tileset_is_isometric(const struct tileset *t)
Definition tilespec.c:738
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:791
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:779
#define NUM_CURSOR_FRAMES
Definition tilespec.h:305
cursor_type
Definition tilespec.h:289
@ CURSOR_DEFAULT
Definition tilespec.h:302
bool have_cities_trade_route(const struct city *pc1, const struct city *pc2)
#define MAP_NATIVE_WIDTH
#define MAP_IS_ISOMETRIC
#define MAP_NATURAL_HEIGHT
#define MAP_NATURAL_WIDTH
float map_zoom
Definition zoom.c:25