DrawingContext Class Reference

This class provides functions for drawing things on screen. More...

#include <drawing_context.hpp>

List of all members.

Public Types

typedef ::Target Target

Public Member Functions

 DrawingContext ()
 ~DrawingContext ()
void init_renderer ()
void draw_surface (SurfacePtr surface, const Vector &position, int layer)
 Adds a drawing request for a surface into the request list.
void draw_surface (SurfacePtr surface, const Vector &position, float angle, const Color &color, const Blend &blend, int layer)
 Adds a drawing request for a surface into the request list.
void draw_surface_part (SurfacePtr surface, const Vector &source, const Vector &size, const Vector &dest, int layer)
 Adds a drawing request for part of a surface.
void draw_text (FontPtr font, const std::string &text, const Vector &position, FontAlignment alignment, int layer, Color color=Color(1.0, 1.0, 1.0))
 Draws a text.
void draw_center_text (FontPtr font, const std::string &text, const Vector &position, int layer, Color color=Color(1.0, 1.0, 1.0))
 Draws text on screen center (feed Vector.x with a 0).
void draw_gradient (const Color &from, const Color &to, int layer)
 Draws a color gradient onto the whole screen */.
void draw_filled_rect (const Vector &topleft, const Vector &size, const Color &color, int layer)
 Fills a rectangle.
void draw_filled_rect (const Rectf &rect, const Color &color, int layer)
void draw_filled_rect (const Rectf &rect, const Color &color, float radius, int layer)
void draw_inverse_ellipse (const Vector &pos, const Vector &size, const Color &color, int layer)
Rectf get_cliprect () const
 Returns the visible area in world coordinates.
void do_drawing ()
 Processes all pending drawing requests and flushes the list.
const Vectorget_translation () const
void set_translation (const Vector &newtranslation)
void push_transform ()
void pop_transform ()
void set_drawing_effect (DrawingEffect effect)
 Apply that effect in the next draws (effects are listed on surface.h).
DrawingEffect get_drawing_effect () const
 return currently applied drawing effect
void set_alpha (float alpha)
 apply that alpha in the next draws (1.0 means fully opaque) */
float get_alpha () const
 return currently set alpha
void get_light (const Vector &position, Color *color)
 on next update, set color to lightmap's color at position
void push_target ()
void pop_target ()
void set_target (Target target)
void set_ambient_color (Color new_color)
void take_screenshot ()
 requests that a screenshot be taken after the next frame has been rendered

Static Public Attributes

static const Target NORMAL = ::NORMAL
static const Target LIGHTMAP = ::LIGHTMAP

Private Types

typedef std::vector< DrawingRequest * > DrawingRequests

Private Member Functions

void handle_drawing_requests (DrawingRequests &requests)
 DrawingContext (const DrawingContext &)
DrawingContextoperator= (const DrawingContext &)

Private Attributes

Rendererrenderer
Lightmaplightmap
std::vector< Transformtransformstack
 the transform stack
Transform transform
 the currently active transform
std::vector< Blendblend_stack
Blend blend_mode
DrawingRequests drawing_requests
DrawingRequests lightmap_requests
DrawingRequestsrequests
Color ambient_color
Target target
std::vector< Targettarget_stack
obstack obst
bool screenshot_requested
 true if a screenshot should be taken after the next frame has been rendered

Classes

class  Transform


Detailed Description

This class provides functions for drawing things on screen.

It also maintains a stack of transforms that are applied to graphics.

Definition at line 52 of file drawing_context.hpp.


Member Typedef Documentation

typedef ::Target DrawingContext::Target

Definition at line 116 of file drawing_context.hpp.

typedef std::vector<DrawingRequest*> DrawingContext::DrawingRequests [private]

Definition at line 131 of file drawing_context.hpp.


Constructor & Destructor Documentation

DrawingContext::DrawingContext (  ) 

Definition at line 34 of file drawing_context.cpp.

References drawing_requests, obst, and requests.

00034                                :
00035   renderer(0), 
00036   lightmap(0),
00037   transformstack(),
00038   transform(),
00039   blend_stack(),
00040   blend_mode(),
00041   drawing_requests(),
00042   lightmap_requests(),
00043   requests(),
00044   ambient_color(1.0f, 1.0f, 1.0f, 1.0f),
00045   target(NORMAL),
00046   target_stack(),
00047   obst(),
00048   screenshot_requested(false)
00049 {
00050   requests = &drawing_requests;
00051   obstack_init(&obst);
00052 }

DrawingContext::~DrawingContext (  ) 

Definition at line 54 of file drawing_context.cpp.

References lightmap, obst, and renderer.

00055 {
00056   delete renderer;
00057   delete lightmap;
00058 
00059   obstack_free(&obst, NULL);
00060 }

DrawingContext::DrawingContext ( const DrawingContext  )  [private]


Member Function Documentation

void DrawingContext::init_renderer (  ) 

Definition at line 63 of file drawing_context.cpp.

References lightmap, VideoSystem::new_lightmap(), VideoSystem::new_renderer(), and renderer.

Referenced by Main::init_video().

00064 {
00065   delete renderer;
00066   delete lightmap;
00067 
00068   renderer = VideoSystem::new_renderer();
00069   lightmap = VideoSystem::new_lightmap();
00070 }

void DrawingContext::draw_surface ( SurfacePtr  surface,
const Vector position,
int  layer 
)

Adds a drawing request for a surface into the request list.

Definition at line 103 of file drawing_context.cpp.

Referenced by Tile::draw(), TextScroller::draw(), PlayerStatus::draw(), InfoBoxLine::draw(), InfoBox::draw(), Console::draw(), Sprite::draw(), Player::draw(), ParticleSystem_Interactive::draw(), ParticleSystem::draw(), LevelTime::draw(), Candle::draw(), Statistics::draw_endseq_panel(), Yeti::draw_hit_points(), Background::draw_image(), and Menu::draw_item().

00105 {
00106   draw_surface(surface, position, 0.0f, Color(1.0f, 1.0f, 1.0f), Blend(), layer);
00107 }

void DrawingContext::draw_surface ( SurfacePtr  surface,
const Vector position,
float  angle,
const Color color,
const Blend blend,
int  layer 
)

Adds a drawing request for a surface into the request list.

Definition at line 73 of file drawing_context.cpp.

References DrawingContext::Transform::alpha, DrawingRequest::alpha, DrawingRequest::angle, DrawingContext::Transform::apply(), DrawingRequest::blend, DrawingRequest::color, DrawingContext::Transform::drawing_effect, DrawingRequest::drawing_effect, DrawingRequest::layer, obst, DrawingRequest::pos, DrawingRequest::request_data, requests, SCREEN_HEIGHT, SCREEN_WIDTH, SURFACE, target, DrawingRequest::target, transform, DrawingRequest::type, Vector::x, and Vector::y.

00076 {
00077   assert(surface != 0);
00078 
00079   DrawingRequest* request = new(obst) DrawingRequest();
00080 
00081   request->target = target;
00082   request->type = SURFACE;
00083   request->pos = transform.apply(position);
00084 
00085   if(request->pos.x >= SCREEN_WIDTH || request->pos.y >= SCREEN_HEIGHT
00086      || request->pos.x + surface->get_width() < 0
00087      || request->pos.y + surface->get_height() < 0)
00088     return;
00089 
00090   request->layer = layer;
00091   request->drawing_effect = transform.drawing_effect;
00092   request->alpha = transform.alpha;
00093   request->angle = angle;
00094   request->color = color;
00095   request->blend = blend;
00096 
00097   request->request_data = surface.get();
00098 
00099   requests->push_back(request);
00100 }

void DrawingContext::draw_surface_part ( SurfacePtr  surface,
const Vector source,
const Vector size,
const Vector dest,
int  layer 
)

Adds a drawing request for part of a surface.

Definition at line 110 of file drawing_context.cpp.

References DrawingContext::Transform::alpha, DrawingRequest::alpha, DrawingContext::Transform::apply(), DrawingContext::Transform::drawing_effect, DrawingRequest::drawing_effect, DrawingRequest::layer, obst, DrawingRequest::pos, DrawingRequest::request_data, requests, SurfacePartRequest::size, SurfacePartRequest::source, SurfacePartRequest::surface, SURFACE_PART, target, DrawingRequest::target, transform, DrawingRequest::type, Vector::x, and Vector::y.

Referenced by MouseCursor::draw(), Button::draw(), and Sprite::draw_part().

00112 {
00113   assert(surface != 0);
00114 
00115   DrawingRequest* request = new(obst) DrawingRequest();
00116 
00117   request->target = target;
00118   request->type = SURFACE_PART;
00119   request->pos = transform.apply(dest);
00120   request->layer = layer;
00121   request->drawing_effect = transform.drawing_effect;
00122   request->alpha = transform.alpha;
00123 
00124   SurfacePartRequest* surfacepartrequest = new(obst) SurfacePartRequest();
00125   surfacepartrequest->size = size;
00126   surfacepartrequest->source = source;
00127   surfacepartrequest->surface = surface.get();
00128 
00129   // clip on screen borders
00130   if(request->pos.x < 0) {
00131     surfacepartrequest->size.x += request->pos.x;
00132     if(surfacepartrequest->size.x <= 0)
00133       return;
00134     surfacepartrequest->source.x -= request->pos.x;
00135     request->pos.x = 0;
00136   }
00137   if(request->pos.y < 0) {
00138     surfacepartrequest->size.y += request->pos.y;
00139     if(surfacepartrequest->size.y <= 0)
00140       return;
00141     surfacepartrequest->source.y -= request->pos.y;
00142     request->pos.y = 0;
00143   }
00144   request->request_data = surfacepartrequest;
00145 
00146   requests->push_back(request);
00147 }

void DrawingContext::draw_text ( FontPtr  font,
const std::string &  text,
const Vector position,
FontAlignment  alignment,
int  layer,
Color  color = Color(1.0, 1.0, 1.0) 
)

Draws a text.

Definition at line 150 of file drawing_context.cpp.

References TextRequest::alignment, DrawingContext::Transform::alpha, DrawingRequest::alpha, DrawingContext::Transform::apply(), DrawingRequest::color, DrawingContext::Transform::drawing_effect, DrawingRequest::drawing_effect, TextRequest::font, DrawingRequest::layer, obst, DrawingRequest::pos, DrawingRequest::request_data, requests, target, DrawingRequest::target, TextRequest::text, TEXT, transform, and DrawingRequest::type.

Referenced by TitleScreen::draw(), PlayerStatus::draw(), InfoBoxLine::draw(), Console::draw(), TextObject::draw(), LevelTime::draw(), FloatingText::draw(), Menu::draw(), Button::draw(), draw_center_text(), Statistics::draw_endseq_panel(), ScreenManager::draw_fps(), Menu::draw_item(), worldmap::WorldMap::draw_status(), and Statistics::draw_worldmap_info().

00152 {
00153   DrawingRequest* request = new(obst) DrawingRequest();
00154 
00155   request->target = target;
00156   request->type = TEXT;
00157   request->pos = transform.apply(position);
00158   request->layer = layer;
00159   request->drawing_effect = transform.drawing_effect;
00160   request->alpha = transform.alpha;
00161   request->color = color;
00162 
00163   TextRequest* textrequest = new(obst) TextRequest();
00164   textrequest->font = font.get();
00165   textrequest->text = text;
00166   textrequest->alignment = alignment;
00167   request->request_data = textrequest;
00168 
00169   requests->push_back(request);
00170 }

void DrawingContext::draw_center_text ( FontPtr  font,
const std::string &  text,
const Vector position,
int  layer,
Color  color = Color(1.0, 1.0, 1.0) 
)

Draws text on screen center (feed Vector.x with a 0).

This is the same as draw_text() with a SCREEN_WIDTH/2 position and alignment set to LEFT_ALIGN

Definition at line 173 of file drawing_context.cpp.

References ALIGN_CENTER, draw_text(), SCREEN_WIDTH, Vector::x, and Vector::y.

Referenced by SecretAreaTrigger::draw(), Climbable::draw(), LevelIntro::draw(), and TextObject::draw().

00175 {
00176   draw_text(font, text, Vector(position.x + SCREEN_WIDTH/2, position.y),
00177             ALIGN_CENTER, layer, color);
00178 }

void DrawingContext::draw_gradient ( const Color from,
const Color to,
int  layer 
)

Draws a color gradient onto the whole screen */.

Definition at line 181 of file drawing_context.cpp.

References DrawingContext::Transform::alpha, DrawingRequest::alpha, GradientRequest::bottom, DrawingContext::Transform::drawing_effect, DrawingRequest::drawing_effect, GRADIENT, DrawingRequest::layer, obst, DrawingRequest::pos, DrawingRequest::request_data, requests, target, DrawingRequest::target, GradientRequest::top, transform, and DrawingRequest::type.

Referenced by Gradient::draw().

00182 {
00183   DrawingRequest* request = new(obst) DrawingRequest();
00184 
00185   request->target = target;
00186   request->type = GRADIENT;
00187   request->pos = Vector(0,0);
00188   request->layer = layer;
00189 
00190   request->drawing_effect = transform.drawing_effect;
00191   request->alpha = transform.alpha;
00192 
00193   GradientRequest* gradientrequest = new(obst) GradientRequest();
00194   gradientrequest->top = top;
00195   gradientrequest->bottom = bottom;
00196   request->request_data = gradientrequest;
00197 
00198   requests->push_back(request);
00199 }

void DrawingContext::draw_filled_rect ( const Vector topleft,
const Vector size,
const Color color,
int  layer 
)

Fills a rectangle.

Definition at line 202 of file drawing_context.cpp.

References Color::alpha, DrawingContext::Transform::alpha, DrawingRequest::alpha, DrawingContext::Transform::apply(), FillRectRequest::color, DrawingContext::Transform::drawing_effect, DrawingRequest::drawing_effect, FILLRECT, DrawingRequest::layer, obst, DrawingRequest::pos, FillRectRequest::radius, DrawingRequest::request_data, requests, FillRectRequest::size, target, DrawingRequest::target, transform, and DrawingRequest::type.

Referenced by worldmap::WorldMap::draw(), TextScroller::draw(), Sector::draw(), LevelIntro::draw(), InfoBox::draw(), FadeOut::draw(), Thunderstorm::draw(), TextObject::draw(), Particles::draw(), MagicBlock::draw(), InfoBlock::draw(), DisplayEffect::draw(), Menu::draw(), ButtonGroup::draw(), Button::draw(), draw_filled_rect(), Menu::draw_item(), and GameSession::draw_pause().

00204 {
00205   DrawingRequest* request = new(obst) DrawingRequest();
00206 
00207   request->target = target;
00208   request->type = FILLRECT;
00209   request->pos = transform.apply(topleft);
00210   request->layer = layer;
00211 
00212   request->drawing_effect = transform.drawing_effect;
00213   request->alpha = transform.alpha;
00214 
00215   FillRectRequest* fillrectrequest = new(obst) FillRectRequest();
00216   fillrectrequest->size = size;
00217   fillrectrequest->color = color;
00218   fillrectrequest->color.alpha = color.alpha * transform.alpha;
00219   fillrectrequest->radius = 0.0f;
00220   request->request_data = fillrectrequest;
00221 
00222   requests->push_back(request);
00223 }

void DrawingContext::draw_filled_rect ( const Rectf rect,
const Color color,
int  layer 
)

Definition at line 226 of file drawing_context.cpp.

References draw_filled_rect().

00228 {
00229   draw_filled_rect(rect, color, 0.0f, layer);
00230 }

void DrawingContext::draw_filled_rect ( const Rectf rect,
const Color color,
float  radius,
int  layer 
)

Definition at line 233 of file drawing_context.cpp.

References Color::alpha, DrawingContext::Transform::alpha, DrawingRequest::alpha, DrawingContext::Transform::apply(), FillRectRequest::color, DrawingContext::Transform::drawing_effect, DrawingRequest::drawing_effect, FILLRECT, Rectf::get_height(), Rectf::get_width(), DrawingRequest::layer, obst, Rectf::p1, DrawingRequest::pos, FillRectRequest::radius, DrawingRequest::request_data, requests, FillRectRequest::size, target, DrawingRequest::target, transform, and DrawingRequest::type.

00234 {
00235   DrawingRequest* request = new(obst) DrawingRequest();
00236 
00237   request->target = target;
00238   request->type   = FILLRECT;
00239   request->pos    = transform.apply(rect.p1);
00240   request->layer  = layer;
00241 
00242   request->drawing_effect = transform.drawing_effect;
00243   request->alpha = transform.alpha;
00244 
00245   FillRectRequest* fillrectrequest = new(obst) FillRectRequest;
00246   fillrectrequest->size = Vector(rect.get_width(), rect.get_height());
00247   fillrectrequest->color = color;
00248   fillrectrequest->color.alpha = color.alpha * transform.alpha;
00249   fillrectrequest->radius = radius;
00250   request->request_data = fillrectrequest;
00251 
00252   requests->push_back(request); 
00253 }

void DrawingContext::draw_inverse_ellipse ( const Vector pos,
const Vector size,
const Color color,
int  layer 
)

Definition at line 256 of file drawing_context.cpp.

References Color::alpha, DrawingContext::Transform::alpha, DrawingRequest::alpha, DrawingContext::Transform::apply(), InverseEllipseRequest::color, DrawingContext::Transform::drawing_effect, DrawingRequest::drawing_effect, INVERSEELLIPSE, DrawingRequest::layer, obst, DrawingRequest::pos, DrawingRequest::request_data, requests, InverseEllipseRequest::size, target, DrawingRequest::target, transform, and DrawingRequest::type.

Referenced by ShrinkFade::draw().

00257 {
00258   DrawingRequest* request = new(obst) DrawingRequest();
00259 
00260   request->target = target;
00261   request->type   = INVERSEELLIPSE;
00262   request->pos    = transform.apply(pos);
00263   request->layer  = layer;
00264 
00265   request->drawing_effect = transform.drawing_effect;
00266   request->alpha = transform.alpha;
00267 
00268   InverseEllipseRequest* ellipse = new(obst)InverseEllipseRequest;
00269   
00270   ellipse->color        = color;
00271   ellipse->color.alpha  = color.alpha * transform.alpha;
00272   ellipse->size         = size;
00273   request->request_data = ellipse;
00274 
00275   requests->push_back(request);     
00276 }

Rectf DrawingContext::get_cliprect (  )  const

Returns the visible area in world coordinates.

Definition at line 279 of file drawing_context.cpp.

References get_translation(), SCREEN_HEIGHT, and SCREEN_WIDTH.

Referenced by Background::draw_image().

00280 {
00281   return Rectf(get_translation().x, get_translation().y,
00282                get_translation().x + SCREEN_WIDTH, 
00283                get_translation().y + SCREEN_HEIGHT);
00284 }

void DrawingContext::do_drawing (  ) 

Processes all pending drawing requests and flushes the list.

Definition at line 315 of file drawing_context.cpp.

References ambient_color, Color::blue, Renderer::do_take_screenshot(), DRAW_LIGHTMAP, drawing_requests, Lightmap::end_draw(), Renderer::flip(), Color::green, handle_drawing_requests(), DrawingRequest::layer, LAYER_HUD, lightmap, lightmap_requests, NORMAL, obst, Color::red, renderer, screenshot_requested, Lightmap::start_draw(), DrawingRequest::target, target_stack, transformstack, and DrawingRequest::type.

Referenced by ScreenManager::draw().

00316 {
00317   assert(transformstack.empty());
00318   assert(target_stack.empty());
00319   transformstack.clear();
00320   target_stack.clear();
00321 
00322   //Use Lightmap if ambient color is not white.
00323   bool use_lightmap = ( ambient_color.red != 1.0f   || ambient_color.green != 1.0f ||
00324                         ambient_color.blue  != 1.0f );
00325 
00326   // PART1: create lightmap
00327   if(use_lightmap) {
00328     lightmap->start_draw(ambient_color);
00329     handle_drawing_requests(lightmap_requests);
00330     lightmap->end_draw();
00331 
00332     DrawingRequest* request = new(obst) DrawingRequest();
00333     request->target = NORMAL;
00334     request->type = DRAW_LIGHTMAP;
00335     request->layer = LAYER_HUD - 1;
00336     drawing_requests.push_back(request);
00337   }
00338   lightmap_requests.clear();
00339 
00340   handle_drawing_requests(drawing_requests);
00341   drawing_requests.clear();
00342   obstack_free(&obst, NULL);
00343   obstack_init(&obst);
00344 
00345   // if a screenshot was requested, take one
00346   if (screenshot_requested) {
00347     renderer->do_take_screenshot();
00348     screenshot_requested = false;
00349   }
00350 
00351   renderer->flip();
00352 }

const Vector& DrawingContext::get_translation (  )  const [inline]

Definition at line 95 of file drawing_context.hpp.

References transform, and DrawingContext::Transform::translation.

Referenced by TileMap::draw(), SpecialRiser::draw(), ParticleSystem::draw(), Background::draw(), Button::draw(), and get_cliprect().

00096   {  return transform.translation;  }

void DrawingContext::set_translation ( const Vector newtranslation  )  [inline]

Definition at line 98 of file drawing_context.hpp.

References transform, and DrawingContext::Transform::translation.

Referenced by worldmap::WorldMap::draw(), SecretAreaTrigger::draw(), Climbable::draw(), Sector::draw(), PlayerStatus::draw(), TileMap::draw(), Thunderstorm::draw(), TextObject::draw(), SpecialRiser::draw(), ParticleSystem::draw(), LevelTime::draw(), Gradient::draw(), FloatingImage::draw(), DisplayEffect::draw(), ButtonGroup::draw(), Yeti::draw_hit_points(), and worldmap::WorldMap::draw_status().

00099   {  transform.translation = newtranslation;  }

void DrawingContext::push_transform (  ) 

Definition at line 442 of file drawing_context.cpp.

References transform, and transformstack.

Referenced by worldmap::WorldMap::draw(), SecretAreaTrigger::draw(), Climbable::draw(), Sector::draw(), PlayerStatus::draw(), Console::draw(), TileMap::draw(), Thunderstorm::draw(), TextObject::draw(), SpecialRiser::draw(), ParticleSystem_Interactive::draw(), ParticleSystem::draw(), LevelTime::draw(), InfoBlock::draw(), Gradient::draw(), FloatingText::draw(), FloatingImage::draw(), DisplayEffect::draw(), BouncyCoin::draw(), ButtonGroup::draw(), GhostTree::draw(), Statistics::draw_endseq_panel(), Yeti::draw_hit_points(), and worldmap::WorldMap::draw_status().

00443 {
00444   transformstack.push_back(transform);
00445 }

void DrawingContext::pop_transform (  ) 

Definition at line 448 of file drawing_context.cpp.

References transform, and transformstack.

Referenced by worldmap::WorldMap::draw(), SecretAreaTrigger::draw(), Climbable::draw(), Sector::draw(), PlayerStatus::draw(), Console::draw(), TileMap::draw(), Thunderstorm::draw(), TextObject::draw(), SpecialRiser::draw(), ParticleSystem_Interactive::draw(), ParticleSystem::draw(), LevelTime::draw(), InfoBlock::draw(), Gradient::draw(), FloatingText::draw(), FloatingImage::draw(), DisplayEffect::draw(), BouncyCoin::draw(), ButtonGroup::draw(), GhostTree::draw(), Statistics::draw_endseq_panel(), Yeti::draw_hit_points(), and worldmap::WorldMap::draw_status().

00449 {
00450   assert(!transformstack.empty());
00451 
00452   transform = transformstack.back();
00453   transformstack.pop_back();
00454 }

void DrawingContext::set_drawing_effect ( DrawingEffect  effect  ) 

Apply that effect in the next draws (effects are listed on surface.h).

Definition at line 457 of file drawing_context.cpp.

References DrawingContext::Transform::drawing_effect, and transform.

Referenced by Sprite::draw(), TileMap::draw(), and BadGuy::draw().

00458 {
00459   transform.drawing_effect = effect;
00460 }

DrawingEffect DrawingContext::get_drawing_effect (  )  const

return currently applied drawing effect

Definition at line 463 of file drawing_context.cpp.

References DrawingContext::Transform::drawing_effect, and transform.

Referenced by BadGuy::draw().

00464 {
00465   return transform.drawing_effect;
00466 }

void DrawingContext::set_alpha ( float  alpha  ) 

apply that alpha in the next draws (1.0 means fully opaque) */

Definition at line 469 of file drawing_context.cpp.

References DrawingContext::Transform::alpha, and transform.

Referenced by Console::draw(), TileMap::draw(), TextObject::draw(), InfoBlock::draw(), FloatingText::draw(), FloatingImage::draw(), BouncyCoin::draw(), GhostTree::draw(), and Statistics::draw_endseq_panel().

00470 {
00471   transform.alpha = alpha;
00472 }

float DrawingContext::get_alpha (  )  const

return currently set alpha

Definition at line 475 of file drawing_context.cpp.

References DrawingContext::Transform::alpha, and transform.

00476 {
00477   return transform.alpha;
00478 }

void DrawingContext::get_light ( const Vector position,
Color color 
)

on next update, set color to lightmap's color at position

Definition at line 287 of file drawing_context.cpp.

References ambient_color, DrawingContext::Transform::apply(), Color::blue, GetLightRequest::color_ptr, GETLIGHT, Color::green, DrawingRequest::layer, LAYER_GUI, lightmap_requests, obst, DrawingRequest::pos, Color::red, DrawingRequest::request_data, SCREEN_HEIGHT, SCREEN_WIDTH, target, DrawingRequest::target, transform, DrawingRequest::type, Vector::x, and Vector::y.

Referenced by MagicBlock::draw().

00288 {
00289   if( ambient_color.red == 1.0f && ambient_color.green == 1.0f
00290       && ambient_color.blue  == 1.0f ) {
00291     *color = Color( 1.0f, 1.0f, 1.0f);
00292     return;
00293   }
00294 
00295   DrawingRequest* request = new(obst) DrawingRequest();
00296   request->target = target;
00297   request->type = GETLIGHT;
00298   request->pos = transform.apply(position);
00299 
00300   //There is no light offscreen.
00301   if(request->pos.x >= SCREEN_WIDTH || request->pos.y >= SCREEN_HEIGHT
00302      || request->pos.x < 0 || request->pos.y < 0){
00303     *color = Color( 0, 0, 0);
00304     return;
00305   }
00306 
00307   request->layer = LAYER_GUI; //make sure all get_light requests are handled last.
00308   GetLightRequest* getlightrequest = new(obst) GetLightRequest();
00309   getlightrequest->color_ptr = color;
00310   request->request_data = getlightrequest;
00311   lightmap_requests.push_back(request);
00312 }

void DrawingContext::push_target (  ) 

Definition at line 481 of file drawing_context.cpp.

References target, and target_stack.

Referenced by TileMap::draw(), Spotlight::draw(), Light::draw(), Lantern::draw(), Candle::draw(), WillOWisp::draw(), TreeWillOWisp::draw(), and GhostTree::draw().

00482 {
00483   target_stack.push_back(target);
00484 }

void DrawingContext::pop_target (  ) 

Definition at line 487 of file drawing_context.cpp.

References set_target(), and target_stack.

Referenced by TileMap::draw(), Spotlight::draw(), Light::draw(), Lantern::draw(), Candle::draw(), WillOWisp::draw(), TreeWillOWisp::draw(), and GhostTree::draw().

00488 {
00489   set_target(target_stack.back());
00490   target_stack.pop_back();
00491 }

void DrawingContext::set_target ( Target  target  ) 

Definition at line 494 of file drawing_context.cpp.

References drawing_requests, LIGHTMAP, lightmap_requests, NORMAL, and requests.

Referenced by TileMap::draw(), Spotlight::draw(), Light::draw(), Lantern::draw(), Candle::draw(), WillOWisp::draw(), TreeWillOWisp::draw(), GhostTree::draw(), and pop_target().

00495 {
00496   this->target = target;
00497   if(target == LIGHTMAP) {
00498     requests = &lightmap_requests;
00499   } else {
00500     assert(target == NORMAL);
00501     requests = &drawing_requests;
00502   }
00503 }

void DrawingContext::set_ambient_color ( Color  new_color  ) 

Definition at line 506 of file drawing_context.cpp.

References ambient_color.

Referenced by worldmap::WorldMap::draw(), and Sector::draw().

00507 {
00508   ambient_color = new_color;
00509 }

void DrawingContext::take_screenshot (  ) 

requests that a screenshot be taken after the next frame has been rendered

Definition at line 512 of file drawing_context.cpp.

References screenshot_requested.

Referenced by ScreenManager::draw().

00513 {
00514   screenshot_requested = true;
00515 }

void DrawingContext::handle_drawing_requests ( DrawingRequests requests  )  [private]

Definition at line 364 of file drawing_context.cpp.

References TextRequest::alignment, Lightmap::do_draw(), Font::draw(), Lightmap::draw_filled_rect(), Renderer::draw_filled_rect(), Lightmap::draw_gradient(), Renderer::draw_gradient(), Renderer::draw_inverse_ellipse(), DRAW_LIGHTMAP, Lightmap::draw_surface(), Renderer::draw_surface(), Lightmap::draw_surface_part(), Renderer::draw_surface_part(), FILLRECT, TextRequest::font, Lightmap::get_light(), GETLIGHT, GRADIENT, INVERSEELLIPSE, LIGHTMAP, lightmap, NORMAL, renderer, SURFACE, SURFACE_PART, TextRequest::text, and TEXT.

Referenced by do_drawing().

00365 {
00366   std::stable_sort(requests.begin(), requests.end(), RequestPtrCompare());
00367 
00368   DrawingRequests::const_iterator i;
00369   for(i = requests.begin(); i != requests.end(); ++i) {
00370     const DrawingRequest& request = **i;
00371 
00372     switch(request.target) {
00373       case NORMAL:
00374         switch(request.type) {
00375           case SURFACE:
00376             renderer->draw_surface(request);
00377             break;
00378           case SURFACE_PART:
00379             renderer->draw_surface_part(request);
00380             break;
00381           case GRADIENT:
00382             renderer->draw_gradient(request);
00383             break;
00384           case TEXT:
00385           {
00386             const TextRequest* textrequest = (TextRequest*) request.request_data;
00387             textrequest->font->draw(renderer, textrequest->text, request.pos,
00388                                     textrequest->alignment, request.drawing_effect, request.color, request.alpha);
00389           }
00390           break;
00391           case FILLRECT:
00392             renderer->draw_filled_rect(request);
00393             break;
00394           case INVERSEELLIPSE:
00395             renderer->draw_inverse_ellipse(request);
00396             break;
00397           case DRAW_LIGHTMAP:
00398             lightmap->do_draw();
00399             break;
00400           case GETLIGHT:
00401             lightmap->get_light(request);
00402             break;
00403         }
00404         break;
00405       case LIGHTMAP:
00406         switch(request.type) {
00407           case SURFACE:
00408             lightmap->draw_surface(request);
00409             break;
00410           case SURFACE_PART:
00411             lightmap->draw_surface_part(request);
00412             break;
00413           case GRADIENT:
00414             lightmap->draw_gradient(request);
00415             break;
00416           case TEXT:
00417           {
00418             const TextRequest* textrequest = (TextRequest*) request.request_data;
00419             textrequest->font->draw(renderer, textrequest->text, request.pos,
00420                                     textrequest->alignment, request.drawing_effect, request.color, request.alpha);
00421           }
00422           break;
00423           case FILLRECT:
00424             lightmap->draw_filled_rect(request);
00425             break;
00426           case INVERSEELLIPSE:
00427             assert(!"InverseEllipse doesn't make sense on the lightmap");
00428             break;
00429           case DRAW_LIGHTMAP:
00430             lightmap->do_draw();
00431             break;
00432           case GETLIGHT:
00433             lightmap->get_light(request);
00434             break;
00435         }
00436         break;
00437     }
00438   }
00439 }

DrawingContext& DrawingContext::operator= ( const DrawingContext  )  [private]


Member Data Documentation

const Target DrawingContext::NORMAL = ::NORMAL [static]

Definition at line 117 of file drawing_context.hpp.

Referenced by do_drawing(), TileMap::draw(), Spotlight::draw(), handle_drawing_requests(), set_target(), and TileMap::TileMap().

const Target DrawingContext::LIGHTMAP = ::LIGHTMAP [static]

Definition at line 118 of file drawing_context.hpp.

Referenced by Spotlight::draw(), Light::draw(), Lantern::draw(), Candle::draw(), WillOWisp::draw(), TreeWillOWisp::draw(), GhostTree::draw(), handle_drawing_requests(), set_target(), and TileMap::TileMap().

Renderer* DrawingContext::renderer [private]

Definition at line 157 of file drawing_context.hpp.

Referenced by do_drawing(), handle_drawing_requests(), init_renderer(), and ~DrawingContext().

Lightmap* DrawingContext::lightmap [private]

Definition at line 158 of file drawing_context.hpp.

Referenced by do_drawing(), handle_drawing_requests(), init_renderer(), and ~DrawingContext().

std::vector<Transform> DrawingContext::transformstack [private]

the transform stack

Definition at line 161 of file drawing_context.hpp.

Referenced by do_drawing(), pop_transform(), and push_transform().

Transform DrawingContext::transform [private]

the currently active transform

Definition at line 163 of file drawing_context.hpp.

Referenced by draw_filled_rect(), draw_gradient(), draw_inverse_ellipse(), draw_surface(), draw_surface_part(), draw_text(), get_alpha(), get_drawing_effect(), get_light(), get_translation(), pop_transform(), push_transform(), set_alpha(), set_drawing_effect(), and set_translation().

std::vector<Blend> DrawingContext::blend_stack [private]

Definition at line 165 of file drawing_context.hpp.

Blend DrawingContext::blend_mode [private]

Definition at line 166 of file drawing_context.hpp.

DrawingRequests DrawingContext::drawing_requests [private]

Definition at line 168 of file drawing_context.hpp.

Referenced by do_drawing(), DrawingContext(), and set_target().

DrawingRequests DrawingContext::lightmap_requests [private]

Definition at line 169 of file drawing_context.hpp.

Referenced by do_drawing(), get_light(), and set_target().

DrawingRequests* DrawingContext::requests [private]

Definition at line 171 of file drawing_context.hpp.

Referenced by draw_filled_rect(), draw_gradient(), draw_inverse_ellipse(), draw_surface(), draw_surface_part(), draw_text(), DrawingContext(), and set_target().

Color DrawingContext::ambient_color [private]

Definition at line 172 of file drawing_context.hpp.

Referenced by do_drawing(), get_light(), and set_ambient_color().

Target DrawingContext::target [private]

Definition at line 174 of file drawing_context.hpp.

Referenced by draw_filled_rect(), draw_gradient(), draw_inverse_ellipse(), draw_surface(), draw_surface_part(), draw_text(), get_light(), and push_target().

std::vector<Target> DrawingContext::target_stack [private]

Definition at line 175 of file drawing_context.hpp.

Referenced by do_drawing(), pop_target(), and push_target().

struct obstack DrawingContext::obst [private]

Definition at line 178 of file drawing_context.hpp.

Referenced by do_drawing(), draw_filled_rect(), draw_gradient(), draw_inverse_ellipse(), draw_surface(), draw_surface_part(), draw_text(), DrawingContext(), get_light(), and ~DrawingContext().

bool DrawingContext::screenshot_requested [private]

true if a screenshot should be taken after the next frame has been rendered

Definition at line 180 of file drawing_context.hpp.

Referenced by do_drawing(), and take_screenshot().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:30 2014 for SuperTux by  doxygen 1.5.1