1 /*      _______   __   __   __   ______   __   __   _______   __   __
2  *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
3  *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
4  *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
5  *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
6  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
7  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
8  *
9  * Copyright (c) 2004, 2005 darkbits                        Js_./
10  * Per Larsson a.k.a finalman                          _RqZ{a<^_aa
11  * Olof Naess�n a.k.a jansem/yakslem                _asww7!uY`>  )\a//
12  *                                                 _Qhm`] _f "'c  1!5m
13  * Visit: http://guichan.darkbits.org             )Qk<P ` _: :+' .'  "{[
14  *                                               .)j(] .d_/ '-(  P .   S
15  * License: (BSD)                                <Td/Z <fP"5(\"??"\a.  .L
16  * Redistribution and use in source and          _dV>ws?a-?'      ._/L  #'
17  * binary forms, with or without                 )4d[#7r, .   '     )d`)[
18  * modification, are permitted provided         _Q-5'5W..j/?'   -?!\)cam'
19  * that the following conditions are met:       j<<WP+k/);.        _W=j f
20  * 1. Redistributions of source code must       .$%w\/]Q  . ."'  .  mj$
21  *    retain the above copyright notice,        ]E.pYY(Q]>.   a     J@\
22  *    this list of conditions and the           j(]1u<sE"L,. .   ./^ ]{a
23  *    following disclaimer.                     4'_uomm\.  )L);-4     (3=
24  * 2. Redistributions in binary form must        )_]X{Z('a_"a7'<a"a,  ]"[
25  *    reproduce the above copyright notice,       #}<]m7`Za??4,P-"'7. ).m
26  *    this list of conditions and the            ]d2e)Q(<Q(  ?94   b-  LQ/
27  *    following disclaimer in the                <B!</]C)d_, '(<' .f. =C+m
28  *    documentation and/or other materials      .Z!=J ]e []('-4f _ ) -.)m]'
29  *    provided with the distribution.          .w[5]' _[ /.)_-"+?   _/ <W"
30  * 3. Neither the name of Guichan nor the      :$we` _! + _/ .        j?
31  *    names of its contributors may be used     =3)= _f  (_yQmWW$#(    "
32  *    to endorse or promote products derived     -   W,  sQQQQmZQ#Wwa]..
33  *    from this software without specific        (js, \[QQW$QWW#?!V"".
34  *    prior written permission.                    ]y:.<\..          .
35  *                                                 -]n w/ '         [.
36  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT       )/ )/           !
37  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY         <  (; sac    ,    '
38  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,               ]^ .-  %
39  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF            c <   r
40  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR            aga<  <La
41  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE          5%  )P'-3L
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR        _bQf` y`..)a
43  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,          ,J?4P'.P"_(\?d'.,
44  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES               _Pa,)!f/<[]/  ?"
45  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT      _2-..:. .r+_,.. .
46  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     ?a.<%"'  " -'.a_ _,
47  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION)                     ^
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
49  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
51  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
52  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53  */
54 
55 /*
56  * For comments regarding functions please see the header file.
57  */
58 #include <assert.h>
59 #include "guichan/graphics.h"
60 #include "guichan/exception.h"
61 #include "guichan/font.h"
62 
63 namespace gcn
64 {
65 
Graphics()66     Graphics::Graphics()
67     {
68         mFont = nullptr;
69     }
70 
pushClipArea(Rectangle area)71     bool Graphics::pushClipArea(Rectangle area)
72     {
73         if (mClipStack.empty())
74         {
75             ClipRectangle carea;
76             carea.x = area.x;
77             carea.y = area.y;
78             carea.width = area.width;
79             carea.height = area.height;
80             mClipStack.push(carea);
81             return true;
82         }
83 
84         ClipRectangle top = mClipStack.top();
85         ClipRectangle carea;
86         carea = area;
87         carea.xOffset = top.xOffset + carea.x;
88         carea.yOffset = top.yOffset + carea.y;
89         carea.x += top.xOffset;
90         carea.y += top.yOffset;
91 
92         bool result = carea.intersect(top);
93 
94         mClipStack.push(carea);
95 
96         return result;
97     }
98 
popClipArea()99     void Graphics::popClipArea()
100     {
101 
102         if (mClipStack.empty())
103         {
104         	assert(!"Tried to pop clip area from empty stack.");
105             //throw GCN_EXCEPTION("Tried to pop clip area from empty stack.");
106         }
107 
108         mClipStack.pop();
109     }
110 
getCurrentClipArea()111     const ClipRectangle& Graphics::getCurrentClipArea()
112     {
113         if (mClipStack.empty())
114         {
115         	assert(!"The clip area stack is empty.");
116             //throw GCN_EXCEPTION("The clip area stack is empty.");
117         }
118 
119         return mClipStack.top();
120     }
121 
122 	//Wyrmgus start
123 //    void Graphics::drawImage(const Image* image, int dstX, int dstY)
drawImage(Image * image,int dstX,int dstY,int player,unsigned int transparency)124     void Graphics::drawImage(Image* image, int dstX, int dstY, int player, unsigned int transparency)
125 	//Wyrmgus end
126     {
127 		//Wyrmgus start
128 //        drawImage(image, 0, 0, dstX, dstY, image->getWidth(), image->getHeight());
129         drawImage(image, 0, 0, dstX, dstY, image->getWidth(), image->getHeight(), player, transparency);
130 		//Wyrmgus end
131     }
132 
setFont(Font * font)133     void Graphics::setFont(Font* font)
134     {
135         mFont = font;
136     }
137 
138 	//Wyrmgus start
139 //    void Graphics::drawText(const std::string& text, int x, int y,
140 //                            unsigned int alignment)
drawText(const std::string & text,int x,int y,unsigned int alignment,bool is_normal)141     void Graphics::drawText(const std::string& text, int x, int y,
142                             unsigned int alignment, bool is_normal)
143 	//Wyrmgus end
144     {
145         if (mFont == nullptr)
146         {
147         	assert(!"No font set.");
148             //throw GCN_EXCEPTION("No font set.");
149         }
150 
151         switch (alignment)
152         {
153           case LEFT:
154 			  //Wyrmgus start
155 //              mFont->drawString(this, text, x, y);
156               mFont->drawString(this, text, x, y, is_normal);
157 			  //Wyrmgus end
158               break;
159           case CENTER:
160 			  //Wyrmgus start
161 //              mFont->drawString(this, text, x - mFont->getWidth(text) / 2, y);
162               mFont->drawString(this, text, x - mFont->getWidth(text) / 2, y, is_normal);
163 			  //Wyrmgus end
164               break;
165           case RIGHT:
166 			  //Wyrmgus start
167 //              mFont->drawString(this, text, x - mFont->getWidth(text), y);
168               mFont->drawString(this, text, x - mFont->getWidth(text), y, is_normal);
169 			  //Wyrmgus end
170               break;
171           default:
172           	assert(!"Unknown alignment.");
173               //throw GCN_EXCEPTION("Unknown alignment.");
174         }
175     }
176 }
177