Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
ScrollbuttonWidget.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 "ScrollbuttonWidget.h"
22 #include "ButtonWidget.h"
23 #include "platform/Graphics.h"
24 
25 using namespace HFCore;
26 
27 #include "debug/CrtDbgNew.h"
28 
30  int32_hf type) :
31  ButtonWidget(id, buttonListener)
32 {
33  mHorizontal = false;
34  mType = type;
35 }
36 
38 {
39 }
40 
42 {
43  int32_hf arrowOffset = 0;
44 
45  Color color;
46 
47  mRenderHelper.drawRect(g, mX, mY, mWidth,
48  mHeight, Color(212, 212, 212));
49 
50  if (mIsDown && mIsOver && !mDisabled)
51  {
52  arrowOffset = 1;
53  mRenderHelper.drawRect(g, mX, mY, mWidth - 1,
54  mHeight - 1, Color(132, 132, 132));
55  }
56  else
57  {
58  color = Color::getColorWhite();
59  mRenderHelper.drawRect(g, mX + 1, mY + 1, mWidth - 2, 1, color);
60  mRenderHelper.drawRect(g, mX + 1, mY + 1, 1, mHeight - 2, color);
61 
62  color = Color::getColorBlack();
63  mRenderHelper.drawRect(g, mX, (mY + mHeight - 1), mWidth, 1, color);
64  mRenderHelper.drawRect(g, (mX + mWidth - 1), mY, 1, mHeight, color);
65 
66  color = Color(132, 132, 132);
67  mRenderHelper.drawRect(g, (mX + 1), (mY + mHeight - 2), (mWidth - 2), 1, color);
68  mRenderHelper.drawRect(g, (mX + mWidth - 2), (mY + 1), 1, (mHeight - 2), color);
69  }
70 
71  if (!mDisabled)
72  {
73  color = Color::getColorBlack();
74  }
75  else
76  {
77  color = Color(132, 132, 132);
78  }
79 
81  {
82  for (int32_hf i = 0; i < 4; i++)
83  {
84  if (mId == 0 || mType == SCROLLBUTTON_LEFT)
85  {
86  mRenderHelper.drawRect(g, (fp32_hf)(mX + i + (mWidth - 4) / 2 + arrowOffset),
87  (fp32_hf)(mY + mHeight / 2 - i - 1 + arrowOffset), 1,
88  (fp32_hf)(1 + i * 2), color);
89  }
90  else
91  {
92  mRenderHelper.drawRect(g, (fp32_hf)((mX + (3 - i) + (mWidth - 4) / 2 + arrowOffset)),
93  (fp32_hf)(mY + mHeight / 2 - i - 1 + arrowOffset), 1,
94  1 + (fp32_hf)(i * 2), color);
95  }
96  }
97  }
98  else
99  {
100  for (int32_hf i = 0; i < 4; i++)
101  {
102  if (mId == 0 || mType == SCROLLBUTTON_UP)
103  {
104  mRenderHelper.drawRect(g, (fp32_hf)(mX + mWidth / 2 - i - 1 + arrowOffset),
105  (fp32_hf)(mY + i + (mHeight - 4) / 2 + arrowOffset),
106  (fp32_hf)(1 + i * 2), 1, color);
107  }
108  else
109  {
110  mRenderHelper.drawRect(g, (fp32_hf)(mX + mWidth / 2 - i - 1 + arrowOffset),
111  (fp32_hf)(mY + (3 - i) + (mHeight - 4) / 2 + arrowOffset),
112  (fp32_hf)(1 + i * 2), 1, color);
113  }
114  }
115  }
116 }
Interface for all rendering related things.
void draw(Graphics *g)
Called by the framework once for every iteration of the main loop.
Interface for UI ScrollbuttonWidget.
Interface for UI ButtonWidget.
Definition: ButtonWidget.h:116
int int32_hf
A type definition for int.
Definition: HFDataTypes.h:349
Interface for UI ButtonWidget.
Interface for ButtonWidget listener callback methods.
static Color getColorBlack()
Get opaque Black Color.
Definition: Color.cpp:281
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.
int32_hf mId
Holds Button ID.
Definition: ButtonWidget.h:275
fp32_hf mX
Holds Widget X position.
bool mIsOver
Flag indicating if over or not.
Definition: Widget.h:1070
bool mHorizontal
Flag indicating whether scrollbutton is placed horizontally or not.
Interface for RGBA Color.
Definition: Color.h:51
virtual ~ScrollbuttonWidget()
Destructor.
ScrollbuttonWidget(int32_hf id, ButtonListener *buttonListener, int32_hf type=SCROLLBUTTON_UNDEFINED)
Constructor.
fp32_hf mY
Holds Widget Y position.
Definition: Actor.h:34
static Color getColorWhite()
Get opaque White Color.
Definition: Color.cpp:331
Interface for all rendering related things.
Definition: Graphics.h:120
bool mDisabled
Flag indicating if disabled or not.
Definition: Widget.h:1055
bool mIsDown
Flag indicating if down or not.
Definition: Widget.h:1065
int32_hf mType
Holds scrollbutton type. Valid values are: ScrollbuttonWidget::SCROLLBUTTON_UNDEFINED, ScrollbuttonWidget::SCROLLBUTTON_UP, ScrollbuttonWidget::SCROLLBUTTON_DOWN, ScrollbuttonWidget::SCROLLBUTTON_LEFT, ScrollbuttonWidget::SCROLLBUTTON_RIGHT.
fp32_hf mWidth
Holds Widget width.
float fp32_hf
A type definition for float.
Definition: HFDataTypes.h:359
fp32_hf mHeight
Holds Widget height.