Skip to content

Commit 7d0a7fd

Browse files
committed
Need all these to build editor (and probably eliminate unresolved symbols in the lib)
1 parent a3fc415 commit 7d0a7fd

21 files changed

+5796
-0
lines changed

Wrappers/AllegroBitmap.cpp

Lines changed: 381 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,381 @@
1+
//////////////////////////////////////////////////////////////////////////////////////////
2+
// File: AllegroBitmap.h
3+
//////////////////////////////////////////////////////////////////////////////////////////
4+
// Description: AllegroBitmap class
5+
// Project: GUI Library
6+
// Author(s): Jason Boettcher
7+
8+
// www.shplorb.com/~jackal
9+
10+
11+
//////////////////////////////////////////////////////////////////////////////////////////
12+
// Inclusions of header files
13+
14+
#include "GUI.h"
15+
#include "AllegroBitmap.h"
16+
#include "RTEError.h"
17+
18+
using namespace RTE;
19+
20+
21+
//////////////////////////////////////////////////////////////////////////////////////////
22+
// Constructor: AllegroBitmap
23+
//////////////////////////////////////////////////////////////////////////////////////////
24+
// Description: Constructor method used to instantiate a AllegroBitmap object in
25+
// system memory.
26+
27+
AllegroBitmap::AllegroBitmap()
28+
{
29+
m_BitmapFile.Reset();
30+
m_pBitmap = 0;
31+
m_SelfCreated = false;
32+
}
33+
34+
35+
//////////////////////////////////////////////////////////////////////////////////////////
36+
// Constructor: AllegroBitmap
37+
//////////////////////////////////////////////////////////////////////////////////////////
38+
// Description: Constructor method used to instantiate a AllegroBitmap object in
39+
// system memory.
40+
41+
AllegroBitmap::AllegroBitmap(BITMAP *pBitmap)
42+
{
43+
m_BitmapFile.Reset();
44+
m_pBitmap = pBitmap;
45+
m_SelfCreated = false;
46+
}
47+
48+
49+
//////////////////////////////////////////////////////////////////////////////////////////
50+
// Method: Create
51+
//////////////////////////////////////////////////////////////////////////////////////////
52+
// Description: Creates a blank bitmap
53+
54+
bool AllegroBitmap::Create(int Width, int Height, int Depth)
55+
{
56+
m_SelfCreated = true;
57+
58+
m_BitmapFile.Reset();
59+
m_pBitmap = create_bitmap_ex(Depth, Width, Height);
60+
61+
if (!m_pBitmap)
62+
{
63+
return false;
64+
}
65+
66+
return true;
67+
}
68+
69+
70+
//////////////////////////////////////////////////////////////////////////////////////////
71+
// Method: Create
72+
//////////////////////////////////////////////////////////////////////////////////////////
73+
// Description: Creates the bitmap from a filename
74+
75+
bool AllegroBitmap::Create(const std::string Filename)
76+
{
77+
m_SelfCreated = false;
78+
79+
m_BitmapFile.Create(Filename.c_str());
80+
81+
m_pBitmap = m_BitmapFile.GetAsBitmap();//COLORCONV_8_TO_32 | COLORCONV_24_TO_32);
82+
assert(m_pBitmap);
83+
84+
return true;
85+
}
86+
87+
88+
//////////////////////////////////////////////////////////////////////////////////////////
89+
// Method: Destroy
90+
//////////////////////////////////////////////////////////////////////////////////////////
91+
// Description: Destroys and frees the bitmap
92+
93+
void AllegroBitmap::Destroy(void)
94+
{
95+
if (m_SelfCreated && m_pBitmap)
96+
destroy_bitmap(m_pBitmap);
97+
98+
m_pBitmap = 0;
99+
}
100+
101+
102+
//////////////////////////////////////////////////////////////////////////////////////////
103+
// Method: Draw
104+
//////////////////////////////////////////////////////////////////////////////////////////
105+
// Description: Draw a section of this bitmap onto another bitmap
106+
107+
void AllegroBitmap::Draw(GUIBitmap *pDestBitmap, int X, int Y, GUIRect *pRect)
108+
{
109+
if (!m_pBitmap)
110+
return;
111+
112+
assert(pDestBitmap && ((AllegroBitmap *)pDestBitmap)->GetBitmap());
113+
114+
if (pRect)
115+
blit(m_pBitmap, ((AllegroBitmap *)pDestBitmap)->GetBitmap(), pRect->left, pRect->top, X, Y, pRect->right - pRect->left, pRect->bottom - pRect->top);
116+
else
117+
blit(m_pBitmap, ((AllegroBitmap *)pDestBitmap)->GetBitmap(), 0, 0, X, Y, pDestBitmap->GetWidth(), pDestBitmap->GetHeight());
118+
}
119+
120+
121+
//////////////////////////////////////////////////////////////////////////////////////////
122+
// Method: DrawTrans
123+
//////////////////////////////////////////////////////////////////////////////////////////
124+
// Description: Draw a section of this bitmap onto another bitmap ignoring
125+
// color-keyed pixels
126+
127+
void AllegroBitmap::DrawTrans(GUIBitmap *pDestBitmap, int X, int Y, GUIRect *pRect)
128+
{
129+
if (!m_pBitmap)
130+
return;
131+
132+
assert(pDestBitmap && ((AllegroBitmap *)pDestBitmap)->GetBitmap());
133+
134+
if (pRect)
135+
masked_blit(m_pBitmap, ((AllegroBitmap *)pDestBitmap)->GetBitmap(), pRect->left, pRect->top, X, Y, pRect->right - pRect->left, pRect->bottom - pRect->top);
136+
else
137+
masked_blit(m_pBitmap, ((AllegroBitmap *)pDestBitmap)->GetBitmap(), 0, 0, X, Y, pDestBitmap->GetWidth(), pDestBitmap->GetHeight());
138+
}
139+
140+
141+
//////////////////////////////////////////////////////////////////////////////////////////
142+
// Virtual Method: DrawTransScaled
143+
//////////////////////////////////////////////////////////////////////////////////////////
144+
// Description: Draw this bitmap scaled onto another bitmap ignoring color-keyed pixels.
145+
146+
void AllegroBitmap::DrawTransScaled(GUIBitmap *pDestBitmap, int X, int Y, int width, int height)
147+
{
148+
if (!m_pBitmap)
149+
return;
150+
151+
assert(pDestBitmap && ((AllegroBitmap *)pDestBitmap)->GetBitmap());
152+
153+
stretch_sprite(((AllegroBitmap *)pDestBitmap)->GetBitmap(), m_pBitmap, X, Y, width, height);
154+
}
155+
156+
157+
//////////////////////////////////////////////////////////////////////////////////////////
158+
// Method: DrawLine
159+
//////////////////////////////////////////////////////////////////////////////////////////
160+
// Description: Draws a line.
161+
162+
void AllegroBitmap::DrawLine(int x1, int y1, int x2, int y2, unsigned long Color)
163+
{
164+
if (!m_pBitmap)
165+
return;
166+
167+
line(m_pBitmap, x1, y1, x2, y2, Color);
168+
}
169+
170+
171+
//////////////////////////////////////////////////////////////////////////////////////////
172+
// Method: DrawRectangle
173+
//////////////////////////////////////////////////////////////////////////////////////////
174+
// Description: Draws a rectangle.
175+
176+
void AllegroBitmap::DrawRectangle(int X, int Y, int Width, int Height, unsigned long Color, bool Filled)
177+
{
178+
if (!m_pBitmap)
179+
return;
180+
181+
if (Filled)
182+
rectfill(m_pBitmap, X, Y, X + Width - 1, Y + Height - 1, Color);
183+
else
184+
rect(m_pBitmap, X, Y, X + Width - 1, Y + Height - 1, Color);
185+
}
186+
187+
188+
//////////////////////////////////////////////////////////////////////////////////////////
189+
// Method: GetPixel
190+
//////////////////////////////////////////////////////////////////////////////////////////
191+
// Description: Gets the colour of a pixel at a specific point.
192+
// Arguments: Point.
193+
194+
unsigned long AllegroBitmap::GetPixel(int X, int Y)
195+
{
196+
if (!m_pBitmap)
197+
return 0;
198+
199+
assert(m_pBitmap);
200+
201+
// m_pBitmap->Lock();
202+
203+
unsigned long col = getpixel(m_pBitmap, X, Y);
204+
205+
// m_pBitmap->UnLock();
206+
207+
return col;
208+
}
209+
210+
211+
//////////////////////////////////////////////////////////////////////////////////////////
212+
// Method: SetPixel
213+
//////////////////////////////////////////////////////////////////////////////////////////
214+
// Description: Sets the color of a pixel at a specific point.
215+
216+
void AllegroBitmap::SetPixel(int X, int Y, unsigned long Color)
217+
{
218+
if (!m_pBitmap)
219+
return;
220+
221+
assert(m_pBitmap);
222+
223+
// m_pBitmap->Lock();
224+
putpixel(m_pBitmap, X, Y, Color);
225+
// m_pBitmap->UnLock();
226+
}
227+
228+
229+
//////////////////////////////////////////////////////////////////////////////////////////
230+
// Method: GetWidth
231+
//////////////////////////////////////////////////////////////////////////////////////////
232+
// Description: Gets the Width of the bitmap.
233+
234+
int AllegroBitmap::GetWidth(void)
235+
{
236+
if (!m_pBitmap)
237+
return 0;
238+
239+
return m_pBitmap->w;
240+
}
241+
242+
243+
//////////////////////////////////////////////////////////////////////////////////////////
244+
// Method: GetHeight
245+
//////////////////////////////////////////////////////////////////////////////////////////
246+
// Description: Gets the Height of the bitmap.
247+
248+
int AllegroBitmap::GetHeight(void)
249+
{
250+
if (!m_pBitmap)
251+
return 0;
252+
253+
return m_pBitmap->h;
254+
}
255+
256+
/* NA
257+
//////////////////////////////////////////////////////////////////////////////////////////
258+
// Method: GetColorKey
259+
//////////////////////////////////////////////////////////////////////////////////////////
260+
// Description: Sets the color key of the bitmap.
261+
262+
void AllegroBitmap::SetColorKey(unsigned long Key)
263+
{
264+
if (m_pBitmap)
265+
m_pBitmap->SetColorKey(Key);
266+
}
267+
268+
269+
//////////////////////////////////////////////////////////////////////////////////////////
270+
// Method: GetColorKey
271+
//////////////////////////////////////////////////////////////////////////////////////////
272+
// Description: Sets the color key of the bitmap.
273+
274+
void AllegroBitmap::GetColorKey()
275+
{
276+
if (m_pBitmap)
277+
m_pBitmap->SetColorKey();
278+
}
279+
*/
280+
281+
//////////////////////////////////////////////////////////////////////////////////////////
282+
// Virtual Method: GetColorDepth
283+
//////////////////////////////////////////////////////////////////////////////////////////
284+
// Description: Gets the number of bits per pixel color depth of this bitmap.
285+
286+
int AllegroBitmap::GetColorDepth()
287+
{
288+
if (m_pBitmap)
289+
return bitmap_color_depth(m_pBitmap);
290+
return 8;
291+
}
292+
293+
294+
//////////////////////////////////////////////////////////////////////////////////////////
295+
// Virtual Method: GetClipRect
296+
//////////////////////////////////////////////////////////////////////////////////////////
297+
// Description: Gets the clipping rectangle of the bitmap.
298+
299+
void AllegroBitmap::GetClipRect(GUIRect *pRect)
300+
{
301+
if (m_pBitmap && pRect)
302+
{
303+
int x1, y1, x2, y2;
304+
get_clip_rect(m_pBitmap, &x1, &y1, &x2, &y2);
305+
pRect->left = x1;
306+
pRect->top = y1;
307+
pRect->right = x2;
308+
pRect->bottom = y2;
309+
}
310+
}
311+
312+
313+
//////////////////////////////////////////////////////////////////////////////////////////
314+
// Method: SetClipRect
315+
//////////////////////////////////////////////////////////////////////////////////////////
316+
// Description: Sets the clipping rectangle of the bitmap.
317+
318+
void AllegroBitmap::SetClipRect(GUIRect *pRect)
319+
{
320+
if (m_pBitmap)
321+
{
322+
set_clip_state(m_pBitmap, 1);
323+
324+
if (!pRect)
325+
{
326+
set_clip_rect(m_pBitmap, 0, 0, m_pBitmap->w - 1, m_pBitmap->h - 1);
327+
}
328+
else
329+
{
330+
set_clip_rect(m_pBitmap, pRect->left, pRect->top, pRect->right, pRect->bottom);
331+
}
332+
}
333+
}
334+
335+
336+
//////////////////////////////////////////////////////////////////////////////////////////
337+
// Virtual Method: AddClipRect
338+
//////////////////////////////////////////////////////////////////////////////////////////
339+
// Description: Sets the clipping rectangle of the specified bitmap as the
340+
// intersection of its current clipping rectangle and the rectangle
341+
// described by the passed-in rect.
342+
343+
void AllegroBitmap::AddClipRect(GUIRect *pRect)
344+
{
345+
if (m_pBitmap)
346+
{
347+
set_clip_state(m_pBitmap, 1);
348+
349+
if (!pRect)
350+
{
351+
set_clip_rect(m_pBitmap, 0, 0, m_pBitmap->w - 1, m_pBitmap->h - 1);
352+
}
353+
else
354+
{
355+
add_clip_rect(m_pBitmap, pRect->left, pRect->top, pRect->right, pRect->bottom);
356+
}
357+
}
358+
}
359+
360+
361+
//////////////////////////////////////////////////////////////////////////////////////////
362+
// Virtual method: GetDataPath
363+
//////////////////////////////////////////////////////////////////////////////////////////
364+
// Description: Returns the path to the datafile object this GUIBitmap uses.
365+
// Arguments: None.
366+
367+
string AllegroBitmap::GetDataPath()
368+
{
369+
return m_BitmapFile.GetDataPath();
370+
}
371+
372+
373+
//////////////////////////////////////////////////////////////////////////////////////////
374+
// Method: GetBitmap
375+
//////////////////////////////////////////////////////////////////////////////////////////
376+
// Description: Gets the BITMAP.
377+
378+
BITMAP *AllegroBitmap::GetBitmap()
379+
{
380+
return m_pBitmap;
381+
}

0 commit comments

Comments
 (0)