DisplayEffect Class Reference

#include <display_effect.hpp>

Inherits GameObject, scripting::DisplayEffect, and ScriptInterface.

List of all members.

Public Member Functions

 DisplayEffect (std::string name="")
virtual ~DisplayEffect ()
void expose (HSQUIRRELVM vm, SQInteger table_idx)
void unexpose (HSQUIRRELVM vm, SQInteger table_idx)
void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.
void draw (DrawingContext &context)
 The GameObject should draw itself onto the provided DrawingContext if this function is called.
Scriptable Methods
void fade_out (float fadetime)
 fade display to black
void fade_in (float fadetime)
 fade display from black to normal
void set_black (bool enabled)
 set display black (or back to normal)
bool is_black ()
 check if display is set to black
void sixteen_to_nine (float fadetime)
 set black borders for cutscenes
void four_to_three (float fadetime)
 deactivate borders

Private Types

enum  FadeType { NO_FADE, FADE_IN, FADE_OUT }

Private Attributes

FadeType screen_fade
float screen_fadetime
float screen_fading
FadeType border_fade
float border_fadetime
float border_fading
float border_size
bool black
bool borders


Detailed Description

Definition at line 24 of file display_effect.hpp.


Member Enumeration Documentation

enum DisplayEffect::FadeType [private]

Enumerator:
NO_FADE 
FADE_IN 
FADE_OUT 

Definition at line 55 of file display_effect.hpp.

00055                 {
00056     NO_FADE, FADE_IN, FADE_OUT
00057   };


Constructor & Destructor Documentation

DisplayEffect::DisplayEffect ( std::string  name = ""  ) 

Definition at line 25 of file display_effect.cpp.

00025                                            :
00026   screen_fade(NO_FADE), 
00027   screen_fadetime(0), 
00028   screen_fading(0),
00029   border_fade(NO_FADE), 
00030   border_fadetime(0), 
00031   border_fading(),
00032   border_size(0), 
00033   black(false),
00034   borders(false)
00035 {
00036   this->name = name;
00037 }

DisplayEffect::~DisplayEffect (  )  [virtual]

Reimplemented from scripting::DisplayEffect.

Definition at line 39 of file display_effect.cpp.

00040 {
00041 }


Member Function Documentation

void DisplayEffect::expose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 44 of file display_effect.cpp.

References scripting::expose_object(), and GameObject::name.

00045 {
00046   if (name.empty()) return;
00047   expose_object(vm, table_idx, dynamic_cast<scripting::DisplayEffect *>(this), name, false);
00048 }

void DisplayEffect::unexpose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 51 of file display_effect.cpp.

References GameObject::name, and scripting::unexpose_object().

00052 {
00053   if (name.empty()) return;
00054   scripting::unexpose_object(vm, table_idx, name);
00055 }

void DisplayEffect::update ( float  elapsed_time  )  [virtual]

This function is called once per frame and allows the object to update it's state.

The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)

Implements GameObject.

Definition at line 58 of file display_effect.cpp.

References black, border_fade, border_fadetime, border_fading, BORDER_SIZE, border_size, borders, FADE_IN, FADE_OUT, NO_FADE, screen_fade, and screen_fading.

00059 {
00060   switch(screen_fade) {
00061     case NO_FADE:
00062       break;
00063     case FADE_IN:
00064       screen_fading -= elapsed_time;
00065       if(screen_fading < 0) {
00066         screen_fade = NO_FADE;
00067       }
00068       break;
00069     case FADE_OUT:
00070       screen_fading -= elapsed_time;
00071       if(screen_fading < 0) {
00072         screen_fade = NO_FADE;
00073         black = true;
00074       }
00075       break;
00076     default:
00077       assert(false);
00078   }
00079 
00080   switch(border_fade) {
00081     case NO_FADE:
00082       break;
00083     case FADE_IN:
00084       border_fading -= elapsed_time;
00085       if(border_fading < 0) {
00086         border_fade = NO_FADE;
00087       }
00088       border_size = (border_fadetime - border_fading)
00089         / border_fadetime * BORDER_SIZE;
00090       break;
00091     case FADE_OUT:
00092       border_fading -= elapsed_time;
00093       if(border_fading < 0) {
00094         borders = false;
00095         border_fade = NO_FADE;
00096       }
00097       border_size = border_fading / border_fadetime * BORDER_SIZE;
00098       break;
00099     default:
00100       assert(false);
00101   }
00102 }

void DisplayEffect::draw ( DrawingContext context  )  [virtual]

The GameObject should draw itself onto the provided DrawingContext if this function is called.

Implements GameObject.

Definition at line 105 of file display_effect.cpp.

References black, border_size, borders, DrawingContext::draw_filled_rect(), FADE_IN, FADE_OUT, LAYER_GUI, NO_FADE, DrawingContext::pop_transform(), DrawingContext::push_transform(), screen_fade, screen_fadetime, screen_fading, SCREEN_HEIGHT, SCREEN_WIDTH, and DrawingContext::set_translation().

00106 {
00107   context.push_transform();
00108   context.set_translation(Vector(0, 0));
00109 
00110   if(black || screen_fade != NO_FADE) {
00111     float alpha;
00112     if(black) {
00113       alpha = 1.0f;
00114     } else {
00115       switch(screen_fade) {
00116         case FADE_IN:
00117           alpha = screen_fading / screen_fadetime;
00118           break;
00119         case FADE_OUT:
00120           alpha = (screen_fadetime - screen_fading) / screen_fadetime;
00121           break;
00122         default:
00123           alpha = 0;
00124           assert(false);
00125       }
00126     }
00127     context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
00128                              Color(0, 0, 0, alpha), LAYER_GUI-10);
00129   }
00130 
00131   if (borders) {
00132     context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, border_size),
00133                              Color(0, 0, 0, 1.0f), LAYER_GUI-10);
00134     context.draw_filled_rect(Vector(0, SCREEN_HEIGHT - border_size), Vector(SCREEN_WIDTH, border_size),
00135                              Color(0, 0, 0, 1.0f), LAYER_GUI-10);
00136   }
00137 
00138   context.pop_transform();
00139 }

void DisplayEffect::fade_out ( float  fadetime  )  [virtual]

fade display to black

Implements scripting::DisplayEffect.

Definition at line 142 of file display_effect.cpp.

References black, FADE_OUT, screen_fade, screen_fadetime, and screen_fading.

Referenced by Player::kill().

00143 {
00144   black = false;
00145   screen_fadetime = fadetime;
00146   screen_fading = fadetime;
00147   screen_fade = FADE_OUT;
00148 }

void DisplayEffect::fade_in ( float  fadetime  )  [virtual]

fade display from black to normal

Implements scripting::DisplayEffect.

Definition at line 151 of file display_effect.cpp.

References black, FADE_IN, screen_fade, screen_fadetime, and screen_fading.

00152 {
00153   black = false;
00154   this->screen_fadetime = fadetime;
00155   screen_fading = fadetime;
00156   screen_fade = FADE_IN;
00157 }

void DisplayEffect::set_black ( bool  enabled  )  [virtual]

set display black (or back to normal)

Implements scripting::DisplayEffect.

Definition at line 160 of file display_effect.cpp.

References black.

00161 {
00162   black = enabled;
00163 }

bool DisplayEffect::is_black (  )  [virtual]

check if display is set to black

Implements scripting::DisplayEffect.

Definition at line 166 of file display_effect.cpp.

References black.

00167 {
00168   return black;
00169 }

void DisplayEffect::sixteen_to_nine ( float  fadetime  )  [virtual]

set black borders for cutscenes

Implements scripting::DisplayEffect.

Definition at line 172 of file display_effect.cpp.

References border_fade, border_fadetime, border_fading, BORDER_SIZE, border_size, borders, and FADE_IN.

00173 {
00174   if(fadetime == 0) {
00175     borders = true;
00176     border_size = BORDER_SIZE;
00177   } else {
00178     borders = true;
00179     border_size = 0;
00180     border_fade = FADE_IN;
00181     border_fadetime = fadetime;
00182     border_fading = border_fadetime;
00183   }
00184 }

void DisplayEffect::four_to_three ( float  fadetime  )  [virtual]

deactivate borders

Implements scripting::DisplayEffect.

Definition at line 187 of file display_effect.cpp.

References border_fade, border_fadetime, border_fading, BORDER_SIZE, border_size, borders, and FADE_OUT.

00188 {
00189   if(fadetime == 0) {
00190     borders = false;
00191   } else {
00192     border_size = BORDER_SIZE;
00193     border_fade = FADE_OUT;
00194     border_fadetime = fadetime;
00195     border_fading = border_fadetime;
00196   }
00197 }


Member Data Documentation

FadeType DisplayEffect::screen_fade [private]

Definition at line 58 of file display_effect.hpp.

Referenced by draw(), fade_in(), fade_out(), and update().

float DisplayEffect::screen_fadetime [private]

Definition at line 59 of file display_effect.hpp.

Referenced by draw(), fade_in(), and fade_out().

float DisplayEffect::screen_fading [private]

Definition at line 60 of file display_effect.hpp.

Referenced by draw(), fade_in(), fade_out(), and update().

FadeType DisplayEffect::border_fade [private]

Definition at line 61 of file display_effect.hpp.

Referenced by four_to_three(), sixteen_to_nine(), and update().

float DisplayEffect::border_fadetime [private]

Definition at line 62 of file display_effect.hpp.

Referenced by four_to_three(), sixteen_to_nine(), and update().

float DisplayEffect::border_fading [private]

Definition at line 63 of file display_effect.hpp.

Referenced by four_to_three(), sixteen_to_nine(), and update().

float DisplayEffect::border_size [private]

Definition at line 64 of file display_effect.hpp.

Referenced by draw(), four_to_three(), sixteen_to_nine(), and update().

bool DisplayEffect::black [private]

Definition at line 66 of file display_effect.hpp.

Referenced by draw(), fade_in(), fade_out(), is_black(), set_black(), and update().

bool DisplayEffect::borders [private]

Definition at line 67 of file display_effect.hpp.

Referenced by draw(), four_to_three(), sixteen_to_nine(), and update().


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