diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-01-18 23:29:48 +0100 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-01-18 23:33:30 +0100 |
commit | 9e29e1fd328304c2852c456e38fcb5da6421be96 (patch) | |
tree | 42bcfa14290fbf9c8f01d8f48254f1c229c5f03e | |
parent | a10cebb21bdd211716628039b406362f2168c852 (diff) | |
download | mana-9e29e1fd328304c2852c456e38fcb5da6421be96.tar.gz mana-9e29e1fd328304c2852c456e38fcb5da6421be96.tar.bz2 mana-9e29e1fd328304c2852c456e38fcb5da6421be96.tar.xz mana-9e29e1fd328304c2852c456e38fcb5da6421be96.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.
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/gui/setup.cpp | 2 | ||||
-rw-r--r-- | src/gui/setup_video.cpp | 104 | ||||
-rw-r--r-- | src/gui/setup_video.h | 15 | ||||
-rw-r--r-- | src/gui/setuptab.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/layout.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/layouthelper.cpp | 63 | ||||
-rw-r--r-- | src/gui/widgets/layouthelper.h | 84 | ||||
-rw-r--r-- | src/gui/window.cpp | 9 |
10 files changed, 209 insertions, 78 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f87b6c8c..d7127801 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,6 +53,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 2936849a..97b62dd9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,6 +3,8 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = tmw tmw_SOURCES = gui/widgets/layout.cpp \ gui/widgets/layout.h \ + gui/widgets/layouthelper.cpp \ + gui/widgets/layouthelper.h \ gui/widgets/resizegrip.cpp \ gui/widgets/resizegrip.h \ gui/widgets/tab.cpp \ diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 80da120a..68d2199d 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -71,7 +71,7 @@ Setup::Setup(): } TabbedArea *panel = new TabbedArea(); - panel->setDimension(gcn::Rectangle(5, 5, 260, 225)); + panel->setDimension(gcn::Rectangle(5, 5, 280, 225)); SetupTab *tab; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 9fb38f13..728c54d1 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -37,6 +37,8 @@ #include "slider.h" #include "textfield.h" +#include "widgets/layouthelper.h" + #include "../configuration.h" #include "../graphics.h" #include "../log.h" @@ -130,34 +132,29 @@ Setup_Video::Setup_Video(): mParticleDetailField(new gcn::Label("")) { setOpaque(false); - setDimension(gcn::Rectangle(0, 0, 250, 200)); 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(false); #ifndef USE_OPENGL mOpenGLCheckBox->setEnabled(false); #endif - mModeList->setDimension(gcn::Rectangle(0, 0, 60, 50)); - scrollArea->setDimension(gcn::Rectangle(10, 10, 90, 50)); - mFsCheckBox->setPosition(110, 10); - mOpenGLCheckBox->setPosition(110, 30); - mCustomCursorCheckBox->setPosition(110, 50); - mAlphaSlider->setDimension(gcn::Rectangle(10, 80, 100, 10)); - alphaLabel->setPosition(20 + mAlphaSlider->getWidth(), - mAlphaSlider->getY()); - mFpsCheckBox->setPosition(90, 100); - mFpsSlider->setDimension(gcn::Rectangle(10, 100, 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); @@ -189,27 +186,12 @@ Setup_Video::Setup_Video(): mParticleDetailSlider->addActionListener(this); mParticleDetailField->addKeyListener(this); - mScrollRadiusSlider->setDimension(gcn::Rectangle(10, 120, 75, 10)); - gcn::Label *scrollRadiusLabel = new gcn::Label(_("Scroll radius")); - scrollRadiusLabel->setPosition(90, 120); - mScrollRadiusField->setPosition(mFpsField->getX(), 120); - mScrollRadiusField->setWidth(30); mScrollRadiusField->setText(toString(mOriginalScrollRadius)); mScrollRadiusSlider->setValue(mOriginalScrollRadius); - mScrollLazinessSlider->setDimension(gcn::Rectangle(10, 140, 75, 10)); - gcn::Label *scrollLazinessLabel = new gcn::Label(_("Scroll laziness")); - scrollLazinessLabel->setPosition(90, 140); - mScrollLazinessField->setPosition(mFpsField->getX(), 140); - mScrollLazinessField->setWidth(30); mScrollLazinessField->setText(toString(mOriginalScrollLaziness)); mScrollLazinessSlider->setValue(mOriginalScrollLaziness); - mOverlayDetailSlider->setDimension(gcn::Rectangle(10, 160, 75, 10)); - gcn::Label *overlayDetailLabel = new gcn::Label(_("Ambient FX")); - overlayDetailLabel->setPosition(90, 160); - mOverlayDetailField->setPosition(180, 160); - mOverlayDetailField->setWidth(30); switch (mOverlayDetail) { case 0: @@ -224,11 +206,6 @@ Setup_Video::Setup_Video(): } mOverlayDetailSlider->setValue(mOverlayDetail); - mParticleDetailSlider->setDimension(gcn::Rectangle(10, 180, 75, 10)); - gcn::Label *particleDetailLabel = new gcn::Label(_("Particle Detail")); - particleDetailLabel->setPosition(90, 180); - mParticleDetailField->setPosition(180, 180); - mParticleDetailField->setWidth(60); switch (mParticleDetail) { case 0: @@ -246,27 +223,36 @@ Setup_Video::Setup_Video(): } mParticleDetailSlider->setValue(mParticleDetail); - add(scrollArea); - add(mFsCheckBox); - add(mOpenGLCheckBox); - add(mCustomCursorCheckBox); - 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, 3).setPadding(2); + place(1, 0, mFsCheckBox, 3); + place(1, 1, mOpenGLCheckBox, 3); + place(1, 2, mCustomCursorCheckBox, 3); + + place(0, 4, mAlphaSlider); + place(0, 5, mFpsSlider); + place(0, 6, mScrollRadiusSlider); + place(0, 7, mScrollLazinessSlider); + place(0, 8, mOverlayDetailSlider); + place(0, 9, mParticleDetailSlider); + + place(1, 4, alphaLabel, 2); + place(1, 5, mFpsCheckBox).setPadding(3); + place(1, 6, scrollRadiusLabel); + place(1, 7, scrollLazinessLabel); + place(1, 8, overlayDetailLabel); + place(1, 9, particleDetailLabel); + + place(2, 5, mFpsField).setPadding(1); + place(2, 6, mScrollRadiusField).setPadding(1); + place(2, 7, mScrollLazinessField).setPadding(1); + place(2, 8, mOverlayDetailField, 2).setPadding(2); + place(2, 9, mParticleDetailField, 2).setPadding(2); + + setDimension(gcn::Rectangle(0, 0, 280, 200)); } Setup_Video::~Setup_Video() @@ -335,9 +321,8 @@ void Setup_Video::apply() mOpenGLEnabled = config.getValue("opengl", 0); } -int -Setup_Video::updateSlider(gcn::Slider *slider, gcn::TextField *field, - const std::string &configName) +int Setup_Video::updateSlider(gcn::Slider *slider, gcn::TextField *field, + const std::string &configName) { int value; std::stringstream temp(field->getText()); @@ -459,8 +444,7 @@ void Setup_Video::action(const gcn::ActionEvent &event) } } -void -Setup_Video::keyPressed(gcn::KeyEvent &event) +void Setup_Video::keyPressed(gcn::KeyEvent &event) { std::stringstream tempFps(mFpsField->getText()); diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 355a321e..2a7bd04c 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -42,10 +42,14 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, void action(const gcn::ActionEvent &event); /** Called when key is pressed */ - void - keyPressed(gcn::KeyEvent &event); + 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; @@ -79,13 +83,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 dfe7ac64..a3864431 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -261,17 +261,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); } } |