diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-02-15 18:07:17 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-02-15 18:38:03 +0300 |
commit | cde42202d69e178da73c698065deca54b24054fd (patch) | |
tree | d636965ecde85db8de36fa65735920826e8e191b /src/guichan/widgets | |
parent | 21e63bbf54679ec236d1f09ed435959ff6a04db2 (diff) | |
download | manaplus-cde42202d69e178da73c698065deca54b24054fd.tar.gz manaplus-cde42202d69e178da73c698065deca54b24054fd.tar.bz2 manaplus-cde42202d69e178da73c698065deca54b24054fd.tar.xz manaplus-cde42202d69e178da73c698065deca54b24054fd.zip |
move exguichan files into gui/base/
Diffstat (limited to 'src/guichan/widgets')
-rw-r--r-- | src/guichan/widgets/button.cpp | 194 | ||||
-rw-r--r-- | src/guichan/widgets/checkbox.cpp | 154 | ||||
-rw-r--r-- | src/guichan/widgets/container.cpp | 136 | ||||
-rw-r--r-- | src/guichan/widgets/label.cpp | 121 | ||||
-rw-r--r-- | src/guichan/widgets/listbox.cpp | 241 | ||||
-rw-r--r-- | src/guichan/widgets/radiobutton.cpp | 207 | ||||
-rw-r--r-- | src/guichan/widgets/scrollarea.cpp | 600 | ||||
-rw-r--r-- | src/guichan/widgets/slider.cpp | 231 | ||||
-rw-r--r-- | src/guichan/widgets/textbox.cpp | 345 | ||||
-rw-r--r-- | src/guichan/widgets/textfield.cpp | 165 | ||||
-rw-r--r-- | src/guichan/widgets/window.cpp | 233 |
11 files changed, 0 insertions, 2627 deletions
diff --git a/src/guichan/widgets/button.cpp b/src/guichan/widgets/button.cpp deleted file mode 100644 index 1226e157a..000000000 --- a/src/guichan/widgets/button.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/button.hpp" - -#include "guichan/exception.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseevent.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - Button::Button() : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - gcn::FocusListener(), - mCaption(), - mHasMouse(false), - mKeyPressed(false), - mMousePressed(false), - mAlignment(Graphics::CENTER), - mSpacing(4) - { - setFocusable(true); - adjustSize(); - setFrameSize(1); - - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - } - - Button::Button(const std::string& caption) : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - gcn::FocusListener(), - mCaption(caption), - mHasMouse(false), - mKeyPressed(false), - mMousePressed(false), - mAlignment(Graphics::CENTER), - mSpacing(4) - { - setFocusable(true); - adjustSize(); - setFrameSize(1); - - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - } - - void Button::setCaption(const std::string& caption) - { - mCaption = caption; - } - - const std::string& Button::getCaption() const - { - return mCaption; - } - - void Button::setAlignment(Graphics::Alignment alignment) - { - mAlignment = alignment; - } - - Graphics::Alignment Button::getAlignment() const - { - return mAlignment; - } - - void Button::setSpacing(unsigned int spacing) - { - mSpacing = spacing; - } - - unsigned int Button::getSpacing() const - { - return mSpacing; - } - - void Button::adjustSize() - { - } - - bool Button::isPressed() const - { - if (mMousePressed) - return mHasMouse; - else - return mKeyPressed; - } - - void Button::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mMousePressed = true; - mouseEvent.consume(); - } - } - - void Button::mouseExited(MouseEvent& mouseEvent A_UNUSED) - { - mHasMouse = false; - } - - void Button::mouseEntered(MouseEvent& mouseEvent A_UNUSED) - { - mHasMouse = true; - } - - void Button::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void Button::focusLost(const Event& event A_UNUSED) - { - mMousePressed = false; - mKeyPressed = false; - } -} // namespace gcn diff --git a/src/guichan/widgets/checkbox.cpp b/src/guichan/widgets/checkbox.cpp deleted file mode 100644 index 4b3c7b966..000000000 --- a/src/guichan/widgets/checkbox.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/checkbox.hpp" - -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - - CheckBox::CheckBox() : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mSelected(false), - mCaption() - { - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } - - CheckBox::CheckBox(const std::string &caption, bool selected) : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mSelected(selected), - mCaption() - { - setCaption(caption); - - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - - adjustSize(); - } - - bool CheckBox::isSelected() const - { - return mSelected; - } - - void CheckBox::setSelected(bool selected) - { - mSelected = selected; - } - - const std::string &CheckBox::getCaption() const - { - return mCaption; - } - - void CheckBox::setCaption(const std::string& caption) - { - mCaption = caption; - } - - void CheckBox::keyPressed(KeyEvent& keyEvent A_UNUSED) - { - } - - void CheckBox::mouseClicked(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - toggleSelected(); - } - } - - void CheckBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void CheckBox::adjustSize() - { - } - - void CheckBox::toggleSelected() - { - mSelected = !mSelected; - distributeActionEvent(); - } -} // namespace gcn diff --git a/src/guichan/widgets/container.cpp b/src/guichan/widgets/container.cpp deleted file mode 100644 index 7ea07e529..000000000 --- a/src/guichan/widgets/container.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/container.hpp" - -#include "guichan/exception.hpp" -#include "guichan/graphics.hpp" - -#include "debug.h" - -namespace gcn -{ - - Container::Container() : - BasicContainer(), - mOpaque(true) - { - } - - Container::~Container() - { - } - - void Container::draw(Graphics* graphics) - { - BLOCK_START("Container::draw") - if (isOpaque()) - { - graphics->setColor(getBaseColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - } - - drawChildren(graphics); - BLOCK_END("Container::draw") - } - - void Container::setOpaque(bool opaque) - { - mOpaque = opaque; - } - - bool Container::isOpaque() const - { - return mOpaque; - } - - void Container::add(Widget* widget) - { - BasicContainer::add(widget); - } - - void Container::add(Widget* widget, int x, int y) - { - widget->setPosition(x, y); - BasicContainer::add(widget); - } - - void Container::remove(Widget* widget) - { - BasicContainer::remove(widget); - } - - void Container::clear() - { - BasicContainer::clear(); - } - - Widget* Container::findWidgetById(const std::string &id) - { - return BasicContainer::findWidgetById(id); - } -} // namespace gcn diff --git a/src/guichan/widgets/label.cpp b/src/guichan/widgets/label.cpp deleted file mode 100644 index 92962e907..000000000 --- a/src/guichan/widgets/label.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/label.hpp" - -#include "guichan/exception.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" - -#include "debug.h" - -namespace gcn -{ - Label::Label() : - gcn::Widget(), - mCaption(), - mAlignment(Graphics::LEFT) - { - } - - Label::Label(const std::string& caption) : - gcn::Widget(), - mCaption(caption), - mAlignment(Graphics::LEFT) - { - setWidth(getFont()->getWidth(caption)); - setHeight(getFont()->getHeight()); - } - - const std::string &Label::getCaption() const - { - return mCaption; - } - - void Label::setCaption(const std::string& caption) - { - mCaption = caption; - } - - void Label::setAlignment(Graphics::Alignment alignment) - { - mAlignment = alignment; - } - - Graphics::Alignment Label::getAlignment() const - { - return mAlignment; - } - - void Label::draw(Graphics* graphics A_UNUSED) - { - } - - void Label::adjustSize() - { - } -} // namespace gcn diff --git a/src/guichan/widgets/listbox.cpp b/src/guichan/widgets/listbox.cpp deleted file mode 100644 index 9122e8cc8..000000000 --- a/src/guichan/widgets/listbox.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/listbox.hpp" - -#include "guichan/basiccontainer.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/listmodel.hpp" -#include "guichan/mouseinput.hpp" -#include "guichan/selectionlistener.hpp" - -#include "debug.h" - -namespace gcn -{ - ListBox::ListBox() : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mSelected(-1), - mListModel(nullptr), - mWrappingEnabled(false), - mSelectionListeners() - { - setWidth(100); - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - ListBox::ListBox(ListModel *listModel) : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mSelected(-1), - mListModel(listModel), - mWrappingEnabled(false), - mSelectionListeners() - { - setWidth(100); - adjustSize(); - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } - - void ListBox::draw(Graphics* graphics A_UNUSED) - { - } - - void ListBox::logic() - { - } - - int ListBox::getSelected() const - { - return mSelected; - } - - void ListBox::setSelected(int selected) - { - if (!mListModel) - { - mSelected = -1; - } - else - { - if (selected < 0) - mSelected = -1; - else if (selected >= mListModel->getNumberOfElements()) - mSelected = mListModel->getNumberOfElements() - 1; - else - mSelected = selected; - } - - Rectangle scroll; - - if (mSelected < 0) - scroll.y = 0; - else - scroll.y = getRowHeight() * mSelected; - - scroll.height = getRowHeight(); - showPart(scroll); - - distributeValueChangedEvent(); - } - - void ListBox::keyPressed(KeyEvent &keyEvent A_UNUSED) - { - } - - void ListBox::mousePressed(MouseEvent &mouseEvent A_UNUSED) - { - } - - void ListBox::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - if (isFocused()) - { - if (getSelected() > 0 ) - setSelected(getSelected() - 1); - - mouseEvent.consume(); - } - } - - void ListBox::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (isFocused()) - { - setSelected(getSelected() + 1); - - mouseEvent.consume(); - } - } - - void ListBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void ListBox::setListModel(ListModel *listModel) - { - mSelected = -1; - mListModel = listModel; - adjustSize(); - } - - ListModel* ListBox::getListModel() - { - return mListModel; - } - - void ListBox::adjustSize() - { - } - - bool ListBox::isWrappingEnabled() const - { - return mWrappingEnabled; - } - - void ListBox::setWrappingEnabled(bool wrappingEnabled) - { - mWrappingEnabled = wrappingEnabled; - } - - void ListBox::addSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.push_back(selectionListener); - } - - void ListBox::removeSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.remove(selectionListener); - } - - void ListBox::distributeValueChangedEvent() - { - for (SelectionListenerIterator iter = mSelectionListeners.begin(); - iter != mSelectionListeners.end(); - ++ iter) - { - SelectionEvent event(this); - (*iter)->valueChanged(event); - } - } - - unsigned int ListBox::getRowHeight() const - { - return getFont()->getHeight(); - } -} // namespace gcn diff --git a/src/guichan/widgets/radiobutton.cpp b/src/guichan/widgets/radiobutton.cpp deleted file mode 100644 index 26ce731ed..000000000 --- a/src/guichan/widgets/radiobutton.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/radiobutton.hpp" - -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - RadioButton::GroupMap RadioButton::mGroupMap; - - RadioButton::RadioButton() : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mSelected(false), - mCaption(), - mGroup() - { - setSelected(false); - - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } - - RadioButton::RadioButton(const std::string &caption, - const std::string &group, - bool selected) : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mSelected(false), - mCaption(), - mGroup() - { - setCaption(caption); - setGroup(group); - setSelected(selected); - - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - - adjustSize(); - } - - RadioButton::~RadioButton() - { - // Remove us from the group list - setGroup(""); - } - - bool RadioButton::isSelected() const - { - return mSelected; - } - - void RadioButton::setSelected(bool selected) - { - if (selected && mGroup != "") - { - for (GroupIterator iter = mGroupMap.lower_bound(mGroup), - iterEnd = mGroupMap.upper_bound(mGroup); - iter != iterEnd; - ++ iter) - { - if (iter->second->isSelected()) - iter->second->setSelected(false); - } - } - - mSelected = selected; - } - - const std::string &RadioButton::getCaption() const - { - return mCaption; - } - - void RadioButton::setCaption(const std::string &caption) - { - mCaption = caption; - } - - void RadioButton::keyPressed(KeyEvent& keyEvent A_UNUSED) - { - } - - void RadioButton::mouseClicked(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - setSelected(true); - distributeActionEvent(); - } - } - - void RadioButton::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void RadioButton::setGroup(const std::string &group) - { - if (mGroup != "") - { - for (GroupIterator iter = mGroupMap.lower_bound(mGroup), - iterEnd = mGroupMap.upper_bound(mGroup); - iter != iterEnd; - ++ iter) - { - if (iter->second == this) - { - mGroupMap.erase(iter); - break; - } - } - } - - if (group != "") - { - mGroupMap.insert( - std::pair<std::string, RadioButton *>(group, this)); - } - - mGroup = group; - } - - const std::string &RadioButton::getGroup() const - { - return mGroup; - } - - void RadioButton::adjustSize() - { - } -} // namespace gcn diff --git a/src/guichan/widgets/scrollarea.cpp b/src/guichan/widgets/scrollarea.cpp deleted file mode 100644 index ddc4405e2..000000000 --- a/src/guichan/widgets/scrollarea.cpp +++ /dev/null @@ -1,600 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/scrollarea.hpp" - -#include "guichan/exception.hpp" -#include "guichan/graphics.hpp" - -#include "debug.h" - -namespace gcn -{ - ScrollArea::ScrollArea() : - gcn::BasicContainer(), - gcn::MouseListener(), - 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) - { - addMouseListener(this); - } - - ScrollArea::ScrollArea(Widget *const content) : - gcn::BasicContainer(), - gcn::MouseListener(), - 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) - { - setContent(content); - addMouseListener(this); - } - - ScrollArea::ScrollArea(Widget *content, - ScrollPolicy hPolicy, - ScrollPolicy vPolicy) : - gcn::BasicContainer(), - gcn::MouseListener(), - mVScroll(0), - mHScroll(0), - mScrollbarWidth(12), - mHPolicy(hPolicy), - mVPolicy(vPolicy), - 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) - { - setContent(content); - addMouseListener(this); - } - - ScrollArea::~ScrollArea() - { - setContent(nullptr); - } - - void ScrollArea::setContent(Widget* widget) - { - if (widget) - { - clear(); - add(widget); - widget->setPosition(0, 0); - } - else - { - clear(); - } - - checkPolicies(); - } - - Widget* ScrollArea::getContent() - { - if (!mWidgets.empty()) - return *mWidgets.begin(); - - return nullptr; - } - - void ScrollArea::setHorizontalScrollPolicy(ScrollPolicy hPolicy) - { - mHPolicy = hPolicy; - checkPolicies(); - } - - ScrollArea::ScrollPolicy ScrollArea::getHorizontalScrollPolicy() const - { - return mHPolicy; - } - - void ScrollArea::setVerticalScrollPolicy(ScrollPolicy vPolicy) - { - mVPolicy = vPolicy; - checkPolicies(); - } - - ScrollArea::ScrollPolicy ScrollArea::getVerticalScrollPolicy() const - { - return mVPolicy; - } - - void ScrollArea::setScrollPolicy(ScrollPolicy hPolicy, - ScrollPolicy vPolicy) - { - mHPolicy = hPolicy; - mVPolicy = vPolicy; - checkPolicies(); - } - - void ScrollArea::setVerticalScrollAmount(int vScroll) - { - const int max = getVerticalMaxScroll(); - - mVScroll = vScroll; - - if (vScroll > max) - mVScroll = max; - - if (vScroll < 0) - mVScroll = 0; - } - - int ScrollArea::getVerticalScrollAmount() const - { - return mVScroll; - } - - void ScrollArea::setHorizontalScrollAmount(int hScroll) - { - const int max = getHorizontalMaxScroll(); - - mHScroll = hScroll; - - if (hScroll > max) - mHScroll = max; - else if (hScroll < 0) - mHScroll = 0; - } - - int ScrollArea::getHorizontalScrollAmount() const - { - return mHScroll; - } - - void ScrollArea::setScrollAmount(int hScroll, int vScroll) - { - setHorizontalScrollAmount(hScroll); - setVerticalScrollAmount(vScroll); - } - - int ScrollArea::getHorizontalMaxScroll() - { - checkPolicies(); - - const Widget *const content = getContent(); - if (!content) - return 0; - - const int value = content->getWidth() - getChildrenArea().width + - 2 * content->getFrameSize(); - - if (value < 0) - return 0; - - return value; - } - - int ScrollArea::getVerticalMaxScroll() - { - checkPolicies(); - - const Widget *const content = getContent(); - if (!content) - return 0; - - int value; - - value = content->getHeight() - getChildrenArea().height + - 2 * content->getFrameSize(); - - if (value < 0) - return 0; - - return value; - } - - void ScrollArea::setScrollbarWidth(int width) - { - if (width > 0) - mScrollbarWidth = width; - else - throw GCN_EXCEPTION("Width should be greater then 0."); - } - - int ScrollArea::getScrollbarWidth() const - { - return mScrollbarWidth; - } - - void ScrollArea::mouseReleased(MouseEvent& mouseEvent) - { - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mIsHorizontalMarkerDragged = false; - mIsVerticalMarkerDragged = false; - - mouseEvent.consume(); - } - - void ScrollArea::draw(Graphics *graphics A_UNUSED) - { - } - - void ScrollArea::drawHBar(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawVBar(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawBackground(Graphics *graphics A_UNUSED) - { - } - - void ScrollArea::drawUpButton(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawDownButton(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawLeftButton(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawRightButton(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawVMarker(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawHMarker(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::logic() - { - BLOCK_START("ScrollArea::logic") - checkPolicies(); - - setVerticalScrollAmount(getVerticalScrollAmount()); - setHorizontalScrollAmount(getHorizontalScrollAmount()); - - Widget *const content = getContent(); - if (content) - { - const int frameSize = content->getFrameSize(); - content->setPosition(-mHScroll + frameSize, -mVScroll + frameSize); - content->logic(); - } - BLOCK_END("ScrollArea::logic") - } - - void ScrollArea::checkPolicies() - { - const int w = getWidth(); - const int h = getHeight(); - - mHBarVisible = false; - mVBarVisible = false; - - const Widget *const content = getContent(); - if (!content) - { - mHBarVisible = (mHPolicy == SHOW_ALWAYS); - mVBarVisible = (mVPolicy == SHOW_ALWAYS); - return; - } - - if (mHPolicy == SHOW_AUTO && - mVPolicy == SHOW_AUTO) - { - if (content->getWidth() <= w - && content->getHeight() <= h) - { - mHBarVisible = false; - mVBarVisible = false; - } - - if (content->getWidth() > w) - { - mHBarVisible = true; - } - - if ((content->getHeight() > h) - || (mHBarVisible && content->getHeight() - > h - mScrollbarWidth)) - { - mVBarVisible = true; - } - - if (mVBarVisible && content->getWidth() > w - mScrollbarWidth) - mHBarVisible = true; - - return; - } - - switch (mHPolicy) - { - case SHOW_NEVER: - mHBarVisible = false; - break; - - case SHOW_ALWAYS: - mHBarVisible = true; - break; - - case SHOW_AUTO: - if (mVPolicy == SHOW_NEVER) - { - mHBarVisible = (content->getWidth() > w); - } - else // (mVPolicy == SHOW_ALWAYS) - { - mHBarVisible = (content->getWidth() - > w - mScrollbarWidth); - } - break; - - default: - throw GCN_EXCEPTION("Horizontal scroll policy invalid."); - } - - switch (mVPolicy) - { - case SHOW_NEVER: - mVBarVisible = false; - break; - - case SHOW_ALWAYS: - mVBarVisible = true; - break; - - case SHOW_AUTO: - if (mHPolicy == SHOW_NEVER) - { - mVBarVisible = (content->getHeight() > h); - } - else // (mHPolicy == SHOW_ALWAYS) - { - mVBarVisible = (content->getHeight() - > h - mScrollbarWidth); - } - break; - default: - throw GCN_EXCEPTION("Vertical scroll policy invalid."); - } - } - - Rectangle ScrollArea::getChildrenArea() - { - const Rectangle area = Rectangle(0, 0, - mVBarVisible ? (getWidth() - mScrollbarWidth) : getWidth(), - mHBarVisible ? (getHeight() - mScrollbarWidth) : getHeight()); - - if (area.width < 0 || area.height < 0) - return Rectangle(); - - return area; - } - - void ScrollArea::showWidgetPart(Widget* widget, Rectangle area) - { - const Widget *const content = getContent(); - if (widget != content) - throw GCN_EXCEPTION("Widget not content widget"); - - BasicContainer::showWidgetPart(widget, area); - - setHorizontalScrollAmount(content->getFrameSize() - - content->getX()); - setVerticalScrollAmount(content->getFrameSize() - - content->getY()); - } - - Widget *ScrollArea::getWidgetAt(int x, int y) - { - if (getChildrenArea().isPointInRect(x, y)) - return getContent(); - - return nullptr; - } - - void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed()) - return; - - setVerticalScrollAmount(getVerticalScrollAmount() - - getChildrenArea().height / 8); - - mouseEvent.consume(); - } - - void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed()) - return; - - setVerticalScrollAmount(getVerticalScrollAmount() - + getChildrenArea().height / 8); - - mouseEvent.consume(); - } - - void ScrollArea::setWidth(int width) - { - Widget::setWidth(width); - checkPolicies(); - } - - void ScrollArea::setHeight(int height) - { - Widget::setHeight(height); - checkPolicies(); - } - - void ScrollArea::setDimension(const Rectangle& dimension) - { - Widget::setDimension(dimension); - checkPolicies(); - } - - void ScrollArea::setLeftButtonScrollAmount(int amount) - { - mLeftButtonScrollAmount = amount; - } - - void ScrollArea::setRightButtonScrollAmount(int amount) - { - mRightButtonScrollAmount = amount; - } - - void ScrollArea::setUpButtonScrollAmount(int amount) - { - mUpButtonScrollAmount = amount; - } - - void ScrollArea::setDownButtonScrollAmount(int amount) - { - mDownButtonScrollAmount = amount; - } - - int ScrollArea::getLeftButtonScrollAmount() const - { - return mLeftButtonScrollAmount; - } - - int ScrollArea::getRightButtonScrollAmount() const - { - return mRightButtonScrollAmount; - } - - int ScrollArea::getUpButtonScrollAmount() const - { - return mUpButtonScrollAmount; - } - - int ScrollArea::getDownButtonScrollAmount() const - { - return mDownButtonScrollAmount; - } - - void ScrollArea::setOpaque(bool opaque) - { - mOpaque = opaque; - } - - bool ScrollArea::isOpaque() const - { - return mOpaque; - } -} // namespace gcn diff --git a/src/guichan/widgets/slider.cpp b/src/guichan/widgets/slider.cpp deleted file mode 100644 index 849101fd8..000000000 --- a/src/guichan/widgets/slider.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/slider.hpp" - -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - Slider::Slider(const double scaleEnd) : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mDragged(false), - mValue(0), - mStepLength(scaleEnd / 10), - mMarkerLength(10), - mScaleStart(0), - mScaleEnd(scaleEnd), - mOrientation(HORIZONTAL) - { - setFocusable(true); - setFrameSize(1); - - addMouseListener(this); - addKeyListener(this); - } - - Slider::Slider(const double scaleStart, const double scaleEnd) : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mDragged(false), - mValue(scaleStart), - mStepLength((scaleEnd - scaleStart) / 10), - mMarkerLength(10), - mScaleStart(scaleStart), - mScaleEnd(scaleEnd), - mOrientation(HORIZONTAL) - { - setFocusable(true); - setFrameSize(1); - - addMouseListener(this); - addKeyListener(this); - } - - void Slider::setScale(double scaleStart, double scaleEnd) - { - mScaleStart = scaleStart; - mScaleEnd = scaleEnd; - } - - double Slider::getScaleStart() const - { - return mScaleStart; - } - - void Slider::setScaleStart(double scaleStart) - { - mScaleStart = scaleStart; - } - - double Slider::getScaleEnd() const - { - return mScaleEnd; - } - - void Slider::setScaleEnd(double scaleEnd) - { - mScaleEnd = scaleEnd; - } - - void Slider::setValue(double value) - { - if (value > getScaleEnd()) - { - mValue = getScaleEnd(); - return; - } - - if (value < getScaleStart()) - { - mValue = getScaleStart(); - return; - } - - mValue = value; - } - - double Slider::getValue() const - { - return mValue; - } - - int Slider::getMarkerLength() const - { - return mMarkerLength; - } - - void Slider::setMarkerLength(int length) - { - mMarkerLength = length; - } - - void Slider::setOrientation(Slider::Orientation orientation) - { - mOrientation = orientation; - } - - Slider::Orientation Slider::getOrientation() const - { - return mOrientation; - } - - double Slider::markerPositionToValue(int v) const - { - int w; - if (getOrientation() == HORIZONTAL) - w = getWidth(); - else - w = getHeight(); - - const double pos = v / (static_cast<double>(w) - getMarkerLength()); - return (1.0 - pos) * getScaleStart() + pos * getScaleEnd(); - } - - int Slider::valueToMarkerPosition(double value) const - { - int v; - if (getOrientation() == HORIZONTAL) - v = getWidth(); - else - v = getHeight(); - - const int w = static_cast<int>((v - getMarkerLength()) - * (value - getScaleStart()) - / (getScaleEnd() - getScaleStart())); - - if (w < 0) - return 0; - - if (w > v - getMarkerLength()) - return v - getMarkerLength(); - - return w; - } - - void Slider::setStepLength(double length) - { - mStepLength = length; - } - - double Slider::getStepLength() const - { - return mStepLength; - } - - int Slider::getMarkerPosition() const - { - return valueToMarkerPosition(getValue()); - } -} // namespace gcn diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp deleted file mode 100644 index e3bfd39f5..000000000 --- a/src/guichan/widgets/textbox.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/textbox.hpp" - -#include "guichan/basiccontainer.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - TextBox::TextBox() : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mTextRows(), - mCaretColumn(0), - mCaretRow(0), - mEditable(true), - mOpaque(true) - { - setText(""); - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - adjustSize(); - } - - TextBox::TextBox(const std::string& text) : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mTextRows(), - mCaretColumn(0), - mCaretRow(0), - mEditable(true), - mOpaque(true) - { - setText(text); - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - adjustSize(); - } - - void TextBox::setText(const std::string& text) - { - mCaretColumn = 0; - mCaretRow = 0; - - mTextRows.clear(); - - size_t pos, lastPos = 0; - int length; - do - { - pos = text.find("\n", lastPos); - - if (pos != std::string::npos) - length = static_cast<int>(pos - lastPos); - else - length = static_cast<int>(text.size() - lastPos); - std::string sub = text.substr(lastPos, length); - mTextRows.push_back(sub); - lastPos = pos + 1; - } while (pos != std::string::npos); - - adjustSize(); - } - -/* - void TextBox::draw(Graphics* graphics) - { - } -*/ - - void TextBox::drawCaret(Graphics* graphics, int x, int y) - { - graphics->setColor(mForegroundColor); - graphics->drawLine(x, getFont()->getHeight() + y, x, y); - } - - void TextBox::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mCaretRow = mouseEvent.getY() / getFont()->getHeight(); - - const int sz = static_cast<int>(mTextRows.size()); - if (mCaretRow >= sz) - mCaretRow = sz - 1; - - mCaretColumn = getFont()->getStringIndexAt( - mTextRows[mCaretRow], mouseEvent.getX()); - } - } - - void TextBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void TextBox::keyPressed(KeyEvent& keyEvent A_UNUSED) - { - } - - void TextBox::adjustSize() - { - int width = 0; - for (size_t i = 0, sz = mTextRows.size(); i < sz; ++i) - { - const int w = getFont()->getWidth(mTextRows[i]); - if (width < w) - width = w; - } - - setWidth(width + 1); - setHeight(static_cast<int>(getFont()->getHeight() * mTextRows.size())); - } - - void TextBox::setCaretPosition(unsigned int position) - { - for (int row = 0, sz = static_cast<int>(mTextRows.size()); - row < sz; row ++) - { - if (position <= mTextRows[row].size()) - { - mCaretRow = row; - mCaretColumn = position; - return; // we are done - } - else - { - position--; - } - } - - // position beyond end of text - mCaretRow = static_cast<int>(mTextRows.size() - 1); - mCaretColumn = static_cast<int>(mTextRows[mCaretRow].size()); - } - - unsigned int TextBox::getCaretPosition() const - { - int pos = 0, row; - - for (row = 0; row < mCaretRow; row++) - pos += static_cast<int>(mTextRows[row].size()); - - return pos + mCaretColumn; - } - - void TextBox::setCaretRowColumn(int row, int column) - { - setCaretRow(row); - setCaretColumn(column); - } - - void TextBox::setCaretRow(int row) - { - mCaretRow = row; - - const int sz = static_cast<int>(mTextRows.size()); - if (mCaretRow >= sz) - mCaretRow = sz - 1; - - if (mCaretRow < 0) - mCaretRow = 0; - - setCaretColumn(mCaretColumn); - } - - unsigned int TextBox::getCaretRow() const - { - return mCaretRow; - } - - void TextBox::setCaretColumn(int column) - { - mCaretColumn = column; - - const int sz = static_cast<int>(mTextRows[mCaretRow].size()); - if (mCaretColumn > sz) - mCaretColumn = sz; - - if (mCaretColumn < 0) - mCaretColumn = 0; - } - - unsigned int TextBox::getCaretColumn() const - { - return mCaretColumn; - } - - const std::string& TextBox::getTextRow(int row) const - { - return mTextRows[row]; - } - - void TextBox::setTextRow(int row, const std::string& text) - { - mTextRows[row] = text; - - if (mCaretRow == row) - setCaretColumn(mCaretColumn); - - adjustSize(); - } - - unsigned int TextBox::getNumberOfRows() const - { - return static_cast<int>(mTextRows.size()); - } - - std::string TextBox::getText() const - { - if (mTextRows.empty()) - return std::string(""); - - int i; - std::string text; - - const int sz = static_cast<int>(mTextRows.size()); - for (i = 0; i < sz - 1; ++ i) - text.append(mTextRows[i]).append("\n"); - text.append(mTextRows[i]); - - return text; - } - - void TextBox::fontChanged() - { - adjustSize(); - } - - void TextBox::scrollToCaret() - { - Rectangle scroll; - scroll.x = getFont()->getWidth( - mTextRows[mCaretRow].substr(0, mCaretColumn)); - scroll.y = getFont()->getHeight() * mCaretRow; - scroll.width = getFont()->getWidth(" "); - - // add 2 for some extra space - scroll.height = getFont()->getHeight() + 2; - - showPart(scroll); - } - - void TextBox::setEditable(bool editable) - { - mEditable = editable; - } - - bool TextBox::isEditable() const - { - return mEditable; - } - - void TextBox::addRow(const std::string &row) - { - mTextRows.push_back(row); - adjustSize(); - } - - bool TextBox::isOpaque() - { - return mOpaque; - } - - void TextBox::setOpaque(bool opaque) - { - mOpaque = opaque; - } -} // namespace gcn diff --git a/src/guichan/widgets/textfield.cpp b/src/guichan/widgets/textfield.cpp deleted file mode 100644 index 1e4309266..000000000 --- a/src/guichan/widgets/textfield.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/textfield.hpp" - -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - TextField::TextField() : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mText(), - mCaretPosition(0), - mXScroll(0) - { - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - TextField::TextField(const std::string& text) : - gcn::Widget(), - gcn::MouseListener(), - gcn::KeyListener(), - mText(text), - mCaretPosition(0), - mXScroll(0) - { - adjustSize(); - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - void TextField::setText(const std::string& text) - { - const size_t sz = text.size(); - if (sz < mCaretPosition) - mCaretPosition = sz; - mText = text; - } - - void TextField::drawCaret(Graphics* graphics A_UNUSED, int x A_UNUSED) - { - } - - void TextField::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mCaretPosition = getFont()->getStringIndexAt( - mText, mouseEvent.getX() + mXScroll); - fixScroll(); - } - } - - void TextField::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void TextField::adjustSize() - { - } - - void TextField::adjustHeight() - { - } - - void TextField::fixScroll() - { - } - - void TextField::setCaretPosition(unsigned int position A_UNUSED) - { - } - - unsigned int TextField::getCaretPosition() const - { - return mCaretPosition; - } - - const std::string& TextField::getText() const - { - return mText; - } - - void TextField::fontChanged() - { - } -} // namespace gcn diff --git a/src/guichan/widgets/window.cpp b/src/guichan/widgets/window.cpp deleted file mode 100644 index 8865444e0..000000000 --- a/src/guichan/widgets/window.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 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 <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/window.hpp" - -#include "guichan/exception.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - Window::Window() : - Container(), - gcn::MouseListener(), - mCaption(), - mAlignment(Graphics::CENTER), - mPadding(2), - mTitleBarHeight(16), - mMovable(true), - mOpaque(true), - mDragOffsetX(0), - mDragOffsetY(0), - mMoved(false) - { - mFrameSize = 1; - addMouseListener(this); - } - - Window::Window(const std::string& caption) : - Container(), - gcn::MouseListener(), - mCaption(caption), - mAlignment(Graphics::CENTER), - mPadding(2), - mTitleBarHeight(16), - mMovable(true), - mOpaque(true), - mDragOffsetX(0), - mDragOffsetY(0), - mMoved(false) - { - mFrameSize = 1; - addMouseListener(this); - } - - Window::~Window() - { - } - - void Window::setPadding(unsigned int padding) - { - mPadding = padding; - } - - unsigned int Window::getPadding() const - { - return mPadding; - } - - void Window::setTitleBarHeight(unsigned int height) - { - mTitleBarHeight = height; - } - - unsigned int Window::getTitleBarHeight() - { - return mTitleBarHeight; - } - - void Window::setCaption(const std::string& caption) - { - mCaption = caption; - } - - const std::string& Window::getCaption() const - { - return mCaption; - } - - void Window::setAlignment(Graphics::Alignment alignment) - { - mAlignment = alignment; - } - - Graphics::Alignment Window::getAlignment() const - { - return mAlignment; - } - - void Window::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getSource() != this) - return; - - if (getParent()) - getParent()->moveToTop(this); - - mDragOffsetX = mouseEvent.getX(); - mDragOffsetY = mouseEvent.getY(); - - mMoved = mouseEvent.getY() <= static_cast<int>(mTitleBarHeight); - } - - void Window::mouseReleased(MouseEvent& mouseEvent A_UNUSED) - { - mMoved = false; - } - - void Window::mouseDragged(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed() || mouseEvent.getSource() != this) - return; - - if (isMovable() && mMoved) - { - setPosition(mouseEvent.getX() - mDragOffsetX + getX(), - mouseEvent.getY() - mDragOffsetY + getY()); - } - - mouseEvent.consume(); - } - - Rectangle Window::getChildrenArea() - { - return Rectangle(getPadding(), - getTitleBarHeight(), - getWidth() - getPadding() * 2, - getHeight() - getPadding() - getTitleBarHeight()); - } - - void Window::setMovable(bool movable) - { - mMovable = movable; - } - - bool Window::isMovable() const - { - return mMovable; - } - - void Window::setOpaque(bool opaque) - { - mOpaque = opaque; - } - - bool Window::isOpaque() - { - return mOpaque; - } - - void Window::resizeToContent() - { - int w = 0, h = 0; - for (WidgetListConstIterator it = mWidgets.begin(); - it != mWidgets.end(); ++ it) - { - if ((*it)->getX() + (*it)->getWidth() > w) - w = (*it)->getX() + (*it)->getWidth(); - - if ((*it)->getY() + (*it)->getHeight() > h) - h = (*it)->getY() + (*it)->getHeight(); - } - - setSize(w + 2* getPadding(), h + getPadding() + getTitleBarHeight()); - } -} // namespace gcn |