Permalink
Browse files

widget: Centralise button rotation management.

  • Loading branch information...
1 parent b3008cf commit 520805303463a957de85a2b4cc72d715d0dcf0ac @Cyp Cyp committed Mar 13, 2013
Showing with 19 additions and 16 deletions.
  1. +14 −16 src/intdisplay.cpp
  2. +3 −0 src/intdisplay.h
  3. +2 −0 src/intelmap.cpp
View
@@ -636,8 +636,18 @@ void intDisplayPowerBar(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset)
IntFancyButton::IntFancyButton(WIDGET *parent)
: W_CLICKFORM(parent)
, imdRotation(DEFAULT_BUTTON_ROTATION)
+ , imdRotationRate(0)
{}
+void IntFancyButton::doRotation()
+{
+ bool isHighlighted = (getState() & WBUT_HIGHLIGHT) != 0;
+
+ imdRotationRate += realTimeAdjustedAverage(isHighlighted? 2*BUTTONOBJ_ROTSPEED : -4*BUTTONOBJ_ROTSPEED);
+ imdRotationRate = clip(imdRotationRate, 0, BUTTONOBJ_ROTSPEED);
+ imdRotation += realTimeAdjustedAverage(imdRotationRate);
+}
+
IntStatusButton::IntStatusButton(WIDGET *parent)
: IntObjectButton(parent)
, theStats(nullptr)
@@ -657,10 +667,7 @@ void IntStatusButton::display(int xOffset, int yOffset)
bool isDown = (getState() & (WBUT_DOWN | WBUT_LOCK | WBUT_CLICKLOCK)) != 0;
bool isHighlighted = (getState() & WBUT_HIGHLIGHT) != 0;
- if (isHighlighted)
- {
- imdRotation += realTimeAdjustedAverage(BUTTONOBJ_ROTSPEED);
- }
+ doRotation();
ImdObject object;
int Image = -1;
@@ -836,10 +843,7 @@ void IntObjectButton::display(int xOffset, int yOffset)
bool isDown = (getState() & (WBUT_DOWN | WBUT_LOCK | WBUT_CLICKLOCK)) != 0;
bool isHighlighted = (getState() & WBUT_HIGHLIGHT) != 0;
- if (isHighlighted)
- {
- imdRotation += realTimeAdjustedAverage(BUTTONOBJ_ROTSPEED);
- }
+ doRotation();
ImdObject object;
@@ -898,10 +902,7 @@ void IntStatsButton::display(int xOffset, int yOffset)
bool isDown = (getState() & (WBUT_DOWN | WBUT_LOCK | WBUT_CLICKLOCK)) != 0;
bool isHighlighted = (getState() & WBUT_HIGHLIGHT) != 0;
- if (isHighlighted)
- {
- imdRotation += realTimeAdjustedAverage(BUTTONOBJ_ROTSPEED);
- }
+ doRotation();
ImdObject object;
int Image = -1;
@@ -2369,10 +2370,7 @@ void IntTransportButton::display(int xOffset, int yOffset)
bool isHighlighted = (getState() & WBUT_HIGHLIGHT) != 0;
- if (isHighlighted)
- {
- imdRotation += realTimeAdjustedAverage(BUTTONOBJ_ROTSPEED);
- }
+ doRotation();
if (psDroid)
{
View
@@ -101,8 +101,11 @@ class IntFancyButton : public W_CLICKFORM
public:
IntFancyButton(WIDGET *parent);
+ void doRotation();
+
protected:
int imdRotation; // Rotation if button is an IMD.
+ int imdRotationRate;
};
class IntObjectButton : public IntFancyButton
View
@@ -937,6 +937,8 @@ void IntMessageButton::display(int xOffset, int yOffset)
bool isDown = (getState() & (WBUT_DOWN | WBUT_CLICKLOCK)) != 0;
bool isHighlighted = (getState() & WBUT_HIGHLIGHT) != 0;
+ doRotation();
+
ImdObject object;
// Get the object associated with this widget.

0 comments on commit 5208053

Please sign in to comment.