00001 /* 00002 $Id: target.h,v 1.1 2001/03/06 15:09:10 mbn Exp $ 00003 00004 ------------------------------------------------------------------------ 00005 ClanLib, the platform independent game SDK. 00006 00007 This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE 00008 version 2. See COPYING for details. 00009 00010 For a total list of contributers see CREDITS. 00011 00012 ------------------------------------------------------------------------ 00013 */ 00014 00016 00017 #ifndef header_target 00018 #define header_target 00019 00020 #include <stack> 00021 #include "cliprect.h" 00022 #include "pixelformat.h" 00023 00024 class CL_Palette; 00025 00026 class CL_Target 00027 //: Target class in ClanLib. 00028 00029 // <p>The CL_Target class represents a renderer target in ClanLib. This can 00030 // be a part of the framebuffer, or a piece of memory specified by the 00031 // application.</p> 00032 // 00033 // <p>This class contains a set of functions used to describe a piece of 00034 // memory, things such as the width, height, color masks and depth. This 00035 // information can then be used by ClanLib or the application to access the 00036 // given piece of memory.</p> 00037 // 00038 // <p>To access the memory itself, call get_data() after a call to lock(). 00039 // When you are finished accessing the memory, call unlock(). Note that 00040 // after the unlock() call, the pointer obtained from get_data() will be 00041 // invalid, and new call to lock() is required before get_data() will return 00042 // anything valid.</p> 00043 // 00044 // <p>CL_Target contain a set of functions doing simple primitive 00045 // operations: draw boxes, lines and clipping. These are provided for 00046 // convience so you won't have to do such simple things manually in a lock 00047 // session.</p> 00048 // 00049 // <p>CL_Surface supports blitting to a target and all surface providers are 00050 // inheritated from a target. This means that you can do surface to provider 00051 // blitting. ClanLib has a special surface provider called CL_Canvas which 00052 // you should use to easilly build a new image.</p> 00053 { 00054 public: 00055 CL_Target() { m_translation_stack.push(TranslationOffset(0,0)); } 00056 virtual ~CL_Target() { return; } 00057 00058 virtual bool is_video() const { return false; } 00059 //: Returns true if in video memory. 00061 00062 virtual void lock()=0; 00063 //: Locks the target. This allows access to the target data using the 00064 //: get_data() function call. 00065 00066 virtual void unlock()=0; 00067 //: Unlock the target. Must be called after you're finished with modifying 00068 //: the target data. 00069 00070 virtual void *get_data() const=0; 00071 //: Returns a pointer to the target data. Only valid between lock/unlock 00072 //: calls. 00074 00075 virtual unsigned int get_num_frames() const=0; 00076 //: Returns the number of frames available on this target. 00077 00078 virtual unsigned int get_width() const=0; 00079 //: Returns the width of the target. 00080 00081 virtual unsigned int get_height() const=0; 00082 //: Returns the height of the target. 00083 00084 virtual unsigned int get_pitch() const=0; 00085 //: Returns the pitch (bytes per line) used by the target. 00086 00087 virtual unsigned int get_depth() const 00088 { 00089 unsigned int mask = 00090 get_red_mask() | 00091 get_green_mask() | 00092 get_blue_mask() | 00093 get_alpha_mask(); 00094 00095 int bits = 0; 00096 while (mask!=0) 00097 { 00098 mask = (mask >> 1); 00099 bits++; 00100 } 00101 bits = (bits+7)/8; 00102 return bits*8; 00103 } 00104 //: Returns the depth used by the target. 00105 00106 virtual unsigned int get_bytes_per_pixel() const { return (get_depth()+7)/8; } 00107 //: Returns the bytes per pixel of the target. 00108 00109 virtual bool is_indexed() const=0; 00110 //: Returns whether the target uses an indexed color mode or not. 00111 00112 virtual unsigned int get_red_mask() const=0; 00113 //: Returns the red color mask used by the target. 00114 00115 virtual unsigned int get_green_mask() const=0; 00116 //: Returns the green color mask by the target. 00117 00118 virtual unsigned int get_blue_mask() const=0; 00119 //: Returns the blue color mask by the target. 00120 00121 virtual unsigned int get_alpha_mask() const=0; 00122 //: Returns the alpha mask by the target. 00123 00124 virtual CL_Palette *get_palette() const=0; 00125 //: Returns the palette used by the target. 00126 00127 virtual void push_clip_rect(); 00128 //: Pushes the current clipping rectangle onto the cliprect stack. 00129 00130 virtual void push_clip_rect(const CL_ClipRect &rect); 00131 //: Pushes the current clipping rectangle onto the cliprect stack. It then clips 00132 //: the passed rectangle 'rect' with the current one, and uses the result as the 00133 //: new clipping rect. 00135 00136 virtual CL_ClipRect get_clip_rect(); 00137 //: Returns the current clipping rectangle. 00139 00140 virtual void set_clip_rect(const CL_ClipRect &rect); 00141 //: Sets the current clipping rectangle. This is an absolute set, so it doesn't 00142 //: get clipped with the previous one. 00143 00144 virtual void pop_clip_rect(); 00145 //: Pop the clipping rectangle last pushed onto the stack. 00146 00147 virtual void push_translate_offset(); 00148 //: Pushes the current translation rectangle onto the cliprect stack. 00149 00150 virtual void push_translate_offset(int x, int y); 00151 //: Push translation offset onto translation stack. This offset will 00152 //: affect any subsequent display operations on the displaycard, by 00153 //: translating the position of the display operation with the offset. 00154 //: The offset will be offset by any previous offsets pushed onto the stack, 00155 //: eg. it inherits the previous offset. 00156 00157 virtual int get_translate_offset_x() const; 00158 //: Returns the current effective x-axis translation offset. 00159 00160 virtual int get_translate_offset_y() const; 00161 //: Returns the current effective y-axis translation offset. 00162 00163 virtual void set_translate_offset(int x, int y); 00164 //: Sets the translation offset as a new absolute translation offset. 00165 //: The new offset will disregard any previous offset's, but will not 00166 //: empty the translation stack. The new translation offset will affect 00167 //: any subsequent display operations on the displaycard, by 00168 //: translating the position of the display operation with the offset 00169 00170 virtual void pop_translate_offset(); 00171 //: Pops the last pushed translation offset from the translation offset 00172 //: stack. If the stack is empty, nothing will happen, and if the last 00173 //: translation offset is popped, the translation offset will be set to 0,0 00174 00175 void draw_pixel(int x1, int y1, int color); 00176 00177 //: TODO add documentation... 00178 00179 virtual void draw_pixel(int x, int y, float r, float g, float b, float a = 1.0) 00180 { 00181 draw_pixel(x, y, CL_Color::get_color(this, r,g,b,a)); 00182 } 00183 00184 virtual void get_pixel(int x, int y, float *r, float *g, float *b, float *a); 00185 virtual int get_pixel(int x, int y); 00186 00187 void flip_vertical(); 00188 void flip_horizontal(); 00189 00190 virtual void fill_rect(int x1, int y1, int x2, int y2, float r, float g, float b, float a = 1.0); 00191 //: Draw a filled rectangle from ('x1', 'y1') to ('x2', 'y2') using the color 00192 //: ('r', 'g', 'b', 'a'). 00201 00202 virtual void draw_rect(int x1, int y1, int x2, int y2, float r, float g, float b, float a = 1.0); 00203 //: Draw a rectangle from ('x1', 'y1') to ('x2', 'y2') using the color 00204 //: ('r', 'g', 'b', 'a'). 00213 00214 virtual void draw_line(int x1, int y1, int x2, int y2, float r, float g, float b, float a = 1.0); 00215 //: Draw a line from ('x1', 'y1') to ('x2', 'y2') using the color 00216 //: ('r', 'g', 'b', 'a'). 00225 00226 private: 00227 std::stack<CL_ClipRect> clip_stack; 00228 typedef std::pair<int,int> TranslationOffset; 00229 std::stack<TranslationOffset> m_translation_stack; 00230 }; 00231 00232 #endif
1.2.6 written by Dimitri van Heesch,
© 1997-2001