00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef HEADER_SUPERTUX_VIDEO_DRAWING_CONTEXT_HPP
00018 #define HEADER_SUPERTUX_VIDEO_DRAWING_CONTEXT_HPP
00019
00020 #include <memory>
00021 #include <string>
00022 #include <vector>
00023 #include <stdint.h>
00024 #include <obstack.h>
00025
00026 #include "math/rectf.hpp"
00027 #include "math/vector.hpp"
00028 #include "video/color.hpp"
00029 #include "video/drawing_request.hpp"
00030 #include "video/font.hpp"
00031 #include "video/font_ptr.hpp"
00032 #include "video/texture.hpp"
00033
00034 class Surface;
00035 class Texture;
00036 class Renderer;
00037 class Lightmap;
00038
00039 inline int next_po2(int val)
00040 {
00041 int result = 1;
00042 while(result < val)
00043 result *= 2;
00044
00045 return result;
00046 }
00047
00052 class DrawingContext
00053 {
00054 public:
00055 DrawingContext();
00056 ~DrawingContext();
00057
00058 void init_renderer();
00059
00061 void draw_surface(SurfacePtr surface, const Vector& position,
00062 int layer);
00064 void draw_surface(SurfacePtr surface, const Vector& position,
00065 float angle, const Color& color, const Blend& blend,
00066 int layer);
00068 void draw_surface_part(SurfacePtr surface, const Vector& source,
00069 const Vector& size, const Vector& dest, int layer);
00071 void draw_text(FontPtr font, const std::string& text,
00072 const Vector& position, FontAlignment alignment, int layer, Color color = Color(1.0,1.0,1.0));
00073
00077 void draw_center_text(FontPtr font, const std::string& text,
00078 const Vector& position, int layer, Color color = Color(1.0,1.0,1.0));
00080 void draw_gradient(const Color& from, const Color& to, int layer);
00082 void draw_filled_rect(const Vector& topleft, const Vector& size,
00083 const Color& color, int layer);
00084 void draw_filled_rect(const Rectf& rect, const Color& color, int layer);
00085 void draw_filled_rect(const Rectf& rect, const Color& color, float radius, int layer);
00086
00087 void draw_inverse_ellipse(const Vector& pos, const Vector& size, const Color& color, int layer);
00088
00090 Rectf get_cliprect() const;
00091
00093 void do_drawing();
00094
00095 const Vector& get_translation() const
00096 { return transform.translation; }
00097
00098 void set_translation(const Vector& newtranslation)
00099 { transform.translation = newtranslation; }
00100
00101 void push_transform();
00102 void pop_transform();
00103
00105 void set_drawing_effect(DrawingEffect effect);
00107 DrawingEffect get_drawing_effect() const;
00109 void set_alpha(float alpha);
00111 float get_alpha() const;
00112
00114 void get_light(const Vector& position, Color* color );
00115
00116 typedef ::Target Target;
00117 static const Target NORMAL = ::NORMAL;
00118 static const Target LIGHTMAP = ::LIGHTMAP;
00119 void push_target();
00120 void pop_target();
00121 void set_target(Target target);
00122
00123 void set_ambient_color( Color new_color );
00124
00128 void take_screenshot();
00129
00130 private:
00131 typedef std::vector<DrawingRequest*> DrawingRequests;
00132
00133 private:
00134 void handle_drawing_requests(DrawingRequests& requests);
00135
00136 private:
00137 class Transform
00138 {
00139 public:
00140 Vector translation;
00141 DrawingEffect drawing_effect;
00142 float alpha;
00143
00144 Transform() :
00145 translation(),
00146 drawing_effect(NO_EFFECT),
00147 alpha(1.0f)
00148 { }
00149
00150 Vector apply(const Vector& v) const
00151 {
00152 return v - translation;
00153 }
00154 };
00155
00156 private:
00157 Renderer *renderer;
00158 Lightmap *lightmap;
00159
00161 std::vector<Transform> transformstack;
00163 Transform transform;
00164
00165 std::vector<Blend> blend_stack;
00166 Blend blend_mode;
00167
00168 DrawingRequests drawing_requests;
00169 DrawingRequests lightmap_requests;
00170
00171 DrawingRequests* requests;
00172 Color ambient_color;
00173
00174 Target target;
00175 std::vector<Target> target_stack;
00176
00177
00178 struct obstack obst;
00179
00180 bool screenshot_requested;
00182 private:
00183 DrawingContext(const DrawingContext&);
00184 DrawingContext& operator=(const DrawingContext&);
00185 };
00186
00187 #endif
00188
00189