summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/graphics/gui/radio.xml5
-rw-r--r--src/gui/charcreatedialog.h8
-rw-r--r--src/gui/quitdialog.cpp6
-rw-r--r--src/gui/quitdialog.h18
-rw-r--r--src/gui/registerdialog.h8
-rw-r--r--src/gui/widgets/checkbox.cpp2
-rw-r--r--src/gui/widgets/radiobutton.cpp137
-rw-r--r--src/gui/widgets/radiobutton.h16
-rw-r--r--src/guichan/widgets/radiobutton.cpp4
9 files changed, 108 insertions, 96 deletions
diff --git a/data/graphics/gui/radio.xml b/data/graphics/gui/radio.xml
index d825e5973..8d4040536 100644
--- a/data/graphics/gui/radio.xml
+++ b/data/graphics/gui/radio.xml
@@ -1,5 +1,10 @@
<skinset name="Default" image="window.png">
<widget type="Window" xpos="137" ypos="132">
+ <option name="padding" value="0" />
+ <option name="imagePadding" value="0" />
+ <option name="imageSize" value="10" />
+ <option name="spacing" value="2" />
+
<part type="in" xpos="0" ypos="0" width="10" height="10" />
<part type="in-highlighted" xpos="14" ypos="0" width="10" height="10" />
<part type="out" xpos="0" ypos="14" width="10" height="10" />
diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h
index 7db506e7f..f14746605 100644
--- a/src/gui/charcreatedialog.h
+++ b/src/gui/charcreatedialog.h
@@ -33,11 +33,11 @@
class Label;
class LocalPlayer;
class PlayerBox;
+class RadioButton;
class TextField;
namespace gcn
{
- class RadioButton;
class Slider;
}
@@ -122,9 +122,9 @@ class CharCreateDialog final : public Window,
Button *mActionButton;
Button *mRotateButton;
- gcn::RadioButton *mMale;
- gcn::RadioButton *mFemale;
- gcn::RadioButton *mOther;
+ RadioButton *mMale;
+ RadioButton *mFemale;
+ RadioButton *mOther;
std::vector<gcn::Slider*> mAttributeSlider;
std::vector<Label*> mAttributeLabel;
diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp
index 907a26493..9af09d24e 100644
--- a/src/gui/quitdialog.cpp
+++ b/src/gui/quitdialog.cpp
@@ -119,7 +119,7 @@ QuitDialog::~QuitDialog()
}
void QuitDialog::placeOption(ContainerPlacer &placer,
- gcn::RadioButton *const option)
+ RadioButton *const option)
{
placer(0, static_cast<int>(mOptions.size()), option, 3);
mOptions.push_back(option);
@@ -194,8 +194,8 @@ void QuitDialog::keyPressed(gcn::KeyEvent &keyEvent)
if (dir != 0)
{
- std::vector<gcn::RadioButton*>::const_iterator it = mOptions.begin();
- std::vector<gcn::RadioButton*>::const_iterator it_end = mOptions.end();
+ std::vector<RadioButton*>::const_iterator it = mOptions.begin();
+ std::vector<RadioButton*>::const_iterator it_end = mOptions.end();
for (; it < it_end; ++it)
{
diff --git a/src/gui/quitdialog.h b/src/gui/quitdialog.h
index a47808d04..e6dcb20e9 100644
--- a/src/gui/quitdialog.h
+++ b/src/gui/quitdialog.h
@@ -31,11 +31,7 @@
#include <vector>
class Button;
-
-namespace gcn
-{
- class RadioButton;
-}
+class RadioButton;
/**
* The quit dialog.
@@ -69,13 +65,13 @@ class QuitDialog final : public Window, public gcn::ActionListener,
private:
void placeOption(ContainerPlacer &placer,
- gcn::RadioButton *const option);
- std::vector<gcn::RadioButton*> mOptions;
+ RadioButton *const option);
+ std::vector<RadioButton*> mOptions;
- gcn::RadioButton *mLogoutQuit;
- gcn::RadioButton *mForceQuit;
- gcn::RadioButton *mSwitchAccountServer;
- gcn::RadioButton *mSwitchCharacter;
+ RadioButton *mLogoutQuit;
+ RadioButton *mForceQuit;
+ RadioButton *mSwitchAccountServer;
+ RadioButton *mSwitchCharacter;
Button *mOkButton;
Button *mCancelButton;
diff --git a/src/gui/registerdialog.h b/src/gui/registerdialog.h
index e11bc7e40..d21cf802d 100644
--- a/src/gui/registerdialog.h
+++ b/src/gui/registerdialog.h
@@ -33,10 +33,10 @@
class Button;
class LoginData;
class OkDialog;
+class RadioButton;
namespace gcn
{
- class RadioButton;
class TextField;
}
@@ -108,9 +108,9 @@ class RegisterDialog final : public Window, public gcn::ActionListener,
gcn::TextField *mEmailField;
Button *mRegisterButton;
Button *mCancelButton;
- gcn::RadioButton *mMaleButton;
- gcn::RadioButton *mFemaleButton;
- gcn::RadioButton *mOtherButton;
+ RadioButton *mMaleButton;
+ RadioButton *mFemaleButton;
+ RadioButton *mOtherButton;
WrongDataNoticeListener *mWrongDataNoticeListener;
};
diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp
index 8349247a4..f3e5993b0 100644
--- a/src/gui/widgets/checkbox.cpp
+++ b/src/gui/widgets/checkbox.cpp
@@ -128,7 +128,7 @@ void CheckBox::drawBox(gcn::Graphics *const graphics)
if (!mSkin)
return;
- ImageRect &rect = mSkin->getBorder();
+ const ImageRect &rect = mSkin->getBorder();
int index = 0;
if (mEnabled && isVisible())
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
index a88a89201..ebe179b53 100644
--- a/src/gui/widgets/radiobutton.cpp
+++ b/src/gui/widgets/radiobutton.cpp
@@ -32,51 +32,44 @@
#include "resources/image.h"
+#include <guichan/font.hpp>
+
#include "debug.h"
int RadioButton::instances = 0;
+Skin *RadioButton::mSkin = nullptr;
float RadioButton::mAlpha = 1.0;
-Image *RadioButton::radioNormal;
-Image *RadioButton::radioChecked;
-Image *RadioButton::radioDisabled;
-Image *RadioButton::radioDisabledChecked;
-Image *RadioButton::radioNormalHi;
-Image *RadioButton::radioCheckedHi;
RadioButton::RadioButton(const std::string &caption, const std::string &group,
const bool marked):
gcn::RadioButton(caption, group, marked),
- mHasMouse(false)
+ mHasMouse(false),
+ mPadding(0),
+ mImagePadding(0),
+ mImageSize(9),
+ mSpacing(2)
{
mForegroundColor = Theme::getThemeColor(Theme::RADIOBUTTON);
if (instances == 0)
{
if (Theme::instance())
{
- ImageRect rect;
- Theme::instance()->loadRect(rect, "radio.xml", "", 0, 3);
- radioChecked = rect.grid[0];
- radioDisabledChecked = rect.grid[0];
- radioCheckedHi = rect.grid[1];
- radioNormal = rect.grid[2];
- radioDisabled = rect.grid[2];
- radioNormalHi = rect.grid[3];
+ mSkin = Theme::instance()->load("radio.xml", "");
+ updateAlpha();
}
- if (radioNormal)
- radioNormal->setAlpha(mAlpha);
- if (radioChecked)
- radioChecked->setAlpha(mAlpha);
-// if (radioDisabled)
-// radioDisabled->setAlpha(mAlpha);
-// if (radioDisabledChecked)
-// radioDisabledChecked->setAlpha(mAlpha);
- if (radioNormalHi)
- radioNormalHi->setAlpha(mAlpha);
- if (radioCheckedHi)
- radioCheckedHi->setAlpha(mAlpha);
}
instances++;
+
+ if (mSkin)
+ {
+ mPadding = mSkin->getPadding();
+ mImagePadding = mSkin->getOption("imagePadding");
+ mImageSize = mSkin->getOption("imageSize");
+ mSpacing = mSkin->getOption("spacing");
+ }
+
+ adjustSize();
}
RadioButton::~RadioButton()
@@ -85,65 +78,74 @@ RadioButton::~RadioButton()
if (instances == 0)
{
- if (radioNormal)
- radioNormal->decRef();
- if (radioChecked)
- radioChecked->decRef();
-// if (radioDisabled)
-// radioDisabled->decRef();
-// if (radioDisabledChecked)
-// radioDisabledChecked->decRef();
- if (radioNormalHi)
- radioNormalHi->decRef();
- if (radioCheckedHi)
- radioCheckedHi->decRef();
+ if (Theme::instance())
+ Theme::instance()->unload(mSkin);
}
}
-void RadioButton::drawBox(gcn::Graphics* graphics)
+void RadioButton::updateAlpha()
{
- if (Client::getGuiAlpha() != mAlpha)
+ const float alpha = std::max(Client::getGuiAlpha(),
+ Theme::instance()->getMinimumOpacity());
+
+ if (mAlpha != alpha)
{
- mAlpha = Client::getGuiAlpha();
- if (radioNormal)
- radioNormal->setAlpha(mAlpha);
- if (radioChecked)
- radioChecked->setAlpha(mAlpha);
-// if (radioDisabled)
-// radioDisabled->setAlpha(mAlpha);
-// if (radioDisabledChecked)
-// radioDisabledChecked->setAlpha(mAlpha);
- if (radioNormalHi)
- radioNormalHi->setAlpha(mAlpha);
- if (radioCheckedHi)
- radioCheckedHi->setAlpha(mAlpha);
+ mAlpha = alpha;
+ if (mSkin)
+ {
+ ImageRect &rect = mSkin->getBorder();
+ for (int a = 0; a < 4; a ++)
+ {
+ Image *const image = rect.grid[a];
+ if (image)
+ image->setAlpha(mAlpha);
+ }
+ }
}
+}
+
+void RadioButton::drawBox(gcn::Graphics* graphics)
+{
+ if (!mSkin)
+ return;
- const Image *box = nullptr;
+ const ImageRect &rect = mSkin->getBorder();
+ int index = 0;
if (mEnabled && isVisible())
{
if (mSelected)
+ {
if (mHasMouse)
- box = radioCheckedHi;
+ index = 1;
else
- box = radioChecked;
+ index = 0;
+ }
else
+ {
if (mHasMouse)
- box = radioNormalHi;
+ index = 3;
else
- box = radioNormal;
+ index = 2;
+ }
}
else
{
if (mSelected)
- box = radioDisabledChecked;
+ index = 0;
else
- box = radioDisabled;
+ index = 2;
}
+ const Image *const box = rect.grid[index];
+
+ updateAlpha();
+
if (box)
- static_cast<Graphics*>(graphics)->drawImage(box, 3, 3);
+ {
+ static_cast<Graphics*>(graphics)->drawImage(
+ box, mImagePadding, (getHeight() - mImageSize) / 2);
+ }
}
void RadioButton::draw(gcn::Graphics* graphics)
@@ -152,7 +154,9 @@ void RadioButton::draw(gcn::Graphics* graphics)
graphics->setFont(getFont());
graphics->setColor(mForegroundColor);
- graphics->drawText(getCaption(), 16, 0);
+
+ graphics->drawText(getCaption(), mPadding + mImageSize + mSpacing,
+ mPadding);
}
void RadioButton::mouseEntered(gcn::MouseEvent& event A_UNUSED)
@@ -176,3 +180,10 @@ void RadioButton::keyPressed(gcn::KeyEvent& keyEvent)
keyEvent.consume();
}
}
+
+void RadioButton::adjustSize()
+{
+ setHeight(getFont()->getHeight() + 2 * mPadding);
+ setWidth(mImagePadding + mImageSize + mSpacing
+ + getFont()->getWidth(mCaption) + mPadding);
+}
diff --git a/src/gui/widgets/radiobutton.h b/src/gui/widgets/radiobutton.h
index 7728d094e..ecf6862ed 100644
--- a/src/gui/widgets/radiobutton.h
+++ b/src/gui/widgets/radiobutton.h
@@ -28,6 +28,7 @@
#include "localconsts.h"
class Image;
+class Skin;
/**
* Guichan based RadioButton with custom look
@@ -71,16 +72,19 @@ class RadioButton final : public gcn::RadioButton
void keyPressed(gcn::KeyEvent& keyEvent) override;
+ void updateAlpha();
+
+ void adjustSize();
+
private:
static int instances;
+ static Skin *mSkin;
static float mAlpha;
bool mHasMouse;
- static Image *radioNormal;
- static Image *radioChecked;
- static Image *radioDisabled;
- static Image *radioDisabledChecked;
- static Image *radioNormalHi;
- static Image *radioCheckedHi;
+ int mPadding;
+ int mImagePadding;
+ int mImageSize;
+ int mSpacing;
};
#endif // RADIOBUTTON_H
diff --git a/src/guichan/widgets/radiobutton.cpp b/src/guichan/widgets/radiobutton.cpp
index 9f19b00a7..8cca3feac 100644
--- a/src/guichan/widgets/radiobutton.cpp
+++ b/src/guichan/widgets/radiobutton.cpp
@@ -183,9 +183,5 @@ namespace gcn
void RadioButton::adjustSize()
{
- const int height = getFont()->getHeight();
-
- setHeight(height);
- setWidth(getFont()->getWidth(getCaption()) + height + height / 2);
}
}