summaryrefslogtreecommitdiff
path: root/src/guichan/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-05-31 01:27:37 +0300
committerAndrei Karas <akaras@inbox.ru>2011-05-31 01:27:37 +0300
commit9d3b975bcb84ad1c61d628de2804751c0d0707dd (patch)
treefe7494b1ecd561a40dc96d088c77d69b6d4ce13e /src/guichan/widgets
parent1d0044cbc81e547ad688a295288910d58e1a3fb1 (diff)
downloadmanaplus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.gz
manaplus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.bz2
manaplus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.xz
manaplus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.zip
Fix code style and missing members initialisations.
Diffstat (limited to 'src/guichan/widgets')
-rw-r--r--src/guichan/widgets/button.cpp13
-rw-r--r--src/guichan/widgets/dropdown.cpp161
-rw-r--r--src/guichan/widgets/dropdown.hpp7
-rw-r--r--src/guichan/widgets/imagebutton.cpp47
-rw-r--r--src/guichan/widgets/listbox.cpp128
-rw-r--r--src/guichan/widgets/radiobutton.cpp55
-rw-r--r--src/guichan/widgets/scrollarea.cpp236
-rw-r--r--src/guichan/widgets/slider.cpp63
-rw-r--r--src/guichan/widgets/tab.cpp29
-rw-r--r--src/guichan/widgets/tabbedarea.cpp73
-rw-r--r--src/guichan/widgets/textbox.cpp84
-rw-r--r--src/guichan/widgets/textfield.cpp44
-rw-r--r--src/guichan/widgets/window.cpp62
13 files changed, 366 insertions, 636 deletions
diff --git a/src/guichan/widgets/button.cpp b/src/guichan/widgets/button.cpp
index 96e64406e..9f18cab40 100644
--- a/src/guichan/widgets/button.cpp
+++ b/src/guichan/widgets/button.cpp
@@ -143,7 +143,8 @@ namespace gcn
}
graphics->setColor(faceColor);
- graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1));
+ graphics->fillRectangle(Rectangle(1, 1,
+ getDimension().width - 1, getHeight() - 1));
graphics->setColor(highlightColor);
graphics->drawLine(0, 0, getWidth() - 1, 0);
@@ -151,7 +152,8 @@ namespace gcn
graphics->setColor(shadowColor);
graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
- graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);
+ graphics->drawLine(1, getHeight() - 1,
+ getWidth() - 1, getHeight() - 1);
graphics->setColor(getForegroundColor());
@@ -177,7 +179,8 @@ namespace gcn
if (isPressed())
{
- graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment());
+ graphics->drawText(getCaption(), textX + 1, textY + 1,
+ getAlignment());
}
else
{
@@ -186,7 +189,7 @@ namespace gcn
if (isFocused())
{
graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4,
- getHeight() - 4));
+ getHeight() - 4));
}
}
}
@@ -267,7 +270,7 @@ namespace gcn
Key key = keyEvent.getKey();
if ((key.getValue() == Key::ENTER
- || key.getValue() == Key::SPACE)
+ || key.getValue() == Key::SPACE)
&& mKeyPressed)
{
mKeyPressed = false;
diff --git a/src/guichan/widgets/dropdown.cpp b/src/guichan/widgets/dropdown.cpp
index 13feaa1f7..c666b47e4 100644
--- a/src/guichan/widgets/dropdown.cpp
+++ b/src/guichan/widgets/dropdown.cpp
@@ -70,22 +70,14 @@ namespace gcn
mInternalListBox = (listBox == NULL);
if (mInternalScrollArea)
- {
mScrollArea = new ScrollArea();
- }
else
- {
mScrollArea = scrollArea;
- }
if (mInternalListBox)
- {
mListBox = new ListBox();
- }
else
- {
mListBox = listBox;
- }
mScrollArea->setContent(mListBox);
add(mScrollArea);
@@ -96,9 +88,7 @@ namespace gcn
setListModel(listModel);
if (mListBox->getSelected() < 0)
- {
mListBox->setSelected(0);
- }
addMouseListener(this);
addKeyListener(this);
@@ -116,14 +106,10 @@ namespace gcn
}
if (mInternalScrollArea)
- {
delete mScrollArea;
- }
if (mInternalListBox)
- {
delete mListBox;
- }
setInternalFocusHandler(NULL);
}
@@ -133,13 +119,9 @@ namespace gcn
int h;
if (mDroppedDown)
- {
h = mFoldedUpHeight;
- }
else
- {
h = getHeight();
- }
Color faceColor = getBaseColor();
Color highlightColor, shadowColor;
@@ -163,15 +145,15 @@ namespace gcn
const Rectangle currentClipArea = graphics->getCurrentClipArea();
graphics->setColor(getBackgroundColor());
- graphics->fillRectangle(Rectangle(0, 0, currentClipArea.width, currentClipArea.height));
-
+ graphics->fillRectangle(Rectangle(0, 0,
+ currentClipArea.width, currentClipArea.height));
+
if (isFocused())
{
graphics->setColor(getSelectionColor());
- graphics->fillRectangle(Rectangle(0,
- 0,
- currentClipArea.width - currentClipArea.height,
- currentClipArea.height));
+ graphics->fillRectangle(Rectangle(0, 0,
+ currentClipArea.width - currentClipArea.height,
+ currentClipArea.height));
graphics->setColor(getForegroundColor());
}
@@ -181,14 +163,14 @@ namespace gcn
graphics->setColor(getForegroundColor());
graphics->setFont(getFont());
- graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0);
+ 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));
+ graphics->pushClipArea(Rectangle(
+ currentClipArea.width - currentClipArea.height,
+ 0, currentClipArea.height, currentClipArea.height));
drawButton(graphics);
graphics->popClipArea();
graphics->popClipArea();
@@ -197,10 +179,8 @@ namespace gcn
{
// Draw a border around the children.
graphics->setColor(shadowColor);
- graphics->drawRectangle(Rectangle(0,
- mFoldedUpHeight,
- getWidth(),
- getHeight() - mFoldedUpHeight));
+ graphics->drawRectangle(Rectangle(0, mFoldedUpHeight,
+ getWidth(), getHeight() - mFoldedUpHeight));
drawChildren(graphics);
}
}
@@ -234,29 +214,17 @@ namespace gcn
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->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->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(1,
- 1,
- currentClipArea.width - 2,
- currentClipArea.height - 2));
+ graphics->fillRectangle(Rectangle(1, 1,
+ currentClipArea.width - 2, currentClipArea.height - 2));
graphics->setColor(getForegroundColor());
@@ -266,10 +234,8 @@ namespace gcn
int dy = (currentClipArea.height * 2) / 3;
for (i = 0; i < n; i++)
{
- graphics->drawLine(dx - i + offset,
- dy - i + offset,
- dx + i + offset,
- dy - i + offset);
+ graphics->drawLine(dx - i + offset, dy - i + offset,
+ dx + i + offset, dy - i + offset);
}
}
@@ -281,16 +247,14 @@ namespace gcn
void DropDown::setSelected(int selected)
{
if (selected >= 0)
- {
mListBox->setSelected(selected);
- }
}
void DropDown::keyPressed(KeyEvent& keyEvent)
{
if (keyEvent.isConsumed())
return;
-
+
Key key = keyEvent.getKey();
if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
@@ -312,7 +276,7 @@ namespace gcn
}
void DropDown::mousePressed(MouseEvent& mouseEvent)
- {
+ {
// If we have a mouse press on the widget.
if (0 <= mouseEvent.getY()
&& mouseEvent.getY() < getHeight()
@@ -353,11 +317,10 @@ namespace gcn
void DropDown::mouseReleased(MouseEvent& mouseEvent)
{
if (mIsDragged)
- {
mPushed = false;
- }
- // Released outside of widget. Can happen when we have modal input focus.
+ // Released outside of widget. Can happen when we have modal
+ // input focus.
if ((0 > mouseEvent.getY()
|| mouseEvent.getY() >= getHeight()
|| mouseEvent.getX() < 0
@@ -368,9 +331,7 @@ namespace gcn
releaseModalMouseInputFocus();
if (mIsDragged)
- {
foldUp();
- }
}
else if (mouseEvent.getButton() == MouseEvent::LEFT)
{
@@ -392,9 +353,7 @@ namespace gcn
mListBox->setListModel(listModel);
if (mListBox->getSelected() < 0)
- {
mListBox->setSelected(0);
- }
adjustHeight();
}
@@ -407,17 +366,13 @@ namespace gcn
void DropDown::adjustHeight()
{
if (mScrollArea == NULL)
- {
throw GCN_EXCEPTION("Scroll area has been deleted.");
- }
if (mListBox == NULL)
- {
throw GCN_EXCEPTION("List box has been deleted.");
- }
int listBoxHeight = mListBox->getHeight();
-
+
// We add 2 for the border
int h2 = getFont()->getHeight() + 2;
@@ -457,9 +412,7 @@ namespace gcn
adjustHeight();
if (getParent())
- {
getParent()->moveToTop(this);
- }
}
mListBox->requestFocus();
@@ -483,11 +436,9 @@ namespace gcn
void DropDown::death(const Event& event)
- {
+ {
if (event.getSource() == mScrollArea)
- {
mScrollArea = NULL;
- }
BasicContainer::death(event);
}
@@ -504,10 +455,8 @@ namespace gcn
if (mDroppedDown)
{
// Calculate the children area (with the one pixel border in mind)
- return Rectangle(1,
- mFoldedUpHeight + 1,
- getWidth() - 2,
- getHeight() - mFoldedUpHeight - 2);
+ return Rectangle(1, mFoldedUpHeight + 1,
+ getWidth() - 2, getHeight() - mFoldedUpHeight - 2);
}
return Rectangle();
@@ -516,14 +465,10 @@ namespace gcn
void DropDown::setBaseColor(const Color& color)
{
if (mInternalScrollArea)
- {
mScrollArea->setBaseColor(color);
- }
if (mInternalListBox)
- {
mListBox->setBaseColor(color);
- }
Widget::setBaseColor(color);
}
@@ -531,14 +476,10 @@ namespace gcn
void DropDown::setBackgroundColor(const Color& color)
{
if (mInternalScrollArea)
- {
mScrollArea->setBackgroundColor(color);
- }
if (mInternalListBox)
- {
mListBox->setBackgroundColor(color);
- }
Widget::setBackgroundColor(color);
}
@@ -546,50 +487,40 @@ namespace gcn
void DropDown::setForegroundColor(const Color& color)
{
if (mInternalScrollArea)
- {
mScrollArea->setForegroundColor(color);
- }
if (mInternalListBox)
- {
mListBox->setForegroundColor(color);
- }
Widget::setForegroundColor(color);
}
- void DropDown::setFont(Font *font)
- {
- if (mInternalScrollArea)
- {
+ void DropDown::setFont(Font *font)
+ {
+ if (mInternalScrollArea)
mScrollArea->setFont(font);
- }
if (mInternalListBox)
- {
mListBox->setFont(font);
- }
Widget::setFont(font);
- }
+ }
- void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent)
- {
+ void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent)
+ {
if (isFocused() && mouseEvent.getSource() == this)
- {
+ {
mouseEvent.consume();
if (mListBox->getSelected() > 0)
- {
mListBox->setSelected(mListBox->getSelected() - 1);
- }
}
}
void DropDown::mouseWheelMovedDown(MouseEvent& mouseEvent)
{
if (isFocused() && mouseEvent.getSource() == this)
- {
+ {
mouseEvent.consume();
mListBox->setSelected(mListBox->getSelected() + 1);
@@ -601,9 +532,7 @@ namespace gcn
Widget::setSelectionColor(color);
if (mInternalListBox)
- {
mListBox->setSelectionColor(color);
- }
}
void DropDown::valueChanged(const SelectionEvent& event _UNUSED_)
@@ -615,17 +544,19 @@ namespace gcn
{
mSelectionListeners.push_back(selectionListener);
}
-
- void DropDown::removeSelectionListener(SelectionListener* selectionListener)
+
+ void DropDown::removeSelectionListener(SelectionListener* listener)
{
- mSelectionListeners.remove(selectionListener);
+ mSelectionListeners.remove(listener);
}
void DropDown::distributeValueChangedEvent()
{
SelectionListenerIterator iter;
- for (iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); ++iter)
+ for (iter = mSelectionListeners.begin();
+ iter != mSelectionListeners.end();
+ ++iter)
{
SelectionEvent event(this);
(*iter)->valueChanged(event);
diff --git a/src/guichan/widgets/dropdown.hpp b/src/guichan/widgets/dropdown.hpp
index 4a0993b1a..5853783e5 100644
--- a/src/guichan/widgets/dropdown.hpp
+++ b/src/guichan/widgets/dropdown.hpp
@@ -63,7 +63,8 @@
#define _UNUSED_
#endif
-namespace gcn {
+namespace gcn
+{
/**
* An implementation of a drop downable list from which an item can be
* selected. The drop down consists of an internal ScrollArea and an
@@ -154,10 +155,10 @@ namespace gcn {
* If you delete your selection listener, be sure to also remove it
* using removeSelectionListener().
*
- * @param selectionListener the selection listener to add.
+ * @param listener the selection listener to add.
* @since 0.8.0
*/
- void addSelectionListener(SelectionListener* selectionListener);
+ void addSelectionListener(SelectionListener* listener);
/**
* Removes a selection listener from the drop down.
diff --git a/src/guichan/widgets/imagebutton.cpp b/src/guichan/widgets/imagebutton.cpp
index f09bca30d..a340face3 100644
--- a/src/guichan/widgets/imagebutton.cpp
+++ b/src/guichan/widgets/imagebutton.cpp
@@ -52,17 +52,17 @@
namespace gcn
{
- ImageButton::ImageButton()
- : mImage(0),
- mInternalImage(false)
+ ImageButton::ImageButton() :
+ mImage(0),
+ mInternalImage(false)
{
setWidth(0);
setHeight(0);
}
- ImageButton::ImageButton(const std::string& filename)
- : mImage(0),
- mInternalImage(false)
+ ImageButton::ImageButton(const std::string& filename) :
+ mImage(0),
+ mInternalImage(false)
{
mImage = Image::load(filename);
mInternalImage = true;
@@ -70,9 +70,9 @@ namespace gcn
setHeight(mImage->getHeight() + mImage->getHeight() / 2);
}
- ImageButton::ImageButton(const Image* image)
- : mImage(image),
- mInternalImage(false)
+ ImageButton::ImageButton(const Image* image) :
+ mImage(image),
+ mInternalImage(false)
{
setWidth(mImage->getWidth() + mImage->getWidth() / 2);
setHeight(mImage->getHeight() + mImage->getHeight() / 2);
@@ -81,17 +81,13 @@ namespace gcn
ImageButton::~ImageButton()
{
if (mInternalImage)
- {
delete mImage;
- }
}
void ImageButton::setImage(const Image* image)
{
if (mInternalImage)
- {
delete mImage;
- }
mImage = image;
mInternalImage = false;
@@ -126,10 +122,8 @@ namespace gcn
}
graphics->setColor(faceColor);
- graphics->fillRectangle(Rectangle(1,
- 1,
- getDimension().width - 1,
- getHeight() - 1));
+ graphics->fillRectangle(Rectangle(1, 1,
+ getDimension().width - 1, getHeight() - 1));
graphics->setColor(highlightColor);
graphics->drawLine(0, 0, getWidth() - 1, 0);
@@ -137,29 +131,30 @@ namespace gcn
graphics->setColor(shadowColor);
graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
- graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);
+ graphics->drawLine(1, getHeight() - 1,
+ getWidth() - 1, getHeight() - 1);
graphics->setColor(getForegroundColor());
- const int textX = (getWidth() - (mImage ? mImage->getWidth() : 0) ) / 2;
- const int textY = (getHeight() - (mImage ? mImage->getHeight() : 0) ) / 2;
+ const int textX = (getWidth() - (mImage
+ ? mImage->getWidth() : 0) ) / 2;
+ const int textY = (getHeight() - (mImage
+ ? mImage->getHeight() : 0) ) / 2;
if (isPressed())
{
- if(mImage)
+ if (mImage)
graphics->drawImage(mImage, textX + 1, textY + 1);
}
else
{
- if(mImage)
+ if (mImage)
graphics->drawImage(mImage, textX, textY);
if (isFocused())
{
- graphics->drawRectangle(Rectangle(2,
- 2,
- getWidth() - 4,
- getHeight() - 4));
+ graphics->drawRectangle(Rectangle(2, 2,
+ getWidth() - 4, getHeight() - 4));
}
}
}
diff --git a/src/guichan/widgets/listbox.cpp b/src/guichan/widgets/listbox.cpp
index 9b20b8538..b8778e596 100644
--- a/src/guichan/widgets/listbox.cpp
+++ b/src/guichan/widgets/listbox.cpp
@@ -57,10 +57,10 @@
namespace gcn
{
- ListBox::ListBox()
- : mSelected(-1),
- mListModel(NULL),
- mWrappingEnabled(false)
+ ListBox::ListBox() :
+ mSelected(-1),
+ mListModel(NULL),
+ mWrappingEnabled(false)
{
setWidth(100);
setFocusable(true);
@@ -69,9 +69,9 @@ namespace gcn
addKeyListener(this);
}
- ListBox::ListBox(ListModel *listModel)
- : mSelected(-1),
- mWrappingEnabled(false)
+ ListBox::ListBox(ListModel *listModel) :
+ mSelected(-1),
+ mWrappingEnabled(false)
{
setWidth(100);
setListModel(listModel);
@@ -87,67 +87,61 @@ namespace gcn
graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight()));
if (mListModel == NULL)
- {
return;
- }
graphics->setColor(getForegroundColor());
graphics->setFont(getFont());
-
+
// Check the current clip area so we don't draw unnecessary items
// that are not visible.
const ClipRectangle currentClipArea = graphics->getCurrentClipArea();
int rowHeight = getRowHeight();
-
- // Calculate the number of rows to draw by checking the clip area.
- // The addition of two makes covers a partial visible row at the top
- // and a partial visible row at the bottom.
- int numberOfRows = currentClipArea.height / rowHeight + 2;
+
+ // Calculate the number of rows to draw by checking the clip area.
+ // The addition of two makes covers a partial visible row at the top
+ // and a partial visible row at the bottom.
+ int numberOfRows = currentClipArea.height / rowHeight + 2;
if (numberOfRows > mListModel->getNumberOfElements())
- {
numberOfRows = mListModel->getNumberOfElements();
- }
- // Calculate which row to start drawing. If the list box
- // has a negative y coordinate value we should check if
- // we should drop rows in the begining of the list as
- // they might not be visible. A negative y value is very
- // common if the list box for instance resides in a scroll
- // area and the user has scrolled the list box downwards.
- int startRow;
- if (getY() < 0)
- {
- startRow = -1 * (getY() / rowHeight);
- }
- else
- {
- startRow = 0;
- }
-
- int i;
- // The y coordinate where we start to draw the text is
- // simply the y coordinate multiplied with the font height.
- int y = rowHeight * startRow;
+ // Calculate which row to start drawing. If the list box
+ // has a negative y coordinate value we should check if
+ // we should drop rows in the begining of the list as
+ // they might not be visible. A negative y value is very
+ // common if the list box for instance resides in a scroll
+ // area and the user has scrolled the list box downwards.
+ int startRow;
+ if (getY() < 0)
+ startRow = -1 * (getY() / rowHeight);
+ else
+ startRow = 0;
+
+ int i;
+ // The y coordinate where we start to draw the text is
+ // simply the y coordinate multiplied with the font height.
+ int y = rowHeight * startRow;
for (i = startRow; i < startRow + numberOfRows; ++i)
{
if (i == mSelected)
{
graphics->setColor(getSelectionColor());
- graphics->fillRectangle(Rectangle(0, y, getWidth(), rowHeight));
+ graphics->fillRectangle(Rectangle(0, y,
+ getWidth(), rowHeight));
graphics->setColor(getForegroundColor());
}
-
- // If the row height is greater than the font height we
- // draw the text with a center vertical alignment.
- if (rowHeight > getFont()->getHeight())
- {
- graphics->drawText(mListModel->getElementAt(i), 1, y + rowHeight / 2 - getFont()->getHeight() / 2);
- }
- else
- {
- graphics->drawText(mListModel->getElementAt(i), 1, y);
- }
+
+ // If the row height is greater than the font height we
+ // draw the text with a center vertical alignment.
+ if (rowHeight > getFont()->getHeight())
+ {
+ graphics->drawText(mListModel->getElementAt(i), 1,
+ y + rowHeight / 2 - getFont()->getHeight() / 2);
+ }
+ else
+ {
+ graphics->drawText(mListModel->getElementAt(i), 1, y);
+ }
y += rowHeight;
}
@@ -172,29 +166,19 @@ namespace gcn
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);
@@ -218,15 +202,11 @@ namespace gcn
if (mSelected == -1)
{
if (mWrappingEnabled)
- {
setSelected(getListModel()->getNumberOfElements() - 1);
- }
else
- {
setSelected(0);
- }
}
-
+
keyEvent.consume();
}
else if (key.getValue() == Key::DOWN)
@@ -240,7 +220,7 @@ namespace gcn
{
setSelected(getSelected() + 1);
}
-
+
keyEvent.consume();
}
else if (key.getValue() == Key::HOME)
@@ -269,9 +249,7 @@ namespace gcn
if (isFocused())
{
if (getSelected() > 0 )
- {
setSelected(getSelected() - 1);
- }
mouseEvent.consume();
}
@@ -307,9 +285,7 @@ namespace gcn
void ListBox::adjustSize()
{
if (mListModel != NULL)
- {
setHeight(getRowHeight() * mListModel->getNumberOfElements());
- }
}
bool ListBox::isWrappingEnabled() const
@@ -336,15 +312,17 @@ namespace gcn
{
SelectionListenerIterator iter;
- for (iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); ++iter)
+ for (iter = mSelectionListeners.begin();
+ iter != mSelectionListeners.end();
+ ++ iter)
{
SelectionEvent event(this);
(*iter)->valueChanged(event);
}
}
- unsigned int ListBox::getRowHeight() const
- {
- return getFont()->getHeight();
- }
+ unsigned int ListBox::getRowHeight() const
+ {
+ return getFont()->getHeight();
+ }
}
diff --git a/src/guichan/widgets/radiobutton.cpp b/src/guichan/widgets/radiobutton.cpp
index 31fdec94d..2b2ae7315 100644
--- a/src/guichan/widgets/radiobutton.cpp
+++ b/src/guichan/widgets/radiobutton.cpp
@@ -88,38 +88,32 @@ namespace gcn
void RadioButton::draw(Graphics* graphics)
{
- graphics->pushClipArea(Rectangle(1,
- 1,
- getWidth() - 1,
- getHeight() - 1));
+ graphics->pushClipArea(Rectangle(1, 1,
+ getWidth() - 1, getHeight() - 1));
+
drawBox(graphics);
graphics->popClipArea();
-
graphics->setFont(getFont());
graphics->setColor(getForegroundColor());
if (isFocused())
{
int fh;
-
- if (getHeight()%2 == 0)
- {
+
+ if (getHeight() % 2 == 0)
fh = getHeight() - 4;
- }
else
- {
fh = getHeight() - 3;
- }
int hh = (fh + 1) / 2;
-
+
graphics->drawLine(0, hh + 1, hh + 1, 0);
graphics->drawLine(hh + 2, 1, fh + 2, hh + 1);
graphics->drawLine(fh + 1, hh + 2, hh + 1, fh + 2);
- graphics->drawLine(hh + 1, fh + 2, 1, hh + 2);
+ graphics->drawLine(hh + 1, fh + 2, 1, hh + 2);
}
-
+
int h = getHeight() + getHeight() / 2;
graphics->drawText(getCaption(), h - 2, 0);
@@ -129,14 +123,10 @@ namespace gcn
{
int h;
- if (getHeight()%2 == 0)
- {
+ if (getHeight() % 2 == 0)
h = getHeight() - 4;
- }
else
- {
h = getHeight() - 3;
- }
int alpha = getBaseColor().a;
Color faceColor = getBaseColor();
@@ -152,20 +142,10 @@ namespace gcn
int hh = (h + 1) / 2;
for (i = 1; i <= hh; ++i)
- {
- graphics->drawLine(hh - i + 1,
- i,
- hh + i - 1,
- i);
- }
+ graphics->drawLine(hh - i + 1, i, hh + i - 1, i);
for (i = 1; i < hh; ++i)
- {
- graphics->drawLine(hh - i + 1,
- h - i,
- hh + i - 1,
- h - i);
- }
+ graphics->drawLine(hh - i + 1, h - i, hh + i - 1, h - i);
graphics->setColor(shadowColor);
graphics->drawLine(hh, 0, 0, hh);
@@ -181,14 +161,9 @@ namespace gcn
if (mSelected)
{
for (i = 0; i < hhh; ++i)
- {
graphics->drawLine(hh - i, 4 + i, hh + i, 4 + i);
- }
for (i = 0; i < hhh; ++i)
- {
graphics->drawLine(hh - i, h - 4 - i, hh + i, h - 4 - i);
- }
-
}
}
@@ -206,12 +181,10 @@ namespace gcn
for (iter = mGroupMap.lower_bound(mGroup);
iter != iterEnd;
- iter++)
+ ++ iter)
{
if (iter->second->isSelected())
- {
iter->second->setSelected(false);
- }
}
}
@@ -264,7 +237,7 @@ namespace gcn
for (iter = mGroupMap.lower_bound(mGroup);
iter != iterEnd;
- iter++)
+ ++ iter)
{
if (iter->second == this)
{
@@ -293,6 +266,6 @@ namespace gcn
int height = getFont()->getHeight();
setHeight(height);
- setWidth(getFont()->getWidth(getCaption()) + height + height/2);
+ setWidth(getFont()->getWidth(getCaption()) + height + height / 2);
}
}
diff --git a/src/guichan/widgets/scrollarea.cpp b/src/guichan/widgets/scrollarea.cpp
index 8e935fc47..2e853caa4 100644
--- a/src/guichan/widgets/scrollarea.cpp
+++ b/src/guichan/widgets/scrollarea.cpp
@@ -68,7 +68,7 @@ namespace gcn
mLeftButtonScrollAmount = 10;
mRightButtonScrollAmount = 10;
mIsVerticalMarkerDragged = false;
- mIsHorizontalMarkerDragged =false;
+ mIsHorizontalMarkerDragged = false;
mOpaque = true;
addMouseListener(this);
@@ -90,7 +90,7 @@ namespace gcn
mLeftButtonScrollAmount = 10;
mRightButtonScrollAmount = 10;
mIsVerticalMarkerDragged = false;
- mIsHorizontalMarkerDragged =false;
+ mIsHorizontalMarkerDragged = false;
mOpaque = true;
setContent(content);
@@ -115,7 +115,7 @@ namespace gcn
mLeftButtonScrollAmount = 10;
mRightButtonScrollAmount = 10;
mIsVerticalMarkerDragged = false;
- mIsHorizontalMarkerDragged =false;
+ mIsHorizontalMarkerDragged = false;
mOpaque = true;
setContent(content);
@@ -133,7 +133,7 @@ namespace gcn
{
clear();
add(widget);
- widget->setPosition(0,0);
+ widget->setPosition(0, 0);
}
else
{
@@ -175,7 +175,8 @@ namespace gcn
return mVPolicy;
}
- void ScrollArea::setScrollPolicy(ScrollPolicy hPolicy, ScrollPolicy vPolicy)
+ void ScrollArea::setScrollPolicy(ScrollPolicy hPolicy,
+ ScrollPolicy vPolicy)
{
mHPolicy = hPolicy;
mVPolicy = vPolicy;
@@ -189,14 +190,10 @@ namespace gcn
mVScroll = vScroll;
if (vScroll > max)
- {
mVScroll = max;
- }
if (vScroll < 0)
- {
mVScroll = 0;
- }
}
int ScrollArea::getVerticalScrollAmount() const
@@ -211,13 +208,9 @@ namespace gcn
mHScroll = hScroll;
if (hScroll > max)
- {
mHScroll = max;
- }
else if (hScroll < 0)
- {
mHScroll = 0;
- }
}
int ScrollArea::getHorizontalScrollAmount() const
@@ -236,17 +229,13 @@ namespace gcn
checkPolicies();
if (getContent() == NULL)
- {
return 0;
- }
int value = getContent()->getWidth() - getChildrenArea().width +
2 * getContent()->getFrameSize();
if (value < 0)
- {
return 0;
- }
return value;
}
@@ -256,9 +245,7 @@ namespace gcn
checkPolicies();
if (getContent() == NULL)
- {
return 0;
- }
int value;
@@ -266,9 +253,7 @@ namespace gcn
2 * getContent()->getFrameSize();
if (value < 0)
- {
return 0;
- }
return value;
}
@@ -276,13 +261,9 @@ namespace gcn
void ScrollArea::setScrollbarWidth(int width)
{
if (width > 0)
- {
mScrollbarWidth = width;
- }
else
- {
throw GCN_EXCEPTION("Width should be greater then 0.");
- }
}
int ScrollArea::getScrollbarWidth() const
@@ -326,17 +307,17 @@ namespace gcn
mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y;
}
- else if (getVerticalBarDimension().isPointInRect(x,y))
+ else if (getVerticalBarDimension().isPointInRect(x, y))
{
if (y < getVerticalMarkerDimension().y)
{
setVerticalScrollAmount(getVerticalScrollAmount()
- - (int)(getChildrenArea().height * 0.95));
+ - (int)(getChildrenArea().height * 0.95));
}
else
{
setVerticalScrollAmount(getVerticalScrollAmount()
- + (int)(getChildrenArea().height * 0.95));
+ + (int)(getChildrenArea().height * 0.95));
}
}
else if (getHorizontalMarkerDimension().isPointInRect(x, y))
@@ -346,17 +327,17 @@ namespace gcn
mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x;
}
- else if (getHorizontalBarDimension().isPointInRect(x,y))
+ else if (getHorizontalBarDimension().isPointInRect(x, y))
{
if (x < getHorizontalMarkerDimension().x)
{
setHorizontalScrollAmount(getHorizontalScrollAmount()
- - (int)(getChildrenArea().width * 0.95));
+ - (int)(getChildrenArea().width * 0.95));
}
else
{
setHorizontalScrollAmount(getHorizontalScrollAmount()
- + (int)(getChildrenArea().width * 0.95));
+ + (int)(getChildrenArea().width * 0.95));
}
}
}
@@ -377,7 +358,8 @@ namespace gcn
{
if (mIsVerticalMarkerDragged)
{
- int pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset;
+ int pos = mouseEvent.getY() - getVerticalBarDimension().y
+ - mVerticalMarkerDragOffset;
int length = getVerticalMarkerDimension().height;
Rectangle barDim = getVerticalBarDimension();
@@ -395,7 +377,8 @@ namespace gcn
if (mIsHorizontalMarkerDragged)
{
- int pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset;
+ int pos = mouseEvent.getX() - getHorizontalBarDimension().x
+ - mHorizontalMarkerDragOffset;
int length = getHorizontalMarkerDimension().width;
Rectangle barDim = getHorizontalBarDimension();
@@ -438,9 +421,8 @@ namespace gcn
{
graphics->setColor(getBaseColor());
graphics->fillRectangle(Rectangle(getWidth() - mScrollbarWidth,
- getHeight() - mScrollbarWidth,
- mScrollbarWidth,
- mScrollbarWidth));
+ getHeight() - mScrollbarWidth,
+ mScrollbarWidth, mScrollbarWidth));
}
drawChildren(graphics);
@@ -549,10 +531,8 @@ namespace gcn
int h = w / 2 + 2;
for (i = 0; i < w / 2; ++i)
{
- graphics->drawLine(w - i + offset,
- i + h + offset,
- w + i + offset,
- i + h + offset);
+ graphics->drawLine(w - i + offset, i + h + offset,
+ w + i + offset, i + h + offset);
}
graphics->popClipArea();
@@ -610,10 +590,8 @@ namespace gcn
int h = w + 1;
for (i = 0; i < w / 2; ++i)
{
- graphics->drawLine(w - i + offset,
- -i + h + offset,
- w + i + offset,
- -i + h + offset);
+ graphics->drawLine(w - i + offset, -i + h + offset,
+ w + i + offset, -i + h + offset);
}
graphics->popClipArea();
@@ -671,10 +649,8 @@ namespace gcn
int h = w - 2;
for (i = 0; i < w / 2; ++i)
{
- graphics->drawLine(i + h + offset,
- w - i + offset,
- i + h + offset,
- w + i + offset);
+ graphics->drawLine(i + h + offset, w - i + offset,
+ i + h + offset, w + i + offset);
}
graphics->popClipArea();
@@ -732,10 +708,8 @@ namespace gcn
int h = w + 1;
for (i = 0; i < w / 2; ++i)
{
- graphics->drawLine(-i + h + offset,
- w - i + offset,
- -i + h + offset,
- w + i + offset);
+ graphics->drawLine(-i + h + offset, w - i + offset,
+ -i + h + offset, w + i + offset);
}
graphics->popClipArea();
@@ -755,7 +729,8 @@ namespace gcn
shadowColor.a = alpha;
graphics->setColor(faceColor);
- graphics->fillRectangle(Rectangle(1, 1, dim.width - 1, dim.height - 1));
+ graphics->fillRectangle(Rectangle(1, 1,
+ dim.width - 1, dim.height - 1));
graphics->setColor(highlightColor);
graphics->drawLine(0, 0, dim.width - 1, 0);
@@ -782,7 +757,8 @@ namespace gcn
shadowColor.a = alpha;
graphics->setColor(faceColor);
- graphics->fillRectangle(Rectangle(1, 1, dim.width - 1, dim.height - 1));
+ graphics->fillRectangle(Rectangle(1, 1,
+ dim.width - 1, dim.height - 1));
graphics->setColor(highlightColor);
graphics->drawLine(0, 0, dim.width - 1, 0);
@@ -805,7 +781,7 @@ namespace gcn
if (getContent() != NULL)
{
getContent()->setPosition(-mHScroll + getContent()->getFrameSize(),
- -mVScroll + getContent()->getFrameSize());
+ -mVScroll + getContent()->getFrameSize());
getContent()->logic();
}
}
@@ -842,88 +818,83 @@ namespace gcn
}
if ((getContent()->getHeight() > h)
- || (mHBarVisible && getContent()->getHeight() > h - mScrollbarWidth))
+ || (mHBarVisible && getContent()->getHeight()
+ > h - mScrollbarWidth))
{
mVBarVisible = true;
}
if (mVBarVisible && getContent()->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 = getContent()->getWidth() > w;
- }
- else // (mVPolicy == SHOW_ALWAYS)
- {
- mHBarVisible = getContent()->getWidth() > w - mScrollbarWidth;
- }
- break;
-
- default:
- throw GCN_EXCEPTION("Horizontal scroll policy invalid.");
+ case SHOW_NEVER:
+ mHBarVisible = false;
+ break;
+
+ case SHOW_ALWAYS:
+ mHBarVisible = true;
+ break;
+
+ case SHOW_AUTO:
+ if (mVPolicy == SHOW_NEVER)
+ {
+ mHBarVisible = (getContent()->getWidth() > w);
+ }
+ else // (mVPolicy == SHOW_ALWAYS)
+ {
+ mHBarVisible = (getContent()->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 = getContent()->getHeight() > h;
- }
- else // (mHPolicy == SHOW_ALWAYS)
- {
- mVBarVisible = getContent()->getHeight() > h - mScrollbarWidth;
- }
- break;
- default:
- throw GCN_EXCEPTION("Vertical scroll policy invalid.");
+ case SHOW_NEVER:
+ mVBarVisible = false;
+ break;
+
+ case SHOW_ALWAYS:
+ mVBarVisible = true;
+ break;
+
+ case SHOW_AUTO:
+ if (mHPolicy == SHOW_NEVER)
+ {
+ mVBarVisible = (getContent()->getHeight() > h);
+ }
+ else // (mHPolicy == SHOW_ALWAYS)
+ {
+ mVBarVisible = (getContent()->getHeight()
+ > h - mScrollbarWidth);
+ }
+ break;
+ default:
+ throw GCN_EXCEPTION("Vertical scroll policy invalid.");
}
}
Rectangle ScrollArea::getUpButtonDimension()
{
if (!mVBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
- return Rectangle(getWidth() - mScrollbarWidth,
- 0,
- mScrollbarWidth,
- mScrollbarWidth);
+ return Rectangle(getWidth() - mScrollbarWidth, 0,
+ mScrollbarWidth, mScrollbarWidth);
}
Rectangle ScrollArea::getDownButtonDimension()
{
if (!mVBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
if (mVBarVisible && mHBarVisible)
{
@@ -942,22 +913,16 @@ namespace gcn
Rectangle ScrollArea::getLeftButtonDimension()
{
if (!mHBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
- return Rectangle(0,
- getHeight() - mScrollbarWidth,
- mScrollbarWidth,
- mScrollbarWidth);
+ return Rectangle(0, getHeight() - mScrollbarWidth,
+ mScrollbarWidth, mScrollbarWidth);
}
Rectangle ScrollArea::getRightButtonDimension()
{
if (!mHBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
if (mVBarVisible && mHBarVisible)
{
@@ -975,11 +940,10 @@ namespace gcn
Rectangle ScrollArea::getChildrenArea()
{
- Rectangle area = Rectangle(0,
- 0,
- mVBarVisible ? getWidth() - mScrollbarWidth : getWidth(),
- mHBarVisible ? getHeight() - mScrollbarWidth : getHeight());
-
+ Rectangle area = Rectangle(0, 0,
+ mVBarVisible ? (getWidth() - mScrollbarWidth) : getWidth(),
+ mHBarVisible ? (getHeight() - mScrollbarWidth) : getHeight());
+
if (area.width < 0 || area.height < 0)
return Rectangle();
@@ -989,9 +953,7 @@ namespace gcn
Rectangle ScrollArea::getVerticalBarDimension()
{
if (!mVBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
if (mHBarVisible)
{
@@ -1015,9 +977,7 @@ namespace gcn
Rectangle ScrollArea::getHorizontalBarDimension()
{
if (!mHBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
if (mVBarVisible)
{
@@ -1041,9 +1001,7 @@ namespace gcn
Rectangle ScrollArea::getVerticalMarkerDimension()
{
if (!mVBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
int length, pos;
Rectangle barDim = getVerticalBarDimension();
@@ -1059,14 +1017,10 @@ namespace gcn
}
if (length < mScrollbarWidth)
- {
length = mScrollbarWidth;
- }
if (length > barDim.height)
- {
length = barDim.height;
- }
if (getVerticalMaxScroll() != 0)
{
@@ -1084,9 +1038,7 @@ namespace gcn
Rectangle ScrollArea::getHorizontalMarkerDimension()
{
if (!mHBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
int length, pos;
Rectangle barDim = getHorizontalBarDimension();
@@ -1127,22 +1079,20 @@ namespace gcn
void ScrollArea::showWidgetPart(Widget* widget, Rectangle area)
{
if (widget != getContent())
- {
throw GCN_EXCEPTION("Widget not content widget");
- }
BasicContainer::showWidgetPart(widget, area);
- setHorizontalScrollAmount(getContent()->getFrameSize() - getContent()->getX());
- setVerticalScrollAmount(getContent()->getFrameSize() - getContent()->getY());
+ setHorizontalScrollAmount(getContent()->getFrameSize()
+ - getContent()->getX());
+ setVerticalScrollAmount(getContent()->getFrameSize()
+ - getContent()->getY());
}
Widget *ScrollArea::getWidgetAt(int x, int y)
{
if (getChildrenArea().isPointInRect(x, y))
- {
return getContent();
- }
return NULL;
}
@@ -1150,11 +1100,10 @@ namespace gcn
void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent)
{
if (mouseEvent.isConsumed())
- {
return;
- }
- setVerticalScrollAmount(getVerticalScrollAmount() - getChildrenArea().height / 8);
+ setVerticalScrollAmount(getVerticalScrollAmount()
+ - getChildrenArea().height / 8);
mouseEvent.consume();
}
@@ -1162,11 +1111,10 @@ namespace gcn
void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent)
{
if (mouseEvent.isConsumed())
- {
return;
- }
- setVerticalScrollAmount(getVerticalScrollAmount() + getChildrenArea().height / 8);
+ setVerticalScrollAmount(getVerticalScrollAmount()
+ + getChildrenArea().height / 8);
mouseEvent.consume();
}
diff --git a/src/guichan/widgets/slider.cpp b/src/guichan/widgets/slider.cpp
index a32209124..3bc9d77aa 100644
--- a/src/guichan/widgets/slider.cpp
+++ b/src/guichan/widgets/slider.cpp
@@ -82,7 +82,7 @@ namespace gcn
setFrameSize(1);
setOrientation(HORIZONTAL);
setValue(scaleStart);
- setStepLength((scaleEnd - scaleStart)/ 10);
+ setStepLength((scaleEnd - scaleStart) / 10);
setMarkerLength(10);
addMouseListener(this);
@@ -122,7 +122,7 @@ namespace gcn
shadowColor.a = alpha;
graphics->setColor(shadowColor);
- graphics->fillRectangle(gcn::Rectangle(0,0,getWidth(),getHeight()));
+ graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
drawMarker(graphics);
}
@@ -142,35 +142,43 @@ namespace gcn
if (getOrientation() == HORIZONTAL)
{
int v = getMarkerPosition();
- graphics->fillRectangle(gcn::Rectangle(v + 1, 1, getMarkerLength() - 2, getHeight() - 2));
+ graphics->fillRectangle(gcn::Rectangle(v + 1, 1,
+ getMarkerLength() - 2, getHeight() - 2));
graphics->setColor(highlightColor);
- graphics->drawLine(v, 0, v + getMarkerLength() - 1,0);
+ graphics->drawLine(v, 0, v + getMarkerLength() - 1, 0);
graphics->drawLine(v, 0, v, getHeight() - 1);
graphics->setColor(shadowColor);
- graphics->drawLine(v + getMarkerLength() - 1, 1, v + getMarkerLength() - 1, getHeight() - 1);
- graphics->drawLine(v + 1, getHeight() - 1, v + getMarkerLength() - 1, getHeight() - 1);
+ graphics->drawLine(v + getMarkerLength() - 1, 1,
+ v + getMarkerLength() - 1, getHeight() - 1);
+ graphics->drawLine(v + 1, getHeight() - 1,
+ v + getMarkerLength() - 1, getHeight() - 1);
if (isFocused())
{
graphics->setColor(getForegroundColor());
- graphics->drawRectangle(Rectangle(v + 2, 2, getMarkerLength() - 4, getHeight() - 4));
+ graphics->drawRectangle(Rectangle(v + 2, 2,
+ getMarkerLength() - 4, getHeight() - 4));
}
}
else
{
int v = (getHeight() - getMarkerLength()) - getMarkerPosition();
- graphics->fillRectangle(gcn::Rectangle(1, v + 1, getWidth() - 2, getMarkerLength() - 2));
+ graphics->fillRectangle(gcn::Rectangle(1, v + 1, getWidth() - 2,
+ getMarkerLength() - 2));
graphics->setColor(highlightColor);
graphics->drawLine(0, v, 0, v + getMarkerLength() - 1);
graphics->drawLine(0, v, getWidth() - 1, v);
graphics->setColor(shadowColor);
- graphics->drawLine(1, v + getMarkerLength() - 1, getWidth() - 1, v + getMarkerLength() - 1);
- graphics->drawLine(getWidth() - 1, v + 1, getWidth() - 1, v + getMarkerLength() - 1);
+ graphics->drawLine(1, v + getMarkerLength() - 1, getWidth() - 1,
+ v + getMarkerLength() - 1);
+ graphics->drawLine(getWidth() - 1, v + 1, getWidth() - 1,
+ v + getMarkerLength() - 1);
if (isFocused())
{
graphics->setColor(getForegroundColor());
- graphics->drawRectangle(Rectangle(2, v + 2, getWidth() - 4, getMarkerLength() - 4));
+ graphics->drawRectangle(Rectangle(2, v + 2, getWidth() - 4,
+ getMarkerLength() - 4));
}
}
}
@@ -185,11 +193,13 @@ namespace gcn
{
if (getOrientation() == HORIZONTAL)
{
- setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2));
+ setValue(markerPositionToValue(
+ mouseEvent.getX() - getMarkerLength() / 2));
}
else
{
- setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2));
+ setValue(markerPositionToValue(getHeight()
+ - mouseEvent.getY() - getMarkerLength() / 2));
}
distributeActionEvent();
@@ -200,11 +210,13 @@ namespace gcn
{
if (getOrientation() == HORIZONTAL)
{
- setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2));
+ setValue(markerPositionToValue(mouseEvent.getX()
+ - getMarkerLength() / 2));
}
else
{
- setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2));
+ setValue(markerPositionToValue(getHeight()
+ - mouseEvent.getY() - getMarkerLength() / 2));
}
distributeActionEvent();
@@ -261,7 +273,7 @@ namespace gcn
setValue(getValue() - getStepLength());
distributeActionEvent();
keyEvent.consume();
- }
+ }
}
else
{
@@ -294,44 +306,31 @@ namespace gcn
{
int w;
if (getOrientation() == HORIZONTAL)
- {
w = getWidth();
- }
else
- {
w = getHeight();
- }
double pos = v / ((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();
- }
- int w = (int)((v - getMarkerLength())
- * (value - getScaleStart())
- / (getScaleEnd() - getScaleStart()));
+ int w = (int)((v - getMarkerLength())
+ * (value - getScaleStart())
+ / (getScaleEnd() - getScaleStart()));
if (w < 0)
- {
return 0;
- }
if (w > v - getMarkerLength())
- {
return v - getMarkerLength();
- }
return w;
}
diff --git a/src/guichan/widgets/tab.cpp b/src/guichan/widgets/tab.cpp
index f6283dfe6..760e77a18 100644
--- a/src/guichan/widgets/tab.cpp
+++ b/src/guichan/widgets/tab.cpp
@@ -55,9 +55,9 @@
namespace gcn
{
- Tab::Tab()
- :mHasMouse(false),
- mTabbedArea(NULL)
+ Tab::Tab() :
+ mHasMouse(false),
+ mTabbedArea(NULL)
{
mLabel = new Label();
mLabel->setPosition(4, 4);
@@ -77,9 +77,7 @@ namespace gcn
mLabel->getHeight() + 8);
if (mTabbedArea != NULL)
- {
mTabbedArea->adjustTabPositions();
- }
}
void Tab::setTabbedArea(TabbedArea* tabbedArea)
@@ -124,7 +122,8 @@ namespace gcn
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(getWidth() - 1, 1,
+ getWidth() - 1, getHeight() - 1);
borderColor = highlightColor;
baseColor = getBaseColor();
@@ -135,7 +134,8 @@ namespace gcn
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);
+ graphics->drawLine(getWidth() - 1, 1, getWidth() - 1,
+ getHeight() - 1);
baseColor = getBaseColor() - 0x151515;
baseColor.a = alpha;
@@ -143,14 +143,13 @@ namespace gcn
// 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));
+ 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));
+ graphics->fillRectangle(Rectangle(0, 0,
+ currentClipArea.width, currentClipArea.height));
drawChildren(graphics);
@@ -159,10 +158,8 @@ namespace gcn
&& mTabbedArea->isTabSelected(this))
{
graphics->setColor(Color(0x000000));
- graphics->drawRectangle(Rectangle(2,
- 2,
- currentClipArea.width - 4,
- currentClipArea.height - 4));
+ graphics->drawRectangle(Rectangle(2, 2,
+ currentClipArea.width - 4, currentClipArea.height - 4));
}
graphics->popClipArea();
diff --git a/src/guichan/widgets/tabbedarea.cpp b/src/guichan/widgets/tabbedarea.cpp
index e07d14c4d..d430a76a3 100644
--- a/src/guichan/widgets/tabbedarea.cpp
+++ b/src/guichan/widgets/tabbedarea.cpp
@@ -59,9 +59,9 @@
namespace gcn
{
- TabbedArea::TabbedArea()
- :mSelectedTab(NULL),
- mOpaque(false)
+ TabbedArea::TabbedArea() :
+ mSelectedTab(NULL),
+ mOpaque(false)
{
setFocusable(true);
addKeyListener(this);
@@ -84,9 +84,7 @@ namespace gcn
delete mWidgetContainer;
for (unsigned int i = 0; i < mTabsToDelete.size(); i++)
- {
delete mTabsToDelete[i];
- }
}
void TabbedArea::addTab(const std::string& caption, Widget* widget)
@@ -107,9 +105,7 @@ namespace gcn
mTabs.push_back(std::pair<Tab*, Widget*>(tab, widget));
if (mSelectedTab == NULL)
- {
setSelectedTab(tab);
- }
adjustTabPositions();
adjustSize();
@@ -118,9 +114,7 @@ namespace gcn
void TabbedArea::removeTabWithIndex(unsigned int index)
{
if (index >= mTabs.size())
- {
throw GCN_EXCEPTION("No such tab index.");
- }
removeTab(mTabs[index].first);
}
@@ -150,7 +144,7 @@ namespace gcn
}
std::vector<std::pair<Tab*, Widget*> >::iterator iter;
- for (iter = mTabs.begin(); iter != mTabs.end(); iter++)
+ for (iter = mTabs.begin(); iter != mTabs.end(); ++ iter)
{
if (iter->first == tab)
{
@@ -161,7 +155,9 @@ namespace gcn
}
std::vector<Tab*>::iterator iter2;
- for (iter2 = mTabsToDelete.begin(); iter2 != mTabsToDelete.end(); iter2++)
+ for (iter2 = mTabsToDelete.begin();
+ iter2 != mTabsToDelete.end();
+ ++ iter2)
{
if (*iter2 == tab)
{
@@ -188,9 +184,7 @@ namespace gcn
bool TabbedArea::isTabSelected(unsigned int index) const
{
if (index >= mTabs.size())
- {
throw GCN_EXCEPTION("No such tab index.");
- }
return mSelectedTab == mTabs[index].first;
}
@@ -203,9 +197,7 @@ namespace gcn
void TabbedArea::setSelectedTab(unsigned int index)
{
if (index >= mTabs.size())
- {
throw GCN_EXCEPTION("No such tab index.");
- }
setSelectedTab(mTabs[index].first);
}
@@ -216,9 +208,7 @@ namespace gcn
for (i = 0; i < mTabs.size(); i++)
{
if (mTabs[i].first == mSelectedTab)
- {
mWidgetContainer->remove(mTabs[i].second);
- }
}
for (i = 0; i < mTabs.size(); i++)
@@ -237,9 +227,7 @@ namespace gcn
for (i = 0; i < mTabs.size(); i++)
{
if (mTabs[i].first == mSelectedTab)
- {
return i;
- }
}
return -1;
@@ -295,10 +283,8 @@ namespace gcn
// Draw a line underneath the tabs.
graphics->setColor(highlightColor);
- graphics->drawLine(1,
- mTabContainer->getHeight(),
- getWidth() - 1,
- mTabContainer->getHeight());
+ graphics->drawLine(1, mTabContainer->getHeight(),
+ getWidth() - 1, mTabContainer->getHeight());
// If a tab is selected, remove the line right underneath
// the selected tab.
@@ -306,9 +292,9 @@ namespace gcn
{
graphics->setColor(getBaseColor());
graphics->drawLine(mSelectedTab->getX() + 1,
- mTabContainer->getHeight(),
- mSelectedTab->getX() + mSelectedTab->getWidth() - 2,
- mTabContainer->getHeight());
+ mTabContainer->getHeight(),
+ mSelectedTab->getX() + mSelectedTab->getWidth() - 2,
+ mTabContainer->getHeight());
}
@@ -326,17 +312,14 @@ namespace gcn
for (unsigned int i = 0; i < mTabs.size(); i++)
{
if (mTabs[i].first->getHeight() > maxTabHeight)
- {
maxTabHeight = mTabs[i].first->getHeight();
- }
}
- mTabContainer->setSize(getWidth() - 2,
- maxTabHeight);
+ mTabContainer->setSize(getWidth() - 2, maxTabHeight);
mWidgetContainer->setPosition(1, maxTabHeight + 1);
mWidgetContainer->setSize(getWidth() - 2,
- getHeight() - maxTabHeight - 2);
+ getHeight() - maxTabHeight - 2);
}
void TabbedArea::adjustTabPositions()
@@ -346,9 +329,7 @@ namespace gcn
for (i = 0; i < mTabs.size(); i++)
{
if (mTabs[i].first->getHeight() > maxTabHeight)
- {
maxTabHeight = mTabs[i].first->getHeight();
- }
}
int x = 0;
@@ -387,9 +368,7 @@ namespace gcn
void TabbedArea::keyPressed(KeyEvent& keyEvent)
{
if (keyEvent.isConsumed() || !isFocused())
- {
return;
- }
if (keyEvent.getKey().getValue() == Key::LEFT)
{
@@ -397,13 +376,9 @@ namespace gcn
index--;
if (index < 0)
- {
return;
- }
else
- {
setSelectedTab(mTabs[index].first);
- }
keyEvent.consume();
}
@@ -413,13 +388,9 @@ namespace gcn
index++;
if (index >= (int)mTabs.size())
- {
return;
- }
else
- {
setSelectedTab(mTabs[index].first);
- }
keyEvent.consume();
}
@@ -429,28 +400,23 @@ namespace gcn
void TabbedArea::mousePressed(MouseEvent& mouseEvent)
{
if (mouseEvent.isConsumed())
- {
return;
- }
if (mouseEvent.getButton() == MouseEvent::LEFT)
{
- Widget* widget = mTabContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY());
+ Widget* widget = mTabContainer->getWidgetAt(
+ mouseEvent.getX(), mouseEvent.getY());
Tab* tab = dynamic_cast<Tab*>(widget);
if (tab != NULL)
- {
setSelectedTab(tab);
- }
}
// Request focus only if the source of the event
// is not focusble. If the source of the event
// is focused we don't want to steal the focus.
if (!mouseEvent.getSource()->isFocusable())
- {
requestFocus();
- }
}
void TabbedArea::death(const Event& event)
@@ -458,13 +424,9 @@ namespace gcn
Tab* tab = dynamic_cast<Tab*>(event.getSource());
if (tab != NULL)
- {
removeTab(tab);
- }
else
- {
BasicContainer::death(event);
- }
}
void TabbedArea::action(const ActionEvent& actionEvent)
@@ -474,7 +436,8 @@ namespace gcn
if (tab == NULL)
{
- throw GCN_EXCEPTION("Received an action from a widget that's not a tab!");
+ throw GCN_EXCEPTION("Received an action from a "
+ "widget that's not a tab!");
}
setSelectedTab(tab);
diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp
index c57296f9c..55858f7c5 100644
--- a/src/guichan/widgets/textbox.cpp
+++ b/src/guichan/widgets/textbox.cpp
@@ -101,13 +101,9 @@ namespace gcn
pos = text.find("\n", lastPos);
if (pos != std::string::npos)
- {
length = pos - lastPos;
- }
else
- {
length = text.size() - lastPos;
- }
std::string sub = text.substr(lastPos, length);
mTextRows.push_back(sub);
lastPos = pos + 1;
@@ -129,7 +125,9 @@ namespace gcn
if (isFocused() && isEditable())
{
- drawCaret(graphics, getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)), mCaretRow * getFont()->getHeight());
+ drawCaret(graphics, getFont()->getWidth(
+ mTextRows[mCaretRow].substr(0, mCaretColumn)),
+ mCaretRow * getFont()->getHeight());
}
graphics->setColor(getForegroundColor());
@@ -155,11 +153,10 @@ namespace gcn
mCaretRow = mouseEvent.getY() / getFont()->getHeight();
if (mCaretRow >= (int)mTextRows.size())
- {
mCaretRow = mTextRows.size() - 1;
- }
- mCaretColumn = getFont()->getStringIndexAt(mTextRows[mCaretRow], mouseEvent.getX());
+ mCaretColumn = getFont()->getStringIndexAt(
+ mTextRows[mCaretRow], mouseEvent.getX());
}
}
@@ -190,7 +187,6 @@ namespace gcn
}
}
}
-
else if (key.getValue() == Key::RIGHT)
{
++mCaretColumn;
@@ -202,9 +198,7 @@ namespace gcn
{
mCaretRow = mTextRows.size() - 1;
if (mCaretRow < 0)
- {
mCaretRow = 0;
- }
mCaretColumn = mTextRows[mCaretRow].size();
}
@@ -214,36 +208,31 @@ namespace gcn
}
}
}
-
else if (key.getValue() == Key::DOWN)
{
setCaretRow(mCaretRow + 1);
}
-
else if (key.getValue() == Key::UP)
{
setCaretRow(mCaretRow - 1);
}
-
else if (key.getValue() == Key::HOME)
{
mCaretColumn = 0;
}
-
else if (key.getValue() == Key::END)
{
mCaretColumn = mTextRows[mCaretRow].size();
}
-
else if (key.getValue() == Key::ENTER && mEditable)
{
mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
- mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn));
+ mTextRows[mCaretRow].substr(mCaretColumn,
+ mTextRows[mCaretRow].size() - mCaretColumn));
mTextRows[mCaretRow].resize(mCaretColumn);
++mCaretRow;
mCaretColumn = 0;
}
-
else if (key.getValue() == Key::BACKSPACE
&& mCaretColumn != 0
&& mEditable)
@@ -251,7 +240,6 @@ namespace gcn
mTextRows[mCaretRow].erase(mCaretColumn - 1, 1);
--mCaretColumn;
}
-
else if (key.getValue() == Key::BACKSPACE
&& mCaretColumn == 0
&& mCaretRow != 0
@@ -262,14 +250,12 @@ namespace gcn
mTextRows.erase(mTextRows.begin() + mCaretRow);
--mCaretRow;
}
-
else if (key.getValue() == Key::DELETE
&& mCaretColumn < (int)mTextRows[mCaretRow].size()
&& mEditable)
{
mTextRows[mCaretRow].erase(mCaretColumn, 1);
}
-
else if (key.getValue() == Key::DELETE
&& mCaretColumn == (int)mTextRows[mCaretRow].size()
&& mCaretRow < ((int)mTextRows.size() - 1)
@@ -278,51 +264,46 @@ namespace gcn
mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
}
-
- else if(key.getValue() == Key::PAGE_UP)
+ else if (key.getValue() == Key::PAGE_UP)
{
Widget* par = getParent();
if (par != NULL)
{
- int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
+ int rowsPerPage = par->getChildrenArea().height
+ / getFont()->getHeight();
mCaretRow -= rowsPerPage;
if (mCaretRow < 0)
- {
mCaretRow = 0;
- }
}
}
-
- else if(key.getValue() == Key::PAGE_DOWN)
+ else if (key.getValue() == Key::PAGE_DOWN)
{
Widget* par = getParent();
if (par != NULL)
{
- int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
+ int rowsPerPage = par->getChildrenArea().height
+ / getFont()->getHeight();
mCaretRow += rowsPerPage;
if (mCaretRow >= (int)mTextRows.size())
- {
mCaretRow = mTextRows.size() - 1;
- }
}
}
-
- else if(key.getValue() == Key::TAB
- && mEditable)
+ else if (key.getValue() == Key::TAB
+ && mEditable)
{
- mTextRows[mCaretRow].insert(mCaretColumn,std::string(" "));
+ mTextRows[mCaretRow].insert(mCaretColumn, std::string(" "));
mCaretColumn += 4;
}
-
else if (key.isCharacter()
&& mEditable)
{
- mTextRows[mCaretRow].insert(mCaretColumn,std::string(1,(char)key.getValue()));
- ++mCaretColumn;
+ mTextRows[mCaretRow].insert(mCaretColumn,
+ std::string(1, (char)key.getValue()));
+ ++ mCaretColumn;
}
adjustSize();
@@ -339,9 +320,7 @@ namespace gcn
{
int w = getFont()->getWidth(mTextRows[i]);
if (width < w)
- {
width = w;
- }
}
setWidth(width + 1);
@@ -376,9 +355,7 @@ namespace gcn
int pos = 0, row;
for (row = 0; row < mCaretRow; row++)
- {
pos += mTextRows[row].size();
- }
return pos + mCaretColumn;
}
@@ -394,14 +371,10 @@ namespace gcn
mCaretRow = row;
if (mCaretRow >= (int)mTextRows.size())
- {
mCaretRow = mTextRows.size() - 1;
- }
if (mCaretRow < 0)
- {
mCaretRow = 0;
- }
setCaretColumn(mCaretColumn);
}
@@ -416,14 +389,10 @@ namespace gcn
mCaretColumn = column;
if (mCaretColumn > (int)mTextRows[mCaretRow].size())
- {
mCaretColumn = mTextRows[mCaretRow].size();
- }
if (mCaretColumn < 0)
- {
mCaretColumn = 0;
- }
}
unsigned int TextBox::getCaretColumn() const
@@ -441,9 +410,7 @@ namespace gcn
mTextRows[row] = text;
if (mCaretRow == row)
- {
setCaretColumn(mCaretColumn);
- }
adjustSize();
}
@@ -455,18 +422,14 @@ namespace gcn
std::string TextBox::getText() const
{
- if (mTextRows.size() == 0)
- {
+ if (mTextRows.empty())
return std::string("");
- }
int i;
std::string text;
for (i = 0; i < (int)mTextRows.size() - 1; ++i)
- {
text = text + mTextRows[i] + "\n";
- }
text = text + mTextRows[i];
@@ -481,10 +444,13 @@ namespace gcn
void TextBox::scrollToCaret()
{
Rectangle scroll;
- scroll.x = getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn));
+ scroll.x = getFont()->getWidth(
+ mTextRows[mCaretRow].substr(0, mCaretColumn));
scroll.y = getFont()->getHeight() * mCaretRow;
scroll.width = getFont()->getWidth(" ");
- scroll.height = getFont()->getHeight() + 2; // add 2 for some extra space
+
+ // add 2 for some extra space
+ scroll.height = getFont()->getHeight() + 2;
showPart(scroll);
}
diff --git a/src/guichan/widgets/textfield.cpp b/src/guichan/widgets/textfield.cpp
index e8fc9c5d6..7f4325529 100644
--- a/src/guichan/widgets/textfield.cpp
+++ b/src/guichan/widgets/textfield.cpp
@@ -81,10 +81,8 @@ namespace gcn
void TextField::setText(const std::string& text)
{
- if(text.size() < mCaretPosition )
- {
+ if (text.size() < mCaretPosition)
mCaretPosition = text.size();
- }
mText = text;
}
@@ -105,11 +103,13 @@ namespace gcn
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);
+ 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->pushClipArea(Rectangle(1, 1,
+ getWidth() - 2, getHeight() - 2));
graphics->setColor(getBackgroundColor());
graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight()));
@@ -117,13 +117,16 @@ namespace gcn
if (isFocused())
{
graphics->setColor(getSelectionColor());
- graphics->drawRectangle(Rectangle(0, 0, getWidth() - 2, getHeight() - 2));
- graphics->drawRectangle(Rectangle(1, 1, getWidth() - 4, getHeight() - 4));
+ graphics->drawRectangle(Rectangle(0, 0,
+ getWidth() - 2, getHeight() - 2));
+ graphics->drawRectangle(Rectangle(1, 1,
+ getWidth() - 4, getHeight() - 4));
}
if (isFocused())
{
- drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll);
+ drawCaret(graphics, getFont()->getWidth(
+ mText.substr(0, mCaretPosition)) - mXScroll);
}
graphics->setColor(getForegroundColor());
@@ -149,7 +152,8 @@ namespace gcn
{
if (mouseEvent.getButton() == MouseEvent::LEFT)
{
- mCaretPosition = getFont()->getStringIndexAt(mText, mouseEvent.getX() + mXScroll);
+ mCaretPosition = getFont()->getStringIndexAt(
+ mText, mouseEvent.getX() + mXScroll);
fixScroll();
}
}
@@ -167,50 +171,42 @@ namespace gcn
{
--mCaretPosition;
}
-
else if (key.getValue() == Key::RIGHT && mCaretPosition < mText.size())
{
++mCaretPosition;
}
-
- else if (key.getValue() == Key::DELETE && mCaretPosition < mText.size())
+ else if (key.getValue() == Key::DELETE
+ && mCaretPosition < mText.size())
{
mText.erase(mCaretPosition, 1);
}
-
else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0)
{
mText.erase(mCaretPosition - 1, 1);
--mCaretPosition;
}
-
else if (key.getValue() == Key::ENTER)
{
distributeActionEvent();
}
-
else if (key.getValue() == Key::HOME)
{
mCaretPosition = 0;
}
-
else if (key.getValue() == Key::END)
{
mCaretPosition = mText.size();
}
-
else if (key.isCharacter()
&& key.getValue() != Key::TAB)
{
- mText.insert(mCaretPosition, std::string(1,(char)key.getValue()));
+ mText.insert(mCaretPosition, std::string(1, (char)key.getValue()));
++mCaretPosition;
}
if (key.getValue() != Key::TAB)
- {
keyEvent.consume();
- }
-
+
fixScroll();
}
@@ -242,9 +238,7 @@ namespace gcn
mXScroll = caretX - getWidth() / 2;
if (mXScroll < 0)
- {
mXScroll = 0;
- }
}
}
}
@@ -252,13 +246,9 @@ namespace gcn
void TextField::setCaretPosition(unsigned int position)
{
if (position > mText.size())
- {
mCaretPosition = mText.size();
- }
else
- {
mCaretPosition = position;
- }
fixScroll();
}
diff --git a/src/guichan/widgets/window.cpp b/src/guichan/widgets/window.cpp
index d73d2339b..f3aca23d0 100644
--- a/src/guichan/widgets/window.cpp
+++ b/src/guichan/widgets/window.cpp
@@ -54,8 +54,8 @@
namespace gcn
{
- Window::Window()
- :mMoved(false)
+ Window::Window() :
+ mMoved(false)
{
setFrameSize(1);
setPadding(2);
@@ -66,8 +66,8 @@ namespace gcn
setOpaque(true);
}
- Window::Window(const std::string& caption)
- :mMoved(false)
+ Window::Window(const std::string& caption) :
+ mMoved(false)
{
setCaption(caption);
setFrameSize(1);
@@ -138,24 +138,19 @@ namespace gcn
// Fill the background around the content
graphics->setColor(faceColor);
// Fill top
- graphics->fillRectangle(Rectangle(0,0,getWidth(),d.y - 1));
+ graphics->fillRectangle(Rectangle(0, 0, getWidth(), d.y - 1));
// Fill left
- graphics->fillRectangle(Rectangle(0,d.y - 1, d.x - 1, getHeight() - d.y + 1));
+ graphics->fillRectangle(Rectangle(0, d.y - 1, d.x - 1,
+ getHeight() - d.y + 1));
// Fill right
- graphics->fillRectangle(Rectangle(d.x + d.width + 1,
- d.y - 1,
- getWidth() - d.x - d.width - 1,
- getHeight() - d.y + 1));
+ graphics->fillRectangle(Rectangle(d.x + d.width + 1, d.y - 1,
+ getWidth() - d.x - d.width - 1, getHeight() - d.y + 1));
// Fill bottom
- graphics->fillRectangle(Rectangle(d.x - 1,
- d.y + d.height + 1,
- d.width + 2,
- getHeight() - d.height - d.y - 1));
+ graphics->fillRectangle(Rectangle(d.x - 1, d.y + d.height + 1,
+ d.width + 2, getHeight() - d.height - d.y - 1));
if (isOpaque())
- {
graphics->fillRectangle(d);
- }
// Construct a rectangle one pixel bigger than the content
d.x -= 1;
@@ -198,22 +193,23 @@ namespace gcn
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.");
+ 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->setColor(getForegroundColor());
graphics->setFont(getFont());
- graphics->pushClipArea(Rectangle(0, 0, getWidth(), getTitleBarHeight() - 1));
+ graphics->pushClipArea(Rectangle(0, 0, getWidth(),
+ getTitleBarHeight() - 1));
graphics->drawText(getCaption(), textX, textY, getAlignment());
graphics->popClipArea();
}
@@ -221,14 +217,10 @@ namespace gcn
void Window::mousePressed(MouseEvent& mouseEvent)
{
if (mouseEvent.getSource() != this)
- {
return;
- }
if (getParent() != NULL)
- {
getParent()->moveToTop(this);
- }
mDragOffsetX = mouseEvent.getX();
mDragOffsetY = mouseEvent.getY();
@@ -244,9 +236,7 @@ namespace gcn
void Window::mouseDragged(MouseEvent& mouseEvent)
{
if (mouseEvent.isConsumed() || mouseEvent.getSource() != this)
- {
return;
- }
if (isMovable() && mMoved)
{
@@ -293,14 +283,10 @@ namespace gcn
for (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());