FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
icon2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
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 <fifechan/rectangle.hpp>
84 #include <fifechan/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 fcn
93 {
94 
95  Icon2::Icon2(Image* image)
96  {
97  mImage = image;
98  mScale = false;
99  mTile = false;
100  if( mImage ) {
101  setHeight(image->getHeight());
102  setWidth(image->getWidth());
103  }
104  }
105 
106  void Icon2::draw(Graphics* graphics)
107  {
108  if ( mImage ) {
109  // draw with widget or image size
110  int w = mScale ? getWidth() : mImage->getWidth();
111  int h = mScale ? getHeight() : mImage->getHeight();
112 
113  if (mTile && !mScale) {
114  Rectangle rect(0, 0, w, h);
115  while (rect.x < getWidth()) {
116  rect.y = 0;
117  while (rect.y < getHeight()) {
118  graphics->drawImage(mImage, rect.x, rect.y, rect.x, rect.y, rect.width, rect.height);
119  rect.y += rect.height;
120  }
121  rect.x += rect.width;
122  }
123  } else {
124  graphics->drawImage(mImage, 0, 0, 0, 0, w, h);
125  }
126  }
127  }
128 
129  void Icon2::drawFrame(Graphics* graphics)
130  {
131  Color faceColor = getBaseColor();
132  Color highlightColor, shadowColor;
133  int32_t alpha = getBaseColor().a;
134  int32_t width = getWidth() + getFrameSize() * 2 - 1;
135  int32_t height = getHeight() + getFrameSize() * 2 - 1;
136  highlightColor = faceColor + 0x303030;
137  highlightColor.a = alpha;
138  shadowColor = faceColor - 0x303030;
139  shadowColor.a = alpha;
140 
141  uint32_t i;
142  for (i = 0; i < getFrameSize(); ++i)
143  {
144  graphics->setColor(shadowColor);
145  graphics->drawLine(i,i, width - i, i);
146  graphics->drawLine(i,i + 1, i, height - i - 1);
147  graphics->setColor(highlightColor);
148  graphics->drawLine(width - i,i + 1, width - i, height - i);
149  graphics->drawLine(i,height - i, width - i - 1, height - i);
150  }
151  }
152 
153  void Icon2::setImage(Image* image) {
154  mImage = image;
155  if( mImage ) {
156  setHeight(image->getHeight());
157  setWidth(image->getWidth());
158  }
159  }
160 
161  bool Icon2::isScaling() const {
162  return mScale;
163  }
164 
165  void Icon2::setScaling(bool scale) {
166  mScale = scale;
167  }
168 
169  bool Icon2::isTiling() const {
170  return mTile;
171  }
172 
173  void Icon2::setTiling(bool tile) {
174  mTile = tile;
175  }
176 }
Icon2(Image *image)
Constructor.
Definition: icon2.cpp:95
virtual void draw(Graphics *graphics)
Definition: icon2.cpp:106
void setTiling(bool tile)
Definition: icon2.cpp:173
bool isScaling() const
Definition: icon2.cpp:161
Image * mImage
Definition: icon2.h:131
bool isTiling() const
Definition: icon2.cpp:169
void setScaling(bool scale)
Definition: icon2.cpp:165
bool mScale
Definition: icon2.h:132
virtual void drawFrame(Graphics *graphics)
Definition: icon2.cpp:129
bool mTile
Definition: icon2.h:133
unsigned int uint32_t
Definition: core.h:40
void setImage(Image *image)
Definition: icon2.cpp:153