1
/***************************************************************************
2
* Copyright (C) 2006 by Bjorn Hansen *
3
* holomorph@users.sourceforge.net *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
21
#include <guichan/rectangle.hpp>
22
#include <guichan/widgets/icon.hpp>
23
#include <guichan/sdl/sdlgraphics.hpp>
25
#include <SDL/SDL_gfxPrimitives.h>
26
#include "menu/widgets/sampleprobe.h"
28
#include "imageloader.h"
30
using namespace Balder;
32
SampleProbe::SampleProbe(): probeFrame(0), probeColor(0)
34
// Loads sprite for sample probe.
35
probeSpriteImage = ImageLoader::LoadGcnImage("probe.png");
36
if (probeSpriteImage == 0){
37
throw "could not load Probe sprite!";
39
setHeight(PROBEWIDTH);
40
setWidth(PROBEHEIGHT);
41
frameTimer = SDL_GetTicks();
44
void SampleProbe::draw(gcn::Graphics* graphics)
46
// looks like we still have to draw directly to the screen here...
47
// no doubt this will choke if the obect is not an SDLGraphics object
48
SDL_Surface *screen = dynamic_cast<gcn::SDLGraphics*>(graphics)->getTarget();
50
gcn::Widget::getAbsolutePosition(x,y);
51
filledCircleColor(screen, x+PROBEWIDTH/2, y+PROBEHEIGHT/2, (PROBEWIDTH/2)-1, probeColor);
52
if (SDL_GetTicks() - frameTimer > SAMPLEPROBE_FRAME_INTERVAL) {
53
frameTimer = SDL_GetTicks();
55
if (probeFrame > MAXFRAME) probeFrame = 0;
57
graphics->drawImage(probeSpriteImage, probeFrame*PROBEWIDTH, 0, 0, 0, PROBEWIDTH, PROBEHEIGHT);
61
void SampleProbe::drawBorder(gcn::Graphics* graphics)
63
gcn::Color faceColor = getBaseColor();
64
gcn::Color highlightColor, shadowColor;
65
int alpha = getBaseColor().a;
66
int width = getWidth() + getFrameSize() * 2 - 1;
67
int height = getHeight() + getFrameSize() * 2 - 1;
68
highlightColor = faceColor + 0x303030;
69
highlightColor.a = alpha;
70
shadowColor = faceColor - 0x303030;
71
shadowColor.a = alpha;
74
for (i = 0; i < getFrameSize(); ++i)
76
graphics->setColor(shadowColor);
77
graphics->drawLine(i,i, width - i, i);
78
graphics->drawLine(i,i + 1, i, height - i - 1);
79
graphics->setColor(highlightColor);
80
graphics->drawLine(width - i,i + 1, width - i, height - i);
81
graphics->drawLine(i,height - i, width - i - 1, height - i);