ManaPlus
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
TouchManager Class Reference

#include <touchmanager.h>

Inheritance diagram for TouchManager:
ConfigListener

Public Types

enum  Types { NORMAL = 0 , LEFT = 1 , RIGHT = 2 }
 

Public Member Functions

 TouchManager ()
 
 ~TouchManager ()
 
void init ()
 
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 clear ()
 
void draw ()
 
void safeDraw ()
 
void drawText ()
 
bool processEvent (const MouseInput &mouseInput)
 
bool isActionActive (const InputActionT index) const
 
void setActionActive (const InputActionT index, const bool value)
 
void resize (const int width, const int height)
 
void unloadTouchItem (TouchItem **unloadItem)
 
void optionChanged (const std::string &value)
 
void loadPad ()
 
void loadButtons ()
 
void loadKeyboard ()
 
int getPadSize () const
 
void setInGame (const bool b)
 
void setTempHide (const bool b)
 
void shutdown ()
 
- Public Member Functions inherited from ConfigListener
 ConfigListener ()
 
virtual ~ConfigListener ()
 

Static Public Member Functions

static void unload (TouchItem *const item)
 
static void executeAction (const std::string &event)
 

Private Attributes

TouchItemmKeyboard
 
TouchItemmPad
 
TouchItemmButtons [buttonsCount]
 
TouchItemVector mObjects
 
ImageCollectionmVertexes
 
bool mActions [actionsSize]
 
bool mRedraw
 
bool mShowJoystick
 
bool mShowButtons
 
bool mShowKeyboard
 
int mButtonsSize
 
int mJoystickSize
 
int mButtonsFormat
 
int mWidth
 
int mHeight
 
bool mShow
 
bool mInGame
 
bool mTempHideButtons
 

Detailed Description

Definition at line 102 of file touchmanager.h.

Member Enumeration Documentation

◆ Types

Enumerator
NORMAL 
LEFT 
RIGHT 

Definition at line 111 of file touchmanager.h.

112  {
113  NORMAL = 0,
114  LEFT = 1,
115  RIGHT = 2
116  };

Constructor & Destructor Documentation

◆ TouchManager()

TouchManager::TouchManager ( )

Definition at line 54 of file touchmanager.cpp.

54  :
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 }
bool mShowKeyboard
Definition: touchmanager.h:192
TouchItem * mPad
Definition: touchmanager.h:184
bool mActions[actionsSize]
Definition: touchmanager.h:188
bool mShowJoystick
Definition: touchmanager.h:190
TouchItemVector mObjects
Definition: touchmanager.h:186
TouchItem * mKeyboard
Definition: touchmanager.h:183
TouchItem * mButtons[buttonsCount]
Definition: touchmanager.h:185
ImageCollection * mVertexes
Definition: touchmanager.h:187
bool mTempHideButtons
Definition: touchmanager.h:200
const int buttonsCount
Definition: touchmanager.h:44
const int actionsSize
Definition: touchmanager.h:43

References actionsSize, buttonsCount, mActions, and mButtons.

◆ ~TouchManager()

TouchManager::~TouchManager ( )

Definition at line 78 of file touchmanager.cpp.

79 {
80  clear();
82 }
#define CHECKLISTENERS
Definition: localconsts.h:277

References CHECKLISTENERS, and clear().

Member Function Documentation

◆ clear()

void TouchManager::clear ( )

Definition at line 199 of file touchmanager.cpp.

200 {
202  unload(*it);
203  mObjects.clear();
205  mRedraw = true;
206 }
static void unload(TouchItem *const item)
#define delete2(var)
Definition: delete2.h:25
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
TouchItemVector::const_iterator TouchItemVectorCIter
Definition: touchmanager.h:99

References delete2, FOR_EACH, mObjects, mRedraw, mVertexes, and unload().

Referenced by Client::gameClear(), and ~TouchManager().

◆ draw()

void TouchManager::draw ( )

Definition at line 208 of file touchmanager.cpp.

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 }
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
virtual void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)=0
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
Graphics * mainGraphics
Definition: graphics.cpp:109
Image * icon
Definition: touchmanager.h:87
ImageRect * images
Definition: touchmanager.h:86

References Graphics::calcTileCollection(), Graphics::calcWindow(), ImageCollection::clear(), drawText(), Graphics::drawTileCollection(), Graphics::finalize(), FOR_EACH, TouchItem::height, TouchItem::icon, TouchItem::images, mainGraphics, mKeyboard, mObjects, mRedraw, mShow, mShowKeyboard, mVertexes, TouchItem::width, TouchItem::x, and TouchItem::y.

Referenced by Gui::draw().

◆ drawText()

void TouchManager::drawText ( )

Definition at line 259 of file touchmanager.cpp.

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 }
Definition: color.h:76
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
int width
Definition: rect.h:219
int height
Definition: rect.h:224
const Color & getColor(const ThemeColorIdT type, const unsigned int alpha)
Definition: theme.h:136
Gui * gui
Definition: gui.cpp:111
Font * boldFont
Definition: gui.cpp:112
std::string text
Definition: touchmanager.h:81
Theme * theme
Definition: theme.cpp:62

References boldFont, Font::drawString(), FOR_EACH, Theme::getColor(), Font::getHeight(), Font::getWidth(), gui, Rect::height, mainGraphics, mObjects, mShow, TouchItem::rect, QuestType::TEXT, TouchItem::text, theme, Rect::width, TouchItem::x, and TouchItem::y.

Referenced by draw(), and safeDraw().

◆ executeAction()

void TouchManager::executeAction ( const std::string &  event)
static

Definition at line 755 of file touchmanager.cpp.

756 {
758  config.getIntValue(event)));
759 }
int getIntValue(const std::string &key) const
void executeAction(const InputActionT keyNum)
Configuration config
InputAction ::T InputActionT
Definition: inputaction.h:717
InputManager inputManager

References config, InputManager::executeAction(), Configuration::getIntValue(), and inputManager.

◆ getPadSize()

int TouchManager::getPadSize ( ) const
inline

Definition at line 171 of file touchmanager.h.

172  { return (mJoystickSize + 2) * 50; }

Referenced by init().

◆ init()

void TouchManager::init ( )

Definition at line 89 of file touchmanager.cpp.

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 }
bool getBoolValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
int mWidth
Definition: graphics.h:484
int mHeight
Definition: graphics.h:485
void loadKeyboard()
int getPadSize() const
Definition: touchmanager.h:171
void loadButtons()
void setHalfJoyPad(const int s)

References Configuration::addListener(), config, Configuration::getBoolValue(), Configuration::getIntValue(), getPadSize(), loadButtons(), loadKeyboard(), loadPad(), mainGraphics, mButtonsFormat, mButtonsSize, mHeight, Graphics::mHeight, mJoystickSize, mShowButtons, mShowJoystick, mShowKeyboard, mVertexes, mWidth, Graphics::mWidth, and setHalfJoyPad().

Referenced by Client::gameInit().

◆ isActionActive()

bool TouchManager::isActionActive ( const InputActionT  index) const

Definition at line 343 of file touchmanager.cpp.

344 {
345  if (CAST_S32(index) < 0 ||
346  CAST_S32(index) >= actionsSize)
347  {
348  return false;
349  }
350  return mActions[CAST_SIZE(index)];
351 }
#define CAST_S32
Definition: cast.h:30
#define CAST_SIZE
Definition: cast.h:34

References actionsSize, CAST_S32, and CAST_SIZE.

Referenced by InputManager::isActionActive0().

◆ loadButtons()

void TouchManager::loadButtons ( )

Definition at line 430 of file touchmanager.cpp.

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 }
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
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:179
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)

References Skin::getOption(), Skin::getPadding(), Theme::getThemePath(), Theme::load(), loadTouchItem(), mButtons, mButtonsFormat, mButtonsSize, RIGHT, theme, Theme::unload(), x, and y.

Referenced by init().

◆ loadKeyboard()

void TouchManager::loadKeyboard ( )

Definition at line 656 of file touchmanager.cpp.

657 {
658  loadTouchItem(&mKeyboard, "keyboard_icon.xml", "", "", -1, -1, 28, 28,
659  NORMAL, "", "screenActionKeyboard",
660  nullptr, nullptr, nullptr, nullptr);
661 }

References loadTouchItem(), mKeyboard, and NORMAL.

Referenced by init().

◆ loadPad()

void TouchManager::loadPad ( )

Definition at line 423 of file touchmanager.cpp.

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 }
void padClick(const MouseInput &mouseInput)
void padOut(const MouseInput &mouseInput)
void padEvents(const MouseInput &mouseInput)
void padUp(const MouseInput &mouseInput)

References LEFT, loadTouchItem(), mJoystickSize, mPad, padClick(), padEvents(), padOut(), and padUp().

Referenced by init().

◆ loadTouchItem()

void TouchManager::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 
)

Definition at line 120 of file touchmanager.cpp.

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 }
Image * grid[9]
Definition: imagerect.h:42
Definition: rect.h:74
static Image * getImageFromThemeXml(const std::string &name, const std::string &name2)
Definition: theme.cpp:926
Skin * loadSkinRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:900
if(!vert) return

References Theme::getImageFromThemeXml(), Skin::getOption(), Skin::getPadding(), ImageRect::grid, if(), BeingDirection::LEFT, Theme::loadSkinRect(), mainGraphics, Graphics::mHeight, Graphics::mWidth, TargetCursorType::NORMAL, BeingDirection::RIGHT, theme, Theme::unload(), x, and y.

Referenced by loadButtons(), loadKeyboard(), and loadPad().

◆ optionChanged()

void TouchManager::optionChanged ( const std::string &  name)
virtual

Called when an option changed. The config listener will have to be registered to the option name first.

Implements ConfigListener.

Definition at line 663 of file touchmanager.cpp.

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
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 ++)
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
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 ++)
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  {
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 ++)
736  loadButtons();
737  }
738  }
739 }
void unloadTouchItem(TouchItem **unloadItem)

References buttonsCount, config, Configuration::getBoolValue(), Configuration::getIntValue(), and setHalfJoyPad().

◆ processEvent()

bool TouchManager::processEvent ( const MouseInput mouseInput)

Definition at line 286 of file touchmanager.cpp.

287 {
288  const int x = mouseInput.getTouchX();
289  const int y = mouseInput.getTouchY();
290 
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())
313  else if (item->funcPressed != nullptr)
314  item->funcPressed(event);
315  break;
317  if (!item->eventReleased.empty())
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 }
int getTouchY() const
Definition: mouseinput.h:184
int getTouchX() const
Definition: mouseinput.h:181
void setX(int x)
Definition: mouseinput.h:144
MouseEventTypeT getType() const
Definition: mouseinput.h:119
bool isPointInRect(const int x_, const int y_) const
Definition: rect.h:197
static void executeAction(const std::string &event)
std::string eventPressed
Definition: touchmanager.h:84
TouchFuncPtr funcOut
Definition: touchmanager.h:95
TouchFuncPtr funcReleased
Definition: touchmanager.h:94
std::string eventReleased
Definition: touchmanager.h:85
TouchFuncPtr funcAll
Definition: touchmanager.h:92
TouchFuncPtr funcPressed
Definition: touchmanager.h:93

References MouseEventType::CLICKED, MouseEventType::DRAGGED, MouseEventType::ENTERED, TouchItem::eventPressed, TouchItem::eventReleased, MouseEventType::EXITED, FOR_EACH, TouchItem::funcAll, TouchItem::funcOut, TouchItem::funcPressed, TouchItem::funcReleased, Rect::isPointInRect(), MouseEventType::MOVED, MouseEventType::PRESSED, TouchItem::rect, MouseEventType::RELEASED, MouseEventType::RELEASED2, MouseInput::setX(), MouseEventType::WHEEL_MOVED_DOWN, MouseEventType::WHEEL_MOVED_UP, TouchItem::x, x, TouchItem::y, and y.

Referenced by Gui::handleMouseInput().

◆ resize()

void TouchManager::resize ( const int  width,
const int  height 
)

Definition at line 353 of file touchmanager.cpp.

354 {
355  mRedraw = true;
356  const int maxHeight = mHeight;
357  const int diffW = width - mWidth;
358  const int diffH = height - maxHeight;
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  }
389 }
int y
Definition: rect.h:214
int x
Definition: rect.h:209

References FOR_EACH, TouchItem::height, BeingDirection::LEFT, mainGraphics, Graphics::mHeight, Graphics::mWidth, TargetCursorType::NORMAL, TouchItem::rect, BeingDirection::RIGHT, TouchItem::type, Rect::x, TouchItem::x, Rect::y, and TouchItem::y.

Referenced by WindowManager::resizeVideo().

◆ safeDraw()

void TouchManager::safeDraw ( )

Definition at line 237 of file touchmanager.cpp.

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 }
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
virtual void drawImageRect(const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0

References Graphics::drawImage(), Graphics::drawImageRect(), drawText(), FOR_EACH, TouchItem::height, TouchItem::icon, TouchItem::images, mainGraphics, mKeyboard, mObjects, mShow, mShowKeyboard, TouchItem::width, TouchItem::x, and TouchItem::y.

Referenced by Gui::draw().

◆ setActionActive()

void TouchManager::setActionActive ( const InputActionT  index,
const bool  value 
)
inline

Definition at line 147 of file touchmanager.h.

149  {
150  if (CAST_S32(index) >= 0 &&
151  CAST_S32(index) < actionsSize)
152  {
153  mActions[CAST_SIZE(index)] = value;
154  }
155  }

References actionsSize, CAST_S32, and CAST_SIZE.

Referenced by moveChar().

◆ setInGame()

void TouchManager::setInGame ( const bool  b)

Definition at line 741 of file touchmanager.cpp.

742 {
743  mInGame = b;
745  mRedraw = true;
746 }

Referenced by Game::Game(), and Game::~Game().

◆ setTempHide()

void TouchManager::setTempHide ( const bool  b)

Definition at line 748 of file touchmanager.cpp.

749 {
750  mTempHideButtons = b;
752  mRedraw = true;
753 }

Referenced by SetupWindow::setVisible().

◆ shutdown()

void TouchManager::shutdown ( )

Definition at line 84 of file touchmanager.cpp.

85 {
86  config.removeListeners(this);
87 }
void removeListeners(ConfigListener *const listener)

References config, and Configuration::removeListeners().

Referenced by Client::gameClear().

◆ unload()

void TouchManager::unload ( TouchItem *const  item)
static

Definition at line 391 of file touchmanager.cpp.

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 }
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:915

References delete2, and Theme::unloadRect().

Referenced by clear().

◆ unloadTouchItem()

void TouchManager::unloadTouchItem ( TouchItem **  unloadItem)

Definition at line 409 of file touchmanager.cpp.

410 {
412  {
413  TouchItem *item = *it;
414  if ((item != nullptr) && *unloadItem == item)
415  {
416  mObjects.erase(it);
417  unload(item);
418  return;
419  }
420  }
421 }
TouchItemVector::iterator TouchItemVectorIter
Definition: touchmanager.h:100

References FOR_EACH, and Net::unload().

Field Documentation

◆ mActions

bool TouchManager::mActions[actionsSize]
private

Definition at line 188 of file touchmanager.h.

Referenced by TouchManager().

◆ mButtons

TouchItem* TouchManager::mButtons[buttonsCount]
private

Definition at line 185 of file touchmanager.h.

Referenced by loadButtons(), and TouchManager().

◆ mButtonsFormat

int TouchManager::mButtonsFormat
private

Definition at line 195 of file touchmanager.h.

Referenced by init(), and loadButtons().

◆ mButtonsSize

int TouchManager::mButtonsSize
private

Definition at line 193 of file touchmanager.h.

Referenced by init(), and loadButtons().

◆ mHeight

int TouchManager::mHeight
private

Definition at line 197 of file touchmanager.h.

Referenced by init().

◆ mInGame

bool TouchManager::mInGame
private

Definition at line 199 of file touchmanager.h.

◆ mJoystickSize

int TouchManager::mJoystickSize
private

Definition at line 194 of file touchmanager.h.

Referenced by init(), and loadPad().

◆ mKeyboard

TouchItem* TouchManager::mKeyboard
private

Definition at line 183 of file touchmanager.h.

Referenced by draw(), loadKeyboard(), and safeDraw().

◆ mObjects

TouchItemVector TouchManager::mObjects
private

Definition at line 186 of file touchmanager.h.

Referenced by clear(), draw(), drawText(), and safeDraw().

◆ mPad

TouchItem* TouchManager::mPad
private

Definition at line 184 of file touchmanager.h.

Referenced by loadPad().

◆ mRedraw

bool TouchManager::mRedraw
private

Definition at line 189 of file touchmanager.h.

Referenced by clear(), and draw().

◆ mShow

bool TouchManager::mShow
private

Definition at line 198 of file touchmanager.h.

Referenced by draw(), drawText(), and safeDraw().

◆ mShowButtons

bool TouchManager::mShowButtons
private

Definition at line 191 of file touchmanager.h.

Referenced by init().

◆ mShowJoystick

bool TouchManager::mShowJoystick
private

Definition at line 190 of file touchmanager.h.

Referenced by init().

◆ mShowKeyboard

bool TouchManager::mShowKeyboard
private

Definition at line 192 of file touchmanager.h.

Referenced by draw(), init(), and safeDraw().

◆ mTempHideButtons

bool TouchManager::mTempHideButtons
private

Definition at line 200 of file touchmanager.h.

◆ mVertexes

ImageCollection* TouchManager::mVertexes
private

Definition at line 187 of file touchmanager.h.

Referenced by clear(), draw(), and init().

◆ mWidth

int TouchManager::mWidth
private

Definition at line 196 of file touchmanager.h.

Referenced by init().


The documentation for this class was generated from the following files: