~ubuntu-branches/ubuntu/natty/balder2d/natty

« back to all changes in this revision

Viewing changes to src/menu/widgets/sampleprobe.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bjørn Hansen
  • Date: 2008-06-15 17:15:38 UTC
  • mfrom: (1.1.1 upstream) (3.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080615171538-e407e07wbtdy0qs8
Tags: 1.0-1
* new upstream release
* update for guichan 8.1 (Closes: #482584)
* use physicsfs to make data/config/map/aiscript loading more flexible
* new skins for menus
* fix typo in control file long description (Closes: #458401)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2006 by Bjorn Hansen                                    *
 
3
 *   holomorph@users.sourceforge.net                                       *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include <guichan/rectangle.hpp>
 
22
#include <guichan/widgets/icon.hpp>
 
23
#include <guichan/sdl/sdlgraphics.hpp>
 
24
#include <SDL/SDL.h>
 
25
#include <SDL/SDL_gfxPrimitives.h>
 
26
#include "menu/widgets/sampleprobe.h"
 
27
#include "probe.h"
 
28
#include "imageloader.h"
 
29
#include "log.h"
 
30
using namespace Balder;
 
31
 
 
32
SampleProbe::SampleProbe(): probeFrame(0), probeColor(0)
 
33
{
 
34
    // Loads sprite for sample probe.
 
35
    probeSpriteImage = ImageLoader::LoadGcnImage("probe.png");
 
36
    if (probeSpriteImage == 0){
 
37
        throw "could not load Probe sprite!";
 
38
    }
 
39
    setHeight(PROBEWIDTH);
 
40
    setWidth(PROBEHEIGHT);
 
41
    frameTimer = SDL_GetTicks();
 
42
}
 
43
 
 
44
void SampleProbe::draw(gcn::Graphics* graphics)
 
45
{
 
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();
 
49
    int x,y;
 
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();
 
54
        ++probeFrame;
 
55
        if (probeFrame > MAXFRAME) probeFrame = 0;
 
56
    }
 
57
    graphics->drawImage(probeSpriteImage, probeFrame*PROBEWIDTH, 0, 0, 0, PROBEWIDTH, PROBEHEIGHT);
 
58
 
 
59
}
 
60
 
 
61
void SampleProbe::drawBorder(gcn::Graphics* graphics)
 
62
{
 
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;
 
72
 
 
73
    unsigned int i;
 
74
    for (i = 0; i < getFrameSize(); ++i)
 
75
    {
 
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);
 
82
    }
 
83
}