summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-01-18 23:29:48 +0100
committerIra Rice <irarice@gmail.com>2009-01-18 16:09:53 -0700
commit640b37b66712d22afd5c453f6aebc4abf7dcd442 (patch)
treea2c00b2ace9c8e146ef3433916da449d396e34b0 /src
parent7b38f31192be70463cfa1fa6f0ffe13181fc26a9 (diff)
downloadmana-client-640b37b66712d22afd5c453f6aebc4abf7dcd442.tar.gz
mana-client-640b37b66712d22afd5c453f6aebc4abf7dcd442.tar.bz2
mana-client-640b37b66712d22afd5c453f6aebc4abf7dcd442.tar.xz
mana-client-640b37b66712d22afd5c453f6aebc4abf7dcd442.zip
Fixed layout of video setup page when translated
Introduced a LayoutHelper class which can be used for any non-Window container where you want to use a layout to place child widgets.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am4
-rw-r--r--src/gui/setup_video.cpp104
-rw-r--r--src/gui/setup_video.h10
-rw-r--r--src/gui/setuptab.h4
-rw-r--r--src/gui/widgets/layout.h2
-rw-r--r--src/gui/widgets/layouthelper.cpp63
-rw-r--r--src/gui/widgets/layouthelper.h84
-rw-r--r--src/gui/window.cpp9
9 files changed, 207 insertions, 75 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6bb1a2f3..adc36eaa 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -55,6 +55,8 @@ SET(SRCS
gui/widgets/resizegrip.h
gui/widgets/layout.cpp
gui/widgets/layout.h
+ gui/widgets/layouthelper.cpp
+ gui/widgets/layouthelper.h
gui/widgets/tab.cpp
gui/widgets/tab.h
gui/widgets/tabbedarea.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 2bb11268..33d01598 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,9 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \
gui/widgets/dropdown.h \
gui/widgets/layout.cpp \
gui/widgets/layout.h \
- gui/widgets/resizegrip.cpp \
+ gui/widgets/layouthelper.cpp \
+ gui/widgets/layouthelper.h \
+ gui/widgets/resizegrip.cpp \
gui/widgets/resizegrip.h \
gui/widgets/tab.cpp \
gui/widgets/tab.h \
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index 78e26e5e..30441bb8 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -36,6 +36,8 @@
#include "slider.h"
#include "textfield.h"
+#include "widgets/layouthelper.h"
+
#include "../configuration.h"
#include "../graphics.h"
#include "../localplayer.h"
@@ -136,37 +138,28 @@ Setup_Video::Setup_Video():
mParticleDetailField(new gcn::Label(""))
{
setOpaque(false);
- setDimension(gcn::Rectangle(0, 0, 290, 255));
ScrollArea *scrollArea = new ScrollArea(mModeList);
+ scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+
gcn::Label *alphaLabel = new gcn::Label(_("Gui opacity"));
+ gcn::Label *scrollRadiusLabel = new gcn::Label(_("Scroll radius"));
+ gcn::Label *scrollLazinessLabel = new gcn::Label(_("Scroll laziness"));
+ gcn::Label *overlayDetailLabel = new gcn::Label(_("Ambient FX"));
+ gcn::Label *particleDetailLabel = new gcn::Label(_("Particle Detail"));
mModeList->setEnabled(true);
#ifndef USE_OPENGL
mOpenGLCheckBox->setEnabled(false);
#endif
- mModeList->setDimension(gcn::Rectangle(0, 0, 60, 70));
- scrollArea->setDimension(gcn::Rectangle(10, 10, 90, 70));
- mFsCheckBox->setPosition(110, 10);
- mNameCheckBox->setPosition(195, 10);
- mOpenGLCheckBox->setPosition(110, 30);
- mParticleEffectsCheckBox->setPosition(180, 30);
- mCustomCursorCheckBox->setPosition(110, 50);
- mSpeechBubbleCheckBox->setPosition(110, 70);
- mAlphaSlider->setDimension(gcn::Rectangle(10, 100, 75, 10));
- alphaLabel->setPosition(20 + mAlphaSlider->getWidth(),
- mAlphaSlider->getY());
- mFpsCheckBox->setPosition(90, 120);
- mFpsSlider->setDimension(gcn::Rectangle(10, 120, 75, 10));
- mFpsField->setPosition(100 + mFpsCheckBox->getWidth(), 100);
- mFpsField->setWidth(30);
-
mModeList->setSelected(-1);
mAlphaSlider->setValue(mOpacity);
+ mAlphaSlider->setWidth(90);
mFpsField->setText(toString(mFps));
mFpsField->setEnabled(mFps > 0);
+ mFpsField->setWidth(30);
mFpsSlider->setValue(mFps);
mFpsSlider->setEnabled(mFps > 0);
mFpsCheckBox->setSelected(mFps > 0);
@@ -206,27 +199,12 @@ Setup_Video::Setup_Video():
mParticleDetailSlider->addActionListener(this);
mParticleDetailField->addKeyListener(this);
- mScrollRadiusSlider->setDimension(gcn::Rectangle(10, 140, 75, 10));
- gcn::Label *scrollRadiusLabel = new gcn::Label(_("Scroll radius"));
- scrollRadiusLabel->setPosition(90, 140);
- mScrollRadiusField->setPosition(mFpsField->getX(), 140);
- mScrollRadiusField->setWidth(30);
mScrollRadiusField->setText(toString(mOriginalScrollRadius));
mScrollRadiusSlider->setValue(mOriginalScrollRadius);
- mScrollLazinessSlider->setDimension(gcn::Rectangle(10, 160, 75, 10));
- gcn::Label *scrollLazinessLabel = new gcn::Label(_("Scroll laziness"));
- scrollLazinessLabel->setPosition(90, 160);
- mScrollLazinessField->setPosition(mFpsField->getX(), 160);
- mScrollLazinessField->setWidth(30);
mScrollLazinessField->setText(toString(mOriginalScrollLaziness));
mScrollLazinessSlider->setValue(mOriginalScrollLaziness);
- mOverlayDetailSlider->setDimension(gcn::Rectangle(10, 180, 75, 10));
- gcn::Label *overlayDetailLabel = new gcn::Label(_("Ambient FX"));
- overlayDetailLabel->setPosition(90, 180);
- mOverlayDetailField->setPosition(180, 180);
- mOverlayDetailField->setWidth(30);
switch (mOverlayDetail)
{
case 0:
@@ -241,11 +219,6 @@ Setup_Video::Setup_Video():
}
mOverlayDetailSlider->setValue(mOverlayDetail);
- mParticleDetailSlider->setDimension(gcn::Rectangle(10, 200, 75, 10));
- gcn::Label *particleDetailLabel = new gcn::Label(_("Particle Detail"));
- particleDetailLabel->setPosition(90, 200);
- mParticleDetailField->setPosition(180, 200);
- mParticleDetailField->setWidth(60);
switch (mParticleDetail)
{
case 0:
@@ -263,30 +236,39 @@ Setup_Video::Setup_Video():
}
mParticleDetailSlider->setValue(mParticleDetail);
- add(scrollArea);
- add(mFsCheckBox);
- add(mOpenGLCheckBox);
- add(mCustomCursorCheckBox);
- add(mParticleEffectsCheckBox);
- add(mSpeechBubbleCheckBox);
- add(mNameCheckBox);
- add(mAlphaSlider);
- add(alphaLabel);
- add(mFpsCheckBox);
- add(mFpsSlider);
- add(mFpsField);
- add(mScrollRadiusSlider);
- add(scrollRadiusLabel);
- add(mScrollRadiusField);
- add(mScrollLazinessSlider);
- add(scrollLazinessLabel);
- add(mScrollLazinessField);
- add(mOverlayDetailSlider);
- add(overlayDetailLabel);
- add(mOverlayDetailField);
- add(mParticleDetailSlider);
- add(particleDetailLabel);
- add(mParticleDetailField);
+ // Do the layout
+ LayoutHelper h(this);
+ ContainerPlacer place = h.getPlacer(0, 0);
+
+ place(0, 0, scrollArea, 1, 5).setPadding(2);
+ place(1, 0, mFsCheckBox, 3);
+ place(2, 0, mNameCheckBox, 3);
+ place(1, 1, mOpenGLCheckBox, 3);
+ place(2, 1, mParticleEffectsCheckBox, 3);
+ place(1, 2, mCustomCursorCheckBox, 3);
+ place(1, 3, mSpeechBubbleCheckBox, 3);
+
+ place(0, 5, mAlphaSlider);
+ place(0, 6, mFpsSlider);
+ place(0, 7, mScrollRadiusSlider);
+ place(0, 8, mScrollLazinessSlider);
+ place(0, 9, mOverlayDetailSlider);
+ place(0, 10, mParticleDetailSlider);
+
+ place(1, 5, alphaLabel, 2);
+ place(1, 6, mFpsCheckBox).setPadding(3);
+ place(1, 7, scrollRadiusLabel);
+ place(1, 8, scrollLazinessLabel);
+ place(1, 9, overlayDetailLabel);
+ place(1, 10, particleDetailLabel);
+
+ place(2, 6, mFpsField).setPadding(1);
+ place(2, 7, mScrollRadiusField).setPadding(1);
+ place(2, 8, mScrollLazinessField).setPadding(1);
+ place(2, 9, mOverlayDetailField, 2).setPadding(2);
+ place(2, 10, mParticleDetailField, 2).setPadding(2);
+
+ setDimension(gcn::Rectangle(0, 0, 295, 255));
}
Setup_Video::~Setup_Video()
diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h
index 370a2d2e..360daff0 100644
--- a/src/gui/setup_video.h
+++ b/src/gui/setup_video.h
@@ -45,6 +45,11 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
void keyPressed(gcn::KeyEvent &event);
private:
+ void updateSliders(bool originalValues);
+
+ int updateSlider(gcn::Slider *slider, gcn::TextField *field,
+ const std::string &configName);
+
bool mFullScreenEnabled;
bool mOpenGLEnabled;
bool mCustomCursorEnabled;
@@ -84,11 +89,6 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
int mParticleDetail;
gcn::Slider *mParticleDetailSlider;
gcn::Label *mParticleDetailField;
-
- void updateSliders(bool originalValues);
-
- int updateSlider(gcn::Slider *slider, gcn::TextField *field,
- const std::string &configName);
};
#endif
diff --git a/src/gui/setuptab.h b/src/gui/setuptab.h
index 6c276c35..9e668a20 100644
--- a/src/gui/setuptab.h
+++ b/src/gui/setuptab.h
@@ -27,8 +27,8 @@
class SetupTab : public GCContainer
{
public:
- virtual void apply() =0;
- virtual void cancel() =0;
+ virtual void apply() = 0;
+ virtual void cancel() = 0;
};
#endif
diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h
index d631c154..9ba97fa1 100644
--- a/src/gui/widgets/layout.h
+++ b/src/gui/widgets/layout.h
@@ -317,4 +317,4 @@ class Layout: public LayoutCell
bool mComputed;
};
-#endif
+#endif // _TMW_WIDGET_LAYOUT_H__
diff --git a/src/gui/widgets/layouthelper.cpp b/src/gui/widgets/layouthelper.cpp
new file mode 100644
index 00000000..4dddaab3
--- /dev/null
+++ b/src/gui/widgets/layouthelper.cpp
@@ -0,0 +1,63 @@
+/*
+ * The Mana World
+ * Copyright 2009 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "layouthelper.h"
+
+LayoutHelper::LayoutHelper(gcn::Container *container):
+ mContainer(container)
+{
+ mContainer->addWidgetListener(this);
+}
+
+LayoutHelper::~LayoutHelper()
+{
+ mContainer->removeWidgetListener(this);
+}
+
+Layout &LayoutHelper::getLayout()
+{
+ return mLayout;
+}
+
+LayoutCell &LayoutHelper::place(int x, int y, gcn::Widget *wg, int w, int h)
+{
+ mContainer->add(wg);
+ return mLayout.place(wg, x, y, w, h);
+}
+
+ContainerPlacer LayoutHelper::getPlacer(int x, int y)
+{
+ return ContainerPlacer(mContainer, &mLayout.at(x, y));
+}
+
+void LayoutHelper::reflowLayout(int w, int h)
+{
+ mLayout.reflow(w, h);
+ mContainer->setSize(w, h);
+}
+
+void LayoutHelper::widgetResized(const gcn::Event &event)
+{
+ const gcn::Rectangle area = mContainer->getChildrenArea();
+ int w = area.width;
+ int h = area.height;
+ mLayout.reflow(w, h);
+}
diff --git a/src/gui/widgets/layouthelper.h b/src/gui/widgets/layouthelper.h
new file mode 100644
index 00000000..b1039fb0
--- /dev/null
+++ b/src/gui/widgets/layouthelper.h
@@ -0,0 +1,84 @@
+/*
+ * The Mana World
+ * Copyright 2009 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef LAYOUTHELPER_H
+#define LAYOUTHELPER_H
+
+#include "layout.h"
+
+#include <guichan/widgetlistener.hpp>
+
+/**
+ * A helper class for adding a layout to a Guichan container widget. The layout
+ * will register itself as a widget listener and relayout the widgets in the
+ * container dynamically on resize.
+ */
+class LayoutHelper : public gcn::WidgetListener
+{
+ public:
+ /**
+ * Constructor.
+ */
+ LayoutHelper(gcn::Container *container);
+
+ /**
+ * Destructor.
+ */
+ ~LayoutHelper();
+
+ /**
+ * Gets the layout handler.
+ */
+ Layout &getLayout();
+
+ /**
+ * Computes the position of the widgets according to the current
+ * layout. Resizes the managed container so that the layout fits.
+ *
+ * @note This function is meant to be called with fixed-size
+ * containers.
+ *
+ * @param w if non-zero, force the container to this width.
+ * @param h if non-zero, force the container to this height.
+ */
+ void reflowLayout(int w = 0, int h = 0);
+
+ /**
+ * Adds a widget to the container and sets it at given cell.
+ */
+ LayoutCell &place(int x, int y, gcn::Widget *, int w = 1, int h = 1);
+
+ /**
+ * Returns a proxy for adding widgets in an inner table of the layout.
+ */
+ ContainerPlacer getPlacer(int x, int y);
+
+ /**
+ * Called whenever the managed container changes size.
+ */
+ void widgetResized(const gcn::Event &event);
+
+ private:
+ Layout mLayout; /**< Layout handler */
+ gcn::Container *mContainer; /**< Managed container */
+};
+
+#endif // LAYOUTHELPER_H
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index f6f5f4b8..d1ada53d 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -257,17 +257,16 @@ void Window::setResizable(bool r)
void Window::widgetResized(const gcn::Event &event)
{
+ const gcn::Rectangle area = getChildrenArea();
+
if (mGrip)
- {
- const gcn::Rectangle area = getChildrenArea();
mGrip->setPosition(getWidth() - mGrip->getWidth() - area.x,
getHeight() - mGrip->getHeight() - area.y);
- }
if (mLayout)
{
- int w = getWidth() - 2 * getPadding();
- int h = getHeight() - getPadding() - getTitleBarHeight();
+ int w = area.width;
+ int h = area.height;
mLayout->reflow(w, h);
}
}