ManaPlus
touchmanager.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
23 
24 #include "configuration.h"
25 
26 #include "gui/gui.h"
27 #include "gui/skin.h"
28 #include "gui/theme.h"
29 
30 #include "gui/fonts/font.h"
31 
32 #include "input/inputmanager.h"
33 #include "input/mouseinput.h"
34 
36 
37 #include "utils/delete2.h"
38 #include "utils/foreach.h"
39 
40 #include "render/graphics.h"
41 
43 
44 #include "resources/imagerect.h"
45 
46 #include "resources/image/image.h"
47 
48 #include "debug.h"
49 
51 
52 extern RenderType openGLMode;
53 
55  mKeyboard(nullptr),
56  mPad(nullptr),
57  mObjects(),
58  mVertexes(nullptr),
59  mRedraw(true),
60  mShowJoystick(false),
61  mShowButtons(false),
62  mShowKeyboard(false),
63  mButtonsSize(1),
64  mJoystickSize(1),
65  mButtonsFormat(0),
66  mWidth(0),
67  mHeight(0),
68  mShow(false),
69  mInGame(false),
70  mTempHideButtons(false)
71 {
72  for (int f = 0; f < actionsSize; f ++)
73  mActions[f] = false;
74  for (int f = 0; f < buttonsCount; f ++)
75  mButtons[f] = nullptr;
76 }
77 
79 {
80  clear();
82 }
83 
85 {
86  config.removeListeners(this);
87 }
88 
90 {
91  delete mVertexes;
93 
94  config.addListener("showScreenJoystick", this);
95  config.addListener("showScreenButtons", this);
96  config.addListener("showScreenKeyboard", this);
97  config.addListener("screenButtonsSize", this);
98  config.addListener("screenJoystickSize", this);
99  config.addListener("screenButtonsFormat", this);
100 
101  mShowJoystick = config.getBoolValue("showScreenJoystick");
102  mShowButtons = config.getBoolValue("showScreenButtons");
103  mShowKeyboard = config.getBoolValue("showScreenKeyboard");
104  mButtonsSize = config.getIntValue("screenButtonsSize");
105  mJoystickSize = config.getIntValue("screenJoystickSize");
106  mButtonsFormat = config.getIntValue("screenButtonsFormat");
107 
108  setHalfJoyPad(getPadSize() / 2);
109 
110  if (mShowKeyboard)
111  loadKeyboard();
112  if (mShowJoystick)
113  loadPad();
114  if (mShowButtons)
115  loadButtons();
118 }
119 
121  const std::string &restrict name,
122  const std::string &restrict imageName,
123  const std::string &restrict text,
124  int x, int y,
125  const int width, const int height,
126  const int type,
127  const std::string &restrict eventPressed,
128  const std::string &restrict eventReleased,
129  const TouchFuncPtr fAll,
130  const TouchFuncPtr fPressed,
131  const TouchFuncPtr fReleased,
132  const TouchFuncPtr fOut) restrict2
133 {
134  *item = nullptr;
135  if (theme == nullptr)
136  return;
137  ImageRect *images = new ImageRect;
138  for (int f = 0; f < 9; f ++)
139  images->grid[f] = nullptr;
140 
141  Image *icon;
142  if (imageName.empty())
143  icon = nullptr;
144  else
145  icon = Theme::getImageFromThemeXml(imageName, "");
146 
147  Skin *const skin = theme->loadSkinRect(*images,
148  name,
149  "",
150  0,
151  8);
152  if (skin != nullptr)
153  {
154  Image *const image = images->grid[0];
155  if (image != nullptr)
156  {
157  if (x == -1)
158  x = skin->getOption("x", 10);
159  if (y == -1)
160  y = skin->getOption("y", 10);
161  const int pad = skin->getPadding();
162  const int pad2 = 2 * pad;
163  const int border = skin->getOption("clickborder");
164  const int border2 = border * 2;
165  const int diff = pad - border;
166  switch (type)
167  {
168  case LEFT:
169  y += (mainGraphics->mHeight - height) / 2;
170  break;
171  case RIGHT:
172  x = mainGraphics->mWidth - width - pad2 - x;
173  y = mainGraphics->mHeight - height - pad2 - y;
174  break;
175  case NORMAL:
176  default:
177  break;
178  }
179  *item = new TouchItem(text, Rect(x + diff, y + diff,
180  width + border2, height + border2), type,
181  eventPressed, eventReleased, images, icon,
182  x + pad, y + pad, width, height,
183  fAll, fPressed, fReleased, fOut);
184  mObjects.push_back(*item);
185  }
186  else
187  {
188  delete images;
189  }
190  theme->unload(skin);
191  }
192  else
193  {
194  delete images;
195  }
196  mRedraw = true;
197 }
198 
200 {
202  unload(*it);
203  mObjects.clear();
205  mRedraw = true;
206 }
207 
209 {
210  if (mRedraw)
211  {
212  mRedraw = false;
213  mVertexes->clear();
215  {
216  const TouchItem *const item = *it;
217  if ((item != nullptr) && (item->images != nullptr) && (mShow ||
218  (item == mKeyboard && mShowKeyboard)))
219  {
220  mainGraphics->calcWindow(mVertexes, item->x, item->y,
221  item->width, item->height, *item->images);
222  const Image *const icon = item->icon;
223  if (icon != nullptr)
224  {
226  item->x + (item->width - icon->mBounds.w) / 2,
227  item->y + (item->height - icon->mBounds.h) / 2);
228  }
229  }
230  }
232  }
234  drawText();
235 }
236 
238 {
240  {
241  const TouchItem *const item = *it;
242  if ((item != nullptr) && (item->images != nullptr) && (mShow ||
243  (item == mKeyboard && mShowKeyboard)))
244  {
245  mainGraphics->drawImageRect(item->x, item->y,
246  item->width, item->height, *item->images);
247  const Image *const icon = item->icon;
248  if (icon != nullptr)
249  {
250  mainGraphics->drawImage(icon,
251  item->x + (item->width - icon->mBounds.w) / 2,
252  item->y + (item->height - icon->mBounds.h) / 2);
253  }
254  }
255  }
256  drawText();
257 }
258 
260 {
261  if (gui == nullptr)
262  return;
263 
264  Font *const font = boldFont;
265  const Color &color1 = theme->getColor(ThemeColorId::TEXT, 255);
266  const Color &color2 = theme->getColor(ThemeColorId::TEXT_OUTLINE, 255);
267 
269  {
270  const TouchItem *const item = *it;
271  if ((item != nullptr) && mShow && !item->text.empty())
272  {
273  const std::string str = item->text;
274  const int textX = (item->rect.width - font->getWidth(str))
275  / 2 + item->x;
276  const int textY = (item->rect.height - font->getHeight())
277  / 2 + item->y;
278  font->drawString(mainGraphics,
279  color1,
280  color2,
281  str, textX, textY);
282  }
283  }
284 }
285 
287 {
288  const int x = mouseInput.getTouchX();
289  const int y = mouseInput.getTouchY();
290 
291  FOR_EACH (TouchItemVectorCIter, it, mObjects)
292  {
293  const TouchItem *const item = *it;
294  if (item == nullptr ||
295  (!mShow && (item != mKeyboard || !mShowKeyboard)))
296  {
297  continue;
298  }
299  const Rect &rect = item->rect;
300  if (rect.isPointInRect(x, y))
301  {
302  MouseInput event = mouseInput;
303  event.setX(event.getTouchX() - item->x);
304  event.setY(event.getTouchY() - item->y);
305  if (item->funcAll != nullptr)
306  item->funcAll(event);
307 
308  switch (mouseInput.getType())
309  {
311  if (!item->eventPressed.empty())
312  executeAction(item->eventPressed);
313  else if (item->funcPressed != nullptr)
314  item->funcPressed(event);
315  break;
317  if (!item->eventReleased.empty())
318  executeAction(item->eventReleased);
319  else if (item->funcReleased != nullptr)
320  item->funcReleased(event);
321  break;
322  default:
331  break;
332  }
333  return true;
334  }
335  else if (item->funcOut != nullptr)
336  {
337  item->funcOut(mouseInput);
338  }
339  }
340  return false;
341 }
342 
344 {
345  if (CAST_S32(index) < 0 ||
346  CAST_S32(index) >= actionsSize)
347  {
348  return false;
349  }
350  return mActions[CAST_SIZE(index)];
351 }
352 
353 void TouchManager::resize(const int width, const int height) restrict2
354 {
355  mRedraw = true;
356  const int maxHeight = mHeight;
357  const int diffW = width - mWidth;
358  const int diffH = height - maxHeight;
359  FOR_EACH (TouchItemVectorCIter, it, mObjects)
360  {
361  TouchItem *const item = *it;
362  if (item == nullptr)
363  continue;
364 
365  switch (item->type)
366  {
367  case LEFT:
368  if (height != maxHeight)
369  {
370  item->y = (height - item->height) / 2;
371  item->rect.y = (height - item->rect.y) / 2;
372  }
373  break;
374  case RIGHT:
375  {
376  item->x += diffW;
377  item->rect.x += diffW;
378  item->y += diffH;
379  item->rect.y += diffH;
380  break;
381  }
382  case NORMAL:
383  default:
384  break;
385  }
386  }
387  mWidth = mainGraphics->mWidth;
388  mHeight = mainGraphics->mHeight;
389 }
390 
392 {
393  if (item != nullptr)
394  {
395  if (item->images != nullptr)
396  {
397  Theme::unloadRect(*item->images, 0, 8);
398  delete2(item->images)
399  if (item->icon != nullptr)
400  {
401  item->icon->decRef();
402  item->icon = nullptr;
403  }
404  }
405  delete item;
406  }
407 }
408 
410 {
411  FOR_EACH (TouchItemVectorIter, it, mObjects)
412  {
413  TouchItem *item = *it;
414  if ((item != nullptr) && *unloadItem == item)
415  {
416  mObjects.erase(it);
417  unload(item);
418  return;
419  }
420  }
421 }
422 
424 {
425  const int sz = (mJoystickSize + 2) * 50;
426  loadTouchItem(&mPad, "dpad.xml", "dpad_image.xml", "", -1, -1, sz, sz,
427  LEFT, "", "", &padEvents, &padClick, &padUp, &padOut);
428 }
429 
431 {
432  if (theme == nullptr)
433  return;
434  Skin *const skin = theme->load("dbutton.xml",
435  "",
436  true,
438 
439  if (skin != nullptr)
440  {
441  const int sz = (mButtonsSize + 1) * 50;
442  const int x = skin->getOption("x", 10);
443  const int y = skin->getOption("y", 10);
444  const int pad = skin->getPadding();
445  const int pad2 = 2 * pad + sz;
446  const int skipWidth = pad2 + x;
447  const int skipHeight = pad2 + y;
448 
449  switch (mButtonsFormat)
450  {
451  // 2x1
452  case 0:
453  default:
454  {
455  loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml",
456  "2", x, y, sz, sz, RIGHT, "screenActionButton1", "",
457  nullptr, nullptr, nullptr, nullptr);
458  loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml",
459  "1", skipWidth, y, sz, sz, RIGHT,
460  "screenActionButton0", "",
461  nullptr, nullptr, nullptr, nullptr);
462  break;
463  }
464  // 2x2
465  case 1:
466  {
467  loadTouchItem(&mButtons[3], "dbutton.xml", "dbutton_image.xml",
468  "4", x, y, sz, sz, RIGHT, "screenActionButton3", "",
469  nullptr, nullptr, nullptr, nullptr);
470  loadTouchItem(&mButtons[2], "dbutton.xml", "dbutton_image.xml",
471  "3", skipWidth, y, sz, sz, RIGHT,
472  "screenActionButton2", "",
473  nullptr, nullptr, nullptr, nullptr);
474  loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml",
475  "2", x, skipHeight, sz, sz, RIGHT,
476  "screenActionButton1", "",
477  nullptr, nullptr, nullptr, nullptr);
478  loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml",
479  "1", skipWidth, skipHeight, sz, sz, RIGHT,
480  "screenActionButton0", "",
481  nullptr, nullptr, nullptr, nullptr);
482  break;
483  }
484  // 3x3
485  case 2:
486  {
487  const int pad4 = pad2 * 2;
488  const int skipWidth2 = pad4 + x;
489  const int skipHeight2 = pad4 + y;
490  loadTouchItem(&mButtons[8], "dbutton.xml", "dbutton_image.xml",
491  "9", x, y, sz, sz, RIGHT, "screenActionButton8", "",
492  nullptr, nullptr, nullptr, nullptr);
493  loadTouchItem(&mButtons[7], "dbutton.xml", "dbutton_image.xml",
494  "8", skipWidth, y, sz, sz, RIGHT,
495  "screenActionButton7", "",
496  nullptr, nullptr, nullptr, nullptr);
497  loadTouchItem(&mButtons[6], "dbutton.xml", "dbutton_image.xml",
498  "7", skipWidth2, y, sz, sz, RIGHT,
499  "screenActionButton6", "",
500  nullptr, nullptr, nullptr, nullptr);
501  loadTouchItem(&mButtons[5], "dbutton.xml", "dbutton_image.xml",
502  "6", x, skipHeight, sz, sz, RIGHT,
503  "screenActionButton5", "",
504  nullptr, nullptr, nullptr, nullptr);
505  loadTouchItem(&mButtons[4], "dbutton.xml", "dbutton_image.xml",
506  "5", skipWidth, skipHeight, sz, sz, RIGHT,
507  "screenActionButton4", "",
508  nullptr, nullptr, nullptr, nullptr);
509  loadTouchItem(&mButtons[3], "dbutton.xml", "dbutton_image.xml",
510  "4", skipWidth2, skipHeight, sz, sz, RIGHT,
511  "screenActionButton3", "",
512  nullptr, nullptr, nullptr, nullptr);
513  loadTouchItem(&mButtons[2], "dbutton.xml", "dbutton_image.xml",
514  "3", x, skipHeight2, sz, sz, RIGHT,
515  "screenActionButton2", "",
516  nullptr, nullptr, nullptr, nullptr);
517  loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml",
518  "2", skipWidth, skipHeight2, sz, sz, RIGHT,
519  "screenActionButton1", "",
520  nullptr, nullptr, nullptr, nullptr);
521  loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml",
522  "1", skipWidth2, skipHeight2, sz, sz, RIGHT,
523  "screenActionButton0", "",
524  nullptr, nullptr, nullptr, nullptr);
525  break;
526  }
527  // 4x2
528  case 3:
529  {
530  const int skipWidth2 = pad2 * 2 + x;
531  const int skipWidth3 = pad2 * 3 + x;
532  loadTouchItem(&mButtons[7], "dbutton.xml", "dbutton_image.xml",
533  "8", x, y, sz, sz, RIGHT, "screenActionButton7", "",
534  nullptr, nullptr, nullptr, nullptr);
535  loadTouchItem(&mButtons[6], "dbutton.xml", "dbutton_image.xml",
536  "7", skipWidth, y, sz, sz, RIGHT,
537  "screenActionButton6", "",
538  nullptr, nullptr, nullptr, nullptr);
539  loadTouchItem(&mButtons[5], "dbutton.xml", "dbutton_image.xml",
540  "6", skipWidth2, y, sz, sz, RIGHT,
541  "screenActionButton5", "",
542  nullptr, nullptr, nullptr, nullptr);
543  loadTouchItem(&mButtons[4], "dbutton.xml", "dbutton_image.xml",
544  "5", skipWidth3, y, sz, sz, RIGHT,
545  "screenActionButton4", "",
546  nullptr, nullptr, nullptr, nullptr);
547  loadTouchItem(&mButtons[3], "dbutton.xml", "dbutton_image.xml",
548  "4", x, skipHeight, sz, sz, RIGHT,
549  "screenActionButton3", "",
550  nullptr, nullptr, nullptr, nullptr);
551  loadTouchItem(&mButtons[2], "dbutton.xml", "dbutton_image.xml",
552  "3", skipWidth, skipHeight, sz, sz, RIGHT,
553  "screenActionButton2", "",
554  nullptr, nullptr, nullptr, nullptr);
555  loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml",
556  "2", skipWidth2, skipHeight, sz, sz, RIGHT,
557  "screenActionButton1", "",
558  nullptr, nullptr, nullptr, nullptr);
559  loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml",
560  "1", skipWidth3, skipHeight, sz, sz, RIGHT,
561  "screenActionButton0", "",
562  nullptr, nullptr, nullptr, nullptr);
563  break;
564  }
565  // 4x3
566  case 4:
567  {
568  const int skipWidth2 = pad2 * 2 + x;
569  const int skipWidth3 = pad2 * 3 + x;
570  const int skipHeight2 = pad2 * 2 + y;
571  loadTouchItem(&mButtons[11], "dbutton.xml",
572  "dbutton_image.xml", "12", x, y, sz, sz, RIGHT,
573  "screenActionButton11", "",
574  nullptr, nullptr, nullptr, nullptr);
575  loadTouchItem(&mButtons[10], "dbutton.xml",
576  "dbutton_image.xml", "11", skipWidth, y, sz, sz, RIGHT,
577  "screenActionButton10", "",
578  nullptr, nullptr, nullptr, nullptr);
579  loadTouchItem(&mButtons[9], "dbutton.xml", "dbutton_image.xml",
580  "10", skipWidth2, y, sz, sz, RIGHT,
581  "screenActionButton9", "",
582  nullptr, nullptr, nullptr, nullptr);
583  loadTouchItem(&mButtons[8], "dbutton.xml", "dbutton_image.xml",
584  "9", skipWidth3, y, sz, sz, RIGHT,
585  "screenActionButton8", "",
586  nullptr, nullptr, nullptr, nullptr);
587  loadTouchItem(&mButtons[7], "dbutton.xml", "dbutton_image.xml",
588  "8", x, skipHeight, sz, sz, RIGHT,
589  "screenActionButton7", "",
590  nullptr, nullptr, nullptr, nullptr);
591  loadTouchItem(&mButtons[6], "dbutton.xml", "dbutton_image.xml",
592  "7", skipWidth, skipHeight, sz, sz, RIGHT,
593  "screenActionButton6", "",
594  nullptr, nullptr, nullptr, nullptr);
595  loadTouchItem(&mButtons[5], "dbutton.xml", "dbutton_image.xml",
596  "6", skipWidth2, skipHeight, sz, sz, RIGHT,
597  "screenActionButton5", "",
598  nullptr, nullptr, nullptr, nullptr);
599  loadTouchItem(&mButtons[4], "dbutton.xml", "dbutton_image.xml",
600  "5", skipWidth3, skipHeight, sz, sz, RIGHT,
601  "screenActionButton4", "",
602  nullptr, nullptr, nullptr, nullptr);
603  loadTouchItem(&mButtons[3], "dbutton.xml", "dbutton_image.xml",
604  "4", x, skipHeight2, sz, sz, RIGHT,
605  "screenActionButton3", "",
606  nullptr, nullptr, nullptr, nullptr);
607  loadTouchItem(&mButtons[2], "dbutton.xml", "dbutton_image.xml",
608  "3", skipWidth, skipHeight2, sz, sz, RIGHT,
609  "screenActionButton2", "",
610  nullptr, nullptr, nullptr, nullptr);
611  loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml",
612  "2", skipWidth2, skipHeight2, sz, sz, RIGHT,
613  "screenActionButton1", "",
614  nullptr, nullptr, nullptr, nullptr);
615  loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml",
616  "1", skipWidth3, skipHeight2, sz, sz, RIGHT,
617  "screenActionButton0", "",
618  nullptr, nullptr, nullptr, nullptr);
619  break;
620  }
621  // 3x2
622  case 5:
623  {
624  const int pad4 = pad2 * 2;
625  const int skipWidth2 = pad4 + x;
626  loadTouchItem(&mButtons[5], "dbutton.xml", "dbutton_image.xml",
627  "6", x, y, sz, sz, RIGHT, "screenActionButton5", "",
628  nullptr, nullptr, nullptr, nullptr);
629  loadTouchItem(&mButtons[4], "dbutton.xml", "dbutton_image.xml",
630  "5", skipWidth, y, sz, sz, RIGHT,
631  "screenActionButton4", "",
632  nullptr, nullptr, nullptr, nullptr);
633  loadTouchItem(&mButtons[3], "dbutton.xml", "dbutton_image.xml",
634  "4", skipWidth2, y, sz, sz, RIGHT,
635  "screenActionButton3", "",
636  nullptr, nullptr, nullptr, nullptr);
637  loadTouchItem(&mButtons[2], "dbutton.xml", "dbutton_image.xml",
638  "3", x, skipHeight, sz, sz, RIGHT,
639  "screenActionButton2", "",
640  nullptr, nullptr, nullptr, nullptr);
641  loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml",
642  "2", skipWidth, skipHeight, sz, sz, RIGHT,
643  "screenActionButton1", "",
644  nullptr, nullptr, nullptr, nullptr);
645  loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml",
646  "1", skipWidth2, skipHeight, sz, sz, RIGHT,
647  "screenActionButton0", "",
648  nullptr, nullptr, nullptr, nullptr);
649  break;
650  }
651  }
652  theme->unload(skin);
653  }
654 }
655 
657 {
658  loadTouchItem(&mKeyboard, "keyboard_icon.xml", "", "", -1, -1, 28, 28,
659  NORMAL, "", "screenActionKeyboard",
660  nullptr, nullptr, nullptr, nullptr);
661 }
662 
663 void TouchManager::optionChanged(const std::string &value) restrict2
664 {
665  if (value == "showScreenJoystick")
666  {
667  if (mShowJoystick == config.getBoolValue("showScreenJoystick"))
668  return;
669  mShowJoystick = config.getBoolValue("showScreenJoystick");
670  if (mShowJoystick)
671  loadPad();
672  else
673  unloadTouchItem(&mPad);
674  mRedraw = true;
675  }
676  else if (value == "showScreenButtons")
677  {
678  if (mShowButtons == config.getBoolValue("showScreenButtons"))
679  return;
680  mShowButtons = config.getBoolValue("showScreenButtons");
681  if (mShowButtons)
682  {
683  loadButtons();
684  }
685  else
686  {
687  for (int f = 0; f < buttonsCount; f ++)
688  unloadTouchItem(&mButtons[f]);
689  }
690  mRedraw = true;
691  }
692  else if (value == "showScreenKeyboard")
693  {
694  if (mShowKeyboard == config.getBoolValue("showScreenKeyboard"))
695  return;
696  mShowKeyboard = config.getBoolValue("showScreenKeyboard");
697  if (mShowKeyboard)
698  loadKeyboard();
699  else
700  unloadTouchItem(&mKeyboard);
701  mRedraw = true;
702  }
703  else if (value == "screenButtonsSize")
704  {
705  if (mButtonsSize == config.getIntValue("screenButtonsSize"))
706  return;
707  mButtonsSize = config.getIntValue("screenButtonsSize");
708  if (mShowButtons)
709  {
710  for (int f = 0; f < buttonsCount; f ++)
711  unloadTouchItem(&mButtons[f]);
712  loadButtons();
713  }
714  }
715  else if (value == "screenJoystickSize")
716  {
717  if (mJoystickSize == config.getIntValue("screenJoystickSize"))
718  return;
719  mJoystickSize = config.getIntValue("screenJoystickSize");
720  setHalfJoyPad(getPadSize() / 2);
721  if (mShowJoystick)
722  {
723  unloadTouchItem(&mPad);
724  loadPad();
725  }
726  }
727  else if (value == "screenButtonsFormat")
728  {
729  if (mButtonsFormat == config.getIntValue("screenButtonsFormat"))
730  return;
731  mButtonsFormat = config.getIntValue("screenButtonsFormat");
732  if (mShowButtons)
733  {
734  for (int f = 0; f < buttonsCount; f ++)
735  unloadTouchItem(&mButtons[f]);
736  loadButtons();
737  }
738  }
739 }
740 
742 {
743  mInGame = b;
744  mShow = mInGame && !mTempHideButtons;
745  mRedraw = true;
746 }
747 
749 {
750  mTempHideButtons = b;
751  mShow = mInGame && !mTempHideButtons;
752  mRedraw = true;
753 }
754 
755 void TouchManager::executeAction(const std::string &restrict event)
756 {
758  config.getIntValue(event)));
759 }
#define CAST_S32
Definition: cast.h:30
#define CAST_SIZE
Definition: cast.h:34
Definition: color.h:76
bool getBoolValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
void removeListeners(ConfigListener *const listener)
int getIntValue(const std::string &key) const
Definition: font.h:90
int getHeight() const
Definition: font.cpp:362
int getWidth(const std::string &text) const
Definition: font.cpp:334
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:254
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
int mWidth
Definition: graphics.h:484
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
virtual void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)=0
int mHeight
Definition: graphics.h:485
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:465
virtual void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
virtual void drawImageRect(const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
Image * grid[9]
Definition: imagerect.h:42
void executeAction(const InputActionT keyNum)
void setX(int x)
Definition: mouseinput.h:144
Definition: rect.h:74
int y
Definition: rect.h:214
int width
Definition: rect.h:219
bool isPointInRect(const int x_, const int y_) const
Definition: rect.h:197
int x
Definition: rect.h:209
int height
Definition: rect.h:224
Definition: skin.h:37
int getOption(const std::string &name) const
Definition: skin.h:106
int getPadding() const
Definition: skin.h:100
void unload(Skin *const skin)
Definition: theme.cpp:250
static std::string getThemePath()
Definition: theme.h:67
static Image * getImageFromThemeXml(const std::string &name, const std::string &name2)
Definition: theme.cpp:926
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:915
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:179
const Color & getColor(const ThemeColorIdT type, const unsigned int alpha)
Definition: theme.h:136
Skin * loadSkinRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:900
bool mShowKeyboard
Definition: touchmanager.h:192
void optionChanged(const std::string &value)
static void executeAction(const std::string &event)
void resize(const int width, const int height)
void loadKeyboard()
TouchItem * mPad
Definition: touchmanager.h:184
bool isActionActive(const InputActionT index) const
int getPadSize() const
Definition: touchmanager.h:171
void setTempHide(const bool b)
static void unload(TouchItem *const item)
bool mActions[actionsSize]
Definition: touchmanager.h:188
bool mShowJoystick
Definition: touchmanager.h:190
void unloadTouchItem(TouchItem **unloadItem)
TouchItemVector mObjects
Definition: touchmanager.h:186
TouchItem * mKeyboard
Definition: touchmanager.h:183
TouchItem * mButtons[buttonsCount]
Definition: touchmanager.h:185
void loadTouchItem(TouchItem **item, const std::string &name, const std::string &imageName, const std::string &text, int x, int y, const int width, const int height, const int type, const std::string &eventPressed, const std::string &eventReleased, const TouchFuncPtr fAll, const TouchFuncPtr fPressed, const TouchFuncPtr fReleased, const TouchFuncPtr fOut)
void setInGame(const bool b)
void loadButtons()
bool processEvent(const MouseInput &mouseInput)
ImageCollection * mVertexes
Definition: touchmanager.h:187
Configuration config
#define delete2(var)
Definition: delete2.h:25
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
Graphics * mainGraphics
Definition: graphics.cpp:109
if(!vert) return
Gui * gui
Definition: gui.cpp:111
Font * boldFont
Definition: gui.cpp:112
InputAction ::T InputActionT
Definition: inputaction.h:717
InputManager inputManager
#define restrict
Definition: localconsts.h:165
#define restrict2
Definition: localconsts.h:166
#define nullptr
Definition: localconsts.h:45
#define CHECKLISTENERS
Definition: localconsts.h:277
void unload()
Definition: net.cpp:180
RenderType
Definition: rendertype.h:26
std::string eventPressed
Definition: touchmanager.h:84
TouchFuncPtr funcOut
Definition: touchmanager.h:95
Image * icon
Definition: touchmanager.h:87
TouchFuncPtr funcReleased
Definition: touchmanager.h:94
std::string eventReleased
Definition: touchmanager.h:85
std::string text
Definition: touchmanager.h:81
TouchFuncPtr funcAll
Definition: touchmanager.h:92
ImageRect * images
Definition: touchmanager.h:86
TouchFuncPtr funcPressed
Definition: touchmanager.h:93
Theme * theme
Definition: theme.cpp:62
void padClick(const MouseInput &mouseInput)
void setHalfJoyPad(const int s)
void padOut(const MouseInput &mouseInput)
void padEvents(const MouseInput &mouseInput)
void padUp(const MouseInput &mouseInput)
RenderType openGLMode
TouchManager touchManager
TouchItemVector::iterator TouchItemVectorIter
Definition: touchmanager.h:100
const int buttonsCount
Definition: touchmanager.h:44
TouchItemVector::const_iterator TouchItemVectorCIter
Definition: touchmanager.h:99
const int actionsSize
Definition: touchmanager.h:43
void(* TouchFuncPtr)(const MouseInput &mouseInput)
Definition: touchmanager.h:41