Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

widget: Simplify fancy button display and highlight code.

  • Loading branch information...
commit 5e541b53ccf9109e24c094c9a38ab4629e43de12 1 parent 951ceb1
@Cyp Cyp authored
Showing with 36 additions and 82 deletions.
  1. +29 −69 src/intdisplay.cpp
  2. +5 −8 src/intdisplay.h
  3. +2 −5 src/intelmap.cpp
View
98 src/intdisplay.cpp
@@ -650,6 +650,14 @@ void IntFancyButton::doRotation()
imdRotation += realTimeAdjustedAverage(imdRotationRate);
}
+void IntFancyButton::displayIfHighlight(int xOffset, int yOffset)
+{
+ if (isHighlighted())
+ {
+ iV_DrawImage(IntImages, buttonType == TOPBUTTON? IMAGE_BUT_HILITE : IMAGE_BUTB_HILITE, xOffset + x(), yOffset + y());
+ }
+}
+
IntStatusButton::IntStatusButton(WIDGET *parent)
: IntObjectButton(parent)
, theStats(nullptr)
@@ -788,37 +796,16 @@ void IntStatusButton::display(int xOffset, int yOffset)
}
// Render the object into the button.
- if (!object.empty())
- {
- displayIMD(image, object, xOffset, yOffset);
- }
- else if (!image.isNull())
- {
- displayImage(image, xOffset, yOffset);
- }
- else
- {
- displayBlank(xOffset, yOffset);
- }
+ displayIMD(image, object, xOffset, yOffset);
//need to flash the button if a factory is on hold production
if (bOnHold)
{
- if (((realTime / 250) % 2) == 0)
- {
- iV_DrawImage(IntImages, IMAGE_BUT0_DOWN, xOffset + x(), yOffset + y());
- }
- else
- {
- iV_DrawImage(IntImages, IMAGE_BUT_HILITE, xOffset + x(), yOffset + y());
- }
+ iV_DrawImage(IntImages, ((realTime / 250) % 2) == 0? IMAGE_BUT0_DOWN : IMAGE_BUT_HILITE, xOffset + x(), yOffset + y());
}
else
{
- if (isHighlighted())
- {
- iV_DrawImage(IntImages, IMAGE_BUT_HILITE, xOffset + x(), yOffset + y());
- }
+ displayIfHighlight(xOffset, yOffset);
}
}
@@ -859,19 +846,8 @@ void IntObjectButton::display(int xOffset, int yOffset)
}
}
- if (!object.empty())
- {
- displayIMD(Image(), object, xOffset, yOffset);
- }
- else
- {
- displayBlank(xOffset, yOffset);
- }
-
- if (isHighlighted())
- {
- iV_DrawImage(IntImages, IMAGE_BUTB_HILITE, xOffset + x(), yOffset + y());
- }
+ displayIMD(Image(), object, xOffset, yOffset);
+ displayIfHighlight(xOffset, yOffset);
}
IntStatsButton::IntStatsButton(WIDGET *parent)
@@ -953,24 +929,8 @@ void IntStatsButton::display(int xOffset, int yOffset)
object = ImdObject::Component(nullptr);
}
-
- if (!object.empty())
- {
- displayIMD(image, object, xOffset, yOffset);
- }
- else if (!image.isNull())
- {
- displayImage(image, xOffset, yOffset);
- }
- else
- {
- displayBlank(xOffset, yOffset);
- }
-
- if (isHighlighted())
- {
- iV_DrawImage(IntImages, IMAGE_BUT_HILITE, xOffset + x(), yOffset + y());
- }
+ displayIMD(image, object, xOffset, yOffset);
+ displayIfHighlight(xOffset, yOffset);
}
IntFormAnimated::IntFormAnimated(WIDGET *parent, bool openAnimate)
@@ -1471,6 +1431,12 @@ void IntFancyButton::displayClear(int xOffset, int yOffset)
// Create a button by rendering an IMD object into it.
void IntFancyButton::displayIMD(Image image, ImdObject imdObject, int xOffset, int yOffset)
{
+ if (imdObject.empty())
+ {
+ displayImage(image, xOffset, yOffset);
+ return;
+ }
+
int ButXPos = xOffset + x();
int ButYPos = yOffset + y();
@@ -1767,6 +1733,12 @@ void IntFancyButton::displayIMD(Image image, ImdObject imdObject, int xOffset, i
// Create a button by rendering an image into it.
void IntFancyButton::displayImage(Image image, int xOffset, int yOffset)
{
+ if (image.isNull())
+ {
+ displayBlank(xOffset, yOffset);
+ return;
+ }
+
displayClear(xOffset, yOffset);
iV_DrawImage(image, xOffset + x(), yOffset + y());
}
@@ -2265,20 +2237,8 @@ void IntTransportButton::display(int xOffset, int yOffset)
ASSERT(psDroid != NULL, "Invalid droid pointer");
doRotation();
-
- if (psDroid)
- {
- displayIMD(Image(), ImdObject::Droid(psDroid), xOffset, yOffset);
- }
- else
- {
- displayBlank(xOffset, yOffset);
- }
-
- if (isHighlighted())
- {
- iV_DrawImage(IntImages, IMAGE_BUT_HILITE, xOffset + x(), yOffset + y());
- }
+ displayIMD(Image(), ImdObject::Droid(psDroid), xOffset, yOffset);
+ displayIfHighlight(xOffset, yOffset);
if (psDroid && missionForReInforcements())
{
View
13 src/intdisplay.h
@@ -36,11 +36,6 @@ power values in the buttons */
#define BUTTONOBJ_ROTSPEED 90 // Speed to rotate objects rendered in
// buttons ( degrees per second )
-//the two types of button used in the object display (bottom bar)
-#define TOPBUTTON 0
-#define BTMBUTTON 1
-
-
enum ImdType
{
IMDTYPE_NONE,
@@ -101,9 +96,11 @@ class IntFancyButton : public W_CLICKFORM
public:
IntFancyButton(WIDGET *parent);
- void doRotation();
-
protected:
+ //the two types of button used in the object display (bottom bar)
+ enum ButtonType {TOPBUTTON = 0, BTMBUTTON = 1};
+
+ void doRotation();
void displayClear(int xOffset, int yOffset);
void displayIMD(Image image, ImdObject imdObject, int xOffset, int yOffset);
void displayImage(Image image, int xOffset, int yOffset);
@@ -112,7 +109,7 @@ class IntFancyButton : public W_CLICKFORM
int imdRotation; // Rotation if button is an IMD.
int imdRotationRate;
- unsigned buttonType; // TOPBUTTON is square, BTMBUTTON has a little up arrow.
+ ButtonType buttonType; // TOPBUTTON is square, BTMBUTTON has a little up arrow.
};
class IntObjectButton : public IntFancyButton
View
7 src/intelmap.cpp
@@ -1002,17 +1002,14 @@ void IntMessageButton::display(int xOffset, int yOffset)
//do we have the same icon for the top right hand corner?
displayIMD(image, object, xOffset, yOffset);
}
- else if (!image.isNull())
+ else
//draw buttons for mission and general messages
{
// Draw the button with the relevant image, don't add isDown() to the image ID if it's a movie button.
displayImage(MovieButton? image : Image(image.images, image.id + isDown()), xOffset, yOffset);
}
- if (isHighlighted())
- {
- iV_DrawImage(IntImages, IMAGE_BUT_HILITE, xOffset + x(), yOffset + y());
- }
+ displayIfHighlight(xOffset, yOffset);
}
Please sign in to comment.
Something went wrong with that request. Please try again.