summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-03-06 00:39:58 +0300
committerAndrei Karas <akaras@inbox.ru>2014-03-06 23:06:15 +0300
commit6b291b6515825f4ce0e09df5dec7ea1b619b63a7 (patch)
treef26a35a21cde34f45538a191b2196bf7c81d2693 /src/gui/widgets
parent833e498f54c1d33be94c09214315b368cccaec06 (diff)
downloadmanaverse-6b291b6515825f4ce0e09df5dec7ea1b619b63a7.tar.gz
manaverse-6b291b6515825f4ce0e09df5dec7ea1b619b63a7.tar.bz2
manaverse-6b291b6515825f4ce0e09df5dec7ea1b619b63a7.tar.xz
manaverse-6b291b6515825f4ce0e09df5dec7ea1b619b63a7.zip
improve a bit different code.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/scrollarea.cpp26
-rw-r--r--src/gui/widgets/scrollarea.h90
-rw-r--r--src/gui/widgets/setupitem.cpp8
-rw-r--r--src/gui/widgets/slider.cpp96
-rw-r--r--src/gui/widgets/slider.h22
-rw-r--r--src/gui/widgets/tabs/setup_colors.cpp16
-rw-r--r--src/gui/widgets/tabs/setup_video.cpp12
-rw-r--r--src/gui/widgets/widget.h2
8 files changed, 131 insertions, 141 deletions
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index 3c50abca0..70f955684 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -99,36 +99,36 @@ ScrollArea::ScrollArea(Widget2 *const widget2,
BasicContainer(widget2),
MouseListener(),
WidgetListener(),
+ mVertexes(new ImageCollection),
+ mVertexes2(new ImageCollection),
+ mHPolicy(SHOW_AUTO),
+ mVPolicy(SHOW_AUTO),
mVScroll(0),
mHScroll(0),
mScrollbarWidth(12),
- mHPolicy(SHOW_AUTO),
- mVPolicy(SHOW_AUTO),
- mVBarVisible(false),
- mHBarVisible(false),
- mUpButtonPressed(false),
- mDownButtonPressed(false),
- mLeftButtonPressed(false),
- mRightButtonPressed(false),
mUpButtonScrollAmount(10),
mDownButtonScrollAmount(10),
mLeftButtonScrollAmount(10),
mRightButtonScrollAmount(10),
- mIsVerticalMarkerDragged(false),
- mIsHorizontalMarkerDragged(false),
mHorizontalMarkerDragOffset(0),
mVerticalMarkerDragOffset(0),
- mOpaque(true),
mX(0),
mY(0),
mClickX(0),
mClickY(0),
- mVertexes(new ImageCollection),
- mVertexes2(new ImageCollection),
mXOffset(0),
mYOffset(0),
mDrawWidth(0),
mDrawHeight(0),
+ mVBarVisible(false),
+ mHBarVisible(false),
+ mUpButtonPressed(false),
+ mDownButtonPressed(false),
+ mLeftButtonPressed(false),
+ mRightButtonPressed(false),
+ mIsVerticalMarkerDragged(false),
+ mIsHorizontalMarkerDragged(false),
+ mOpaque(true),
mHasMouse(false),
mRedraw(true)
{
diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h
index 70abac6ef..4653359e8 100644
--- a/src/gui/widgets/scrollarea.h
+++ b/src/gui/widgets/scrollarea.h
@@ -470,6 +470,19 @@ class ScrollArea final : public BasicContainer,
static ImageRect hBackground;
static Image *buttons[4][2];
+ ImageCollection *mVertexes;
+ ImageCollection *mVertexes2;
+
+ /**
+ * Holds the horizontal scroll bar policy.
+ */
+ ScrollPolicy mHPolicy;
+
+ /**
+ * Holds the vertical scroll bar policy.
+ */
+ ScrollPolicy mVPolicy;
+
/**
* Holds the vertical scroll amount.
*/
@@ -486,64 +499,73 @@ class ScrollArea final : public BasicContainer,
int mScrollbarWidth;
/**
- * Holds the horizontal scroll bar policy.
+ * Holds the up button scroll amount.
*/
- ScrollPolicy mHPolicy;
+ int mUpButtonScrollAmount;
/**
- * Holds the vertical scroll bar policy.
+ * Holds the down button scroll amount.
*/
- ScrollPolicy mVPolicy;
+ int mDownButtonScrollAmount;
/**
- * True if the vertical scroll bar is visible, false otherwise.
+ * Holds the left button scroll amount.
*/
- bool mVBarVisible;
+ int mLeftButtonScrollAmount;
/**
- * True if the horizontal scroll bar is visible, false otherwise.
+ * Holds the right button scroll amount.
*/
- bool mHBarVisible;
+ int mRightButtonScrollAmount;
/**
- * True if the up button is pressed, false otherwise.
+ * Holds the horizontal markers drag offset.
*/
- bool mUpButtonPressed;
+ int mHorizontalMarkerDragOffset;
/**
- * True if the down button is pressed, false otherwise.
+ * Holds the vertical markers drag offset.
*/
- bool mDownButtonPressed;
+ int mVerticalMarkerDragOffset;
+
+ int mX;
+ int mY;
+ int mClickX;
+ int mClickY;
+ int mXOffset;
+ int mYOffset;
+ int mDrawWidth;
+ int mDrawHeight;
/**
- * True if the left button is pressed, false otherwise.
+ * True if the vertical scroll bar is visible, false otherwise.
*/
- bool mLeftButtonPressed;
+ bool mVBarVisible;
/**
- * True if the right button is pressed, false otherwise.
+ * True if the horizontal scroll bar is visible, false otherwise.
*/
- bool mRightButtonPressed;
+ bool mHBarVisible;
/**
- * Holds the up button scroll amount.
+ * True if the up button is pressed, false otherwise.
*/
- int mUpButtonScrollAmount;
+ bool mUpButtonPressed;
/**
- * Holds the down button scroll amount.
+ * True if the down button is pressed, false otherwise.
*/
- int mDownButtonScrollAmount;
+ bool mDownButtonPressed;
/**
- * Holds the left button scroll amount.
+ * True if the left button is pressed, false otherwise.
*/
- int mLeftButtonScrollAmount;
+ bool mLeftButtonPressed;
/**
- * Holds the right button scroll amount.
+ * True if the right button is pressed, false otherwise.
*/
- int mRightButtonScrollAmount;
+ bool mRightButtonPressed;
/**
* True if the vertical marked is dragged.
@@ -556,31 +578,11 @@ class ScrollArea final : public BasicContainer,
bool mIsHorizontalMarkerDragged;
/**
- * Holds the horizontal markers drag offset.
- */
- int mHorizontalMarkerDragOffset;
-
- /**
- * Holds the vertical markers drag offset.
- */
- int mVerticalMarkerDragOffset;
-
- /**
* True if the scroll area should be opaque (that is
* display its background), false otherwise.
*/
bool mOpaque;
- int mX;
- int mY;
- int mClickX;
- int mClickY;
- ImageCollection *mVertexes;
- ImageCollection *mVertexes2;
- int mXOffset;
- int mYOffset;
- int mDrawWidth;
- int mDrawHeight;
bool mHasMouse;
bool mRedraw;
};
diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp
index 218efe8a2..4c32b0572 100644
--- a/src/gui/widgets/setupitem.cpp
+++ b/src/gui/widgets/setupitem.cpp
@@ -769,7 +769,7 @@ void SetupItemSlider::createControls()
mSlider = new Slider(this, mMin, mMax);
mSlider->setActionEventId(mEventName);
mSlider->addActionListener(mParent);
- mSlider->setValue2(atof(mValue.c_str()));
+ mSlider->setValue(atof(mValue.c_str()));
mSlider->setHeight(30);
mWidget = mSlider;
@@ -798,7 +798,7 @@ void SetupItemSlider::toWidget()
if (!mSlider)
return;
- mSlider->setValue2(atof(mValue.c_str()));
+ mSlider->setValue(atof(mValue.c_str()));
}
void SetupItemSlider::action(const ActionEvent &event A_UNUSED)
@@ -893,7 +893,7 @@ void SetupItemSlider2::createControls()
mSlider = new Slider(this, mMin, mMax);
mSlider->setActionEventId(mEventName);
mSlider->addActionListener(mParent);
- mSlider->setValue2(atof(mValue.c_str()));
+ mSlider->setValue(atof(mValue.c_str()));
mSlider->setHeight(30);
mWidget = mSlider;
@@ -952,7 +952,7 @@ void SetupItemSlider2::toWidget()
int val = roundDouble(atof(mValue.c_str()));
if (mInvert)
val = mInvertValue - val;
- mSlider->setValue2(val);
+ mSlider->setValue(val);
updateLabel();
}
diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp
index ab8cb97c2..8da4f34ae 100644
--- a/src/gui/widgets/slider.cpp
+++ b/src/gui/widgets/slider.cpp
@@ -93,14 +93,14 @@ Slider::Slider(Widget2 *const widget,
Widget(widget),
MouseListener(),
KeyListener(),
- mDragged(false),
mValue(0),
mStepLength(scaleEnd / 10),
- mMarkerLength(10),
mScaleStart(0),
mScaleEnd(scaleEnd),
mOrientation(HORIZONTAL),
mVertexes(new ImageCollection),
+ mMarkerLength(10),
+ mDragged(false),
mHasMouse(false),
mRedraw(true)
{
@@ -113,14 +113,14 @@ Slider::Slider(Widget2 *const widget,
Widget(widget),
MouseListener(),
KeyListener(),
- mDragged(false),
mValue(scaleStart),
mStepLength((scaleEnd - scaleStart) / 10),
- mMarkerLength(10),
mScaleStart(scaleStart),
mScaleEnd(scaleEnd),
mOrientation(HORIZONTAL),
mVertexes(new ImageCollection),
+ mMarkerLength(10),
+ mDragged(false),
mHasMouse(false),
mRedraw(true)
{
@@ -356,22 +356,18 @@ void Slider::mouseExited(MouseEvent& event A_UNUSED)
void Slider::mousePressed(MouseEvent &mouseEvent)
{
+ const int x = mouseEvent.getX();
+ const int y = mouseEvent.getY();
+ const int width = mDimension.width;
+ const int height = mDimension.height;
+
if (mouseEvent.getButton() == MouseEvent::LEFT
- && mouseEvent.getX() >= 0
- && mouseEvent.getX() <= getWidth()
- && mouseEvent.getY() >= 0
- && mouseEvent.getY() <= getHeight())
+ && x >= 0 && x <= width && y >= 0 && y <= height)
{
- if (getOrientation() == HORIZONTAL)
- {
- setValue2(markerPositionToValue(
- mouseEvent.getX() - getMarkerLength() / 2));
- }
+ if (mOrientation == HORIZONTAL)
+ setValue(markerPositionToValue(x - mMarkerLength / 2));
else
- {
- setValue2(markerPositionToValue(getHeight()
- - mouseEvent.getY() - getMarkerLength() / 2));
- }
+ setValue(markerPositionToValue(height - y - mMarkerLength / 2));
distributeActionEvent();
}
@@ -379,15 +375,14 @@ void Slider::mousePressed(MouseEvent &mouseEvent)
void Slider::mouseDragged(MouseEvent &mouseEvent)
{
- if (getOrientation() == HORIZONTAL)
+ if (mOrientation == HORIZONTAL)
{
- setValue2(markerPositionToValue(mouseEvent.getX()
- - getMarkerLength() / 2));
+ setValue(markerPositionToValue(mouseEvent.getX() - mMarkerLength / 2));
}
else
{
- setValue2(markerPositionToValue(getHeight()
- - mouseEvent.getY() - getMarkerLength() / 2));
+ setValue(markerPositionToValue(
+ mDimension.height - mouseEvent.getY() - mMarkerLength / 2));
}
distributeActionEvent();
@@ -397,17 +392,15 @@ void Slider::mouseDragged(MouseEvent &mouseEvent)
void Slider::mouseWheelMovedUp(MouseEvent &mouseEvent)
{
- setValue2(getValue() + getStepLength());
+ setValue(mValue + mStepLength);
distributeActionEvent();
-
mouseEvent.consume();
}
void Slider::mouseWheelMovedDown(MouseEvent &mouseEvent)
{
- setValue2(getValue() - getStepLength());
+ setValue(mValue - mStepLength);
distributeActionEvent();
-
mouseEvent.consume();
}
@@ -415,17 +408,17 @@ void Slider::keyPressed(KeyEvent& keyEvent)
{
const int action = keyEvent.getActionId();
- if (getOrientation() == HORIZONTAL)
+ if (mOrientation == HORIZONTAL)
{
if (action == Input::KEY_GUI_RIGHT)
{
- setValue2(getValue() + getStepLength());
+ setValue(mValue + mStepLength);
distributeActionEvent();
keyEvent.consume();
}
else if (action == Input::KEY_GUI_LEFT)
{
- setValue2(getValue() - getStepLength());
+ setValue(mValue - mStepLength);
distributeActionEvent();
keyEvent.consume();
}
@@ -434,25 +427,19 @@ void Slider::keyPressed(KeyEvent& keyEvent)
{
if (action == Input::KEY_GUI_UP)
{
- setValue2(getValue() + getStepLength());
+ setValue(mValue + mStepLength);
distributeActionEvent();
keyEvent.consume();
}
else if (action == Input::KEY_GUI_DOWN)
{
- setValue2(getValue() - getStepLength());
+ setValue(mValue - mStepLength);
distributeActionEvent();
keyEvent.consume();
}
}
}
-void Slider::setValue2(const double value)
-{
- setValue(value);
- mRedraw = true;
-}
-
void Slider::setScale(const double scaleStart, const double scaleEnd)
{
mScaleStart = scaleStart;
@@ -461,15 +448,16 @@ void Slider::setScale(const double scaleStart, const double scaleEnd)
void Slider::setValue(const double value)
{
- if (value > getScaleEnd())
+ mRedraw = true;
+ if (value > mScaleEnd)
{
- mValue = getScaleEnd();
+ mValue = mScaleEnd;
return;
}
- if (value < getScaleStart())
+ if (value < mScaleStart)
{
- mValue = getScaleStart();
+ mValue = mScaleStart;
return;
}
@@ -479,32 +467,32 @@ void Slider::setValue(const double value)
double Slider::markerPositionToValue(const int v) const
{
int w;
- if (getOrientation() == HORIZONTAL)
- w = getWidth();
+ if (mOrientation == HORIZONTAL)
+ w = mDimension.width;
else
- w = getHeight();
+ w = mDimension.height;
- const double pos = v / (static_cast<double>(w) - getMarkerLength());
- return (1.0 - pos) * getScaleStart() + pos * getScaleEnd();
+ const double pos = v / (static_cast<double>(w) - mMarkerLength);
+ return (1.0 - pos) * mScaleStart + pos * mScaleEnd;
}
int Slider::valueToMarkerPosition(const double value) const
{
int v;
- if (getOrientation() == HORIZONTAL)
- v = getWidth();
+ if (mOrientation == HORIZONTAL)
+ v = mDimension.width;
else
- v = getHeight();
+ v = mDimension.height;
- const int w = static_cast<int>((v - getMarkerLength())
- * (value - getScaleStart())
- / (getScaleEnd() - getScaleStart()));
+ const int w = static_cast<int>((v - mMarkerLength)
+ * (value - mScaleStart)
+ / (mScaleEnd - mScaleStart));
if (w < 0)
return 0;
- if (w > v - getMarkerLength())
- return v - getMarkerLength();
+ if (w > v - mMarkerLength)
+ return v - mMarkerLength;
return w;
}
diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h
index 0b900e230..3fbb66a5c 100644
--- a/src/gui/widgets/slider.h
+++ b/src/gui/widgets/slider.h
@@ -145,8 +145,6 @@ class Slider final : public Widget,
void keyPressed(KeyEvent& keyEvent) override final;
- void setValue2(const double value);
-
/**
* Sets the scale of the slider.
*
@@ -315,10 +313,6 @@ class Slider final : public Widget,
static ImageRect buttons[2];
static float mAlpha;
static int mInstances;
- /**
- * True if the slider is dragged, false otherwise.
- */
- bool mDragged;
/**
* Holds the current selected value.
@@ -332,11 +326,6 @@ class Slider final : public Widget,
double mStepLength;
/**
- * Holds the length of the marker.
- */
- int mMarkerLength;
-
- /**
* Holds the start value of the scale.
*/
double mScaleStart;
@@ -353,6 +342,17 @@ class Slider final : public Widget,
Orientation mOrientation;
ImageCollection *mVertexes;
+
+ /**
+ * Holds the length of the marker.
+ */
+ int mMarkerLength;
+
+ /**
+ * True if the slider is dragged, false otherwise.
+ */
+ bool mDragged;
+
bool mHasMouse;
bool mRedraw;
};
diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp
index 940d0cd3f..eb7e695f4 100644
--- a/src/gui/widgets/tabs/setup_colors.cpp
+++ b/src/gui/widgets/tabs/setup_colors.cpp
@@ -96,7 +96,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) :
mGradTypeSlider->setWidth(180);
mGradTypeSlider->setActionEventId("slider_grad");
- mGradTypeSlider->setValue2(0);
+ mGradTypeSlider->setValue(0);
mGradTypeSlider->addActionListener(this);
mGradTypeSlider->setEnabled(false);
@@ -128,7 +128,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) :
mGradDelayText->setEnabled(false);
mGradDelaySlider->setWidth(180);
- mGradDelaySlider->setValue2(mGradDelayText->getValue());
+ mGradDelaySlider->setValue(mGradDelayText->getValue());
mGradDelaySlider->setActionEventId("slider_graddelay");
mGradDelaySlider->addActionListener(this);
mGradDelaySlider->setEnabled(false);
@@ -139,7 +139,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) :
mRedText->setEnabled(false);
mRedSlider->setWidth(180);
- mRedSlider->setValue2(mRedText->getValue());
+ mRedSlider->setValue(mRedText->getValue());
mRedSlider->setActionEventId("slider_red");
mRedSlider->addActionListener(this);
mRedSlider->setEnabled(false);
@@ -150,7 +150,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) :
mGreenText->setEnabled(false);
mGreenSlider->setWidth(180);
- mGreenSlider->setValue2(mGreenText->getValue());
+ mGreenSlider->setValue(mGreenText->getValue());
mGreenSlider->setActionEventId("slider_green");
mGreenSlider->addActionListener(this);
mGreenSlider->setEnabled(false);
@@ -161,7 +161,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) :
mBlueText->setEnabled(false);
mBlueSlider->setWidth(180);
- mBlueSlider->setValue2(mBlueText->getValue());
+ mBlueSlider->setValue(mBlueText->getValue());
mBlueSlider->setActionEventId("slider_blue");
mBlueSlider->addActionListener(this);
mBlueSlider->setEnabled(false);
@@ -356,7 +356,7 @@ void Setup_Colors::valueChanged(const SelectionEvent &event A_UNUSED)
setEntry(mGreenSlider, mGreenText, col->g);
setEntry(mBlueSlider, mBlueText, col->b);
- mGradTypeSlider->setValue2(grad);
+ mGradTypeSlider->setValue(grad);
updateGradType();
mGradTypeSlider->setEnabled(true);
}
@@ -365,7 +365,7 @@ void Setup_Colors::setEntry(Slider *const s, TextField *const t,
const int value)
{
if (s)
- s->setValue2(value);
+ s->setValue(value);
if (t)
t->setText(toString(value));
}
@@ -384,7 +384,7 @@ void Setup_Colors::cancel()
userPalette->rollback();
const int type = userPalette->getColorTypeAt(mSelected);
const Color *const col = &userPalette->getColor(type);
- mGradTypeSlider->setValue2(userPalette->getGradientType(type));
+ mGradTypeSlider->setValue(userPalette->getGradientType(type));
const int delay = userPalette->getGradientDelay(type);
setEntry(mGradDelaySlider, mGradDelayText, delay);
setEntry(mRedSlider, mRedText, col->r);
diff --git a/src/gui/widgets/tabs/setup_video.cpp b/src/gui/widgets/tabs/setup_video.cpp
index d09704203..416ae8c3c 100644
--- a/src/gui/widgets/tabs/setup_video.cpp
+++ b/src/gui/widgets/tabs/setup_video.cpp
@@ -241,9 +241,9 @@ Setup_Video::Setup_Video(const Widget2 *const widget) :
? toString(mAltFps) : _("None")));
mAltFpsLabel->setWidth(150);
mFpsSlider->setEnabled(mFps > 0);
- mFpsSlider->setValue2(mFps);
+ mFpsSlider->setValue(mFps);
mAltFpsSlider->setEnabled(mAltFps > 0);
- mAltFpsSlider->setValue2(mAltFps);
+ mAltFpsSlider->setValue(mAltFps);
mFpsCheckBox->setSelected(mFps > 0);
// Pre-select the current video mode.
@@ -419,9 +419,9 @@ void Setup_Video::cancel()
mOpenGLDropDown->setSelected(renderToIndex[mOpenGLEnabled]);
mCustomCursorCheckBox->setSelected(mCustomCursorEnabled);
mFpsSlider->setEnabled(mFps > 0);
- mFpsSlider->setValue2(mFps);
+ mFpsSlider->setValue(mFps);
mAltFpsSlider->setEnabled(mAltFps > 0);
- mAltFpsSlider->setValue2(mAltFps);
+ mAltFpsSlider->setValue(mAltFps);
mFpsLabel->setCaption(mFpsCheckBox->isSelected()
// TRANSLATORS: video settings label
? toString(mFps) : _("None"));
@@ -542,7 +542,7 @@ void Setup_Video::action(const ActionEvent &event)
mFpsLabel->setCaption(text);
mFpsSlider->setEnabled(mFps > 0);
- mFpsSlider->setValue2(mFps);
+ mFpsSlider->setValue(mFps);
}
else if (id == "altfpslimitslider")
{
@@ -556,7 +556,7 @@ void Setup_Video::action(const ActionEvent &event)
// TRANSLATORS: video settings label
mAltFpsLabel->setCaption(_("Alt FPS limit: ") + text);
mAltFpsSlider->setEnabled(mAltFps > 0);
- mAltFpsSlider->setValue2(mAltFps);
+ mAltFpsSlider->setValue(mAltFps);
}
else if (id == "enableresize")
{
diff --git a/src/gui/widgets/widget.h b/src/gui/widgets/widget.h
index 34f3647d5..3af00d247 100644
--- a/src/gui/widgets/widget.h
+++ b/src/gui/widgets/widget.h
@@ -196,7 +196,7 @@ class Widget : public Widget2
* has no parent.
* @since 0.1.0
*/
- virtual Widget* getParent() const A_WARN_UNUSED
+ Widget* getParent() const A_WARN_UNUSED
{ return mParent; }
/**