Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
ButtonWidget.cpp
1 /*
2  Harmonic Flow Framework
3  Copyright (C) 2011-2018 Andreas Widen <andreas@harmonicflow.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "ButtonWidget.h"
22 #include "ButtonListener.h"
23 #include "WidgetManager.h"
24 
25 #include "platform/Image.h"
26 #include "platform/Environment.h"
27 
28 #include <assert.h>
29 
30 using namespace HFCore;
31 
32 #include "debug/CrtDbgNew.h"
33 
34 static int32_hf gButtonWidgetColors[][3] =
35 {
36  {0, 0, 0},
37  {0, 0, 0},
38  {0, 0, 0},
39  {255, 255, 255},
40  {132, 132, 132},
41  {212, 212, 212}
42 };
43 
45  UString &label, Image *buttonImage, Image *buttonImageOver,
46  Image *buttonImageDown, Image *buttonImageDisabled)
47 {
48  assert(buttonListener != NULL);
49 
50  mId = id;
51  mFont = font;
52  mLabel = label;
54 
55  mButtonImage = buttonImage;
56  mOverImage = buttonImageOver;
57  mDownImage = buttonImageDown;
58  mDisabledImage = buttonImageDisabled;
59 
60  mAtlasImage = NULL;
65 
66  mInverted = false;
67  mBtnNoDraw = false;
68  mButtonListener = buttonListener;
69  mHasAlpha = true;
70 
71  mOverAlpha = 0;
72  mOverAlphaSpeed = 0;
74 
75  mToolTipText = "";
76  mToolTipStringWidth = 0;
77  mToolTipFont = NULL;
78  mToolTipTextColor = Color::getColorWhite();
79  mToolTipBackgroundColor = Color::getColorBlack();
80  mToolTipDelayShowTimeInSeconds = 0.0f;
81  mToolTipOffsetX = 0;
82  mToolTipOffsetY = 0;
83  mToolTipExists = false;
84  mToolTipShow = false;
85  mToolTipStartTime = 0.0f;
86  mToolTipAlpha = 0.0f;
87  mToolTipFadeIn = false;
88  mToolTipFadeInStartTime = 0.0f;
89 
90  setColors(gButtonWidgetColors, NUM_COLORS);
91 
92  mUsingAtlas = false;
93 }
94 
96 {
97  assert(buttonListener != NULL);
98 
99  mId = id;
100  mButtonListener = buttonListener;
101 
102  mFont = NULL;
103  mLabel = L"";
105 
106  mButtonImage = NULL;
107  mOverImage = NULL;
108  mDownImage = NULL;
110 
111  mAtlasImage = NULL;
116 
117  mInverted = false;
118  mBtnNoDraw = false;
119  mHasAlpha = true;
120 
121  mOverAlpha = 0;
122  mOverAlphaSpeed = 0;
124 
125  mToolTipText = "";
126  mToolTipStringWidth = 0;
127  mToolTipFont = NULL;
128  mToolTipTextColor = Color::getColorWhite();
129  mToolTipBackgroundColor = Color::getColorBlack();
130  mToolTipDelayShowTimeInSeconds = 0.0f;
131  mToolTipOffsetX = 0;
132  mToolTipOffsetY = 0;
133  mToolTipExists = false;
134  mToolTipShow = false;
135  mToolTipStartTime = 0.0f;
136  mToolTipAlpha = 0.0f;
137  mToolTipFadeIn = false;
138  mToolTipFadeInStartTime = 0.0f;
139 
140  setColors(gButtonWidgetColors, NUM_COLORS);
141 
142  mUsingAtlas = false;
143 }
144 
146  UString &label, Image *atlasImage, const Rect &buttonRect,
147  const Rect &buttonOverRect, const Rect &buttonDownRect,
148  const Rect &buttonDisabledRect)
149 {
150  assert(buttonListener != NULL);
151  assert(atlasImage != NULL);
152 
153  mId = id;
154  mFont = font;
155  mLabel = label;
157 
158  mButtonImage = NULL;
159  mOverImage = NULL;
160  mDownImage = NULL;
162 
163  mAtlasImage = atlasImage;
164  mButtonRect = buttonRect;
165  mButtonOverRect = buttonOverRect;
166  mButtonDownRect = buttonDownRect;
167  mButtonDisabledRect = buttonDisabledRect;
168 
169  mInverted = false;
170  mBtnNoDraw = false;
171  mButtonListener = buttonListener;
172  mHasAlpha = true;
173 
174  mOverAlpha = 0;
175  mOverAlphaSpeed = 0;
177 
178  mToolTipText = "";
179  mToolTipStringWidth = 0;
180  mToolTipFont = NULL;
181  mToolTipTextColor = Color::getColorWhite();
182  mToolTipBackgroundColor = Color::getColorBlack();
183  mToolTipDelayShowTimeInSeconds = 0.0f;
184  mToolTipOffsetX = 0;
185  mToolTipOffsetY = 0;
186  mToolTipExists = false;
187  mToolTipShow = false;
188  mToolTipStartTime = 0.0f;
189  mToolTipAlpha = 0.0f;
190  mToolTipFadeIn = false;
191  mToolTipFadeInStartTime = 0.0f;
192 
193  setColors(gButtonWidgetColors, NUM_COLORS);
194 
195  mUsingAtlas = true;
196 }
197 
199 {
200 }
201 
202 bool ButtonWidget::haveButtonImage(Image *image)
203 {
204  return (image != NULL);
205 }
206 
207 bool ButtonWidget::haveButtonImage(const Rect &rect)
208 {
209  return (rect != Rect::ZERO());
210 }
211 
213 {
214  mFont = font;
215 }
216 
218 {
219  mLabel = label;
220 }
221 
223 {
224  mLabelJustify = labelJustify;
225 }
226 
227 void ButtonWidget::setToolTip(UString &toolTipText, Font *font, Color textColor,
228  Color backgroundColor, fp32_hf delayShowTimeInSeconds,
229  int32_hf offsetX, int32_hf offsetY)
230 {
231  assert(toolTipText.length() > 0);
232  assert(font != NULL);
233 
234  mToolTipText = toolTipText;
235  mToolTipStringWidth = font->getStringWidth(mToolTipText);
236  mToolTipFont = font;
237  mToolTipTextColor = textColor;
238  mToolTipBackgroundColor = backgroundColor;
239  mToolTipDelayShowTimeInSeconds = delayShowTimeInSeconds;
240  mToolTipOffsetX = offsetX;
241  mToolTipOffsetY = offsetY;
242  mToolTipExists = true;
243  mToolTipShow = false;
244  mToolTipStartTime = 0.0f;
245  mToolTipAlpha = 0.0f;
246  mToolTipFadeIn = false;
247  mToolTipFadeInStartTime = 0.0f;
248 }
249 
250 void ButtonWidget::setDisabled(bool isDisabled)
251 {
252  Widget::setDisabled(isDisabled);
253 }
254 
256 {
257  return mIsDown && mIsOver && !mDisabled;
258 }
259 
261 {
262  if (mBtnNoDraw)
263  {
264  return;
265  }
266 
267  bool isDown = isButtonDown();
268  isDown ^= mInverted;
269 
270  fp32_hf fontX = 0; // BUTTON_LABEL_LEFT
271  fp32_hf fontY = 0;
272  fp32_hf labelw = 0.0f;
273 
274  if (mFont != NULL && mLabel.length() != 0)
275  {
276  labelw = (fp32_hf)mFont->getStringWidth(mLabel) / 2;
277  fp32_hf width = (mWidth / 2) - 2;
278  fp32_hf height = (mHeight / 2) - 2;
279 
281  {
282  fontX = width - labelw;
283  }
284  else if (mLabelJustify == BUTTON_LABEL_RIGHT)
285  {
286  fontX = width - mFont->getStringWidth(mLabel);
287  }
288 
289  fontY = height;
290  }
291 
292  if (!isDown)
293  {
294  if (mUsingAtlas)
295  {
296  if (mDisabled && haveButtonImage(mButtonDisabledRect))
297  {
298  drawButtonImageAtlas(g, mButtonDisabledRect , 0, 0);
299  }
300  else if ((mOverAlpha > 0) && haveButtonImage(mButtonOverRect))
301  {
302  if (haveButtonImage(mButtonRect) && mOverAlpha < 1)
303  {
304  drawButtonImageAtlas(g, mButtonRect, 0, 0);
305  }
306 
307  Color color(255, 255, 255, (int32_hf)(mOverAlpha * 255));
308  drawButtonImageAtlas(g, mButtonOverRect, 0, 0, color);
309  }
310  else if ((mIsOver || mIsDown) && haveButtonImage(mButtonOverRect))
311  {
312  drawButtonImageAtlas(g, mButtonOverRect, 0, 0);
313  }
314  else if (haveButtonImage(mButtonRect))
315  {
316  drawButtonImageAtlas(g, mButtonRect, 0, 0);
317  }
318  }
319  else
320  {
321  if (mDisabled && haveButtonImage(mDisabledImage))
322  {
323  drawButtonImage(g, mDisabledImage , 0, 0);
324  }
325  else if ((mOverAlpha > 0) && haveButtonImage(mOverImage))
326  {
327  if (haveButtonImage(mButtonImage) && mOverAlpha < 1)
328  {
329  drawButtonImage(g, mButtonImage, 0, 0);
330  }
331 
332  Color color(255, 255, 255, (int32_hf)(mOverAlpha * 255));
333  drawButtonImage(g, mOverImage, 0, 0, color);
334  }
335  else if ((mIsOver || mIsDown) && haveButtonImage(mOverImage))
336  {
337  drawButtonImage(g, mOverImage, 0, 0);
338  }
339  else if (haveButtonImage(mButtonImage))
340  {
341  drawButtonImage(g, mButtonImage, 0, 0);
342  }
343  }
344 
345  if (mFont != NULL && mLabel.length() != 0)
346  {
347  Color color = mColors[COLOR_LABEL];
348  if (mIsOver)
349  {
350  color = mColors[COLOR_LABEL_HILITE];
351  }
352 
353  drawLabel(g, mX + fontX, mY + fontY, color, true);
354  }
355  }
356  else
357  {
358  if (mUsingAtlas)
359  {
360  if (haveButtonImage(mButtonDownRect))
361  {
362  drawButtonImageAtlas(g, mButtonDownRect, 0, 0);
363  }
364  else if (haveButtonImage(mButtonOverRect))
365  {
366  drawButtonImageAtlas(g, mButtonOverRect, 1, 1);
367  }
368  else
369  {
370  drawButtonImageAtlas(g, mButtonRect, 1, 1);
371  }
372  }
373  else
374  {
375  if (haveButtonImage(mDownImage))
376  {
377  drawButtonImage(g, mDownImage, 0, 0);
378  }
379  else if (haveButtonImage(mOverImage))
380  {
381  drawButtonImage(g, mOverImage, 1, 1);
382  }
383  else
384  {
385  drawButtonImage(g, mButtonImage, 1, 1);
386  }
387  }
388 
389  if (mFont != NULL && mLabel.length() != 0)
390  {
391  drawLabel(g, mX + fontX + 1, mY + fontY + 1, mColors[COLOR_LABEL_HILITE], true);
392  }
393  }
394 
395  // tool tip:
396  if (mToolTipFadeIn && mToolTipAlpha > 0.0f)
397  {
398  drawToolTip(g);
399  }
400 }
401 
402 void ButtonWidget::drawButtonImage(Graphics *g, Image *image, fp32_hf x, fp32_hf y)
403 {
404  if (image != NULL)
405  {
406  fp32_hf posx = (image->getWidth() / 2) + (mX + x);
407  fp32_hf posy = (image->getHeight() / 2) + (mY + y);
408 
409  mRenderHelper.drawImage(g, image, posx, posy, 1.0f, Graphics::DRAWMODE_NORMAL,
411  }
412 }
413 
414 void ButtonWidget::drawButtonImage(Graphics *g, Image *image, fp32_hf x, fp32_hf y, Color color)
415 {
416  if (image != NULL)
417  {
418  fp32_hf posx = (image->getWidth() / 2) + (mX + x);
419  fp32_hf posy = (image->getHeight() / 2) + (mY + y);
420 
421  mRenderHelper.drawImage(g, image, posx, posy, 1.0f, Graphics::DRAWMODE_NORMAL,
423  }
424 }
425 
426 void ButtonWidget::drawButtonImageAtlas(Graphics *g, Rect &rect, fp32_hf x, fp32_hf y)
427 {
428  if (mAtlasImage != NULL && rect != Rect::ZERO())
429  {
430  fp32_hf posx = (rect.getWidth() / 2) + (mX + x);
431  fp32_hf posy = (rect.getHeight() / 2) + (mY + y);
432 
433  mRenderHelper.drawImage(g, mAtlasImage, rect, posx, posy, 1.0f, Graphics::DRAWMODE_NORMAL,
435  }
436 }
437 
438 void ButtonWidget::drawButtonImageAtlas(Graphics *g, Rect &rect, fp32_hf x, fp32_hf y,
439  Color color)
440 {
441  if (mAtlasImage != NULL && rect != Rect::ZERO())
442  {
443  fp32_hf posx = (rect.getWidth() / 2) + (mX + x);
444  fp32_hf posy = (rect.getHeight() / 2) + (mY + y);
445 
446  mRenderHelper.drawImage(g, mAtlasImage, rect, posx, posy, 1.0f, Graphics::DRAWMODE_NORMAL,
448  }
449 }
450 
451 void ButtonWidget::drawLabel(Graphics *g, fp32_hf x, fp32_hf y, Color color,
452  bool clip)
453 {
454  // mRenderHelper.beginBatch(g, Graphics::BATCHMODE_STATIC);
455  mRenderHelper.drawString(g, mFont, color, mLabel, (int32_hf)x, (int32_hf)y);
456  // mRenderHelper.endBatch(g, true);
457 }
458 
459 void ButtonWidget::drawToolTip(Graphics *g)
460 {
461  // background rect:
462  Color color(mToolTipBackgroundColor.getRed(),
463  mToolTipBackgroundColor.getGreen(),
464  mToolTipBackgroundColor.getBlue(),
465  (int32_hf)(255 * mToolTipAlpha));
466 
467  int32_hf x = (int32_hf)((mX - (mToolTipFont->getStringWidth(mToolTipText) / 2)) + (mWidth / 2));
468  int32_hf y = (int32_hf)(mY - mToolTipFont->getHeight());
469  int32_hf offsetY = mToolTipFont->getHeight() / 2;
470 
471  int32_hf logicalw = HFCORE_ENV->getLogicalScreenWidth();
472  int32_hf logicalh = HFCORE_ENV->getLogicalScreenHeight();
473 
474  // make sure it stays within boundaries:
475  if (x < 0)
476  {
477  x = 0;
478  }
479  else if ((x + mToolTipStringWidth + 8) > logicalw)
480  {
481  x = logicalw - (mToolTipStringWidth + 8);
482  }
483 
484  if (y < 0)
485  {
486  y = 0;
487  }
488  else if ((y + mToolTipFont->getHeight() + 8) > logicalh)
489  {
490  y = logicalh - (mToolTipFont->getHeight() + 8);
491  }
492 
493  mRenderHelper.drawRect(g,
494  (fp32_hf)(x + mToolTipOffsetX),
495  (fp32_hf)(y + mToolTipOffsetY),
496  (fp32_hf)(mToolTipStringWidth + 8),
497  (fp32_hf)(mToolTipFont->getHeight() + 8),
498  color);
499 
500  // actual tool tip text:
501  Color tooltipColor(mToolTipTextColor.getRed(), mToolTipTextColor.getGreen(),
502  mToolTipTextColor.getBlue(), (int32_hf)(mToolTipAlpha * 255));
503 
504  mRenderHelper.beginBatch(g, Graphics::BATCHMODE_STATIC);
505  mRenderHelper.drawString(g, mToolTipFont, tooltipColor,
506  mToolTipText, (x + 4) + mToolTipOffsetX, (y + 2 + offsetY) + mToolTipOffsetY);
507  mRenderHelper.endBatch(g, true);
508 }
509 
511 {
512  Widget::update(dt);
513 
514  if (mIsDown && mIsOver)
515  {
517  }
518 
519  if (!mIsDown && !mIsOver && (mOverAlpha > 0))
520  {
521  if (mOverAlphaSpeed > 0)
522  {
524  if (mOverAlpha < 0)
525  {
526  mOverAlpha = 0;
527  }
528  }
529  else
530  {
531  mOverAlpha = 0;
532  }
533  }
534  else if (mIsOver && mOverAlphaFadeInSpeed > 0 && mOverAlpha < 1)
535  {
537  if (mOverAlpha > 1)
538  {
539  mOverAlpha = 1;
540  }
541  }
542 
543  Environment *env = HFCORE_ENV;
544  assert(env != NULL);
545  if (mToolTipShow && ((env->getTime() - mToolTipStartTime) > mToolTipDelayShowTimeInSeconds)
546  && !mToolTipFadeIn)
547  {
548  mToolTipFadeIn = true;
549  mToolTipFadeInStartTime = env->getTime();
550  }
551 
552  if (mToolTipFadeIn)
553  {
554  RenderHelper renderHelper;
555  mToolTipAlpha = renderHelper.getVal(mToolTipFadeInStartTime, 0.4f, 0.0f, 1.0f);
556  }
557 }
558 
560 {
561  Widget::touchDown(touch);
562 
564  {
567  }
568 }
569 
571 {
572  Widget::touchUp(touch);
573 
575  {
577  }
578 }
579 
581 {
582  Widget::touchMove(touch);
583 
584  /* if (mButtonListener)
585  {
586  mButtonListener->buttonMouseMove(mId, touch);
587  }*/
588 }
589 
591 {
592  Widget::mouseMove(mouse);
593 
594  if (mButtonListener)
595  {
597  }
598 }
599 
601 {
603 
605  {
608  }
609 }
610 
612 {
613  Widget::mouseButtonUp(mouse);
614 
616  {
618  }
619 }
620 
622 {
623  Widget::mouseEnter(mouse);
624 
625  if (mOverAlphaFadeInSpeed == 0 && mOverAlpha > 0)
626  {
627  mOverAlpha = 0;
628  }
629 
630  // tool tip:
631  if (mToolTipExists)
632  {
633  mToolTipStartTime = HFCORE_ENV->getTime();
634  mToolTipShow = true;
635  mToolTipFadeIn = false;
636  mToolTipFadeInStartTime = 0.0f;
637  }
638 
639  if (mButtonListener)
640  {
643  }
644 }
645 
647 {
648  Widget::mouseLeave(mouse);
649 
650  if (mOverAlphaSpeed == 0 && mOverAlpha > 0)
651  {
652  mOverAlpha = 0;
653  }
654  else if (mOverAlphaSpeed > 0 && mOverAlpha == 0) // fade out from full
655  {
656  mOverAlpha = 1;
657  }
658 
659  // tool tip:
660  if (mToolTipExists)
661  {
662  mToolTipStartTime = 0.0f;
663  mToolTipShow = false;
664  mToolTipFadeIn = false;
665  mToolTipFadeInStartTime = 0.0f;
666  }
667 
668  if (mButtonListener)
669  {
672  }
673 }
void endBatch(Graphics *g, bool render)
End current Batch.
virtual int32_hf getStringWidth(const UString &str, fp32_hf scale=1.0f)=0
Get the width of str.
virtual void update(fp32_hf dt)
Called by the framework once for every iteration of the game loop, immediately before rendering takes...
fp32_hf mOverAlphaFadeInSpeed
Holds mouse over button alpha fadeIn speed.
Definition: ButtonWidget.h:375
Color for hilite label text.
Definition: ButtonWidget.h:135
fp32_hf drawString(Graphics *g, Font *font, Color color, const UString &string, int32_hf x, int32_hf y, fp32_hf scale=1.0f)
Draw a string.
Button label text alignment CENTER.
Definition: ButtonWidget.h:125
virtual fp32_hf getTime()=0
Get Time in Seconds since start.
virtual void setBatchUIUpdateNeeded(bool update)
Set BatchUI update needed flag.
Definition: Widget.cpp:503
UString mLabel
Holds Button label text.
Definition: ButtonWidget.h:280
virtual void mouseMove(Mouse::MouseInfo mouse)
Called automatically when Mouse motion event occurs.
virtual void touchUp(Touch::TouchInfo touch)
Called automatically when Touch up event occurs.
virtual void mouseButtonDown(Mouse::MouseInfo mouse)
Called automatically when Mouse button down event occurs.
fp32_hf getVal(fp32_hf startTime, fp32_hf duration, fp32_hf start, fp32_hf end)
Get a value in the specified range.
Interface for unicode string class UString.
Definition: UString.h:35
Rect mButtonDownRect
Holds Rect for button down Image region within mAtlasImage.
Definition: ButtonWidget.h:338
virtual void touchMove(Touch::TouchInfo touch)
Called automatically when Touch move/drag event occurs.
Definition: Widget.cpp:268
fp32_hf getWidth() const
Get Rect Width (or maxX).
Definition: Rect.h:168
Image * mAtlasImage
Holds pointer to atlas Image.
Definition: ButtonWidget.h:320
int int32_hf
A type definition for int.
Definition: HFDataTypes.h:349
int32_hf mLabelJustify
Holds Button label justify. Valid values are: ButtonWidget::BUTTON_LABEL_LEFT, ButtonWidget::BUTTON_L...
Definition: ButtonWidget.h:288
virtual void setToolTip(UString &toolTipText, Font *font, Color textColor, Color backgroundColor, fp32_hf delayShowTimeInSeconds, int32_hf offsetX, int32_hf offsetY)
Set tool tip text to use when over button.
Interface for UI ButtonWidget.
fp32_hf mOverAlphaSpeed
Holds mouse over button alpha speed.
Definition: ButtonWidget.h:370
Interface for ButtonWidget listener callback methods.
static Color getColorBlack()
Get opaque Black Color.
Definition: Color.cpp:281
virtual void mouseLeave(Mouse::MouseInfo mouse)
Called automatically when Mouse leave event occurs.
Definition: Widget.cpp:292
void drawRect(Graphics *g, fp32_hf x0, fp32_hf y0, fp32_hf w, fp32_hf h, Color color, Graphics::DrawMode drawMode=Graphics::DRAWMODE_NORMAL)
Draw a Rect.
virtual void buttonDown(int32_hf id, int32_hf clickCount)
Called automatically when a buttonDown event occurs.
int32_hf mId
Holds Button ID.
Definition: ButtonWidget.h:275
static Rect ZERO()
Initialize Rect with 0 for all members.
Definition: Rect.h:141
Image * mOverImage
Holds pointer to mouse over button Image.
Definition: ButtonWidget.h:304
virtual void touchUp(Touch::TouchInfo touch)
Called automatically when Touch up event occurs.
Definition: Widget.cpp:264
Rect mButtonRect
Holds Rect for normal button Image region within mAtlasImage.
Definition: ButtonWidget.h:326
fp32_hf mX
Holds Widget X position.
virtual void mouseEnter(Mouse::MouseInfo mouse)
Called automatically when Mouse enter event occurs.
bool mIsOver
Flag indicating if over or not.
Definition: Widget.h:1070
virtual void buttonMouseMove(int32_hf id, HFCore::Mouse *mouse)
Called automatically when buttonMouseMove even occurs.
Rect mButtonOverRect
Holds Rect for mouse over button Image region within mAtlasImage.
Definition: ButtonWidget.h:332
int32_hf getRed() const
Get red color component as int32_hf.
Definition: Color.cpp:91
A structure that contains Touch event information.
Definition: Touch.h:50
bool mHasFocus
Flag indicating if has focus or not.
fp32_hf width()
Get Widget width.
Definition: Widget.h:994
virtual void mouseMove(Mouse::MouseInfo mouse)
Called automatically when Mouse motion event occurs.
Definition: Widget.cpp:272
Image * mDisabledImage
Holds pointer to disabled button Image.
Definition: ButtonWidget.h:314
Button label text alignment RIGHT.
Definition: ButtonWidget.h:126
Interface for Resource type Image.
virtual void touchMove(Touch::TouchInfo touch)
Called automatically when Touch move/drag event occurs.
virtual void setFont(Font *font)
Set Font to use for label text.
virtual int32_hf getHeight()=0
Get Font height.
#define NULL
Convenient define for 0.
Definition: HFDataTypes.h:42
ButtonListener * mButtonListener
Holds pointer to ButtonListener class.
Definition: ButtonWidget.h:360
Singleton interface for platform specific things.
Definition: Environment.h:151
virtual void draw(Graphics *g)
Called by the framework once for every iteration of the main loop.
Useful for static content.
Definition: Graphics.h:199
virtual Graphics::MinFilter getMinRenderFilter()
Get Graphics::MinFilter currently set.
Definition: Widget.cpp:488
Font * mFont
Holds pointer to Font to use for label text.
Definition: ButtonWidget.h:293
virtual void mouseEnter(Mouse::MouseInfo mouse)
Called automatically when Mouse enter event occurs.
Definition: Widget.cpp:288
int32_hf length() const
Get the length of the string.
Definition: UString.cpp:178
Interface for RGBA Color.
Definition: Color.h:51
A structure that contains Mouse event information.
Definition: Mouse.h:63
virtual Graphics::MagFilter getMagRenderFilter()
Get Graphics::MagFilter currently set.
Definition: Widget.cpp:483
virtual void buttonMouseEnter(int32_hf id)
Called automatically when a buttonMouseEnter event occurs.
Rect mButtonDisabledRect
Holds Rect for disabled button Image region within mAtlasImage.
Definition: ButtonWidget.h:344
int32_hf tapCount
Tap count.
Definition: Touch.h:60
Mouse * self
Pointer to Mouse.
Definition: Mouse.h:65
Color for normal label text.
Definition: ButtonWidget.h:134
virtual void setLabelJustify(int32_hf labelJustify)
Set label text justify.
Image * mDownImage
Holds pointer to button down Image.
Definition: ButtonWidget.h:309
virtual void buttonDownTick(int32_hf id)
Called automatically when a buttonDownTick event occurs.
virtual void setLabel(UString &label)
Set label text.
virtual void mouseButtonUp(Mouse::MouseInfo mouse)
Called automatically when Mouse button up event occurs.
Definition: Widget.cpp:280
Interface which act as a convenient rendering helper.
Definition: RenderHelper.h:50
fp32_hf mOverAlpha
Holds mouse over button alpha value.
Definition: ButtonWidget.h:365
virtual void touchDown(Touch::TouchInfo touch)
Called automatically when Touch down event occurs.
virtual ~ButtonWidget()
Destructor.
fp32_hf mY
Holds Widget Y position.
virtual void mouseLeave(Mouse::MouseInfo mouse)
Called automatically when Mouse leave event occurs.
Definition: Actor.h:34
Image * mButtonImage
Holds pointer to normal button Image.
Definition: ButtonWidget.h:299
Interface for Resource type Image.
Definition: Image.h:63
ButtonWidget(int32_hf id, ButtonListener *buttonListener, Font *font, UString &label, Image *buttonImage=NULL, Image *buttonImageOver=NULL, Image *buttonImageDown=NULL, Image *buttonImageDisabled=NULL)
Constructor.
Interface for Resource type Font.
Definition: Font.h:84
Singleton interface for platform specific things.
Draw mode default / normal.
Definition: Graphics.h:143
virtual void update(fp32_hf dt)
Called by the framework once for every iteration of the game loop, immediately before rendering takes...
Definition: Widget.cpp:225
void drawImage(Graphics *g, Image *img, fp32_hf x, fp32_hf y, fp32_hf alpha=1.0f, Graphics::DrawMode drawMode=Graphics::DRAWMODE_NORMAL, Graphics::MagFilter magFilter=Graphics::MAGFILTER_LINEAR, Graphics::MinFilter minFilter=Graphics::MINFILTER_LINEAR)
Draw a Image.
Definition: RenderHelper.h:530
virtual void setDisabled(bool isDisabled)
Set disabled flag.
Definition: Widget.cpp:146
static Color getColorWhite()
Get opaque White Color.
Definition: Color.cpp:331
bool mHasAlpha
Flag indicating if Widget has Alpha or not.
virtual bool isButtonDown()
Determine whether button is down.
Specialized Boundary representing a Rect.
Definition: Rect.h:34
#define HFCORE_ENV
Get HFCore::Environment instance shortcut macro.
Definition: Environment.h:68
Interface for all rendering related things.
Definition: Graphics.h:120
virtual void mouseButtonDown(Mouse::MouseInfo mouse)
Called automatically when Mouse button down event occurs.
Definition: Widget.cpp:276
WidgetManager manages Widget&#39;s and interacts with Game interface.
bool mDisabled
Flag indicating if disabled or not.
Definition: Widget.h:1055
void beginBatch(Graphics *g, Graphics::BatchMode mode, Rect clipRect=Rect::ZERO())
Begin Batch using specified Graphics::BatchMode and optional clipping Rect.
bool mIsDown
Flag indicating if down or not.
Definition: Widget.h:1065
virtual int32_hf getHeight()=0
Get the Image original height.
virtual void setColors(int32_hf colors[][3], int32_hf numColors)
Set RGB colors.
Definition: Widget.cpp:107
bool mInverted
Flag indicating if inverted or not.
Definition: ButtonWidget.h:350
fp32_hf getHeight() const
Get Rect Height (or maxY).
Definition: Rect.h:177
ColorVector mColors
Vector holding Color&#39;s set by setColor() and setColors().
Definition: Widget.h:1081
WidgetManager * mWidgetManager
Pointer to WidgetManager.
fp32_hf height()
Get Widget height.
Definition: Widget.h:1001
virtual void buttonUp(int32_hf id)
Called automatically when a buttonUp event occurs.
int32_hf clickCount
Mouse click count.
Definition: Mouse.h:73
virtual void setDisabled(bool isDisabled)
Set button state as disabled.
int32_hf getBlue() const
Get blue color component as int32_hf.
Definition: Color.cpp:101
virtual int32_hf getWidth()=0
Get the Image original width.
fp32_hf mWidth
Holds Widget width.
virtual void touchDown(Touch::TouchInfo touch)
Called automatically when Touch down event occurs.
Definition: Widget.cpp:260
virtual void mouseButtonUp(Mouse::MouseInfo mouse)
Called automatically when Mouse button up event occurs.
float fp32_hf
A type definition for float.
Definition: HFDataTypes.h:359
int32_hf getGreen() const
Get green color component as int32_hf.
Definition: Color.cpp:96
Interface for ButtonWidget listener callback methods.
virtual void buttonMouseLeave(int32_hf id)
Called automatically when a buttonMouseLeave event occurs.
bool mBtnNoDraw
Flag indicating if button should be drawn or not.
Definition: ButtonWidget.h:355
fp32_hf mHeight
Holds Widget height.