-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathAllegroScreen.cpp
More file actions
179 lines (138 loc) · 5.83 KB
/
AllegroScreen.cpp
File metadata and controls
179 lines (138 loc) · 5.83 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//////////////////////////////////////////////////////////////////////////////////////////
// File: AllegroScreen.h
//////////////////////////////////////////////////////////////////////////////////////////
// Description: AllegroScreen class
// Project: GUI Library
// Author(s): Jason Boettcher
// jackal@shplorb.com
// www.shplorb.com/~jackal
//////////////////////////////////////////////////////////////////////////////////////////
// Inclusions of header files
#include "GUI.h"
#include "AllegroScreen.h"
#include "AllegroBitmap.h"
#include "allegro.h"
using namespace RTE;
//////////////////////////////////////////////////////////////////////////////////////////
// Constructor: AllegroScreen
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Constructor method used to instantiate a AllegroScreen object in system
// memory.
AllegroScreen::AllegroScreen(BITMAP *pBackBuffer)
{
// Create the bitmap interface from the screen's back buffer
m_pBackBitmap = new AllegroBitmap(pBackBuffer);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Destroy
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Destroy the screen
void AllegroScreen::Destroy(void)
{
delete m_pBackBitmap;
m_pBackBitmap = 0;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: CreateBitmap
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Creates a bitmap from a file
GUIBitmap * AllegroScreen::CreateBitmap(const std::string Filename)
{
AllegroBitmap *pABitmap = new AllegroBitmap();
if (!pABitmap)
return 0;
// Load from file
if (!pABitmap->Create(Filename)) {
delete pABitmap;
return 0;
}
return pABitmap;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: CreateBitmap
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Creates an empty bitmap
GUIBitmap * AllegroScreen::CreateBitmap(int Width, int Height)
{
AllegroBitmap *pABitmap = new AllegroBitmap();
if (!pABitmap)
return 0;
// Create it, using the same color depth as the screen
if (!pABitmap->Create(Width, Height, bitmap_color_depth(m_pBackBitmap->GetBitmap()))) {
delete pABitmap;
return 0;
}
return pABitmap;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: DrawBitmap
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Draws a bitmap onto the back buffer
void AllegroScreen::DrawBitmap(GUIBitmap *pGUIBitmap, int destX, int destY, RECT *pRect)
{
if (!pGUIBitmap)
return;
BITMAP *pSourceBitmap = ((AllegroBitmap *)pGUIBitmap)->GetBitmap();
if (!pSourceBitmap)
return;
if (pRect)
blit(pSourceBitmap, m_pBackBitmap->GetBitmap(), pRect->left, pRect->top, destX, destY, pRect->right - pRect->left, pRect->bottom - pRect->top);
else
blit(pSourceBitmap, m_pBackBitmap->GetBitmap(), 0, 0, destX, destY, pSourceBitmap->w, pSourceBitmap->h);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: DrawBitmapTrans
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Draws a bitmap onto the back buffer using the colorkey.
void AllegroScreen::DrawBitmapTrans(GUIBitmap *pGUIBitmap, int destX, int destY, RECT *pRect)
{
if (!pGUIBitmap)
return;
BITMAP *pSourceBitmap = ((AllegroBitmap *)pGUIBitmap)->GetBitmap();
if (!pSourceBitmap)
return;
if (pRect)
masked_blit(pSourceBitmap, m_pBackBitmap->GetBitmap(), pRect->left, pRect->top, destX, destY, pRect->right - pRect->left, pRect->bottom - pRect->top);
else
masked_blit(pSourceBitmap, m_pBackBitmap->GetBitmap(), 0, 0, destX, destY, pSourceBitmap->w, pSourceBitmap->h);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetBitmap
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets a bitmap representing the screen.
GUIBitmap * AllegroScreen::GetBitmap(void)
{
return m_pBackBitmap;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ConvertColor
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Converts an 8bit palette index to a valid pixel format.
// Primarily used for development in windowed mode.
Uint32 AllegroScreen::ConvertColor(Uint32 color, int targetDepth)
{
// If no target to shoot for, use the current video mode depth
if (targetDepth == 0)
targetDepth = get_color_depth();
// We need to end up with palettized color
if (targetDepth == 8)
{
// Isn't indexed, don't convert
if (!(color >= 0 && color <= 255))
color = makecol8(getr32(color), getg32(color), getb32(color));
}
// We need a 32bpp color
else
{
// Indexed? Convert
if (color >= 0 && color <= 255)
{
RGB rgbEntry;
get_color(color, &rgbEntry);
// Times 4 because RGB struct's elements are in range 0-63, and makecol needs 0-255
color = makecol(rgbEntry.r * 4, rgbEntry.g * 4, rgbEntry.b * 4);
}
}
// Return converted color
return color;
}