# HG changeset patch
# User cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
# Date 1232914661 0
# Node ID 3fb17daa1b274c5af2efe67a6214bb593acc1c9a
# Parent 542213eebe73a3639eb3ba08597efaaa5bb07138
* Added ToggleButton widget
* Modified editor to use togglebuttons in toolbox
diff -r 542213eebe73 -r 3fb17daa1b27 clients/editor/content/gui/tools.xml
--- a/clients/editor/content/gui/tools.xml Sun Jan 25 19:48:41 2009 +0000
+++ b/clients/editor/content/gui/tools.xml Sun Jan 25 20:17:41 2009 +0000
@@ -1,8 +1,8 @@
-
-
-
-
+
+
+
+
diff -r 542213eebe73 -r 3fb17daa1b27 clients/editor/plugins/mapeditor.py
--- a/clients/editor/plugins/mapeditor.py Sun Jan 25 19:48:41 2009 +0000
+++ b/clients/editor/plugins/mapeditor.py Sun Jan 25 20:17:41 2009 +0000
@@ -85,16 +85,25 @@
self._toolbar.hide()
def _enableBtn(self, enabled, btn):
- pass
-
+ btn.toggled = enabled;
+
+ def enableSelect(self, enabled):
+ self._enableBtn(enabled, self._toolbar.findChild(name='btnSelect'))
+
+ def enableMove(self, enabled):
+ self._enableBtn(enabled, self._toolbar.findChild(name='btnMove'))
+
def enableInsert(self, enabled):
self._enableBtn(enabled, self._toolbar.findChild(name='btnInsert'))
-
+
def enableDelete(self, enabled):
self._enableBtn(enabled, self._toolbar.findChild(name='btnDelete'))
- def enableSelect(self, enabled):
- self._enableBtn(enabled, self._toolbar.findChild(name='btnSelect'))
+ def disableAll(self):
+ self.enableDelete(False)
+ self.enableSelect(False)
+ self.enableInsert(False)
+ self.enableMove(False)
class StatusBar(object):
def __init__(self, screenw, screenh):
@@ -157,8 +166,8 @@
rb = self._engine.getRenderBackend()
self._statusbar = StatusBar(rb.getWidth(), rb.getHeight())
self._toolbar = Toolbar(cbwa(self._setMode, VIEWING), cbwa(self._setMode, MOVING),
- cbwa(self._setMode, INSERTING), cbwa(self._setMode, REMOVING),
- self._statusbar.showTooltip, self._statusbar.hideTooltip)
+ cbwa(self._setMode, INSERTING), cbwa(self._setMode, REMOVING),
+ self._statusbar.showTooltip, self._statusbar.hideTooltip)
self._toolbar.show()
self._setMode(NOTHING_LOADED)
@@ -173,10 +182,24 @@
def _setMode(self, mode):
if (mode != NOTHING_LOADED) and (not self._camera):
self._statusbar.setStatus('Please load map first')
+ self._toolbar.disableAll()
return
if (mode == INSERTING) and (not self._object):
self._statusbar.setStatus('Please select object first')
- return
+ mode = self._mode
+
+ # Update toolbox buttons
+ if (mode == INSERTING):
+ self._toolbar.enableInsert(True)
+ elif mode == VIEWING:
+ self._toolbar.enableSelect(True)
+ elif mode == REMOVING:
+ self._toolbar.enableDelete(True)
+ elif mode == MOVING:
+ self._toolbar.enableMove(True)
+ else:
+ self._toolbar.disableAll()
+
self._mode = mode
print "Entered mode " + mode
self._statusbar.setStatus(mode.replace('_', ' ').capitalize())
diff -r 542213eebe73 -r 3fb17daa1b27 engine/core/gui/widgets/togglebutton.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/engine/core/gui/widgets/togglebutton.cpp Sun Jan 25 20:17:41 2009 +0000
@@ -0,0 +1,267 @@
+/***************************************************************************
+ * Copyright (C) 2005-2008 by the FIFE team *
+ * http://www.fifengine.de *
+ * This file is part of FIFE. *
+ * *
+ * FIFE is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * This library 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 *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this library; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+/***************************************************************************
+ * Note! Group and groupmap borrows heavily from ideas of Guichan library *
+ * version 0.8.1 *
+ ***************************************************************************/
+
+
+
+// Standard C++ library includes
+#include
+
+// 3rd party library includes
+
+// FIFE includes
+// These includes are split up in two parts, separated by one empty line
+// First block: files included from the FIFE root src directory
+// Second block: files included from the same folder
+#include
+
+#include
+
+#include "togglebutton.h"
+
+
+namespace gcn {
+ ToggleButton::GroupMap ToggleButton::m_groupMap;
+
+ ToggleButton::ToggleButton(Image *up_file , Image *down_file, Image *hover_file, const std::string& caption, const std::string& group):
+ Button(),
+ m_upImage(up_file),
+ m_downImage(down_file),
+ m_hoverImage(hover_file),
+ x_downoffset(0),
+ y_downoffset(0),
+ m_helptext(""),
+ m_group(group) {
+
+ m_hoverImage = hover_file;
+ setFrameSize(0);
+ setGroup(m_group);
+ adjustSize();
+ mCaption = caption;
+ m_toggled = false;
+
+ addActionListener(this);
+ }
+
+ ToggleButton::~ToggleButton() {
+ setGroup(""); // Remove button from group
+ }
+
+ void ToggleButton::setDownOffset(int x, int y) {
+ x_downoffset = x;
+ y_downoffset = y;
+ }
+
+ void ToggleButton::draw(Graphics *graphics) {
+ Color faceColor = getBaseColor();
+ Color highlightColor;
+ Color shadowColor;
+ int alpha = getBaseColor().a;
+
+ Image* img = NULL;
+ int xoffset = 0;
+ int yoffset = 0;
+
+ if (isPressed() || m_toggled) {
+ faceColor = faceColor - 0x303030;
+ faceColor.a = alpha;
+ highlightColor = faceColor - 0x303030;
+ highlightColor.a = alpha;
+ shadowColor = faceColor + 0x303030;
+ shadowColor.a = alpha;
+
+ if( m_downImage ) {
+ img = m_downImage;
+ xoffset = x_downoffset;
+ yoffset = y_downoffset;
+ }
+ } else if(mHasMouse) {
+ faceColor = faceColor + 0x303030;
+ faceColor.a = alpha;
+ highlightColor = faceColor + 0x303030;
+ highlightColor.a = alpha;
+ shadowColor = faceColor - 0x303030;
+ shadowColor.a = alpha;
+
+ if ( m_hoverImage ) {
+ img = m_hoverImage;
+ }
+ } else{
+ highlightColor = faceColor + 0x303030;
+ highlightColor.a = alpha;
+ shadowColor = faceColor - 0x303030;
+ shadowColor.a = alpha;
+
+ if (m_upImage) {
+ img = m_upImage;
+ }
+ }
+
+
+ graphics->setColor(faceColor);
+ graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1));
+
+ graphics->setColor(highlightColor);
+ graphics->drawLine(0, 0, getWidth() - 1, 0);
+ graphics->drawLine(0, 1, 0, getHeight() - 1);
+
+ graphics->setColor(shadowColor);
+ graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
+ graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);
+
+ graphics->setColor(getForegroundColor());
+
+ if (img) {
+ graphics->drawImage(img, xoffset, yoffset);
+ }
+
+ int textX;
+ int textY = getHeight() / 2 - getFont()->getHeight() / 2;
+ switch (getAlignment())
+ {
+ case Graphics::LEFT:
+ textX = 4;
+ break;
+ case Graphics::CENTER:
+ textX = getWidth() / 2;
+ break;
+ case Graphics::RIGHT:
+ textX = getWidth() - 4;
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown alignment.");
+ }
+
+ graphics->setFont(getFont());
+ if (mCaption.size() > 0) {
+ if (isPressed())
+ graphics->drawText(getCaption(), textX + 1,
+ textY + 1, getAlignment());
+ else
+ graphics->drawText(getCaption(), textX, textY, getAlignment());
+ }
+ }
+
+ void ToggleButton::action(const ActionEvent& actionEvent) {
+ setToggled(!m_toggled);
+ }
+
+ void ToggleButton::adjustSize() {
+ int w = 0;
+ int h = w;
+ if( m_upImage ) {
+ w = m_upImage->getWidth();
+ h = m_upImage->getHeight();
+ }
+ if( m_downImage ) {
+ w = std::max(m_downImage->getWidth(), w);
+ h = std::max(m_downImage->getHeight(), h);
+ }
+ if( m_hoverImage ) {
+ w = std::max(m_hoverImage->getWidth(), w);
+ h = std::max(m_hoverImage->getHeight(), h);
+ }
+ setWidth(w);
+ setHeight(h);
+ }
+
+ void ToggleButton::setUpImage(Image* image) {
+ m_upImage = image;
+ adjustSize();
+ }
+
+ void ToggleButton::setDownImage(Image* image) {
+ m_downImage = image;
+ adjustSize();
+ }
+
+ void ToggleButton::setHoverImage(Image* image) {
+ m_hoverImage = image;
+ adjustSize();
+ }
+
+ bool ToggleButton::isToggled() const {
+ return m_toggled;
+ }
+
+ void ToggleButton::setToggled(bool toggled) {
+ if (toggled && m_group != "") {
+ // untoggle all buttons in group
+ GroupIterator iter, iterEnd;
+ iterEnd = m_groupMap.upper_bound(m_group);
+
+ for (iter = m_groupMap.lower_bound(m_group); iter != iterEnd; iter++) {
+ if (iter->second->isToggled()) {
+ iter->second->setToggled(false);
+ }
+ }
+ }
+
+ m_toggled = toggled;
+ }
+
+ void ToggleButton::setGroup(const std::string &group) {
+ // Remove button from previous group
+ if (m_group != "") {
+ GroupIterator iter, iterEnd;
+ iterEnd = m_groupMap.upper_bound(m_group);
+
+ for (iter = m_groupMap.lower_bound(m_group); iter != iterEnd; iter++) {
+ if (iter->second == this) {
+ m_groupMap.erase(iter);
+ break;
+ }
+ }
+ }
+
+ // Add button to new group
+ if (group != "") {
+ m_groupMap.insert( std::pair(group, this));
+ }
+
+ m_group = group;
+ }
+
+ const std::string &ToggleButton::getGroup() const {
+ return m_group;
+ }
+
+ int ToggleButton::getDownXOffset() const {
+ return x_downoffset;
+ }
+
+ int ToggleButton::getDownYOffset() const {
+ return y_downoffset;
+ }
+
+ void ToggleButton::setHelpText(const std::string& txt) {
+ m_helptext = txt;
+ }
+
+ const std::string& ToggleButton::getHelpText() {
+ return m_helptext;
+ }
+}
+/* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */
+
diff -r 542213eebe73 -r 3fb17daa1b27 engine/core/gui/widgets/togglebutton.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/engine/core/gui/widgets/togglebutton.h Sun Jan 25 20:17:41 2009 +0000
@@ -0,0 +1,236 @@
+/***************************************************************************
+ * Copyright (C) 2005-2008 by the FIFE team *
+ * http://www.fifengine.de *
+ * This file is part of FIFE. *
+ * *
+ * FIFE is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * This library 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 *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this library; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef FIFE_GUICHAN_ADDON_TOGGLEBUTTON_H
+#define FIFE_GUICHAN_ADDON_TOGGLEBUTTON_H
+
+// Standard C++ library includes
+#include
+#include