1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "Interface.h"
28 const TypeID
Sprite2D::ID
= { "Sprite2D" };
40 Sprite2D::~Sprite2D(void)
44 bool Sprite2D::IsPixelTransparent(unsigned short x
, unsigned short y
) const
46 if (x
>= Width
|| y
>= Height
) return true;
49 return core
->GetVideoDriver()->GetPixel(vptr
, x
, y
)==0;
52 Sprite2D_BAM_Internal
* data
= (Sprite2D_BAM_Internal
*)vptr
;
59 int skipcount
= y
* Width
+ x
;
61 const ieByte
* rle
= (const ieByte
*)pixels
;
63 while (skipcount
> 0) {
64 if (*rle
++ == data
->transindex
)
65 skipcount
-= (*rle
++)+1;
74 if (skipcount
< 0 || *rle
== data
->transindex
)
80 /** Get the Palette of a Sprite */
81 Palette
* Sprite2D::GetPalette() const
83 if (!vptr
) return NULL
;
85 return core
->GetVideoDriver()->GetPalette(vptr
);
88 Sprite2D_BAM_Internal
* data
= (Sprite2D_BAM_Internal
*)vptr
;
93 void Sprite2D::SetPalette(Palette
* pal
)
97 core
->GetVideoDriver()->SetPalette(vptr
, pal
);
99 Sprite2D_BAM_Internal
* data
= (Sprite2D_BAM_Internal
*)vptr
;
100 data
->pal
->Release();
106 Color
Sprite2D::GetPixel(unsigned short x
, unsigned short y
) const
108 Color c
= { 0, 0, 0, 0 };
110 if (x
>= Width
|| y
>= Height
) return c
;
113 core
->GetVideoDriver()->GetPixel(vptr
, x
, y
, c
);
117 Sprite2D_BAM_Internal
* data
= (Sprite2D_BAM_Internal
*)vptr
;
124 int skipcount
= y
* Width
+ x
;
126 const ieByte
*rle
= (const ieByte
*)pixels
;
128 while (skipcount
> 0) {
129 if (*rle
++ == data
->transindex
)
130 skipcount
-= (*rle
++)+1;
140 if (skipcount
>= 0 && *rle
!= data
->transindex
) {
141 c
= data
->pal
->col
[*rle
];
147 void Sprite2D::release()
149 Sprite2D
*that
= this;
150 core
->GetVideoDriver()->FreeSprite(that
);