summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-07-26 22:33:53 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-07-26 22:33:53 +0000
commit9e4f25acd69489d949104eebec690ce5586849e6 (patch)
treedc4fe4483ece1a374bc44280c72e43cfd5725feb /src/gui
parent34e18a818a7696629515c39b920ba35b64832748 (diff)
downloadmana-9e4f25acd69489d949104eebec690ce5586849e6.tar.gz
mana-9e4f25acd69489d949104eebec690ce5586849e6.tar.bz2
mana-9e4f25acd69489d949104eebec690ce5586849e6.tar.xz
mana-9e4f25acd69489d949104eebec690ce5586849e6.zip
OpenGL/SDL combined in the same exe. Not in the cutest way, but we'll find a
nicer approach after the release.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/browserbox.cpp69
-rw-r--r--src/gui/button.cpp4
-rw-r--r--src/gui/gui.cpp30
-rw-r--r--src/gui/listbox.cpp12
-rw-r--r--src/gui/minimap.cpp10
-rw-r--r--src/gui/playerbox.cpp2
-rw-r--r--src/gui/progressbar.cpp11
-rw-r--r--src/gui/scrollarea.cpp69
-rw-r--r--src/gui/textfield.cpp2
-rw-r--r--src/gui/window.cpp2
10 files changed, 157 insertions, 54 deletions
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp
index c4d063ea..56539455 100644
--- a/src/gui/browserbox.cpp
+++ b/src/gui/browserbox.cpp
@@ -22,11 +22,10 @@
*/
#include <guichan.hpp>
+#include "../graphics.h"
#include "../main.h"
#include "browserbox.h"
-#ifndef USE_OPENGL
#include "gui.h"
-#endif
int BrowserBox::instances = 0;
gcn::ImageFont* BrowserBox::browserFont;
@@ -44,14 +43,16 @@ BrowserBox::BrowserBox(unsigned int mode):
if (instances == 0)
{
-#ifdef USE_OPENGL
- browserFont = new gcn::ImageFont(
- TMW_DATADIR "data/graphics/gui/browserfont.png",
- " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567"
- "89:@!\"$%&/=?^+*#[]{}()<>_;'.,\\|-~`");
-#else
- browserFont = gui->getFont();
-#endif
+ if (useOpenGL) {
+ browserFont = new gcn::ImageFont(
+ TMW_DATADIR "data/graphics/gui/browserfont.png",
+ " abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567"
+ "89:@!\"$%&/=?^+*#[]{}()<>_;'.,\\|-~`");
+ }
+ else {
+ browserFont = gui->getFont();
+ }
}
instances++;
@@ -84,7 +85,7 @@ void BrowserBox::setHighlightMode(unsigned int highMode)
{
mHighMode = highMode;
}
-
+
void BrowserBox::disableLinksAndUserColors()
{
mUseLinksAndUserColors = false;
@@ -96,10 +97,10 @@ void BrowserBox::addRow(const std::string& row)
std::string newRow;
BROWSER_LINK bLink;
int idx1, idx2, idx3;
-
+
// Use links and user defined colors
if (mUseLinksAndUserColors)
- {
+ {
// Check for links in format "@@link|Caption@@"
idx1 = tmp.find("@@");
while (idx1 >= 0)
@@ -137,7 +138,7 @@ void BrowserBox::addRow(const std::string& row)
newRow += tmp;
}
-
+
// Don't use links and user defined colors
else
{
@@ -153,7 +154,7 @@ void BrowserBox::addRow(const std::string& row)
std::string plain = newRow;
for (idx1 = plain.find("##"); idx1 >= 0; idx1 = plain.find("##"))
plain.erase(idx1, 3);
-
+
// Adjust the BrowserBox size
int w = browserFont->getWidth(plain);
if (w > getWidth())
@@ -207,20 +208,38 @@ void BrowserBox::draw(gcn::Graphics* graphics)
{
if (mOpaque)
{
- graphics->setColor(gcn::Color(BGCOLOR));
- graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
+ graphics->setColor(gcn::Color(BGCOLOR));
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
+ }
}
if (mSelectedLink >= 0)
{
if ((mHighMode == BACKGROUND) || (mHighMode == BOTH))
{
- graphics->setColor(gcn::Color(HIGHLIGHT));
- graphics->fillRectangle(gcn::Rectangle(
- mLinks[mSelectedLink].x1,
- mLinks[mSelectedLink].y1,
- mLinks[mSelectedLink].x2 - mLinks[mSelectedLink].x1,
- mLinks[mSelectedLink].y2 - mLinks[mSelectedLink].y1));
+ graphics->setColor(gcn::Color(HIGHLIGHT));
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->fillRectangle(
+ gcn::Rectangle(
+ mLinks[mSelectedLink].x1,
+ mLinks[mSelectedLink].y1,
+ mLinks[mSelectedLink].x2 - mLinks[mSelectedLink].x1,
+ mLinks[mSelectedLink].y2 - mLinks[mSelectedLink].y1
+ ));
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->fillRectangle(
+ gcn::Rectangle(
+ mLinks[mSelectedLink].x1,
+ mLinks[mSelectedLink].y1,
+ mLinks[mSelectedLink].x2 - mLinks[mSelectedLink].x1,
+ mLinks[mSelectedLink].y2 - mLinks[mSelectedLink].y1
+ ));
+ }
}
if ((mHighMode == UNDERLINE) || (mHighMode == BOTH))
@@ -342,7 +361,7 @@ void BrowserBox::draw(gcn::Graphics* graphics)
if (nextSpacePos <= 0)
{
nextSpacePos = row.size() - 1;
- }
+ }
int nextWordWidth = browserFont->getWidth(
row.substr(nextChar,
(nextSpacePos - nextChar)));
@@ -355,7 +374,7 @@ void BrowserBox::draw(gcn::Graphics* graphics)
j++;
}
}
-
+
// Wrapping looong lines (brutal force)
else if ((x + 2 * hyphenWidth) > getWidth())
{
diff --git a/src/gui/button.cpp b/src/gui/button.cpp
index 10fbe625..0fe207c7 100644
--- a/src/gui/button.cpp
+++ b/src/gui/button.cpp
@@ -105,7 +105,7 @@ void Button::draw(gcn::Graphics* graphics)
int x, y;
getAbsolutePosition(x, y);
- ((Graphics*)graphics)->drawImageRect(x, y, getWidth(), getHeight(),
+ dynamic_cast<Graphics*>(graphics)->drawImageRect(x, y, getWidth(), getHeight(),
button[mode]);
graphics->setColor(getForegroundColor());
@@ -127,7 +127,7 @@ void Button::draw(gcn::Graphics* graphics)
throw GCN_EXCEPTION("Button::draw. Uknown alignment.");
}
- graphics->setFont(getFont());
+ graphics->setFont((gcn::ImageFont*)getFont());
if (isPressed()) {
graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment());
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 3babd746..ca5c8133 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -56,7 +56,13 @@ Gui::Gui(Graphics *graphics):
{
// Set graphics
guiGraphics = graphics;
- setGraphics(graphics);
+ //setGraphics(graphics);
+ if (useOpenGL) {
+ setGraphics((gcn::OpenGLGraphics*)graphics);
+ }
+ else {
+ setGraphics((gcn::SDLGraphics*)graphics);
+ }
// Set input
guiInput = new gcn::SDLInput();
@@ -112,7 +118,7 @@ Gui::Gui(Graphics *graphics):
logger->error("Unable to load sansserif8.png!");
}
}
-
+
// Set speech font
try {
speechFont = new gcn::ImageFont(
@@ -180,7 +186,7 @@ Gui::~Gui()
delete hitRedFont;
delete hitBlueFont;
delete hitYellowFont;
-
+
if (mMouseCursor) {
mMouseCursor->decRef();
}
@@ -220,9 +226,14 @@ void Gui::logic()
void Gui::draw()
{
- guiGraphics->pushClipArea(guiTop->getDimension());
-
- guiTop->draw(guiGraphics);
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(guiGraphics)->pushClipArea(guiTop->getDimension());
+ guiTop->draw((gcn::OpenGLGraphics*)guiGraphics);
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(guiGraphics)->pushClipArea(guiTop->getDimension());
+ guiTop->draw((gcn::SDLGraphics*)guiGraphics);
+ }
int mouseX, mouseY;
Uint8 button = SDL_GetMouseState(&mouseX, &mouseY);
@@ -233,7 +244,12 @@ void Gui::draw()
guiGraphics->drawImage(mMouseCursor, mouseX - 5, mouseY - 2);
}
- guiGraphics->popClipArea();
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(guiGraphics)->popClipArea();
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(guiGraphics)->popClipArea();
+ }
}
void Gui::mousePress(int mx, int my, int button)
diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp
index b45823a6..bf80589a 100644
--- a/src/gui/listbox.cpp
+++ b/src/gui/listbox.cpp
@@ -22,6 +22,8 @@
*/
#include "listbox.h"
+#include "../graphics.h"
+#include "../main.h"
ListBox::ListBox():
gcn::ListBox()
@@ -49,10 +51,16 @@ void ListBox::draw(gcn::Graphics *graphics)
for (i = 0; i < mListModel->getNumberOfElements(); ++i)
{
if (i == mSelected) {
- graphics->fillRectangle(
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->fillRectangle(
gcn::Rectangle(0, y, getWidth(), fontHeight));
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->fillRectangle(
+ gcn::Rectangle(0, y, getWidth(), fontHeight));
+ }
}
-
+
graphics->drawText(mListModel->getElementAt(i), 1, y);
y += fontHeight;
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index c733da42..59447fd7 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -23,6 +23,7 @@
#include "minimap.h"
#include "../being.h"
+#include "../main.h"
#include "../resources/resourcemanager.h"
Minimap::Minimap():
@@ -87,9 +88,16 @@ void Minimap::draw(gcn::Graphics *graphics)
{
// Player dot
graphics->setColor(gcn::Color(209, 52, 61));
- graphics->fillRectangle(gcn::Rectangle(
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->fillRectangle(gcn::Rectangle(
being->x / 2 + getPadding() - 1,
being->y / 2 + getTitleBarHeight() - 1, 3, 3));
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->fillRectangle(gcn::Rectangle(
+ being->x / 2 + getPadding() - 1,
+ being->y / 2 + getTitleBarHeight() - 1, 3, 3));
+ }
}
else
{
diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp
index a94e7c4b..3b23f3f2 100644
--- a/src/gui/playerbox.cpp
+++ b/src/gui/playerbox.cpp
@@ -107,5 +107,5 @@ void PlayerBox::drawBorder(gcn::Graphics *graphics)
x -= bs;
y -= bs;
- ((Graphics*)graphics)->drawImageRect(x, y, w, h, background);
+ dynamic_cast<Graphics*>(graphics)->drawImageRect(x, y, w, h, background);
}
diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp
index e9e3f1b9..a1083db3 100644
--- a/src/gui/progressbar.cpp
+++ b/src/gui/progressbar.cpp
@@ -23,6 +23,7 @@
#include "progressbar.h"
#include "../graphics.h"
+#include "../main.h"
#include "../resources/resourcemanager.h"
ImageRect ProgressBar::mBorder;
@@ -96,15 +97,21 @@ void ProgressBar::draw(gcn::Graphics *graphics)
int x, y;
getAbsolutePosition(x, y);
- ((Graphics*)graphics)->drawImageRect(x, y, getWidth(), getHeight(),
+ dynamic_cast<Graphics*>(graphics)->drawImageRect(x, y, getWidth(), getHeight(),
mBorder);
// The bar
if (progress > 0)
{
graphics->setColor(gcn::Color(red, green, blue, 200));
- graphics->fillRectangle(gcn::Rectangle(4, 4,
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->fillRectangle(gcn::Rectangle(4, 4,
(int)(progress * (getWidth() - 8)), getHeight() - 8));
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->fillRectangle(gcn::Rectangle(4, 4,
+ (int)(progress * (getWidth() - 8)), getHeight() - 8));
+ }
}
}
diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp
index 863f8a85..c8524657 100644
--- a/src/gui/scrollarea.cpp
+++ b/src/gui/scrollarea.cpp
@@ -22,6 +22,7 @@
*/
#include "scrollarea.h"
+#include "../main.h"
#include "../resources/resourcemanager.h"
int ScrollArea::instances = 0;
@@ -178,16 +179,29 @@ void ScrollArea::draw(gcn::Graphics *graphics)
if (mHBarVisible && mVBarVisible)
{
graphics->setColor(getBaseColor());
- graphics->fillRectangle(gcn::Rectangle(getWidth() - mScrollbarWidth,
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->fillRectangle(gcn::Rectangle(getWidth() - mScrollbarWidth,
getHeight() - mScrollbarWidth,
mScrollbarWidth,
mScrollbarWidth));
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->fillRectangle(gcn::Rectangle(getWidth() - mScrollbarWidth,
+ getHeight() - mScrollbarWidth,
+ mScrollbarWidth,
+ mScrollbarWidth));
+ }
}
if (mContent)
{
gcn::Rectangle contdim = mContent->getDimension();
- graphics->pushClipArea(getContentDimension());
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->pushClipArea(getContentDimension());
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->pushClipArea(getContentDimension());
+ }
if (mContent->getBorderSize() > 0)
{
@@ -196,15 +210,36 @@ void ScrollArea::draw(gcn::Graphics *graphics)
rec.y -= mContent->getBorderSize();
rec.width += 2 * mContent->getBorderSize();
rec.height += 2 * mContent->getBorderSize();
- graphics->pushClipArea(rec);
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->pushClipArea(rec);
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->pushClipArea(rec);
+ }
mContent->drawBorder(graphics);
- graphics->popClipArea();
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->popClipArea();
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->popClipArea();
+ }
}
- graphics->pushClipArea(contdim);
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->pushClipArea(contdim);
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->pushClipArea(contdim);
+ }
mContent->draw(graphics);
- graphics->popClipArea();
- graphics->popClipArea();
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->popClipArea();
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->popClipArea();
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->popClipArea();
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->popClipArea();
+ }
}
}
@@ -219,7 +254,7 @@ void ScrollArea::drawBorder(gcn::Graphics *graphics)
y -= bs;
if (isOpaque()) {
- ((Graphics*)graphics)->drawImageRect(x, y, w, h, background);
+ dynamic_cast<Graphics*>(graphics)->drawImageRect(x, y, w, h, background);
}
}
@@ -294,7 +329,12 @@ void ScrollArea::drawVBar(gcn::Graphics *graphics)
{
gcn::Rectangle dim = getVerticalBarDimension();
graphics->setColor(gcn::Color(0, 0, 0, 32));
- graphics->fillRectangle(dim);
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->fillRectangle(dim);
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->fillRectangle(dim);
+ }
graphics->setColor(gcn::Color(255, 255, 255));
}
@@ -302,7 +342,12 @@ void ScrollArea::drawHBar(gcn::Graphics *graphics)
{
gcn::Rectangle dim = getHorizontalBarDimension();
graphics->setColor(gcn::Color(0, 0, 0, 32));
- graphics->fillRectangle(dim);
+ if (useOpenGL) {
+ dynamic_cast<gcn::OpenGLGraphics*>(graphics)->fillRectangle(dim);
+ }
+ else {
+ dynamic_cast<gcn::SDLGraphics*>(graphics)->fillRectangle(dim);
+ }
graphics->setColor(gcn::Color(255, 255, 255));
}
@@ -312,7 +357,7 @@ void ScrollArea::drawVMarker(gcn::Graphics *graphics)
gcn::Rectangle dim = getVerticalMarkerDimension();
getAbsolutePosition(x, y);
- ((Graphics*)graphics)->drawImageRect(
+ dynamic_cast<Graphics*>(graphics)->drawImageRect(
x + dim.x, y + dim.y, dim.width, dim.height, vMarker);
}
@@ -322,6 +367,6 @@ void ScrollArea::drawHMarker(gcn::Graphics *graphics)
gcn::Rectangle dim = getHorizontalMarkerDimension();
getAbsolutePosition(x, y);
- ((Graphics*)graphics)->drawImageRect(
+ dynamic_cast<Graphics*>(graphics)->drawImageRect(
x + dim.x, y + dim.y, dim.width, dim.height, vMarker);
}
diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp
index c89b7ea4..9470fd54 100644
--- a/src/gui/textfield.cpp
+++ b/src/gui/textfield.cpp
@@ -100,5 +100,5 @@ void TextField::drawBorder(gcn::Graphics *graphics)
x -= bs;
y -= bs;
- ((Graphics*)graphics)->drawImageRect(x, y, w, h, skin);
+ dynamic_cast<Graphics*>(graphics)->drawImageRect(x, y, w, h, skin);
}
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 158e9272..0228e183 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -126,7 +126,7 @@ void Window::draw(gcn::Graphics* graphics)
int x, y;
getAbsolutePosition(x, y);
- ((Graphics*)graphics)->drawImageRect(x, y, getWidth(), getHeight(),
+ dynamic_cast<Graphics*>(graphics)->drawImageRect(x, y, getWidth(), getHeight(),
border);
// Draw title