summaryrefslogtreecommitdiffhomepage
path: root/nGenEx/FadeView.cpp
blob: 3ff62f78f3042a91a3370bbc0581e7e0838da4f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*  Project nGenEx
    Destroyer Studios LLC
    Copyright © 1997-2004. All Rights Reserved.

    SUBSYSTEM:    nGenEx.lib
    FILE:         FadeView.cpp
    AUTHOR:       John DiCamillo


    OVERVIEW
    ========
    Fading Bitmap "billboard" Image View class
*/

#include "MemDebug.h"
#include "FadeView.h"
#include "Color.h"
#include "Window.h"
#include "Video.h"
#include "Screen.h"
#include "Game.h"

// +--------------------------------------------------------------------+

FadeView::FadeView(Window* c, double in, double out, double hold)
   : View(c),
     fade_in(in * 1000),
     fade_out(out * 1000),
     hold_time(hold * 1000),
     step_time(0),
     fast(1),
     time(0)
{
   state = StateStart;
}

FadeView::~FadeView()
{ }

// +--------------------------------------------------------------------+

void FadeView::FadeIn(double in)       { fade_in   = in  * 1000; }
void FadeView::FadeOut(double out)     { fade_out  = out * 1000; }
void FadeView::FastFade(int fade_fast) { fast      = fade_fast;  }
void FadeView::StopHold()
{
   //Print("  FadeView::StopHold()\n");
   hold_time = 0;
}

// +--------------------------------------------------------------------+

void
FadeView::Refresh()
{
   double msec = 0;

   if (state == StateStart) {
      time = Game::RealTime();
   }
   else if (state != StateDone) {
      double new_time = Game::RealTime();
      msec = new_time - time;
      time = new_time;
   }

   switch (state) {
   case StateStart:
      if (fade_in) {
         //Print("  *  FadeView: %f, %f, %f\n", fade_in, fade_out, hold_time);
         Color::SetFade(0);
         //Print("  1. FadeView SetFade to   0  (%6.1f)\n", time);
      }

      step_time = 0;
      state = State2;
      break;

   case State2:
      if (fade_in) {
         Color::SetFade(0);
         //Print("  1. FadeView SetFade to   0  (%6.1f)\n", time);
      }

      step_time = 0;
      state = StateIn;
      break;

   case StateIn:
      if (step_time < fade_in) {
         double fade = step_time / fade_in;
         Color::SetFade(fade);
         //Print("  2. FadeView SetFade to %3d  (%6.1f) %6.1f\n", (int) (fade * 100), time, step_time);
         step_time += msec;
      }
      else {
         Color::SetFade(1);
         //Print("  2. FadeView SetFade to %3d  (%6.1f) %6.1f => HOLDING\n", 100, time, step_time);
         step_time = 0;
         state = StateHold;
      }
      break;

   case StateHold:
      if (step_time < hold_time) {
         step_time += msec;
         //Print("  3. FadeView holding at %3d  (%6.1f) %6.1f\n", 100, time, step_time);
      }
      else {
         //Print("  3. FadeView HOLD COMPLETE   (%6.1f) %6.1f\n", time, step_time);
         step_time = 0;
         state = StateOut;
      }
      break;

   case StateOut:
      if (fade_out > 0) {
         if (step_time < fade_out) {
            double fade = 1 - step_time / fade_out;
            Color::SetFade(fade);
            //Print("  4. FadeView SetFade to %3d  (%6.1f) %6.1f\n", (int) (fade*100), time, step_time);
            step_time += msec;
         }
         else {
            Color::SetFade(0);
            //Print("  4. FadeView SetFade to %3d  (%6.1f) %6.1f\n", 0, time, step_time);
            step_time = 0;
            state = StateDone;
         }
      }
      else {
         Color::SetFade(1);
         //Print("  4. FadeView SetFade to %3d  (%6.1f) %6.1f\n", 0, time, step_time);
         step_time = 0;
         state = StateDone;
      }
      break;

   default:
   case StateDone:
      //Print("  5. FadeView done  (%6.1f) %6.1f\n", time, step_time);
      break;
   }
}