Author: mir3x
Date: Tue Jan 31 22:07:53 2017
New Revision: 34915

URL: http://svn.gna.org/viewcvs/freeciv?rev=34915&view=rev
Log:
Qt client - added scaling tileset

See patch #8087


Modified:
    trunk/client/gui-qt/canvas.cpp
    trunk/client/gui-qt/citydlg.cpp
    trunk/client/gui-qt/fonts.cpp
    trunk/client/gui-qt/fonts.h
    trunk/client/gui-qt/gui_main.cpp
    trunk/client/gui-qt/menu.cpp
    trunk/client/gui-qt/menu.h
    trunk/client/gui-qt/shortcuts.cpp
    trunk/client/gui-qt/shortcuts.h
    trunk/client/gui-qt/sprite.cpp

Modified: trunk/client/gui-qt/canvas.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/canvas.cpp?rev=34915&r1=34914&r2=34915&view=diff
==============================================================================
--- trunk/client/gui-qt/canvas.cpp      (original)
+++ trunk/client/gui-qt/canvas.cpp      Tue Jan 31 22:07:53 2017
@@ -22,6 +22,7 @@
 // qt-client
 #include "canvas.h"
 #include "colors.h"
+#include "fc_client.h"
 #include "fonts.h"
 #include "qtg_cxxside.h"
 #include "sprite.h"
@@ -350,12 +351,26 @@
 QFont *get_font(client_font font)
 {
   QFont *qf;
+  int ssize;
+  
   switch (font) {
   case FONT_CITY_NAME:
-    qf = fc_font::instance()->get_font(fonts::city_names);
+  qf = fc_font::instance()->get_font(fonts::city_names);
+    if (gui()->map_scale != 1.0f) {
+     ssize = ceil(gui()->map_scale * fc_font::instance()->city_fontsize);
+      if (qf->pointSize() != ssize) {
+        qf->setPointSize(ssize);
+      }
+    }
     break;
   case FONT_CITY_PROD:
     qf = fc_font::instance()->get_font(fonts::city_productions);
+    if (gui()->map_scale != 1.0f) {
+      ssize = ceil(gui()->map_scale * fc_font::instance()->prod_fontsize);
+      if (qf->pointSize() != ssize) {
+        qf->setPointSize(ssize);
+      }
+    }
     break;
   case FONT_REQTREE_TEXT:
     qf = fc_font::instance()->get_font(fonts::reqtree_text);

Modified: trunk/client/gui-qt/citydlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/citydlg.cpp?rev=34915&r1=34914&r2=34915&view=diff
==============================================================================
--- trunk/client/gui-qt/citydlg.cpp     (original)
+++ trunk/client/gui-qt/citydlg.cpp     Tue Jan 31 22:07:53 2017
@@ -1049,7 +1049,7 @@
 void city_label::mousePressEvent(QMouseEvent *event)
 {
   int citnum, i;
-  int w = tileset_small_sprite_width(tileset);
+  int w = tileset_small_sprite_width(tileset) / gui()->map_scale;
   int num_citizens = pcity->size;
 
   if (cma_is_city_under_agent(pcity, NULL)) {
@@ -2542,8 +2542,8 @@
   QPainter p;
   QPixmap *pix;
   int num_citizens = get_city_citizen_types(pcity, FEELING_FINAL, categories);
-  int w = tileset_small_sprite_width(tileset);
-  int h = tileset_small_sprite_height(tileset);
+  int w = tileset_small_sprite_width(tileset) / gui()->map_scale;
+  int h = tileset_small_sprite_height(tileset) / gui()->map_scale;
 
   i = 1 + (num_citizens * 5 / 200);
   w = w  / i;

Modified: trunk/client/gui-qt/fonts.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/fonts.cpp?rev=34915&r1=34914&r2=34915&view=diff
==============================================================================
--- trunk/client/gui-qt/fonts.cpp       (original)
+++ trunk/client/gui-qt/fonts.cpp       Tue Jan 31 22:07:53 2017
@@ -98,6 +98,7 @@
       set_font(s, f);
     }
   } options_iterate_end;
+  get_mapfont_size();
 }
 
 /****************************************************************************
@@ -110,6 +111,14 @@
   }
 }
 
+/****************************************************************************
+  Stores default font sizes
+****************************************************************************/
+void fc_font::get_mapfont_size()
+{
+  city_fontsize = get_font(fonts::city_names)->pointSize();
+  prod_fontsize = get_font(fonts::city_productions)->pointSize();
+}
 
 /****************************************************************************
   Adds new font or overwrite old one

Modified: trunk/client/gui-qt/fonts.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/fonts.h?rev=34915&r1=34914&r2=34915&view=diff
==============================================================================
--- trunk/client/gui-qt/fonts.h (original)
+++ trunk/client/gui-qt/fonts.h Tue Jan 31 22:07:53 2017
@@ -55,6 +55,9 @@
   QFont* get_font(QString name);
   void init_fonts();
   void release_fonts();
+  void get_mapfont_size();
+  int city_fontsize;
+  int prod_fontsize;
 };
 
 void configure_fonts();

Modified: trunk/client/gui-qt/gui_main.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/gui_main.cpp?rev=34915&r1=34914&r2=34915&view=diff
==============================================================================
--- trunk/client/gui-qt/gui_main.cpp    (original)
+++ trunk/client/gui-qt/gui_main.cpp    Tue Jan 31 22:07:53 2017
@@ -397,6 +397,7 @@
     gui()->infotab->chtwdg->update_font();
     QApplication::setFont(*fc_font::instance()->get_font(fonts::default_font));
     real_science_report_dialog_update();
+    fc_font::instance()->get_mapfont_size();
   }
 }
 
@@ -499,6 +500,7 @@
   remove_old = fc_font::instance()->get_font(fname);
   delete remove_old;
   fc_font::instance()->set_font(fname, f);
+  fc_font::instance()->get_mapfont_size();
 }
 
 /****************************************************************************

Modified: trunk/client/gui-qt/menu.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/menu.cpp?rev=34915&r1=34914&r2=34915&view=diff
==============================================================================
--- trunk/client/gui-qt/menu.cpp        (original)
+++ trunk/client/gui-qt/menu.cpp        Tue Jan 31 22:07:53 2017
@@ -1051,6 +1051,15 @@
   lock_status->setChecked(false);
   connect(lock_status, SIGNAL(triggered()), this, SLOT(slot_lock()));
   connect(minimap_status, SIGNAL(triggered()), this, SLOT(slot_lock()));
+  menu->addSeparator();
+  act = menu->addAction(_("Zoom in"));
+  act->setShortcut(QKeySequence(shortcut_to_string(
+                          fc_shortcuts::sc()->get_shortcut(SC_ZOOM_IN))));
+  connect(act, SIGNAL(triggered()), this, SLOT(zoom_in()));
+  act = menu->addAction(_("Zoom out"));
+  act->setShortcut(QKeySequence(shortcut_to_string(
+                          fc_shortcuts::sc()->get_shortcut(SC_ZOOM_OUT))));
+  connect(act, SIGNAL(triggered()), this, SLOT(zoom_out()));
   menu->addSeparator();
   act = menu->addAction(_("City Outlines"));
   act->setCheckable(true);
@@ -2933,6 +2942,24 @@
 }
 
 /***************************************************************************
+  Action "RELOAD ZOOMED IN TILESET"
+***************************************************************************/
+void mr_menu::zoom_in()
+{
+  gui()->map_scale = gui()->map_scale * 1.2f;
+  tilespec_reread(tileset_basename(tileset), true, gui()->map_scale);
+}
+
+/***************************************************************************
+  Action "RELOAD ZOOMED OUT TILESET"
+***************************************************************************/
+void mr_menu::zoom_out()
+{
+  gui()->map_scale = gui()->map_scale / 1.2f;
+  tilespec_reread(tileset_basename(tileset), true, gui()->map_scale);
+}
+
+/***************************************************************************
   Action "SHOW CITY NAMES"
 ***************************************************************************/
 void mr_menu::slot_city_names()
@@ -3143,6 +3170,7 @@
 
   but = qobject_cast<QPushButton *>(sender());
   tilespec_reread(but->text().toLocal8Bit().data(), true, 1.0f);
+  gui()->map_scale = 1.0f;
   but->parentWidget()->close();
 }
 

Modified: trunk/client/gui-qt/menu.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/menu.h?rev=34915&r1=34914&r2=34915&view=diff
==============================================================================
--- trunk/client/gui-qt/menu.h  (original)
+++ trunk/client/gui-qt/menu.h  Tue Jan 31 22:07:53 2017
@@ -377,6 +377,8 @@
   void slot_city_buycost();
   void slot_city_traderoutes();
   void slot_city_names();
+  void zoom_in();
+  void zoom_out();
 
   /*used by select menu */
   void slot_select_one();

Modified: trunk/client/gui-qt/shortcuts.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/shortcuts.cpp?rev=34915&r1=34914&r2=34915&view=diff
==============================================================================
--- trunk/client/gui-qt/shortcuts.cpp   (original)
+++ trunk/client/gui-qt/shortcuts.cpp   Tue Jan 31 22:07:53 2017
@@ -52,7 +52,7 @@
   RESPONSE_SAVE
 };
 
-static int num_shortcuts = 50;
+static int num_shortcuts = 52;
 fc_shortcut default_shortcuts[] = {
   {SC_SCROLL_MAP, 0, Qt::RightButton, Qt::NoModifier, "Scroll map" },
   {SC_CENTER_VIEW, Qt::Key_C, Qt::AllButtons, Qt::NoModifier,
@@ -151,7 +151,11 @@
   {SC_RELOAD_TILESET, Qt::Key_F6, Qt::AllButtons, Qt::ControlModifier
     | Qt::ShiftModifier, _("Reload tileset") },
   {SC_SHOW_FULLBAR, Qt::Key_F, Qt::AllButtons, Qt::ControlModifier,
-    _("Toggle city full bar visiblity") }
+    _("Toggle city full bar visiblity") },
+  {SC_ZOOM_IN, Qt::Key_Plus, Qt::AllButtons, Qt::NoModifier,
+    _("Reload zoomed in tileset") },
+  {SC_ZOOM_OUT, Qt::Key_Minus, Qt::AllButtons, Qt::NoModifier,
+    _("Reload zoomed out tileset") }
 };
 
 

Modified: trunk/client/gui-qt/shortcuts.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/shortcuts.h?rev=34915&r1=34914&r2=34915&view=diff
==============================================================================
--- trunk/client/gui-qt/shortcuts.h     (original)
+++ trunk/client/gui-qt/shortcuts.h     Tue Jan 31 22:07:53 2017
@@ -80,7 +80,9 @@
   SC_POPUP_COMB_INF = 47,
   SC_RELOAD_THEME = 48,
   SC_RELOAD_TILESET = 49,
-  SC_SHOW_FULLBAR = 50
+  SC_SHOW_FULLBAR = 50,
+  SC_ZOOM_IN = 51,
+  SC_ZOOM_OUT = 52
 };
 
 

Modified: trunk/client/gui-qt/sprite.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/sprite.cpp?rev=34915&r1=34914&r2=34915&view=diff
==============================================================================
--- trunk/client/gui-qt/sprite.cpp      (original)
+++ trunk/client/gui-qt/sprite.cpp      Tue Jan 31 22:07:53 2017
@@ -99,7 +99,11 @@
                                float scale)
 {
   QPainter p;
+  QRectF source_rect;
+  QRectF dest_rect;
   sprite *cropped;
+  int widthzoom;
+  int heightzoom;
 
   fc_assert_ret_val(source, NULL);
 
@@ -107,21 +111,30 @@
     return NULL;
   }
 
+  widthzoom = ceil(width * scale);
+  heightzoom = ceil(height * scale);
   cropped = new sprite;
-
-  cropped->pm = new QPixmap(width, height);
+  cropped->pm = new QPixmap(widthzoom, heightzoom);
   cropped->pm->fill(Qt::transparent);
-  QRectF source_rect(x, y, width, height);
-  QRectF dest_rect(0, 0, width, height);
+  source_rect = QRectF(x, y, width, height);
+  dest_rect = QRectF(0, 0, widthzoom, heightzoom);
 
   p.begin(cropped->pm);
-  p.drawPixmap(dest_rect, *source->pm,source_rect);
+  p.setRenderHint(QPainter::Antialiasing);
+  p.drawPixmap(dest_rect, *source->pm, source_rect);
   p.end();
 
   if (mask) {
+    int mw = mask->pm->width();
+    int mh = mask->pm->height();
+
+    source_rect = QRectF(0, 0, mw, mh);
+    dest_rect = QRectF(mask_offset_x - x, mask_offset_y - y, mw, mh);
     p.begin(cropped->pm);
     p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
-    p.drawPixmap(mask_offset_x-x, mask_offset_y - y, *mask->pm);
+    p.setRenderHint(QPainter::Antialiasing);
+    p.setRenderHint(QPainter::SmoothPixmapTransform);
+    p.drawPixmap(dest_rect, *mask->pm, source_rect);
     p.end();
   }
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to