/* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004, 2005 darkbits 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 (hasFocus()) { 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 { return (hasMouse() && mMouseDown) || mKeyDown || mHotKeyDown; } void Button::mouseClick(int x, int y, int button, int count) { if (button == MouseInput::LEFT) { generateAction(); } } void Button::mousePress(int x, int y, int button) { if (button == MouseInput::LEFT && hasMouse()) { mMouseDown = true; } } void Button::mouseRelease(int x, int y, int button) { if (button == MouseInput::LEFT) { mMouseDown = false; } } bool Button::keyPress(const Key& key) { bool ret = false; if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) { mKeyDown = true; ret = true; } mHotKeyDown = false; mMouseDown = false; return ret; } bool Button::keyRelease(const Key& key) { bool ret = false; if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) && mKeyDown) { mKeyDown = false; generateAction(); ret = true; } return ret; } void Button::hotKeyPress() { mHotKeyDown = true; mMouseDown = false; } void Button::hotKeyRelease() { if (mHotKeyDown) { mHotKeyDown = false; generateAction(); } } void Button::lostFocus() { mMouseDown = false; mKeyDown = false; mHotKeyDown = false; } }