summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-02-03 16:33:18 -0700
committerIra Rice <irarice@gmail.com>2009-02-03 16:33:18 -0700
commit7d45452187b1c2911b688bbed5fb8981a67b1934 (patch)
tree173857b19d0662837a48178739412aec908b040e /src/gui/widgets
parent8857a59c3818c1ce6eeb6c054cb5543bfc35c087 (diff)
downloadmana-7d45452187b1c2911b688bbed5fb8981a67b1934.tar.gz
mana-7d45452187b1c2911b688bbed5fb8981a67b1934.tar.bz2
mana-7d45452187b1c2911b688bbed5fb8981a67b1934.tar.xz
mana-7d45452187b1c2911b688bbed5fb8981a67b1934.zip
Modified the dropdown class to handle opacity.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/dropdown.cpp58
-rw-r--r--src/gui/widgets/dropdown.h22
2 files changed, 67 insertions, 13 deletions
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index 88a12d68..ac5cbaa2 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -23,6 +23,9 @@
#include "dropdown.h"
+#include "../colour.h"
+
+#include "../../configuration.h"
#include "../../graphics.h"
#include "../../resources/image.h"
@@ -33,12 +36,12 @@
int DropDown::instances = 0;
Image *DropDown::buttons[2][2];
ImageRect DropDown::skin;
+float DropDown::mAlpha = config.getValue("guialpha", 0.8);
-DropDown::DropDown(gcn::ListModel *listModel,
- gcn::ScrollArea *scrollArea,
- gcn::ListBox *listBox):
- gcn::DropDown::DropDown(listModel,
- scrollArea, listBox)
+DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea,
+ gcn::ListBox *listBox, bool opacity):
+ gcn::DropDown::DropDown(listModel, scrollArea, listBox),
+ mOpaque(opacity)
{
setFrameSize(2);
@@ -58,6 +61,11 @@ DropDown::DropDown(gcn::ListModel *listModel,
buttons[0][1] =
resman->getImage("graphics/gui/vscroll_down_pressed.png");
+ buttons[0][0]->setAlpha(mAlpha);
+ buttons[0][1]->setAlpha(mAlpha);
+ buttons[1][0]->setAlpha(mAlpha);
+ buttons[1][1]->setAlpha(mAlpha);
+
// get the border skin
Image *boxBorder = resman->getImage("graphics/gui/deepbox.png");
int gridx[4] = {0, 3, 28, 31};
@@ -70,6 +78,7 @@ DropDown::DropDown(gcn::ListModel *listModel,
gridx[x], gridy[y],
gridx[x + 1] - gridx[x] + 1,
gridy[y + 1] - gridy[y] + 1);
+ skin.grid[a]->setAlpha(mAlpha);
a++;
}
}
@@ -108,19 +117,44 @@ void DropDown::draw(gcn::Graphics* graphics)
h = getHeight();
}
- int alpha = getBaseColor().a;
+ if (config.getValue("guialpha", 0.8) != mAlpha)
+ {
+ mAlpha = config.getValue("guialpha", 0.8);
+
+ buttons[0][0]->setAlpha(mAlpha);
+ buttons[0][1]->setAlpha(mAlpha);
+ buttons[1][0]->setAlpha(mAlpha);
+ buttons[1][1]->setAlpha(mAlpha);
+
+ for (int a = 0; a < 9; a++)
+ {
+ skin.grid[a]->setAlpha(mAlpha);
+ }
+ }
+
+ bool valid;
+ const int alpha = mAlpha * 255;
gcn::Color faceColor = getBaseColor();
faceColor.a = alpha;
- gcn::Color highlightColor = faceColor + 0x303030;
+ gcn::Color highlightColor = textColour->getColour('H', valid);
highlightColor.a = alpha;
gcn::Color shadowColor = faceColor - 0x303030;
shadowColor.a = alpha;
+ if (mOpaque)
+ {
+ int red = getBackgroundColor().r;
+ int green = getBackgroundColor().g;
+ int blue = getBackgroundColor().b;
+ graphics->setColor(gcn::Color(red, green, blue, alpha));
+ graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h));
+
+ red = getForegroundColor().r;
+ green = getForegroundColor().g;
+ blue = getForegroundColor().b;
+ graphics->setColor(gcn::Color(red, green, blue, alpha));
+ }
- graphics->setColor(getBackgroundColor());
- graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h));
-
- graphics->setColor(getForegroundColor());
graphics->setFont(getFont());
if (mListBox->getListModel() && mListBox->getSelected() >= 0)
@@ -140,7 +174,7 @@ void DropDown::draw(gcn::Graphics* graphics)
{
drawChildren(graphics);
- // Draw two lines separating the ListBox with se selected
+ // Draw two lines separating the ListBox with selected
// element view.
graphics->setColor(highlightColor);
graphics->drawLine(0, h, getWidth(), h);
diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h
index 25ae05f8..bff8bd1e 100644
--- a/src/gui/widgets/dropdown.h
+++ b/src/gui/widgets/dropdown.h
@@ -56,7 +56,8 @@ class DropDown : public gcn::DropDown
*/
DropDown(gcn::ListModel *listModel = NULL,
gcn::ScrollArea *scrollArea = NULL,
- gcn::ListBox *listBox = NULL);
+ gcn::ListBox *listBox = NULL,
+ bool opacity = true);
/**
* Destructor.
@@ -67,6 +68,22 @@ class DropDown : public gcn::DropDown
void drawFrame(gcn::Graphics* graphics);
+ /**
+ * Sets the widget to be opaque, that is sets the widget to display its
+ * background.
+ *
+ * @param opaque True if the widget should be opaque, false otherwise.
+ */
+ void setOpaque(bool opaque) {mOpaque = opaque;}
+
+ /**
+ * Checks if the widget is opaque, that is if the widget area displays
+ * its background.
+ *
+ * @return True if the widget is opaque, false otherwise.
+ */
+ bool isOpaque() const {return mOpaque;}
+
protected:
/**
@@ -80,6 +97,9 @@ class DropDown : public gcn::DropDown
static int instances;
static Image *buttons[2][2];
static ImageRect skin;
+ static float mAlpha;
+
+ bool mOpaque;
};
#endif // end DROPDOWN_H