From 03de33661b6e3b76fd490f9d582706d09186c9f0 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Sat, 2 Dec 2023 11:40:52 +0100 Subject: [PATCH] Apply guichan's changes from 753608c0c8cd0196c19c467db0f8df5f61d99b3c (25/dec/2007) to 8a4565b962dc5c71d1c115bdce4ddc3906575fa1 (31/dec/2007): - The drawing of the text field widget and the drop down widget have been enhanced. - Drawing has been enhanced. + Fix dropdown keyPressed event (handled by both listbox and dropdown). --- TODO | 2 +- include/guisan/widget.hpp | 2 +- include/guisan/widgets/button.hpp | 2 - include/guisan/widgets/checkbox.hpp | 2 - include/guisan/widgets/container.hpp | 1 - include/guisan/widgets/dropdown.hpp | 2 - include/guisan/widgets/icon.hpp | 1 - include/guisan/widgets/inputbox.hpp | 2 - include/guisan/widgets/label.hpp | 1 - include/guisan/widgets/listbox.hpp | 2 - include/guisan/widgets/messagebox.hpp | 2 - include/guisan/widgets/progressbar.hpp | 1 - include/guisan/widgets/radiobutton.hpp | 2 - include/guisan/widgets/scrollarea.hpp | 2 - include/guisan/widgets/slider.hpp | 2 - include/guisan/widgets/tab.hpp | 2 - include/guisan/widgets/tabbedarea.hpp | 2 - include/guisan/widgets/textbox.hpp | 2 - include/guisan/widgets/textfield.hpp | 2 - include/guisan/widgets/window.hpp | 2 - src/widget.cpp | 25 ++++ src/widgets/button.cpp | 24 ---- src/widgets/checkbox.cpp | 24 ---- src/widgets/container.cpp | 24 ---- src/widgets/dropdown.cpp | 155 +++++++++++-------------- src/widgets/icon.cpp | 23 ---- src/widgets/inputbox.cpp | 24 ---- src/widgets/label.cpp | 24 ---- src/widgets/listbox.cpp | 33 +----- src/widgets/messagebox.cpp | 24 ---- src/widgets/progressbar.cpp | 24 ---- src/widgets/radiobutton.cpp | 24 ---- src/widgets/scrollarea.cpp | 24 ---- src/widgets/slider.cpp | 24 ---- src/widgets/tab.cpp | 74 ++++++------ src/widgets/tabbedarea.cpp | 91 ++++++--------- src/widgets/textbox.cpp | 33 +++--- src/widgets/textfield.cpp | 60 +++++----- src/widgets/window.cpp | 24 ---- 39 files changed, 219 insertions(+), 575 deletions(-) diff --git a/TODO b/TODO index 84fff90..e393ac8 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Continue rebasing from 753608c0c8cd0196c19c467db0f8df5f61d99b3c +* Continue rebasing from b62d153a5dd699add2109671d4569578dd4f2671 * Add a focus listener interface. * Make focus apply synchronously. * Graphics and input objects for DirectX. diff --git a/include/guisan/widget.hpp b/include/guisan/widget.hpp index 29aed85..6cdf44f 100644 --- a/include/guisan/widget.hpp +++ b/include/guisan/widget.hpp @@ -136,7 +136,7 @@ namespace gcn * @param graphics a graphics object to draw with. * @see setFrameSize, getFrameSize */ - virtual void drawFrame(Graphics* graphics) { } + virtual void drawFrame(Graphics* graphics); /** * Sets the size of the widget's frame. The frame is not considered a part of diff --git a/include/guisan/widgets/button.hpp b/include/guisan/widgets/button.hpp index c4a6968..63307c0 100644 --- a/include/guisan/widgets/button.hpp +++ b/include/guisan/widgets/button.hpp @@ -149,8 +149,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); - // Inherited from FocusListener diff --git a/include/guisan/widgets/checkbox.hpp b/include/guisan/widgets/checkbox.hpp index 1ca0aff..ec2abe2 100644 --- a/include/guisan/widgets/checkbox.hpp +++ b/include/guisan/widgets/checkbox.hpp @@ -144,8 +144,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); - // Inherited from KeyListener diff --git a/include/guisan/widgets/container.hpp b/include/guisan/widgets/container.hpp index 5396f0a..5423f63 100644 --- a/include/guisan/widgets/container.hpp +++ b/include/guisan/widgets/container.hpp @@ -164,7 +164,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); protected: /** diff --git a/include/guisan/widgets/dropdown.hpp b/include/guisan/widgets/dropdown.hpp index 738892d..0fcd0ed 100644 --- a/include/guisan/widgets/dropdown.hpp +++ b/include/guisan/widgets/dropdown.hpp @@ -177,8 +177,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); - void setBaseColor(const Color& color); void setBackgroundColor(const Color& color); diff --git a/include/guisan/widgets/icon.hpp b/include/guisan/widgets/icon.hpp index d444e80..9f6bbc1 100644 --- a/include/guisan/widgets/icon.hpp +++ b/include/guisan/widgets/icon.hpp @@ -93,7 +93,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); protected: /** diff --git a/include/guisan/widgets/inputbox.hpp b/include/guisan/widgets/inputbox.hpp index 57406f1..a76baac 100644 --- a/include/guisan/widgets/inputbox.hpp +++ b/include/guisan/widgets/inputbox.hpp @@ -119,8 +119,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); - // Inherited from MouseListener diff --git a/include/guisan/widgets/label.hpp b/include/guisan/widgets/label.hpp index 89fe25f..cd3cfe6 100644 --- a/include/guisan/widgets/label.hpp +++ b/include/guisan/widgets/label.hpp @@ -130,7 +130,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); protected: /** diff --git a/include/guisan/widgets/listbox.hpp b/include/guisan/widgets/listbox.hpp index c7d04d3..5e4e84c 100644 --- a/include/guisan/widgets/listbox.hpp +++ b/include/guisan/widgets/listbox.hpp @@ -189,8 +189,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); - virtual void logic(); diff --git a/include/guisan/widgets/messagebox.hpp b/include/guisan/widgets/messagebox.hpp index 44a9d04..87c797c 100644 --- a/include/guisan/widgets/messagebox.hpp +++ b/include/guisan/widgets/messagebox.hpp @@ -209,8 +209,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); - // Inherited from MouseListener diff --git a/include/guisan/widgets/progressbar.hpp b/include/guisan/widgets/progressbar.hpp index 6030ce5..932f716 100644 --- a/include/guisan/widgets/progressbar.hpp +++ b/include/guisan/widgets/progressbar.hpp @@ -190,7 +190,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); protected: /** diff --git a/include/guisan/widgets/radiobutton.hpp b/include/guisan/widgets/radiobutton.hpp index 0acbf99..66a3ef6 100644 --- a/include/guisan/widgets/radiobutton.hpp +++ b/include/guisan/widgets/radiobutton.hpp @@ -169,8 +169,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); - // Inherited from KeyListener diff --git a/include/guisan/widgets/scrollarea.hpp b/include/guisan/widgets/scrollarea.hpp index 37ad2df..131267b 100644 --- a/include/guisan/widgets/scrollarea.hpp +++ b/include/guisan/widgets/scrollarea.hpp @@ -306,8 +306,6 @@ namespace gcn virtual void draw(Graphics *graphics); - virtual void drawFrame(Graphics* graphics); - virtual void logic(); void setWidth(int width); diff --git a/include/guisan/widgets/slider.hpp b/include/guisan/widgets/slider.hpp index eadb793..9fe0719 100644 --- a/include/guisan/widgets/slider.hpp +++ b/include/guisan/widgets/slider.hpp @@ -221,8 +221,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); - // Inherited from MouseListener. diff --git a/include/guisan/widgets/tab.hpp b/include/guisan/widgets/tab.hpp index 1bcabb7..25bf3b3 100644 --- a/include/guisan/widgets/tab.hpp +++ b/include/guisan/widgets/tab.hpp @@ -134,8 +134,6 @@ namespace gcn virtual void draw(Graphics *graphics); - virtual void drawFrame(Graphics* graphics); - // Inherited from MouseListener diff --git a/include/guisan/widgets/tabbedarea.hpp b/include/guisan/widgets/tabbedarea.hpp index 8db17e9..b16d312 100644 --- a/include/guisan/widgets/tabbedarea.hpp +++ b/include/guisan/widgets/tabbedarea.hpp @@ -184,8 +184,6 @@ namespace gcn virtual void draw(Graphics *graphics); - virtual void drawFrame(Graphics* graphics); - virtual void logic(); void setWidth(int width); diff --git a/include/guisan/widgets/textbox.hpp b/include/guisan/widgets/textbox.hpp index 7368b6d..27676a1 100644 --- a/include/guisan/widgets/textbox.hpp +++ b/include/guisan/widgets/textbox.hpp @@ -242,8 +242,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); - virtual void fontChanged(); diff --git a/include/guisan/widgets/textfield.hpp b/include/guisan/widgets/textfield.hpp index 4a9dd7d..84c94e5 100644 --- a/include/guisan/widgets/textfield.hpp +++ b/include/guisan/widgets/textfield.hpp @@ -139,8 +139,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); - // Inherited from MouseListener diff --git a/include/guisan/widgets/window.hpp b/include/guisan/widgets/window.hpp index 9c35cfe..a3e9303 100644 --- a/include/guisan/widgets/window.hpp +++ b/include/guisan/widgets/window.hpp @@ -204,8 +204,6 @@ namespace gcn virtual void draw(Graphics* graphics); - virtual void drawFrame(Graphics* graphics); - // Inherited from MouseListener diff --git a/src/widget.cpp b/src/widget.cpp index ff7e496..36113ac 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -68,6 +68,7 @@ #include "guisan/event.hpp" #include "guisan/exception.hpp" #include "guisan/focushandler.hpp" +#include "guisan/graphics.hpp" #include "guisan/keyinput.hpp" #include "guisan/keylistener.hpp" #include "guisan/mouseinput.hpp" @@ -114,6 +115,30 @@ namespace gcn mWidgets.remove(this); } + void Widget::drawFrame(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getFrameSize() * 2 - 1; + int height = getHeight() + getFrameSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + unsigned int i; + for (i = 0; i < getFrameSize(); ++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 Widget::_setParent(Widget* parent) { mParent = parent; diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index 4b8b4e0..9965d49 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -207,30 +207,6 @@ namespace gcn } } - void Button::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++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) + 2*mSpacing); diff --git a/src/widgets/checkbox.cpp b/src/widgets/checkbox.cpp index 7520d7a..c72fa91 100644 --- a/src/widgets/checkbox.cpp +++ b/src/widgets/checkbox.cpp @@ -104,30 +104,6 @@ namespace gcn graphics->drawText(getCaption(), h - 2, 0); } - void CheckBox::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++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 CheckBox::drawBox(Graphics* graphics) { int h = getHeight() - 2; diff --git a/src/widgets/container.cpp b/src/widgets/container.cpp index 649e6f4..b2cf292 100644 --- a/src/widgets/container.cpp +++ b/src/widgets/container.cpp @@ -87,30 +87,6 @@ namespace gcn drawChildren(graphics); } - void Container::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++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 Container::setOpaque(bool opaque) { mOpaque = opaque; diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 700f77f..7b7a3de 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -118,7 +118,6 @@ namespace gcn addFocusListener(this); adjustHeight(); - setFrameSize(1); } DropDown::~DropDown() @@ -156,65 +155,63 @@ namespace gcn Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; - Color backCol = getBackgroundColor(); - if (!isEnabled()) - backCol = backCol - 0x303030; - graphics->setColor(backCol); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), h)); + // Draw a border. + graphics->setColor(shadowColor); + graphics->drawLine(0, 0, getWidth() - 1, 0); + graphics->drawLine(0, 1, 0, h - 2); + graphics->setColor(highlightColor); + graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, h - 1); + graphics->drawLine(0, h - 1, getWidth() - 1, h - 1); - if (isEnabled()) - graphics->setColor(getForegroundColor()); - else - graphics->setColor(Color(128, 128, 128)); + // Push a clip area so the other drawings don't need to worry + // about the border. + graphics->pushClipArea(Rectangle(1, 1, getWidth() - 2, h - 2)); + const Rectangle currentClipArea = graphics->getCurrentClipArea(); - graphics->setFont(getFont()); + Color backgroundColor = getBackgroundColor(); + if (!isEnabled()) + { + backgroundColor = backgroundColor - 0x303030; + } + graphics->setColor(backgroundColor); + graphics->fillRectangle(Rectangle(0, 0, currentClipArea.width, currentClipArea.height)); if (isFocused()) { graphics->setColor(getSelectionColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth() - h, h)); + graphics->fillRectangle(Rectangle( + 0, 0, currentClipArea.width - currentClipArea.height, currentClipArea.height)); graphics->setColor(getForegroundColor()); } + if (isEnabled()) + graphics->setColor(getForegroundColor()); + else + graphics->setColor(Color(128, 128, 128)); + + graphics->setFont(getFont()); + if (mListBox->getListModel() && mListBox->getSelected() >= 0) - graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 2, 1); + graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0); + + // Push a clip area before drawing the button. + graphics->pushClipArea(Rectangle(currentClipArea.width - currentClipArea.height, + 0, + currentClipArea.height, + currentClipArea.height)); drawButton(graphics); + graphics->popClipArea(); + graphics->popClipArea(); if (mDroppedDown) { - drawChildren(graphics); - - // Draw two lines separating the ListBox with se selected - // element view. - graphics->setColor(highlightColor); - graphics->drawLine(0, h, getWidth(), h); + // Draw a border around the children. graphics->setColor(shadowColor); - graphics->drawLine(0, h + 1, getWidth(), h + 1); - } - } - - void DropDown::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + graphics->drawRectangle( + Rectangle(0, mFoldedUpHeight, getWidth(), getHeight() - mFoldedUpHeight)); - unsigned int i; - for (i = 0; i < getFrameSize(); ++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); + drawChildren(graphics); } } @@ -245,55 +242,29 @@ namespace gcn offset = 0; } - int h; - if (mDroppedDown) - { - h = mFoldedUpHeight; - } - else - { - h = getHeight(); - } - int x = getWidth() - h; - int y = 0; + const Rectangle currentClipArea = graphics->getCurrentClipArea(); + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, currentClipArea.width - 1, 0); + graphics->drawLine(0, 1, 0, currentClipArea.height - 1); + graphics->setColor(shadowColor); + graphics->drawLine( + currentClipArea.width - 1, 1, currentClipArea.width - 1, currentClipArea.height - 1); + graphics->drawLine( + 1, currentClipArea.height - 1, currentClipArea.width - 2, currentClipArea.height - 1); graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(x + 1, - y + 1, - h - 2, - h - 2)); - - graphics->setColor(highlightColor); - graphics->drawLine(x, - y, - x + h - 1, - y); - graphics->drawLine(x, - y + 1, - x, - y + h - 1); + graphics->fillRectangle( + Rectangle(1, 1, currentClipArea.width - 2, currentClipArea.height - 2)); - graphics->setColor(shadowColor); - graphics->drawLine(x + h - 1, - y + 1, - x + h - 1, - y + h - 1); - graphics->drawLine(x + 1, - y + h - 1, - x + h - 2, - y + h - 1); graphics->setColor(getForegroundColor()); int i; - int hh = h / 3; - int hx = x + h / 2; - int hy = y + (h * 2) / 3; - for (i = 0; i < hh; i++) + int n = currentClipArea.height / 3; + int dx = currentClipArea.height / 2; + int dy = (currentClipArea.height * 2) / 3; + for (i = 0; i < n; i++) { - graphics->drawLine(hx - i + offset, - hy - i + offset, - hx + i + offset, - hy - i + offset); + graphics->drawLine(dx - i + offset, dy - i + offset, dx + i + offset, dy - i + offset); } } @@ -312,6 +283,10 @@ namespace gcn void DropDown::keyPressed(KeyEvent& keyEvent) { + if (keyEvent.isConsumed()) + { + return; + } Key key = keyEvent.getKey(); if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) @@ -434,7 +409,8 @@ namespace gcn throw GCN_EXCEPTION("List box has been deleted."); int listBoxHeight = mListBox->getHeight(); - int h2 = getFont()->getHeight(); + // We add 2 for the border + int h2 = getFont()->getHeight() + 2; setHeight(h2); @@ -517,10 +493,9 @@ namespace gcn { if (mDroppedDown) { - return Rectangle(0, - mFoldedUpHeight + 2, - getWidth(), - getHeight() - mFoldedUpHeight); + // Calculate the children area (with the one pixel border in mind) + return Rectangle( + 1, mFoldedUpHeight + 1, getWidth() - 2, getHeight() - mFoldedUpHeight - 2); } return Rectangle(); diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 5759116..9bff176 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -95,27 +95,4 @@ namespace gcn graphics->drawImage(mImage, 0, 0); } - void Icon::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++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); - } - } } diff --git a/src/widgets/inputbox.cpp b/src/widgets/inputbox.cpp index 31a140a..de21805 100644 --- a/src/widgets/inputbox.cpp +++ b/src/widgets/inputbox.cpp @@ -232,30 +232,6 @@ namespace gcn graphics->popClipArea(); } - void InputBox::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++i) - { - graphics->setColor(highlightColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(shadowColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - void InputBox::mousePressed(MouseEvent& mouseEvent) { if (mouseEvent.getSource() != this) diff --git a/src/widgets/label.cpp b/src/widgets/label.cpp index 16311eb..4b20ba2 100644 --- a/src/widgets/label.cpp +++ b/src/widgets/label.cpp @@ -128,30 +128,6 @@ namespace gcn graphics->drawText(getCaption(), textX, textY, getAlignment()); } - void Label::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++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 Label::adjustSize() { setWidth(getFont()->getWidth(getCaption())); diff --git a/src/widgets/listbox.cpp b/src/widgets/listbox.cpp index ebd15da..d353939 100644 --- a/src/widgets/listbox.cpp +++ b/src/widgets/listbox.cpp @@ -70,11 +70,8 @@ namespace gcn { - ListBox::ListBox() + ListBox::ListBox() : mListModel(NULL), mSelected(-1), mWrappingEnabled(false) { - mSelected = -1; - mListModel = NULL; - mWrappingEnabled = false; setWidth(100); setFocusable(true); @@ -82,10 +79,8 @@ namespace gcn addKeyListener(this); } - ListBox::ListBox(ListModel *listModel) + ListBox::ListBox(ListModel *listModel) : mSelected(-1), mWrappingEnabled(false) { - mSelected = -1; - mWrappingEnabled = false; setWidth(100); setListModel(listModel); setFocusable(true); @@ -171,30 +166,6 @@ namespace gcn } } - void ListBox::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++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 ListBox::logic() { adjustSize(); diff --git a/src/widgets/messagebox.cpp b/src/widgets/messagebox.cpp index c4fd096..db801f0 100644 --- a/src/widgets/messagebox.cpp +++ b/src/widgets/messagebox.cpp @@ -339,30 +339,6 @@ namespace gcn graphics->popClipArea(); } - void MessageBox::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++i) - { - graphics->setColor(highlightColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(shadowColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - void MessageBox::mousePressed(MouseEvent& mouseEvent) { if (mouseEvent.getSource() != this) diff --git a/src/widgets/progressbar.cpp b/src/widgets/progressbar.cpp index c238469..00aa390 100644 --- a/src/widgets/progressbar.cpp +++ b/src/widgets/progressbar.cpp @@ -191,30 +191,6 @@ namespace gcn graphics->drawText(getCaption(), textX, textY, getAlignment()); } - void ProgressBar::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++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 ProgressBar::adjustSize() { setHeight(getFont()->getHeight()); diff --git a/src/widgets/radiobutton.cpp b/src/widgets/radiobutton.cpp index 996c511..ea5ef81 100644 --- a/src/widgets/radiobutton.cpp +++ b/src/widgets/radiobutton.cpp @@ -122,30 +122,6 @@ namespace gcn graphics->drawText(getCaption(), h - 2, 0); } - void RadioButton::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++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 RadioButton::drawBox(Graphics* graphics) { int h; diff --git a/src/widgets/scrollarea.cpp b/src/widgets/scrollarea.cpp index dc116ec..df572e7 100644 --- a/src/widgets/scrollarea.cpp +++ b/src/widgets/scrollarea.cpp @@ -454,30 +454,6 @@ namespace gcn drawChildren(graphics); } - void ScrollArea::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++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 ScrollArea::drawHBar(Graphics* graphics) { Rectangle dim = getHorizontalBarDimension(); diff --git a/src/widgets/slider.cpp b/src/widgets/slider.cpp index ce0575c..2eb91b1 100644 --- a/src/widgets/slider.cpp +++ b/src/widgets/slider.cpp @@ -146,30 +146,6 @@ namespace gcn drawMarker(graphics); } - void Slider::drawFrame(gcn::Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++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 Slider::drawMarker(gcn::Graphics* graphics) { gcn::Color faceColor = getBaseColor(); diff --git a/src/widgets/tab.cpp b/src/widgets/tab.cpp index 4a92d9d..9538507 100644 --- a/src/widgets/tab.cpp +++ b/src/widgets/tab.cpp @@ -68,8 +68,7 @@ namespace gcn { - Tab::Tab() - :mHasMouse(false) + Tab::Tab() : mTabbedArea(NULL), mHasMouse(false) { mLabel = new Label(); mLabel->setPosition(4, 4); @@ -112,50 +111,59 @@ namespace gcn } void Tab::draw(Graphics *graphics) - { - if (mTabbedArea->isTabSelected(this) || mHasMouse) - { - graphics->setColor(getBaseColor()); - } - else - { - graphics->setColor(getBaseColor() - 0x151515); - } - - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - - drawChildren(graphics); - - if (mTabbedArea->isFocused() - && mTabbedArea->isTabSelected(this)) - { - graphics->setColor(Color(0x000000)); - graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, getHeight() - 4)); - } - } - - void Tab::drawFrame(Graphics* graphics) { Color faceColor = getBaseColor(); Color highlightColor, shadowColor; int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; - unsigned int i; - for (i = 0; i < getFrameSize(); ++i) + Color borderColor; + Color baseColor; + + if ((mTabbedArea != NULL && mTabbedArea->isTabSelected(this)) || mHasMouse) { + // Draw a border. graphics->setColor(highlightColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->drawLine(0, 0, getWidth() - 1, 0); + graphics->drawLine(0, 1, 0, getHeight() - 1); graphics->setColor(shadowColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); + graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); + + borderColor = highlightColor; + baseColor = getBaseColor(); + } + else + { + // Draw a border. + graphics->setColor(shadowColor); + graphics->drawLine(0, 0, getWidth() - 1, 0); + graphics->drawLine(0, 1, 0, getHeight() - 1); + graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); + + baseColor = getBaseColor() - 0x151515; + baseColor.a = alpha; + } + + // Push a clip area so the other drawings don't need to worry + // about the border. + graphics->pushClipArea(Rectangle(1, 1, getWidth() - 2, getHeight() - 1)); + const Rectangle currentClipArea = graphics->getCurrentClipArea(); + + graphics->setColor(baseColor); + graphics->fillRectangle(Rectangle(0, 0, currentClipArea.width, currentClipArea.height)); + + drawChildren(graphics); + + if (mTabbedArea != NULL && mTabbedArea->isFocused() && mTabbedArea->isTabSelected(this)) + { + graphics->setColor(Color(0x000000)); + graphics->drawRectangle( + Rectangle(2, 2, currentClipArea.width - 4, currentClipArea.height - 4)); } + graphics->popClipArea(); } void Tab::mouseEntered(MouseEvent& mouseEvent) diff --git a/src/widgets/tabbedarea.cpp b/src/widgets/tabbedarea.cpp index 06821c3..77759de 100644 --- a/src/widgets/tabbedarea.cpp +++ b/src/widgets/tabbedarea.cpp @@ -265,53 +265,51 @@ namespace gcn { return mSelectedTab; } - - + + void TabbedArea::draw(Graphics *graphics) { - graphics->setColor(getBaseColor() + 0x303030); - graphics->drawLine(0, + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + // Draw a border. + graphics->setColor(highlightColor); + graphics->drawLine(0, mTabContainer->getHeight(), 0, getHeight() - 2); + graphics->setColor(shadowColor); + graphics->drawLine( + getWidth() - 1, mTabContainer->getHeight() + 1, getWidth() - 1, getHeight() - 1); + graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); + + graphics->setColor(getBaseColor()); + graphics->fillRectangle(Rectangle(1, 1, getWidth() - 2, getHeight() - 2)); + + // Draw a line underneath the tabs. + graphics->setColor(highlightColor); + graphics->drawLine(1, mTabContainer->getHeight(), - getWidth(), + getWidth() - 1, mTabContainer->getHeight()); + // If a tab is selected, + // remove the line right underneath the selected tab. if (mSelectedTab != NULL) { graphics->setColor(getBaseColor()); - graphics->drawLine(mSelectedTab->getX(), + graphics->drawLine(mSelectedTab->getX() + 1, mTabContainer->getHeight(), - mSelectedTab->getX() + mSelectedTab->getWidth(), + mSelectedTab->getX() + mSelectedTab->getWidth() - 2, mTabContainer->getHeight()); } drawChildren(graphics); } - - void TabbedArea::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++i) - { - graphics->setColor(highlightColor); - graphics->drawLine(i,i + mWidgetContainer->getY(), i, height - i - 1); - graphics->setColor(shadowColor); - graphics->drawLine(width - i,i + 1 + mWidgetContainer->getY(), width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - void TabbedArea::logic() { @@ -328,20 +326,13 @@ namespace gcn maxTabHeight = mTabs[i].first->getHeight(); } } - - if (getHeight() < maxTabHeight) - { - mTabContainer->setHeight(maxTabHeight); - } - else - { - mTabContainer->setHeight(maxTabHeight); - mWidgetContainer->setHeight(getHeight() - maxTabHeight - 1); - mWidgetContainer->setY(maxTabHeight + 1); - } - mTabContainer->setWidth(getWidth()); - mWidgetContainer->setWidth(getWidth()); + mTabContainer->setWidth(getWidth() - 2); + mTabContainer->setHeight(maxTabHeight); + + mWidgetContainer->setPosition(1, maxTabHeight + 1); + mWidgetContainer->setWidth(getWidth() - 2); + mWidgetContainer->setHeight(getHeight() - maxTabHeight - 2); } void TabbedArea::adjustTabPositions() @@ -361,25 +352,19 @@ namespace gcn { Tab* tab = mTabs[i].first; - if (x == 0) - { - x = tab->getFrameSize() + 2; - } - tab->setX(x); if (tab->getHeight() < maxTabHeight) { tab->setY(maxTabHeight - - tab->getHeight() - + tab->getFrameSize()); + - tab->getHeight()); } else { - tab->setY(mTabs[i].first->getFrameSize()); + tab->setY(0); } - x += tab->getWidth() + tab->getFrameSize() * 2; + x += tab->getWidth(); } } diff --git a/src/widgets/textbox.cpp b/src/widgets/textbox.cpp index 05b08bf..c33eeef 100644 --- a/src/widgets/textbox.cpp +++ b/src/widgets/textbox.cpp @@ -133,6 +133,22 @@ namespace gcn void TextBox::draw(Graphics* graphics) { + /* + int width = getWidth() + getFrameSize() * 2 - 1; + int height = getHeight() + getFrameSize() * 2 - 1; + + graphics->setColor(getBackgroundColor()); + + unsigned int i; + for (i = 0; i < getFrameSize(); ++i) + { + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + */ + unsigned int i; if (mOpaque) @@ -156,23 +172,6 @@ namespace gcn } } - void TextBox::drawFrame(Graphics* graphics) - { - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - - graphics->setColor(getBackgroundColor()); - - unsigned int i; - for (i = 0; i < getFrameSize(); ++i) - { - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - void TextBox::drawCaret(Graphics* graphics, int x, int y) { graphics->setColor(getForegroundColor()); diff --git a/src/widgets/textfield.cpp b/src/widgets/textfield.cpp index 3e10f10..ca058fe 100644 --- a/src/widgets/textfield.cpp +++ b/src/widgets/textfield.cpp @@ -77,7 +77,6 @@ namespace gcn addMouseListener(this); addKeyListener(this); adjustHeight(); - setFrameSize(1); } TextField::TextField(const std::string& text) @@ -87,7 +86,6 @@ namespace gcn mText = text; adjustSize(); - setFrameSize(1); setFocusable(true); @@ -107,8 +105,27 @@ namespace gcn void TextField::draw(Graphics* graphics) { - Color faceColor = getBackgroundColor(); - graphics->setColor(faceColor); + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + // Draw a border. + graphics->setColor(shadowColor); + graphics->drawLine(0, 0, getWidth() - 1, 0); + graphics->drawLine(0, 1, 0, getHeight() - 2); + graphics->setColor(highlightColor); + graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); + graphics->drawLine(0, getHeight() - 1, getWidth() - 1, getHeight() - 1); + + // Push a clip area so the other drawings don't need to worry + // about the border. + graphics->pushClipArea(Rectangle(1, 1, getWidth() - 2, getHeight() - 2)); + + graphics->setColor(Color(0xffffff)); graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); if (isFocused()) @@ -122,37 +139,20 @@ namespace gcn graphics->setColor(Color(128, 128, 128)); graphics->setFont(getFont()); - graphics->drawText(mText, 1 - mXScroll, 2); - } - - void TextField::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++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); - } + graphics->drawText(mText, 1 - mXScroll, 1); + graphics->popClipArea(); } void TextField::drawCaret(Graphics* graphics, int x) { + // Check the current clip area as a clip area with a different + // size than the widget might have been pushed (which is the + // case in the draw method when we push a clip area after we have + // drawn a border). + const Rectangle clipArea = graphics->getCurrentClipArea(); + graphics->setColor(getForegroundColor()); - graphics->drawLine(x, getHeight() - 2, x, 1); + graphics->drawLine(x, clipArea.height - 2, x, 1); } void TextField::mousePressed(MouseEvent& mouseEvent) diff --git a/src/widgets/window.cpp b/src/widgets/window.cpp index 4be331b..34c24c8 100644 --- a/src/widgets/window.cpp +++ b/src/widgets/window.cpp @@ -233,30 +233,6 @@ namespace gcn graphics->popClipArea(); } - void Window::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++i) - { - graphics->setColor(highlightColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(shadowColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } - void Window::mousePressed(MouseEvent& mouseEvent) { if (mouseEvent.getSource() != this)