From 2c7d0b3518d72a7ab0726b72f7d2137e5944f049 Mon Sep 17 00:00:00 2001 From: Björn Steinbrink Date: Thu, 25 Aug 2005 18:06:19 +0000 Subject: Made our drawImage() method respect the clip area from the guichan graphics part. Removed some (now) obsolete code. Fixed compilation errors. --- src/gui/button.cpp | 5 +---- src/gui/checkbox.cpp | 7 +------ src/gui/equipmentwindow.cpp | 8 ++------ src/gui/itemcontainer.cpp | 6 ++---- src/gui/minimap.cpp | 5 +---- src/gui/passwordfield.cpp | 8 ++------ src/gui/playerbox.cpp | 39 +++++++++++++++++---------------------- src/gui/progressbar.cpp | 5 +---- src/gui/radiobutton.cpp | 7 +------ src/gui/scrollarea.cpp | 21 ++++++--------------- src/gui/slider.cpp | 16 ++++------------ src/gui/textfield.cpp | 12 ++---------- src/gui/window.cpp | 11 +++-------- 13 files changed, 43 insertions(+), 107 deletions(-) (limited to 'src/gui') diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 680a9152..b2468036 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -112,10 +112,7 @@ void Button::draw(gcn::Graphics* graphics) mode = 0; } - int x, y; - getAbsolutePosition(x, y); - - dynamic_cast(graphics)->drawImageRect(x, y, getWidth(), getHeight(), + dynamic_cast(graphics)->drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); graphics->setColor(getForegroundColor()); diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp index ce7762d9..7506d3c0 100644 --- a/src/gui/checkbox.cpp +++ b/src/gui/checkbox.cpp @@ -68,9 +68,6 @@ CheckBox::~CheckBox() void CheckBox::drawBox(gcn::Graphics* graphics) { Image *box = NULL; - int x, y; - - getAbsolutePosition(x, y); if (mMarked) { if (isEnabled()) { @@ -84,9 +81,7 @@ void CheckBox::drawBox(gcn::Graphics* graphics) box = checkBoxDisabled; } - x += 2; - y += 2; if (box != NULL) { - dynamic_cast(graphics)->drawImage(box, x, y); + dynamic_cast(graphics)->drawImage(box, 2, 2); } } diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 0aeb58e4..5ed0c189 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -54,9 +54,6 @@ EquipmentWindow::~EquipmentWindow() void EquipmentWindow::draw(gcn::Graphics *graphics) { - int x, y; - getAbsolutePosition(x, y); - // Draw window graphics Window::draw(graphics); @@ -75,7 +72,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) image = itemset->spriteset[item->getInfo()->getImage() - 1]; dynamic_cast(graphics)->drawImage( - image, x + 36 * (i % 4) + 10, y + 36 * (i / 4) + 25); + image, 36 * (i % 4) + 10, 36 * (i / 4) + 25); } graphics->setColor(gcn::Color(0, 0, 0)); @@ -87,8 +84,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) image = itemset->spriteset[item->getInfo()->getImage() - 1]; - dynamic_cast(graphics)->drawImage( - image, x + 160, y + 25); + dynamic_cast(graphics)->drawImage(image, 160, 25); std::stringstream n; n << item->getQuantity(); graphics->drawText(n.str(), 170, 62, diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index e2eb6085..7c7baddc 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -78,8 +78,6 @@ void ItemContainer::draw(gcn::Graphics* graphics) int gridHeight = itemset->spriteset[0]->getHeight() + 10; int w = getWidth(); int columns = w / gridWidth; - int x, y; - getAbsolutePosition(x, y); // Have at least 1 column if (columns < 1) @@ -113,7 +111,7 @@ void ItemContainer::draw(gcn::Graphics* graphics) if (selectedItem == item) { dynamic_cast(graphics)->drawImage( - selImg, x + itemX, y + itemY); + selImg, itemX, itemY); } // Draw item icon @@ -121,7 +119,7 @@ void ItemContainer::draw(gcn::Graphics* graphics) if ((idx = item->getInfo()->getImage()) > 0) { dynamic_cast(graphics)->drawImage( - itemset->spriteset[idx - 1], x + itemX, y + itemY); + itemset->spriteset[idx - 1], itemX, itemY); } // Draw item caption diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 7b2367c0..6e8d8a04 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -73,13 +73,10 @@ void Minimap::draw(gcn::Graphics *graphics) { Window::draw(graphics); - int x, y; - getAbsolutePosition(x, y); - if (mMapImage != NULL) { dynamic_cast(graphics)->drawImage( - mMapImage, x + getPadding(), y + getTitleBarHeight()); + mMapImage, getPadding(), getTitleBarHeight()); } std::list::iterator bi; diff --git a/src/gui/passwordfield.cpp b/src/gui/passwordfield.cpp index 29ddb86b..51316fa8 100644 --- a/src/gui/passwordfield.cpp +++ b/src/gui/passwordfield.cpp @@ -31,14 +31,10 @@ PasswordField::PasswordField(const std::string& text): void PasswordField::draw(gcn::Graphics *graphics) { - int x, y, w, h; - getAbsolutePosition(x, y); - w = getWidth(); - h = getHeight(); std::string stars; stars.assign(mText.length(), '*'); - if (hasFocus()) { + if (hasFocus()) { drawCaret(graphics, getFont()->getWidth(stars.substr(0, mCaretPosition)) - mXScroll); @@ -46,5 +42,5 @@ void PasswordField::draw(gcn::Graphics *graphics) graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); - graphics->drawText(stars, 1 - mXScroll, 1); + graphics->drawText(stars, 1 - mXScroll, 1); } diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index 169c37fc..b1414ef8 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -83,37 +83,32 @@ PlayerBox::~PlayerBox() void PlayerBox::draw(gcn::Graphics *graphics) { - if (showPlayer) + if (!showPlayer) { + return; + } + + // Draw character + dynamic_cast(graphics)->drawImage( + playerset->spriteset[0], 23, 23); + + // Draw his hair + if (hairColor >= 0 && hairStyle >= 0 && + hairColor < NR_HAIR_COLORS && hairStyle < NR_HAIR_STYLES) { - int x, y; - getAbsolutePosition(x, y); - - // Draw character - dynamic_cast(graphics)->drawImage( - playerset->spriteset[0], x + 23, y + 23); - - // Draw his hair - if (hairColor >= 0 && hairStyle >= 0 && - hairColor < NR_HAIR_COLORS && hairStyle < NR_HAIR_STYLES) - { - int hf = hairColor + 40 * (hairStyle); - if (hf >= 0 && hf < (int)hairset->spriteset.size()) { - dynamic_cast(graphics)->drawImage( - hairset->spriteset[hf], x + 37, y + 5); - } + int hf = hairColor + 40 * (hairStyle); + if (hf >= 0 && hf < (int)hairset->spriteset.size()) { + dynamic_cast(graphics)->drawImage( + hairset->spriteset[hf], 37, 5); } } } void PlayerBox::drawBorder(gcn::Graphics *graphics) { - int x, y, w, h, bs; - getAbsolutePosition(x, y); + int w, h, bs; bs = getBorderSize(); w = getWidth() + bs * 2; h = getHeight() + bs * 2; - x -= bs; - y -= bs; - dynamic_cast(graphics)->drawImageRect(x, y, w, h, background); + dynamic_cast(graphics)->drawImageRect(0, 0, w, h, background); } diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 26933e22..834ca73a 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -98,10 +98,7 @@ void ProgressBar::logic() void ProgressBar::draw(gcn::Graphics *graphics) { - int x, y; - getAbsolutePosition(x, y); - - dynamic_cast(graphics)->drawImageRect(x, y, getWidth(), getHeight(), + dynamic_cast(graphics)->drawImageRect(0, 0, getWidth(), getHeight(), mBorder); // The bar diff --git a/src/gui/radiobutton.cpp b/src/gui/radiobutton.cpp index d3358604..bbebe48f 100644 --- a/src/gui/radiobutton.cpp +++ b/src/gui/radiobutton.cpp @@ -66,9 +66,6 @@ RadioButton::~RadioButton() void RadioButton::drawBox(gcn::Graphics* graphics) { Image *box = NULL; - int x, y; - - getAbsolutePosition(x, y); if (mMarked) { if (isEnabled()) { @@ -82,9 +79,7 @@ void RadioButton::drawBox(gcn::Graphics* graphics) box = radioDisabled; } - x += 2; - y += 2; if (box != NULL) { - dynamic_cast(graphics)->drawImage(box, x, y); + dynamic_cast(graphics)->drawImage(box, 2, 2); } } diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 6bc428e2..ec8a7946 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -216,16 +216,13 @@ void ScrollArea::draw(gcn::Graphics *graphics) void ScrollArea::drawBorder(gcn::Graphics *graphics) { - int x, y, w, h, bs; - getAbsolutePosition(x, y); + int w, h, bs; bs = getBorderSize(); w = getWidth() + bs * 2; h = getHeight() + bs * 2; - x -= bs; - y -= bs; if (isOpaque()) { - dynamic_cast(graphics)->drawImageRect(x, y, w, h, background); + dynamic_cast(graphics)->drawImageRect(0, 0, w, h, background); } } @@ -248,11 +245,9 @@ bool ScrollArea::isOpaque() void ScrollArea::drawButton(gcn::Graphics *graphics, BUTTON_DIR dir) { - int x, y, state = 0; + int state = 0; gcn::Rectangle dim; - getAbsolutePosition(x,y); - switch(dir) { case UP: state = mUpButtonPressed ? 1 : 0; @@ -273,7 +268,7 @@ void ScrollArea::drawButton(gcn::Graphics *graphics, BUTTON_DIR dir) } dynamic_cast(graphics)->drawImage( - buttons[dir][state], x + dim.x, y + dim.y); + buttons[dir][state], dim.x, dim.y); } void ScrollArea::drawUpButton(gcn::Graphics *graphics) @@ -314,20 +309,16 @@ void ScrollArea::drawHBar(gcn::Graphics *graphics) void ScrollArea::drawVMarker(gcn::Graphics *graphics) { - int x, y; gcn::Rectangle dim = getVerticalMarkerDimension(); - getAbsolutePosition(x, y); dynamic_cast(graphics)->drawImageRect( - x + dim.x, y + dim.y, dim.width, dim.height, vMarker); + dim.x, dim.y, dim.width, dim.height, vMarker); } void ScrollArea::drawHMarker(gcn::Graphics *graphics) { - int x, y; gcn::Rectangle dim = getHorizontalMarkerDimension(); - getAbsolutePosition(x, y); dynamic_cast(graphics)->drawImageRect( - x + dim.x, y + dim.y, dim.width, dim.height, vMarker); + dim.x, dim.y, dim.width, dim.height, vMarker); } diff --git a/src/gui/slider.cpp b/src/gui/slider.cpp index 088b2794..98efc409 100644 --- a/src/gui/slider.cpp +++ b/src/gui/slider.cpp @@ -106,10 +106,8 @@ void Slider::draw(gcn::Graphics *graphics) { int w = getWidth(); int h = getHeight(); - int x, y; - getAbsolutePosition(x, y); - - y += (h - hStart->getHeight()) / 2; + int x = 0; + int y = (h - hStart->getHeight()) / 2; dynamic_cast(graphics)->drawImage(hStart, x, y); @@ -127,12 +125,6 @@ void Slider::draw(gcn::Graphics *graphics) void Slider::drawMarker(gcn::Graphics *graphics) { - int h = getHeight(); - int x, y; - getAbsolutePosition(x, y); - - x += getMarkerPosition(); - y += (h - hGrip->getHeight()) / 2; - - dynamic_cast(graphics)->drawImage(hGrip, x, y); + dynamic_cast(graphics)->drawImage(hGrip, + getMarkerPosition(), (getHeight() - hGrip->getHeight()) / 2); } diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index 94ab856e..5055c328 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -80,11 +80,6 @@ TextField::~TextField() void TextField::draw(gcn::Graphics *graphics) { - int x, y, w, h; - getAbsolutePosition(x, y); - w = getWidth(); - h = getHeight(); - if (hasFocus()) { drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - @@ -98,13 +93,10 @@ void TextField::draw(gcn::Graphics *graphics) void TextField::drawBorder(gcn::Graphics *graphics) { - int x, y, w, h, bs; - getAbsolutePosition(x, y); + int w, h, bs; bs = getBorderSize(); w = getWidth() + bs * 2; h = getHeight() + bs * 2; - x -= bs; - y -= bs; - dynamic_cast(graphics)->drawImageRect(x, y, w, h, skin); + dynamic_cast(graphics)->drawImageRect(0, 0, w, h, skin); } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index f59e6438..4184f17a 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -134,18 +134,15 @@ void Window::setWindowContainer(WindowContainer *wc) void Window::draw(gcn::Graphics* graphics) { - int x, y; - getAbsolutePosition(x, y); - - dynamic_cast(graphics)->drawImageRect(x, y, getWidth(), getHeight(), + dynamic_cast(graphics)->drawImageRect(0, 0, getWidth(), getHeight(), border); // Draw grip if (resizable) { dynamic_cast(graphics)->drawImage(Window::resizeGrip, - x + getWidth() - resizeGrip->getWidth(), - y + getHeight() - resizeGrip->getHeight()); + getWidth() - resizeGrip->getWidth(), + getHeight() - resizeGrip->getHeight()); } // Draw title @@ -393,8 +390,6 @@ void Window::optionChanged(const std::string &name) gcn::Rectangle Window::getGripDimension () { - int x, y; - getAbsolutePosition(x, y); return gcn::Rectangle(getWidth() - resizeGrip->getWidth(), getHeight() - resizeGrip->getHeight(), getWidth(), getHeight()); } -- cgit v1.2.3-60-g2f50