/* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson * * Js_./ * Per Larsson a.k.a finalman _RqZ{a<^_aa * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// * _Qhm`] _f "'c 1!5m * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' * binary forms, with or without )4d[#7r, . ' )d`)[ * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' * that the following conditions are met: j<. a J@\ * this list of conditions and the j(]1usetColor(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()); 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 (isPressed()) { graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment()); } else { graphics->drawText(getCaption(), textX, textY, getAlignment()); if (isFocused()) { graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, getHeight() - 4)); } } } void Button::drawBorder(Graphics* graphics) { Color faceColor = getBaseColor(); Color highlightColor, shadowColor; int alpha = getBaseColor().a; int width = getWidth() + getBorderSize() * 2 - 1; int height = getHeight() + getBorderSize() * 2 - 1; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; unsigned int i; for (i = 0; i < getBorderSize(); ++i) { graphics->setColor(shadowColor); graphics->drawLine(i,i, width - i, i); graphics->drawLine(i,i + 1, i, height - i - 1); graphics->setColor(highlightColor); graphics->drawLine(width - i,i + 1, width - i, height - i); graphics->drawLine(i,height - i, width - i - 1, height - i); } } void Button::adjustSize() { setWidth(getFont()->getWidth(mCaption) + 8); setHeight(getFont()->getHeight() + 8); } 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) { mHasMouse = false; } void Button::mouseEntered(MouseEvent& mouseEvent) { mHasMouse = true; } void Button::mouseReleased(MouseEvent& mouseEvent) { if (mouseEvent.getButton() == MouseEvent::LEFT && mMousePressed && mHasMouse) { mMousePressed = false; generateAction(); mouseEvent.consume(); } else if (mouseEvent.getButton() == MouseEvent::LEFT) { mMousePressed = false; mouseEvent.consume(); } } void Button::mouseDragged(MouseEvent& mouseEvent) { mouseEvent.consume(); } void Button::keyPressed(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) { mKeyPressed = true; keyEvent.consume(); } } void Button::keyReleased(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) && mKeyPressed) { mKeyPressed = false; generateAction(); keyEvent.consume(); } } void Button::focusLost() { mMousePressed = false; mKeyPressed = false; } }