From dc6771670569d2f296f4c12595966bbcb9aadf65 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 18 Jun 2011 23:35:58 +0300 Subject: Start implimenting new setup pages. Add new container for setup items. Imporved other containers. --- src/gui/widgets/horizontcontainer.cpp | 6 ++--- src/gui/widgets/setuptabscroll.cpp | 49 +++++++++++++++++++++++++++++++++++ src/gui/widgets/setuptabscroll.h | 41 +++++++++++++++++++++++++++++ src/gui/widgets/vertcontainer.cpp | 43 +++++++++++++++++++++++------- src/gui/widgets/vertcontainer.h | 18 ++++++++++--- 5 files changed, 142 insertions(+), 15 deletions(-) create mode 100644 src/gui/widgets/setuptabscroll.cpp create mode 100644 src/gui/widgets/setuptabscroll.h (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/horizontcontainer.cpp b/src/gui/widgets/horizontcontainer.cpp index a04230871..95320055c 100644 --- a/src/gui/widgets/horizontcontainer.cpp +++ b/src/gui/widgets/horizontcontainer.cpp @@ -26,7 +26,7 @@ HorizontContainer::HorizontContainer(int height, int spacing): mSpacing(spacing), mCount(0), - mLastX(0) + mLastX(spacing) { setHeight(height); addWidgetListener(this); @@ -38,9 +38,9 @@ void HorizontContainer::add(gcn::Widget *widget) return; Container::add(widget); - widget->setPosition(mLastX, 0); + widget->setPosition(mLastX, mSpacing); mCount++; - mLastX += widget->getWidth() + mSpacing; + mLastX += widget->getWidth() + 2 * mSpacing; } void HorizontContainer::clear() diff --git a/src/gui/widgets/setuptabscroll.cpp b/src/gui/widgets/setuptabscroll.cpp new file mode 100644 index 000000000..c46ebaf97 --- /dev/null +++ b/src/gui/widgets/setuptabscroll.cpp @@ -0,0 +1,49 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#include "gui/widgets/setuptabscroll.h" + +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/scrollarea.h" +#include "gui/widgets/vertcontainer.h" + +#include "debug.h" + +SetupTabScroll::SetupTabScroll() : + SetupTab() +{ + mContainer = new VertContainer(32, false, 8); + mScroll = new ScrollArea(mContainer); + mScroll->setOpaque(false); + mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); + mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); + +// LayoutHelper h(this); +// ContainerPlacer place = h.getPlacer(0, 0); +// place(0, 0, mScroll, 10, 10); +} + +SetupTabScroll::~SetupTabScroll() +{ +// delete mScroll; + mScroll = 0; + delete mContainer; + mContainer = 0; +} diff --git a/src/gui/widgets/setuptabscroll.h b/src/gui/widgets/setuptabscroll.h new file mode 100644 index 000000000..83a5e272c --- /dev/null +++ b/src/gui/widgets/setuptabscroll.h @@ -0,0 +1,41 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#ifndef GUI_SETUPTABSCROLL_H +#define GUI_SETUPTABSCROLL_H + +#include "gui/widgets/setuptab.h" + +class ScrollArea; +class VertContainer; + +class SetupTabScroll : public SetupTab +{ + public: + SetupTabScroll(); + + ~SetupTabScroll(); + + protected: + VertContainer *mContainer; + ScrollArea *mScroll; +}; + +#endif diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp index d4cf0a13f..6f94df535 100644 --- a/src/gui/widgets/vertcontainer.cpp +++ b/src/gui/widgets/vertcontainer.cpp @@ -23,23 +23,45 @@ #include "debug.h" -VertContainer::VertContainer(int spacing): - mSpacing(spacing), - mCount(0) +VertContainer::VertContainer(int verticalItemSize, bool resizable, + int leftSpacing): + mVerticalItemSize(verticalItemSize), + mCount(0), + mNextY(0), + mLeftSpacing(leftSpacing), + mVerticalSpacing(0), + mResizable(resizable) { addWidgetListener(this); } -void VertContainer::add(gcn::Widget *widget) +void VertContainer::add(gcn::Widget *widget, int spacing) +{ + add(widget, mResizable, spacing); +} + +void VertContainer::add(gcn::Widget *widget, bool resizable, int spacing) { if (!widget) return; Container::add(widget); - widget->setPosition(0, mCount * mSpacing); - widget->setSize(getWidth(), mSpacing); - mCount++; - setHeight(mCount * mSpacing); + widget->setPosition(mLeftSpacing, mNextY); + if (resizable) + { + widget->setSize(getWidth() - mLeftSpacing, mVerticalItemSize); + mResizableWidgets.push_back(widget); + } + else if (widget->getHeight() > mVerticalItemSize) + { + widget->setSize(widget->getWidth(), mVerticalItemSize); + } + + if (spacing == -1) + mNextY += mVerticalItemSize + (mVerticalSpacing * 2); + else + mNextY += mVerticalItemSize + (spacing * 2); + setHeight(mNextY); } void VertContainer::clear() @@ -51,6 +73,9 @@ void VertContainer::clear() void VertContainer::widgetResized(const gcn::Event &event _UNUSED_) { - for (WidgetListIterator it = mWidgets.begin(); it != mWidgets.end(); it++) + for (WidgetListIterator it = mResizableWidgets.begin(); + it != mResizableWidgets.end(); it++) + { (*it)->setWidth(getWidth()); + } } diff --git a/src/gui/widgets/vertcontainer.h b/src/gui/widgets/vertcontainer.h index e96bd5561..268c61d4f 100644 --- a/src/gui/widgets/vertcontainer.h +++ b/src/gui/widgets/vertcontainer.h @@ -40,14 +40,26 @@ class VertContainer : public Container, public gcn::WidgetListener { public: - VertContainer(int spacing); - virtual void add(gcn::Widget *widget); + VertContainer(int verticalItemSize, bool resizable = true, + int leftSpacing = 0); + + virtual void add(gcn::Widget *widget, bool resizable, + int spacing = -1); + + virtual void add(gcn::Widget *widget, int spacing = -1); + virtual void clear(); + void widgetResized(const gcn::Event &event); private: - int mSpacing; + std::list mResizableWidgets; + int mVerticalItemSize; int mCount; + int mNextY; + int mLeftSpacing; + int mVerticalSpacing; + bool mResizable; }; #endif -- cgit v1.2.3-60-g2f50