FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
icon2.cpp
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 /* _______ __ __ __ ______ __ __ _______ __ __
23  * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
24  * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
25  * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
26  * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
27  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
28  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
29  *
30  * Copyright (c) 2004, 2005 darkbits Js_./
31  * Per Larsson a.k.a finalman _RqZ{a<^_aa
32  * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a//
33  * _Qhm`] _f "'c 1!5m
34  * Visit: http://guichan.darkbits.org )Qk<P ` _: :+' .' "{[
35  * .)j(] .d_/ '-( P . S
36  * License: (BSD) <Td/Z <fP"5(\"??"\a. .L
37  * Redistribution and use in source and _dV>ws?a-?' ._/L #'
38  * binary forms, with or without )4d[#7r, . ' )d`)[
39  * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam'
40  * that the following conditions are met: j<<WP+k/);. _W=j f
41  * 1. Redistributions of source code must .$%w\/]Q . ."' . mj$
42  * retain the above copyright notice, ]E.pYY(Q]>. a J@\
43  * this list of conditions and the j(]1u<sE"L,. . ./^ ]{a
44  * following disclaimer. 4'_uomm\. )L);-4 (3=
45  * 2. Redistributions in binary form must )_]X{Z('a_"a7'<a"a, ]"[
46  * reproduce the above copyright notice, #}<]m7`Za??4,P-"'7. ).m
47  * this list of conditions and the ]d2e)Q(<Q( ?94 b- LQ/
48  * following disclaimer in the <B!</]C)d_, '(<' .f. =C+m
49  * documentation and/or other materials .Z!=J ]e []('-4f _ ) -.)m]'
50  * provided with the distribution. .w[5]' _[ /.)_-"+? _/ <W"
51  * 3. Neither the name of Guichan nor the :$we` _! + _/ . j?
52  * names of its contributors may be used =3)= _f (_yQmWW$#( "
53  * to endorse or promote products derived - W, sQQQQmZQ#Wwa]..
54  * from this software without specific (js, \[QQW$QWW#?!V"".
55  * prior written permission. ]y:.<\.. .
56  * -]n w/ ' [.
57  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT )/ )/ !
58  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY < (; sac , '
59  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, ]^ .- %
60  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF c < r
61  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR aga< <La
62  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 5% )P'-3L
63  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR _bQf` y`..)a
64  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ,J?4P'.P"_(\?d'.,
65  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES _Pa,)!f/<[]/ ?"
66  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT _2-..:. .r+_,.. .
67  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ?a.<%"' " -'.a_ _,
68  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ^
69  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
70  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
71  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
72  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
73  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74  */
75 
76 /*
77  * For comments regarding functions please see the header file.
78  */
79 
80 // Standard C++ library includes
81 
82 // 3rd party library includes
83 #include <guichan/rectangle.hpp>
84 #include <guichan/graphics.hpp>
85 
86 // FIFE includes
87 // These includes are split up in two parts, separated by one empty line
88 // First block: files included from the FIFE root src directory
89 // Second block: files included from the same folder
90 #include "icon2.h"
91 
92 namespace gcn
93 {
94 
95  Icon2::Icon2(Image* image)
96  {
97  mImage = image;
98  if( mImage ) {
99  setHeight(image->getHeight());
100  setWidth(image->getWidth());
101  }
102  }
103 
104  void Icon2::draw(Graphics* graphics)
105  {
106  if ( mImage )
107  graphics->drawImage(mImage, 0, 0, 0, 0, getWidth(), getHeight());
108 
109  }
110 
111  void Icon2::drawFrame(Graphics* graphics)
112  {
113  Color faceColor = getBaseColor();
114  Color highlightColor, shadowColor;
115  int32_t alpha = getBaseColor().a;
116  int32_t width = getWidth() + getFrameSize() * 2 - 1;
117  int32_t height = getHeight() + getFrameSize() * 2 - 1;
118  highlightColor = faceColor + 0x303030;
119  highlightColor.a = alpha;
120  shadowColor = faceColor - 0x303030;
121  shadowColor.a = alpha;
122 
123  uint32_t i;
124  for (i = 0; i < getFrameSize(); ++i)
125  {
126  graphics->setColor(shadowColor);
127  graphics->drawLine(i,i, width - i, i);
128  graphics->drawLine(i,i + 1, i, height - i - 1);
129  graphics->setColor(highlightColor);
130  graphics->drawLine(width - i,i + 1, width - i, height - i);
131  graphics->drawLine(i,height - i, width - i - 1, height - i);
132  }
133  }
134 
135  void Icon2::setImage(Image* image) {
136  mImage = image;
137  if( mImage ) {
138  setHeight(image->getHeight());
139  setWidth(image->getWidth());
140  }
141  }
142 
143 }