- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

ugraphics.hpp

00001 /*************************************************************************** 00002 LibUFO - UI For OpenGL 00003 copyright : (C) 2001-2005 by Johannes Schmidt 00004 email : schmidtjf at users.sourceforge.net 00005 ------------------- 00006 00007 file : include/ufo/ugraphics.hpp 00008 begin : Sat Jul 20 2002 00009 $Id: ugraphics.hpp,v 1.13 2005/10/11 19:16:13 schmidtjf Exp $ 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * This library is free software; you can redistribute it and/or * 00014 * modify it under the terms of the GNU Lesser General Public * 00015 * License as published by the Free Software Foundation; either * 00016 * version 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00021 * Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00026 ***************************************************************************/ 00027 00028 #ifndef UGRAPHICS_HPP 00029 #define UGRAPHICS_HPP 00030 00031 #include "uobject.hpp" 00032 00033 #include "font/ufont.hpp" 00034 #include "util/urectangle.hpp" 00035 #include "util/ucolor.hpp" 00036 00037 #include "image/uimage.hpp" 00038 00039 namespace ufo { 00040 00041 class UContext; 00042 00043 class UImage; 00044 class UImageIO; 00045 class UVertexArray; 00046 00060 class UFO_EXPORT UGraphics : public UObject { 00061 UFO_DECLARE_ABSTRACT_CLASS(UGraphics) 00062 public: 00063 enum VertexType { 00064 Points, 00065 Lines, 00066 LineStrip, 00067 Triangles, 00068 TriangleStrip, 00069 TriangleFan 00070 }; 00071 enum GCState { 00072 Blending = 1, 00073 SmoothShading, 00074 LineAntialiasing, 00075 FillAntialiasing 00076 }; 00077 public: // initialization 00079 virtual UContext * getContext() const = 0; 00080 00085 virtual URectangle mapToDevice(const URectangle & rect) = 0; 00086 00091 virtual URectangle mapFromDevice(const URectangle & rect) = 0; 00092 00093 public: // extended methods 00099 virtual void begin() = 0; 00104 virtual void end() = 0; 00106 virtual void clear() = 0; 00110 virtual UImageIO * dump() = 0; 00111 00116 virtual void resetDeviceAttributes() {} 00121 virtual void resetDeviceViewMatrix() {} 00123 void flush() {} 00124 00125 virtual void setEnabled(GCState state, bool b) = 0; 00126 virtual bool isEnabled(GCState state) const = 0; 00127 00128 00129 public: // Public attributes 00134 virtual void setColor(const UColor & color) = 0; 00140 virtual UColor getColor() const = 0; 00141 00142 virtual void setClearColor(const UColor & clearColor) = 0; 00143 virtual UColor getClearColor() const = 0; 00144 00146 virtual void setFont(const UFont & font) = 0; 00148 virtual UFont getFont() const = 0; 00149 00150 public: // text drawing functions 00154 virtual void drawString(const std::string & string, int x = 0, int y = 0) = 0; 00155 00159 virtual UDimension getStringSize(const std::string & string) = 0; 00160 00161 public: // 00165 virtual void setClipRect(const URectangle & rect) = 0; 00167 virtual URectangle getClipRect() const = 0; 00168 00169 virtual void setLineWidth(float width) = 0; 00170 virtual float getLineWidth() const = 0; 00171 public: // 00173 virtual void translate(float x, float y) = 0; 00174 virtual float getTranslationX() const = 0; 00175 virtual float getTranslationY() const = 0; 00176 00177 public: // basic drawing operations 00181 virtual void drawRect(const URectangle & rect) = 0; 00183 virtual void fillRect(const URectangle & rect) = 0; 00184 00186 virtual void drawLine(const UPoint & p1, const UPoint & p2) = 0; 00187 00192 virtual void drawVertexArray(VertexType type, UVertexArray * buffer) = 0; 00193 00203 virtual void drawImage(UImage * image, const URectangle & rect) = 0; 00204 00214 virtual void drawSubImage(UImage * image, 00215 const URectangle & srcRect, const URectangle & destRect) = 0; 00216 00217 public: // inline helper methods 00218 void drawRect(int x, int y, int w, int h) { 00219 drawRect(URectangle(x, y, w, h)); 00220 } 00221 void fillRect(int x, int y, int w, int h) { 00222 fillRect(URectangle(x, y, w, h)); 00223 } 00224 00225 void drawLine(int x1, int y1, int x2, int y2) { 00226 drawLine(UPoint(x1, y1), UPoint(x2, y2)); 00227 } 00230 void drawImage(UImage * image, int x, int y) { 00231 drawImage(image, UPoint(x, y)); 00232 } 00233 void drawImage(UImage * image, const UPoint & p) { 00234 drawImage(image, URectangle(p, image->getImageSize())); 00235 } 00236 void drawImage(UImage * image, int x, int y, int w, int h) { 00237 drawImage(image, URectangle(x, y, w, h)); 00238 } 00239 void drawSubImage(UImage * image, 00240 int srcX, int srcY, int srcWidth, int srcHeight, 00241 int destX, int destY) { 00242 drawSubImage(image, URectangle(srcX, srcY, srcWidth, srcHeight), 00243 UPoint(destX, destY)); 00244 } 00246 void drawSubImage(UImage * image, const URectangle & srcRect, 00247 const UPoint & destLocation) { 00248 drawSubImage(image, srcRect, URectangle(destLocation, image->getImageSize())); 00249 } 00250 00251 void drawSubImage(UImage * image, 00252 int srcX, int srcY, int srcWidth, int srcHeight, 00253 int destX, int destY, int destWidth, int destHeight) { 00254 drawSubImage(image, URectangle(srcX, srcY, srcWidth, srcHeight), 00255 URectangle(destX, destY, destWidth, destHeight)); 00256 } 00257 }; 00258 00259 } // namespace ufo 00260 00261 #endif // UGRAPHICS_HPP

The libUFO Project - written by Johannes Schmidt