1 /***************************************************************************
2  *   Copyright (c) 2017-2019 by the fifechan team                               *
3  *   https://github.com/fifengine/fifechan                                 *
4  *   This file is part of fifechan.                                        *
5  *                                                                         *
6  *   fifechan 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 - 2008 Olof Naess�n and Per Larsson
31  *
32  *
33  * Per Larsson a.k.a finalman
34  * Olof Naess�n a.k.a jansem/yakslem
35  *
36  * Visit: http://guichan.sourceforge.net
37  *
38  * License: (BSD)
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  *    notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  *    notice, this list of conditions and the following disclaimer in
46  *    the documentation and/or other materials provided with the
47  *    distribution.
48  * 3. Neither the name of Guichan nor the names of its contributors may
49  *    be used to endorse or promote products derived from this software
50  *    without specific prior written permission.
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
58  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
59  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
60  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
61  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
62  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63  */
64 
65 #ifndef FCN_ALLEGROGRAPHICS_HPP
66 #define FCN_ALLEGROGRAPHICS_HPP
67 
68 #include <allegro.h>
69 
70 #include "fifechan/color.hpp"
71 #include "fifechan/graphics.hpp"
72 #include "fifechan/platform.hpp"
73 
74 namespace fcn
75 {
76     class Font;
77 
78     /**
79      * Allegro implementation of Graphics.
80      */
81     class FCN_EXTENSION_DECLSPEC AllegroGraphics : public Graphics
82     {
83     public:
84 
85         // Needed so that drawImage(fcn::Image *, int, int) is visible.
86         using Graphics::drawImage;
87 
88         /**
89          * Constructor.
90          */
91         AllegroGraphics();
92 
93         /**
94          * Contsructor. Sets the drawing target.
95          *
96          * @param target the target to draw to.
97          */
98         AllegroGraphics(BITMAP *target);
99 
100         /**
101          * Destructor.
102          */
103         virtual ~AllegroGraphics();
104 
105         /**
106          * Sets the target bitmap to draw to. It can be any bitmap with the same
107          * bit-depth as the screen. However, if you pass the screen bitmap you
108          * will probably get flicker. Use a double buffer!
109          *
110          * @param target the bitmap to draw to.
111          */
112         virtual void setTarget(BITMAP *target);
113 
114         /**
115          * Gets the target bitmap.
116          *
117          * @return the target bitmap.
118          */
119         virtual BITMAP *getTarget();
120 
121         /**
122          * Gets the color in Allegro format.
123          *
124          * @return the color in Allegro format.
125          */
126         int getAllegroColor() const;
127 
128         /**
129          * Draws an Allegro bitmap.
130          *
131          * @param bitmap the bitmap to draw.
132          * @param dstX the x-coordinate where to draw the bitmap.
133          * @param dstY the y-coordinate where to draw the bitmap.
134          */
135         virtual void drawBitmap(BITMAP* bitmap, int dstX, int dstY);
136 
137 
138         // Inherited from Graphics
139 
140         virtual void _beginDraw();
141 
142         virtual void _endDraw();
143 
144         virtual bool pushClipArea(Rectangle area);
145 
146         virtual void popClipArea();
147 
148         virtual void drawImage(const Image* image,
149                                int srcX,
150                                int srcY,
151                                int dstX,
152                                int dstY,
153                                int width,
154                                int height);
155 
156         virtual void drawPoint(int x, int y);
157 
158         virtual void drawLine(int x1, int y1, int x2, int y2);
159 
160         virtual void drawRectangle(const Rectangle& rectangle);
161 
162         virtual void fillRectangle(const Rectangle& rectangle);
163 
164         virtual void setColor(const Color& color);
165 
166         virtual const Color& getColor() const;
167 
168     protected:
169         BITMAP *mTarget;
170         bool mClipNull;
171         int mAllegroColor;
172         Color mColor;
173     };
174 }
175 
176 #endif // end FCN_ALLEGROGRAPHICS_HPP
177 
178