1 //=============================================================================
2 //
3 // Adventure Game Studio (AGS)
4 //
5 // Copyright (C) 1999-2011 Chris Jones and 2011-20xx others
6 // The full list of copyright holders can be found in the Copyright.txt
7 // file, which is part of this source code distribution.
8 //
9 // The AGS source code is provided under the Artistic License 2.0.
10 // A copy of this license can be found in the file License.txt and at
11 // http://www.opensource.org/licenses/artistic-license-2.0.php
12 //
13 //=============================================================================
14
15 #include "ac/common.h"
16 #include "ac/draw.h"
17 #include "ac/gamesetupstruct.h"
18 #include "ac/gamestate.h"
19 #include "ac/global_game.h"
20 #include "ac/global_screen.h"
21 #include "ac/screen.h"
22 #include "platform/base/agsplatformdriver.h"
23 #include "plugin/agsplugin.h"
24 #include "plugin/plugin_engine.h"
25 #include "gfx/bitmap.h"
26 #include "gfx/graphicsdriver.h"
27
28 using namespace AGS::Common;
29 using namespace AGS::Engine;
30
31 extern GameSetupStruct game;
32 extern GameState play;
33 extern IGraphicsDriver *gfxDriver;
34 extern AGSPlatformDriver *platform;
35
my_fade_in(PALLETE p,int speed)36 void my_fade_in(PALLETE p, int speed) {
37 if (game.color_depth > 1) {
38 set_palette (p);
39
40 play.screen_is_faded_out = 0;
41
42 if (play.no_hicolor_fadein) {
43 return;
44 }
45 }
46
47 gfxDriver->FadeIn(speed, p, play.fade_to_red, play.fade_to_green, play.fade_to_blue);
48 }
49
50 //#define _get_script_data_stack_size() (256*sizeof(int)+((int*)&scrpt[10*4])[0]+((int*)&scrpt[12*4])[0])
51 //#define _get_script_data_stack_size(instac) ((int*)instac->code)[10]
52 Bitmap *temp_virtual = NULL;
53 color old_palette[256];
current_fade_out_effect()54 void current_fade_out_effect () {
55 if (pl_run_plugin_hooks(AGSE_TRANSITIONOUT, 0))
56 return;
57
58 // get the screen transition type
59 int theTransition = play.fade_effect;
60 // was a temporary transition selected? if so, use it
61 if (play.next_screen_transition >= 0)
62 theTransition = play.next_screen_transition;
63
64 if ((theTransition == FADE_INSTANT) || (play.screen_tint >= 0)) {
65 if (!play.keep_screen_during_instant_transition)
66 set_palette_range(black_palette, 0, 255, 0);
67 }
68 else if (theTransition == FADE_NORMAL)
69 {
70 my_fade_out(5);
71 }
72 else if (theTransition == FADE_BOXOUT)
73 {
74 gfxDriver->BoxOutEffect(true, get_fixed_pixel_size(16), 1000 / GetGameSpeed());
75 play.screen_is_faded_out = 1;
76 }
77 else
78 {
79 get_palette(old_palette);
80 const Rect &viewport = play.viewport;
81 temp_virtual = CopyScreenIntoBitmap(viewport.GetWidth(), viewport.GetHeight());
82 }
83 }
84
prepare_screen_for_transition_in()85 IDriverDependantBitmap* prepare_screen_for_transition_in()
86 {
87 if (temp_virtual == NULL)
88 quit("Crossfade: buffer is null attempting transition");
89
90 temp_virtual = ReplaceBitmapWithSupportedFormat(temp_virtual);
91 if (temp_virtual->GetHeight() < play.viewport.GetHeight())
92 {
93 Bitmap *enlargedBuffer = BitmapHelper::CreateBitmap(temp_virtual->GetWidth(), play.viewport.GetHeight(), temp_virtual->GetColorDepth());
94 enlargedBuffer->Blit(temp_virtual, 0, 0, 0, (play.viewport.GetHeight() - temp_virtual->GetHeight()) / 2, temp_virtual->GetWidth(), temp_virtual->GetHeight());
95 delete temp_virtual;
96 temp_virtual = enlargedBuffer;
97 }
98 else if (temp_virtual->GetHeight() > play.viewport.GetHeight())
99 {
100 Bitmap *clippedBuffer = BitmapHelper::CreateBitmap(temp_virtual->GetWidth(), play.viewport.GetHeight(), temp_virtual->GetColorDepth());
101 clippedBuffer->Blit(temp_virtual, 0, (temp_virtual->GetHeight() - play.viewport.GetHeight()) / 2, 0, 0, temp_virtual->GetWidth(), temp_virtual->GetHeight());
102 delete temp_virtual;
103 temp_virtual = clippedBuffer;
104 }
105 temp_virtual->Acquire();
106 IDriverDependantBitmap *ddb = gfxDriver->CreateDDBFromBitmap(temp_virtual, false);
107 return ddb;
108 }
109