summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp8
-rw-r--r--src/defaults.cpp4
-rw-r--r--src/graphics.cpp69
-rw-r--r--src/graphics.h15
-rw-r--r--src/gui/charcreatedialog.cpp3
-rw-r--r--src/gui/equipmentwindow.cpp3
-rw-r--r--src/gui/gui.cpp7
-rw-r--r--src/gui/sdlinput.cpp15
-rw-r--r--src/gui/setup_video.cpp116
-rw-r--r--src/gui/setup_video.h16
-rw-r--r--src/gui/viewport.cpp7
-rw-r--r--src/gui/widgets/resizegrip.cpp12
-rw-r--r--src/gui/widgets/window.cpp6
-rw-r--r--src/gui/windowmenu.cpp3
-rw-r--r--src/openglgraphics.cpp97
-rw-r--r--src/openglgraphics.h13
-rw-r--r--src/resources/image.cpp157
-rw-r--r--src/resources/image.h3
18 files changed, 233 insertions, 321 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 28affce6..fec41f5e 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1397,10 +1397,7 @@ void Client::handleVideoResize(int width, int height)
// Keep a minimum size. This isn't adhered to by the actual window, but
// it keeps some window positions from getting messed up.
width = std::max(640, width);
- height = std::max(480, height);
-
- if (graphics->getWidth() == width && graphics->getHeight() == height)
- return;
+ height = std::max(360, height);
if (graphics->changeVideoMode(width,
height,
@@ -1408,7 +1405,8 @@ void Client::handleVideoResize(int width, int height)
false,
graphics->getHWAccel()))
{
- videoResized(width, height);
+ videoResized(graphics->getWidth(),
+ graphics->getHeight());
// Since everything appears to have worked out, remember to store the
// new size in the configuration.
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 0dc8e3ed..e8a6e6e6 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -142,8 +142,8 @@ DefaultsData* getBrandingDefaults()
AddDEF(brandingData, "onlineServerList", "");
AddDEF(brandingData, "guiThemePath", "");
AddDEF(brandingData, "theme", "");
- AddDEF(brandingData, "font", "fonts/dejavusans.ttf");
- AddDEF(brandingData, "boldFont", "fonts/dejavusans-bold.ttf");
+ AddDEF(brandingData, "font", "fonts/DejaVuSerifCondensed.ttf");
+ AddDEF(brandingData, "boldFont", "fonts/DejaVuSerifCondensed-Bold.ttf");
AddDEF(brandingData, "monoFont", "fonts/dejavusans-mono.ttf");
return brandingData;
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 7b56d974..d36d2fa7 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -30,15 +30,19 @@
#include "utils/gettext.h"
#include <SDL_gfxBlitFunc.h>
+#include <SDL/SDL_rotozoom.h>
Graphics::Graphics():
mWidth(0),
mHeight(0),
+ mScale(1),
mBpp(0),
mFullscreen(false),
mHWAccel(false),
- mBlitMode(BLIT_NORMAL)
+ mBlitMode(BLIT_NORMAL),
+ mScreenSurface(0)
{
+ mTarget = 0;
}
Graphics::~Graphics()
@@ -65,13 +69,24 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
else
displayFlags |= SDL_SWSURFACE;
- setTarget(SDL_SetVideoMode(w, h, bpp, displayFlags));
+ SDL_FreeSurface(mTarget);
+ mTarget = 0;
+
+ // Calculate scaling factor
+ mScale = std::max(w / 640, h / 360);
+
+ mScreenSurface = SDL_SetVideoMode(w, h, bpp, displayFlags);
+ const SDL_PixelFormat& fmt = *(mScreenSurface->format);
+ setTarget(SDL_CreateRGBSurface(SDL_SWSURFACE,
+ w / mScale, h / mScale,
+ fmt.BitsPerPixel,
+ fmt.Rmask, fmt.Gmask, fmt.Bmask, 0));
if (!mTarget)
return false;
- mWidth = w;
- mHeight = h;
+ mWidth = mTarget->w;
+ mHeight = mTarget->h;
mBpp = bpp;
mFullscreen = fs;
mHWAccel = hwaccel;
@@ -111,8 +126,8 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
bool Graphics::changeVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
{
// Just return success if we're already in this mode
- if (mWidth == w &&
- mHeight == h &&
+ if (mScreenSurface && mScreenSurface->w == w &&
+ mScreenSurface->h == h &&
mBpp == bpp &&
mFullscreen == fs &&
mHWAccel == hwaccel)
@@ -122,12 +137,14 @@ bool Graphics::changeVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
bool success = setVideoMode(w, h, bpp, fs, hwaccel);
- // If it didn't work, try to restore the previous mode. If that doesn't
+ // If it didn't work, try to restore fallback resolution. If that doesn't
// work either, we're in big trouble and bail out.
- if (!success) {
- if (!setVideoMode(mWidth, mHeight, mBpp, mFullscreen, mHWAccel)) {
+ if (!success)
+ {
+ if (!setVideoMode(640, 360, mBpp, mFullscreen, mHWAccel))
+ {
logger->error(_("Failed to change video mode and couldn't "
- "switch back to the previous mode!"));
+ "switch back to the fallback mode!"));
}
}
@@ -136,16 +153,6 @@ bool Graphics::changeVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
return success;
}
-int Graphics::getWidth() const
-{
- return mWidth;
-}
-
-int Graphics::getHeight() const
-{
- return mHeight;
-}
-
bool Graphics::drawImage(Image *image, int x, int y)
{
if (image)
@@ -371,7 +378,27 @@ void Graphics::drawImageRect(int x, int y, int w, int h,
void Graphics::updateScreen()
{
- SDL_Flip(mTarget);
+ // Center viewport
+ SDL_Rect dstRect;
+ dstRect.x = (mScreenSurface->w-getWidth() * mScale) / 2;
+ dstRect.y = (mScreenSurface->h-getHeight() * mScale) / 2;
+
+ // Zoom in if necessary
+ if (mScale > 1)
+ {
+ SDL_Surface *tmp = zoomSurface(mTarget, mScale, mScale, 0);
+
+ // Copy temporary surface to screen
+ SDL_BlitSurface(tmp, NULL, mScreenSurface, &dstRect);
+ SDL_FreeSurface(tmp);
+ }
+ else
+ {
+ // Copy mTarget directly to screen
+ SDL_BlitSurface(mTarget, NULL, mScreenSurface, &dstRect);
+ }
+
+ SDL_Flip(mScreenSurface);
}
SDL_Surface *Graphics::getScreenshot()
diff --git a/src/graphics.h b/src/graphics.h
index 6a17aab4..cffdb143 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -195,14 +195,19 @@ class Graphics : public gcn::SDLGraphics
virtual void updateScreen();
/**
- * Returns the width of the screen.
+ * Returns the width of the drawable surface.
*/
- int getWidth() const;
+ int getWidth() const { return mWidth; }
/**
- * Returns the height of the screen.
+ * Returns the height of the drawable surface.
*/
- int getHeight() const;
+ int getHeight() const { return mHeight; }
+
+ /**
+ * Returns the current scale ratio of the screen.
+ */
+ int getScale() const { return mScale; }
/**
* Returns the amount of bits per pixel that was requested (not the
@@ -231,10 +236,12 @@ class Graphics : public gcn::SDLGraphics
protected:
int mWidth;
int mHeight;
+ int mScale;
int mBpp;
bool mFullscreen;
bool mHWAccel;
BlitMode mBlitMode;
+ SDL_Surface *mScreenSurface;
};
extern Graphics *graphics;
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp
index 8fee148b..a36dfadf 100644
--- a/src/gui/charcreatedialog.cpp
+++ b/src/gui/charcreatedialog.cpp
@@ -148,6 +148,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
center();
setVisible(true);
mNameField->requestFocus();
+ setFixedGender(true, GENDER_MALE);
}
CharCreateDialog::~CharCreateDialog()
@@ -359,6 +360,8 @@ void CharCreateDialog::setFixedGender(bool fixed, Gender gender)
if (fixed)
{
mMale->setEnabled(false);
+ mMale->setVisible(false);
+ mFemale->setVisible(false);
mFemale->setEnabled(false);
}
}
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 85a4c766..9df8c98c 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -254,6 +254,9 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event)
int mouseX, mouseY;
SDL_GetMouseState(&mouseX, &mouseY);
+ mouseX /= graphics->getScale();
+ mouseY /= graphics->getScale();
+
// Show ItemTooltip
std::string slotName = getSlotName(x, y);
if (!slotName.empty())
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 78fc42fb..1b600a3d 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -112,7 +112,7 @@ Gui::Gui(Graphics *graphics):
// Set global font
const int fontSize = config.getValue("fontSize", 11);
- std::string fontFile = branding.getValue("font", "fonts/dejavusans.ttf");
+ std::string fontFile = branding.getValue("font", "fonts/DejaVuSerifCondensed.ttf");
std::string path = resman->getPath(fontFile);
try
@@ -127,7 +127,7 @@ Gui::Gui(Graphics *graphics):
}
// Set bold font
- fontFile = branding.getValue("boldFont", "fonts/dejavusans-bold.ttf");
+ fontFile = branding.getValue("boldFont", "fonts/DejaVuSerifCondensed-Bold.ttf");
path = resman->getPath(fontFile);
try
{
@@ -205,6 +205,9 @@ void Gui::draw()
int mouseX, mouseY;
Uint8 button = SDL_GetMouseState(&mouseX, &mouseY);
+ mouseX /= graphics->getScale();
+ mouseY /= graphics->getScale();
+
if ((Client::hasMouseFocus() || button & SDL_BUTTON(1))
&& mCustomCursor
&& mMouseCursorAlpha > 0.0f)
diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp
index 4ccb7580..46636d52 100644
--- a/src/gui/sdlinput.cpp
+++ b/src/gui/sdlinput.cpp
@@ -60,6 +60,8 @@
#include <guichan/exception.hpp>
+#include "graphics.h"
+
SDLInput::SDLInput()
{
mMouseInWindow = true;
@@ -73,14 +75,12 @@ bool SDLInput::isKeyQueueEmpty()
gcn::KeyInput SDLInput::dequeueKeyInput()
{
- gcn::KeyInput keyInput;
-
if (mKeyInputQueue.empty())
{
throw GCN_EXCEPTION("The queue is empty.");
}
- keyInput = mKeyInputQueue.front();
+ gcn::KeyInput keyInput = mKeyInputQueue.front();
mKeyInputQueue.pop();
return keyInput;
@@ -93,16 +93,19 @@ bool SDLInput::isMouseQueueEmpty()
gcn::MouseInput SDLInput::dequeueMouseInput()
{
- gcn::MouseInput mouseInput;
-
if (mMouseInputQueue.empty())
{
throw GCN_EXCEPTION("The queue is empty.");
}
- mouseInput = mMouseInputQueue.front();
+ gcn::MouseInput mouseInput = mMouseInputQueue.front();
mMouseInputQueue.pop();
+ // Scale the mouse input by the graphics scale ratio
+ int scale = graphics->getScale();
+ mouseInput.setX(mouseInput.getX() / scale);
+ mouseInput.setY(mouseInput.getY() / scale);
+
return mouseInput;
}
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index 3c92aa31..6968e51c 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -28,7 +28,6 @@
#include "localplayer.h"
#include "log.h"
#include "main.h"
-#include "particle.h"
#include "gui/okdialog.h"
@@ -123,40 +122,10 @@ int ModeListModel::getIndexOf(const std::string &widthXHeightMode)
return -1;
}
-const char *Setup_Video::overlayDetailToString(int detail)
-{
- if (detail == -1)
- detail = config.getIntValue("OverlayDetail");
-
- switch (detail)
- {
- case 0: return _("off");
- case 1: return _("low");
- case 2: return _("high");
- }
- return "";
-}
-
-const char *Setup_Video::particleDetailToString(int detail)
-{
- if (detail == -1)
- detail = 3 - config.getIntValue("particleEmitterSkip");
-
- switch (detail)
- {
- case 0: return _("low");
- case 1: return _("medium");
- case 2: return _("high");
- case 3: return _("max");
- }
- return "";
-}
-
Setup_Video::Setup_Video():
mFullScreenEnabled(config.getBoolValue("screen")),
mOpenGLEnabled(config.getBoolValue("opengl")),
mCustomCursorEnabled(config.getBoolValue("customcursor")),
- mParticleEffectsEnabled(config.getBoolValue("particleeffects")),
mFps(config.getIntValue("fpslimit")),
mSDLTransparencyDisabled(config.getBoolValue("disableTransparency")),
mModeListModel(new ModeListModel),
@@ -165,17 +134,9 @@ Setup_Video::Setup_Video():
mOpenGLCheckBox(new CheckBox(_("OpenGL"), mOpenGLEnabled)),
mCustomCursorCheckBox(new CheckBox(_("Custom cursor"),
mCustomCursorEnabled)),
- mParticleEffectsCheckBox(new CheckBox(_("Particle effects"),
- mParticleEffectsEnabled)),
mFpsCheckBox(new CheckBox(_("FPS limit:"))),
mFpsSlider(new Slider(10, 120)),
mFpsLabel(new Label),
- mOverlayDetail(config.getIntValue("OverlayDetail")),
- mOverlayDetailSlider(new Slider(0, 2)),
- mOverlayDetailField(new Label),
- mParticleDetail(3 - config.getIntValue("particleEmitterSkip")),
- mParticleDetailSlider(new Slider(0, 3)),
- mParticleDetailField(new Label),
mDisableSDLTransparencyCheckBox(
new CheckBox(_("Disable transparency (Low CPU mode)"),
mSDLTransparencyDisabled))
@@ -188,9 +149,6 @@ Setup_Video::Setup_Video():
scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
scrollArea->setSize(100, 200);
- overlayDetailLabel = new Label(_("Ambient FX:"));
- particleDetailLabel = new Label(_("Particle detail:"));
-
mModeList->setEnabled(true);
#ifndef USE_OPENGL
@@ -203,9 +161,6 @@ Setup_Video::Setup_Video():
mFpsSlider->setEnabled(mFps > 0);
mFpsCheckBox->setSelected(mFps > 0);
- overlayDetailLabel->setAlignment(Graphics::RIGHT);
- particleDetailLabel->setAlignment(Graphics::RIGHT);
-
// If the openGL Mode is enabled, disabling the transaprency
// is irrelevant.
mDisableSDLTransparencyCheckBox->setEnabled(!mOpenGLEnabled);
@@ -218,34 +173,18 @@ Setup_Video::Setup_Video():
// Set actions
mModeList->setActionEventId("videomode");
mCustomCursorCheckBox->setActionEventId("customcursor");
- mParticleEffectsCheckBox->setActionEventId("particleeffects");
mDisableSDLTransparencyCheckBox->setActionEventId("disableTransparency");
mFpsCheckBox->setActionEventId("fpslimitcheckbox");
mFpsSlider->setActionEventId("fpslimitslider");
- mOverlayDetailSlider->setActionEventId("overlaydetailslider");
- mOverlayDetailField->setActionEventId("overlaydetailfield");
mOpenGLCheckBox->setActionEventId("opengl");
- mParticleDetailSlider->setActionEventId("particledetailslider");
- mParticleDetailField->setActionEventId("particledetailfield");
// Set listeners
mModeList->addActionListener(this);
mCustomCursorCheckBox->addActionListener(this);
mOpenGLCheckBox->addActionListener(this);
- mParticleEffectsCheckBox->addActionListener(this);
mDisableSDLTransparencyCheckBox->addActionListener(this);
mFpsCheckBox->addActionListener(this);
mFpsSlider->addActionListener(this);
- mOverlayDetailSlider->addActionListener(this);
- mOverlayDetailField->addKeyListener(this);
- mParticleDetailSlider->addActionListener(this);
- mParticleDetailField->addKeyListener(this);
-
- mOverlayDetailField->setCaption(overlayDetailToString(mOverlayDetail));
- mOverlayDetailSlider->setValue(mOverlayDetail);
-
- mParticleDetailField->setCaption(particleDetailToString(mParticleDetail));
- mParticleDetailSlider->setValue(mParticleDetail);
// Do the layout
LayoutHelper h(this);
@@ -258,26 +197,10 @@ Setup_Video::Setup_Video():
place(2, 0, mFsCheckBox);
place(2, 1, mOpenGLCheckBox);
place(2, 2, mCustomCursorCheckBox);
-
- place = h.getPlacer(0, 1);
- place.getCell().setHAlign(LayoutCell::FILL);
-
- place(0, 0, space, 3);
- place(0, 1, mDisableSDLTransparencyCheckBox, 4);
-
- place(0, 2, mFpsCheckBox);
- place(1, 2, mFpsSlider, 2);
- place(3, 2, mFpsLabel);
-
- place(0, 3, mParticleEffectsCheckBox, 4);
-
- place(0, 4, particleDetailLabel);
- place(1, 4, mParticleDetailSlider, 2);
- place(3, 4, mParticleDetailField);
-
- place(0, 5, overlayDetailLabel);
- place(1, 5, mOverlayDetailSlider, 2);
- place(3, 5, mOverlayDetailField);
+ place(2, 3, mDisableSDLTransparencyCheckBox, 4);
+ place(2, 4, mFpsCheckBox);
+ place(3, 4, mFpsSlider, 2);
+ place(5, 4, mFpsLabel);
setDimension(gcn::Rectangle(0, 0, 370, 300));
}
@@ -402,8 +325,6 @@ void Setup_Video::apply()
// We sync old and new values at apply time
mFullScreenEnabled = config.getBoolValue("screen");
mCustomCursorEnabled = config.getBoolValue("customcursor");
- mParticleEffectsEnabled = config.getBoolValue("particleeffects");
- mOverlayDetail = config.getIntValue("OverlayDetail");
mOpenGLEnabled = config.getBoolValue("opengl");
mSDLTransparencyDisabled = config.getBoolValue("disableTransparency");
}
@@ -414,11 +335,8 @@ void Setup_Video::cancel()
mFsCheckBox->setSelected(mFullScreenEnabled);
mOpenGLCheckBox->setSelected(mOpenGLEnabled);
mCustomCursorCheckBox->setSelected(mCustomCursorEnabled);
- mParticleEffectsCheckBox->setSelected(mParticleEffectsEnabled);
mFpsSlider->setValue(mFps);
mFpsSlider->setEnabled(mFps > 0);
- mOverlayDetailSlider->setValue(mOverlayDetail);
- mParticleDetailSlider->setValue(mParticleDetail);
std::string text = mFpsCheckBox->isSelected() ? toString(mFps) : _("None");
mFpsLabel->setCaption(text);
mDisableSDLTransparencyCheckBox->setSelected(mSDLTransparencyDisabled);
@@ -432,7 +350,6 @@ void Setup_Video::cancel()
mModeList->setSelected(mModeListModel->getIndexOf(videoMode));
config.setValue("customcursor", mCustomCursorEnabled);
- config.setValue("particleeffects", mParticleEffectsEnabled);
config.setValue("opengl", mOpenGLEnabled);
config.setValue("disableTransparency", mSDLTransparencyDisabled);
}
@@ -445,31 +362,6 @@ void Setup_Video::action(const gcn::ActionEvent &event)
{
config.setValue("customcursor", mCustomCursorCheckBox->isSelected());
}
- else if (id == "particleeffects")
- {
- config.setValue("particleeffects",
- mParticleEffectsCheckBox->isSelected());
- Particle::enabled = mParticleEffectsCheckBox->isSelected();
-
- if (Game::instance())
- {
- new OkDialog(_("Particle Effect Settings Changed."),
- _("Changes will take effect on map change."));
- }
- }
- else if (id == "overlaydetailslider")
- {
- int val = (int) mOverlayDetailSlider->getValue();
- mOverlayDetailField->setCaption(overlayDetailToString(val));
- config.setValue("OverlayDetail", val);
- }
- else if (id == "particledetailslider")
- {
- int val = (int) mParticleDetailSlider->getValue();
- mParticleDetailField->setCaption(particleDetailToString(val));
- config.setValue("particleEmitterSkip", 3 - val);
- Particle::emitterSkip = 4 - val;
- }
else if (id == "fpslimitcheckbox" || id == "fpslimitslider")
{
int fps = (int) mFpsSlider->getValue();
diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h
index 7002a936..d09620fa 100644
--- a/src/gui/setup_video.h
+++ b/src/gui/setup_video.h
@@ -44,15 +44,10 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
void action(const gcn::ActionEvent &event);
- static const char *overlayDetailToString(int detail = -1);
-
- static const char *particleDetailToString(int detail = -1);
-
private:
bool mFullScreenEnabled;
bool mOpenGLEnabled;
bool mCustomCursorEnabled;
- bool mParticleEffectsEnabled;
int mFps;
bool mSDLTransparencyDisabled;
@@ -60,27 +55,16 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
//gcn::Label *scrollRadiusLabel;
//gcn::Label *scrollLazinessLabel;
- gcn::Label *overlayDetailLabel;
- gcn::Label *particleDetailLabel;
gcn::ListBox *mModeList;
gcn::CheckBox *mFsCheckBox;
gcn::CheckBox *mOpenGLCheckBox;
gcn::CheckBox *mCustomCursorCheckBox;
- gcn::CheckBox *mParticleEffectsCheckBox;
gcn::CheckBox *mFpsCheckBox;
gcn::Slider *mFpsSlider;
gcn::Label *mFpsLabel;
- int mOverlayDetail;
- gcn::Slider *mOverlayDetailSlider;
- gcn::Label *mOverlayDetailField;
-
- int mParticleDetail;
- gcn::Slider *mParticleDetailSlider;
- gcn::Label *mParticleDetailField;
-
gcn::CheckBox *mDisableSDLTransparencyCheckBox;
};
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 1b5b00c3..0aab399c 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -286,6 +286,10 @@ void Viewport::logic()
void Viewport::_followMouse()
{
Uint8 button = SDL_GetMouseState(&mMouseX, &mMouseY);
+
+ mMouseX /= graphics->getScale();
+ mMouseY /= graphics->getScale();
+
// If the left button is dragged
if (mPlayerFollowMouse && button & SDL_BUTTON(1))
{
@@ -313,6 +317,9 @@ void Viewport::_drawDebugPath(Graphics *graphics)
// Get the current mouse position
SDL_GetMouseState(&mMouseX, &mMouseY);
+ mMouseX /= graphics->getScale();
+ mMouseY /= graphics->getScale();
+
// Prepare the walkmask corresponding to the protocol
unsigned char walkMask;
switch (Net::getNetworkType())
diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp
index da97ac69..7b37b282 100644
--- a/src/gui/widgets/resizegrip.cpp
+++ b/src/gui/widgets/resizegrip.cpp
@@ -58,11 +58,11 @@ ResizeGrip::~ResizeGrip()
void ResizeGrip::draw(gcn::Graphics *graphics)
{
- if (config.getFloatValue("guialpha") != mAlpha)
- {
- mAlpha = config.getFloatValue("guialpha");
- gripImage->setAlpha(mAlpha);
- }
+ //if (config.getFloatValue("guialpha") != mAlpha)
+ //{
+ // mAlpha = config.getFloatValue("guialpha");
+ // gripImage->setAlpha(mAlpha);
+ //}
- static_cast<Graphics*>(graphics)->drawImage(gripImage, 0, 0);
+ //static_cast<Graphics*>(graphics)->drawImage(gripImage, 0, 0);
}
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index c8788c75..406f55ef 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -68,8 +68,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent,
instances++;
setFrameSize(0);
- setPadding(3);
- setTitleBarHeight(20);
+ setPadding(5);
+ setTitleBarHeight(25);
// Loads the skin
mSkin = Theme::instance()->load(skin);
@@ -123,7 +123,7 @@ void Window::draw(gcn::Graphics *graphics)
{
g->setColor(Theme::getThemeColor(Theme::TEXT));
g->setFont(getFont());
- g->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT);
+ g->drawText(getCaption(), 7, 10, gcn::Graphics::LEFT);
}
// Draw Close Button
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index 12624bf1..f503c84c 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -62,8 +62,7 @@ WindowMenu::WindowMenu():
addButton(N_("Skills"), x, h, "button-icon-skills.png",
KeyboardConfig::KEY_WINDOW_SKILL);
- if (specialsWindow->hasSpecials())
- addButton(N_("Specials"), x, h, "button-icon-specials.png");
+ addButton(N_("Specials"), x, h, "button-icon-specials.png");
addButton(N_("Social"), x, h, "button-icon-social.png",
KeyboardConfig::KEY_WINDOW_SOCIAL);
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index 74a309e1..530b40b0 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -33,6 +33,8 @@
#include <SDL.h>
+#include <cmath>
+
#ifndef GL_TEXTURE_RECTANGLE_ARB
#define GL_TEXTURE_RECTANGLE_ARB 0x84F5
#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8
@@ -70,8 +72,19 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
int displayFlags = SDL_ANYFORMAT | SDL_OPENGL;
- mWidth = w;
- mHeight = h;
+ const double targetRatio = (double) 640 / 360; // 1.77778
+ const double requestedRatio = (double) w / h;
+
+ if (requestedRatio < targetRatio) {
+ // Screen is higher / narrower than target aspect ratio: calculate
+ // scale based on height.
+ mScale = (int) std::floor((double) h / 360);
+ } else {
+ mScale = (int) std::floor((double) w / 640);
+ }
+
+ mWidth = w / mScale;
+ mHeight = h / mScale;
mBpp = bpp;
mFullscreen = fs;
mHWAccel = hwaccel;
@@ -103,7 +116,7 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
#endif
// Setup OpenGL
- glViewport(0, 0, w, h);
+ glViewport(0, 0, mWidth * mScale, mHeight * mScale);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
int gotDoubleBuffer;
SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer);
@@ -113,14 +126,17 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
char const *glExtensions = (char const *)glGetString(GL_EXTENSIONS);
GLint texSize;
bool rectTex = strstr(glExtensions, "GL_ARB_texture_rectangle");
- if (rectTex)
+ bool npotTex = strstr(glExtensions, "GL_ARB_texture_non_power_of_two");
+ if (rectTex && !npotTex)
{
Image::mTextureType = GL_TEXTURE_RECTANGLE_ARB;
+ Image::mPowerOfTwoTextures = false;
glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
}
else
{
Image::mTextureType = GL_TEXTURE_2D;
+ Image::mPowerOfTwoTextures = !npotTex;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
}
Image::mTextureSize = texSize;
@@ -162,8 +178,8 @@ static inline void drawQuad(Image *image,
dstX, dstY + height
};
- glVertexPointer(2, GL_FLOAT, 0, &vert);
- glTexCoordPointer(2, GL_INT, 0, &tex);
+ glVertexPointer(2, GL_INT, 0, &vert);
+ glTexCoordPointer(2, GL_FLOAT, 0, &tex);
glDrawArrays(GL_QUADS, 0, 4);
}
@@ -224,8 +240,8 @@ static inline void drawRescaledQuad(Image *image,
dstX, dstY + desiredHeight
};
- glVertexPointer(2, GL_FLOAT, 0, &vert);
- glTexCoordPointer(2, GL_INT, 0, &tex);
+ glVertexPointer(2, GL_INT, 0, &vert);
+ glTexCoordPointer(2, GL_FLOAT, 0, &tex);
glDrawArrays(GL_QUADS, 0, 4);
}
@@ -290,19 +306,6 @@ bool OpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY,
int desiredWidth, int desiredHeight,
bool useColor)
{
- return drawRescaledImage(image, srcX, srcY,
- dstX, dstY,
- width, height,
- desiredWidth, desiredHeight,
- useColor, true);
-}
-
-bool OpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY,
- int dstX, int dstY,
- int width, int height,
- int desiredWidth, int desiredHeight,
- bool useColor, bool smooth)
-{
if (!image)
return false;
@@ -313,11 +316,6 @@ bool OpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY,
width, height, useColor);
}
- // When the desired image is smaller than the current one,
- // disable smooth effect.
- if (width > desiredWidth && height > desiredHeight)
- smooth = false;
-
srcX += image->mBounds.x;
srcY += image->mBounds.y;
@@ -332,20 +330,6 @@ bool OpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY,
drawRescaledQuad(image, srcX, srcY, dstX, dstY, width, height,
desiredWidth, desiredHeight);
- if (smooth) // A basic smooth effect...
- {
- glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
- drawRescaledQuad(image, srcX, srcY, dstX - 1, dstY - 1, width, height,
- desiredWidth + 1, desiredHeight + 1);
- drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY + 1, width, height,
- desiredWidth - 1, desiredHeight - 1);
-
- drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY, width, height,
- desiredWidth - 1, desiredHeight);
- drawRescaledQuad(image, srcX, srcY, dstX, dstY + 1, width, height,
- desiredWidth, desiredHeight - 1);
- }
-
if (!useColor)
{
glColor4ub(static_cast<GLubyte>(mColor.r),
@@ -633,8 +617,6 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image,
void OpenGLGraphics::updateScreen()
{
- glFlush();
- glFinish();
SDL_GL_SwapBuffers();
}
@@ -646,20 +628,19 @@ void OpenGLGraphics::_beginDraw()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0.0, (double)mTarget->w, (double)mTarget->h, 0.0, -1.0, 1.0);
+ glOrtho(0.0, (double) mWidth, (double) mHeight, 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_SCISSOR_TEST);
- glEnableClientState(GL_VERTEX_ARRAY);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- pushClipArea(gcn::Rectangle(0, 0, mTarget->w, mTarget->h));
+ pushClipArea(gcn::Rectangle(0, 0, mWidth, mHeight));
}
void OpenGLGraphics::_endDraw()
@@ -726,12 +707,15 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area)
transX += mClipStack.top().xOffset;
transY += mClipStack.top().yOffset;
+ int x = (int) (mClipStack.top().x * mScale);
+ int y = mTarget->h - (int) ((mClipStack.top().y +
+ mClipStack.top().height) * mScale);
+ int width = (int) (mClipStack.top().width * mScale);
+ int height = (int) (mClipStack.top().height * mScale);
+
glPushMatrix();
glTranslatef(transX, transY, 0);
- glScissor(mClipStack.top().x,
- mTarget->h - mClipStack.top().y - mClipStack.top().height,
- mClipStack.top().width,
- mClipStack.top().height);
+ glScissor(x, y, width, height);
return result;
}
@@ -743,11 +727,14 @@ void OpenGLGraphics::popClipArea()
if (mClipStack.empty())
return;
+ int x = (int) (mClipStack.top().x * mScale);
+ int y = mTarget->h - (int) ((mClipStack.top().y +
+ mClipStack.top().height) * mScale);
+ int width = (int) (mClipStack.top().width * mScale);
+ int height = (int) (mClipStack.top().height * mScale);
+
glPopMatrix();
- glScissor(mClipStack.top().x,
- mTarget->h - mClipStack.top().y - mClipStack.top().height,
- mClipStack.top().width,
- mClipStack.top().height);
+ glScissor(x, y, width, height);
}
void OpenGLGraphics::setColor(const gcn::Color& color)
@@ -791,10 +778,6 @@ void OpenGLGraphics::fillRectangle(const gcn::Rectangle& rect)
drawRectangle(rect, true);
}
-void OpenGLGraphics::setTargetPlane(int width, int height)
-{
-}
-
void OpenGLGraphics::setTexturingAndBlending(bool enable)
{
if (enable)
diff --git a/src/openglgraphics.h b/src/openglgraphics.h
index d61bf3db..a1d78e46 100644
--- a/src/openglgraphics.h
+++ b/src/openglgraphics.h
@@ -52,7 +52,7 @@ class OpenGLGraphics : public Graphics
bool useColor);
/**
- * Draws a resclaled version of the image
+ * Draws a rescaled version of the image
*/
bool drawRescaledImage(Image *image, int srcX, int srcY,
int dstX, int dstY,
@@ -60,15 +60,6 @@ class OpenGLGraphics : public Graphics
int desiredWidth, int desiredHeight,
bool useColor);
- /**
- * Used to get the smooth rescale option over the standard function.
- */
- bool drawRescaledImage(Image *image, int srcX, int srcY,
- int dstX, int dstY,
- int width, int height,
- int desiredWidth, int desiredHeight,
- bool useColor, bool smooth);
-
void drawImagePattern(Image *image,
int x, int y,
int w, int h);
@@ -100,8 +91,6 @@ class OpenGLGraphics : public Graphics
void fillRectangle(const gcn::Rectangle &rect);
- void setTargetPlane(int width, int height);
-
/**
* Takes a screenshot and returns it as SDL surface.
*/
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index a29d475d..b7e6c200 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -36,6 +36,7 @@
#ifdef USE_OPENGL
bool Image::mUseOpenGL = false;
+bool Image::mPowerOfTwoTextures = true;
int Image::mTextureType = 0;
int Image::mTextureSize = 0;
#endif
@@ -437,101 +438,113 @@ Image *Image::_SDLload(SDL_Surface *tmpImage)
}
#ifdef USE_OPENGL
-Image *Image::_GLload(SDL_Surface *tmpImage)
+Image *Image::_GLload(SDL_Surface *image)
{
- // Flush current error flag.
- glGetError();
+ // Flush current error flag.
+ glGetError();
- int width = tmpImage->w;
- int height = tmpImage->h;
- int realWidth = powerOfTwo(width);
- int realHeight = powerOfTwo(height);
+ int width = image->w;
+ int height = image->h;
+ int realWidth = powerOfTwo(width);
+ int realHeight = powerOfTwo(height);
- if (realWidth < width || realHeight < height)
- {
- logger->log("Warning: image too large, cropping to %dx%d texture!",
- tmpImage->w, tmpImage->h);
- }
-
- // Make sure the alpha channel is not used, but copied to destination
- SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE);
+ if (realWidth < width || realHeight < height)
+ {
+ logger->log("Warning: image too large, cropping to %dx%d texture!",
+ realWidth, realHeight);
+ }
- // Determine 32-bit masks based on byte order
- Uint32 rmask, gmask, bmask, amask;
+ // Determine 32-bit masks based on byte order
+ Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- rmask = 0xff000000;
- gmask = 0x00ff0000;
- bmask = 0x0000ff00;
- amask = 0x000000ff;
+ rmask = 0xff000000;
+ gmask = 0x00ff0000;
+ bmask = 0x0000ff00;
+ amask = 0x000000ff;
#else
- rmask = 0x000000ff;
- gmask = 0x0000ff00;
- bmask = 0x00ff0000;
- amask = 0xff000000;
+ rmask = 0x000000ff;
+ gmask = 0x0000ff00;
+ bmask = 0x00ff0000;
+ amask = 0xff000000;
#endif
- SDL_Surface *oldImage = tmpImage;
- tmpImage = SDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight,
- 32, rmask, gmask, bmask, amask);
+ bool needsConversion = !(realWidth == width &&
+ realHeight == height &&
+ image->format->BytesPerPixel == 4 &&
+ image->format->Rmask == rmask &&
+ image->format->Gmask == gmask &&
+ image->format->Bmask == bmask &&
+ image->format->Amask == amask);
+
+ if (needsConversion)
+ {
+ SDL_Surface *oldImage = image;
+ image = SDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight,
+ 32, rmask, gmask, bmask, amask);
- if (!tmpImage)
+ if (!image)
{
logger->log("Error, image convert failed: out of memory");
return NULL;
}
- SDL_BlitSurface(oldImage, NULL, tmpImage, NULL);
+ // Make sure the alpha channel is not used, but copied to destination
+ SDL_SetAlpha(oldImage, 0, SDL_ALPHA_OPAQUE);
+ SDL_BlitSurface(oldImage, NULL, image, NULL);
+ }
- GLuint texture;
- glGenTextures(1, &texture);
- OpenGLGraphics::bindTexture(mTextureType, texture);
+ GLuint texture;
+ glGenTextures(1, &texture);
+ OpenGLGraphics::bindTexture(mTextureType, texture);
- if (SDL_MUSTLOCK(tmpImage))
- SDL_LockSurface(tmpImage);
+ if (SDL_MUSTLOCK(image))
+ SDL_LockSurface(image);
- glTexImage2D(
- mTextureType, 0, 4,
- tmpImage->w, tmpImage->h,
- 0, GL_RGBA, GL_UNSIGNED_BYTE,
- tmpImage->pixels);
+ glTexImage2D(mTextureType, 0, GL_RGBA8,
+ image->w, image->h,
+ 0, GL_RGBA, GL_UNSIGNED_BYTE,
+ image->pixels);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- if (SDL_MUSTLOCK(tmpImage))
- SDL_UnlockSurface(tmpImage);
+ if (SDL_MUSTLOCK(image))
+ SDL_UnlockSurface(image);
- SDL_FreeSurface(tmpImage);
+ if (needsConversion)
+ SDL_FreeSurface(image);
- GLenum error = glGetError();
- if (error)
+ GLenum error = glGetError();
+ if (error)
+ {
+ std::string errmsg = "Unknown error";
+ switch (error)
{
- std::string errmsg = "Unknown error";
- switch (error)
- {
- case GL_INVALID_ENUM:
- errmsg = "GL_INVALID_ENUM";
- break;
- case GL_INVALID_VALUE:
- errmsg = "GL_INVALID_VALUE";
- break;
- case GL_INVALID_OPERATION:
- errmsg = "GL_INVALID_OPERATION";
- break;
- case GL_STACK_OVERFLOW:
- errmsg = "GL_STACK_OVERFLOW";
- break;
- case GL_STACK_UNDERFLOW:
- errmsg = "GL_STACK_UNDERFLOW";
- break;
- case GL_OUT_OF_MEMORY:
- errmsg = "GL_OUT_OF_MEMORY";
- break;
- }
- logger->log("Error: Image GL import failed: %s", errmsg.c_str());
- return NULL;
+ case GL_INVALID_ENUM:
+ errmsg = "GL_INVALID_ENUM";
+ break;
+ case GL_INVALID_VALUE:
+ errmsg = "GL_INVALID_VALUE";
+ break;
+ case GL_INVALID_OPERATION:
+ errmsg = "GL_INVALID_OPERATION";
+ break;
+ case GL_STACK_OVERFLOW:
+ errmsg = "GL_STACK_OVERFLOW";
+ break;
+ case GL_STACK_UNDERFLOW:
+ errmsg = "GL_STACK_UNDERFLOW";
+ break;
+ case GL_OUT_OF_MEMORY:
+ errmsg = "GL_OUT_OF_MEMORY";
+ break;
}
+ logger->log("Error: Image GL import failed: %s", errmsg.c_str());
+ return NULL;
+ }
- return new Image(texture, width, height, realWidth, realHeight);
+ return new Image(texture, width, height, realWidth, realHeight);
}
void Image::setLoadAsOpenGL(bool useOpenGL)
@@ -542,7 +555,7 @@ void Image::setLoadAsOpenGL(bool useOpenGL)
int Image::powerOfTwo(int input)
{
int value;
- if (mTextureType == GL_TEXTURE_2D)
+ if (mPowerOfTwoTextures)
{
value = 1;
while (value < input && value < mTextureSize)
diff --git a/src/resources/image.h b/src/resources/image.h
index 7df74c3f..b1831ada 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -243,12 +243,13 @@ class Image : public Resource
*/
static int powerOfTwo(int input);
- static Image *_GLload(SDL_Surface *tmpImage);
+ static Image *_GLload(SDL_Surface *image);
GLuint mGLImage;
int mTexWidth, mTexHeight;
static bool mUseOpenGL;
+ static bool mPowerOfTwoTextures;
static int mTextureType;
static int mTextureSize;
#endif