-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathsprite.cpp
700 lines (575 loc) · 17.7 KB
/
sprite.cpp
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
//////////////////////////////////////////////////////////////////////
// Yet Another Tibia Client
//////////////////////////////////////////////////////////////////////
// Base engine-independant sprite class
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#ifndef __APPLE__
#include <SDL/SDL_rotozoom.h> // library you need is called SDL_gfx
#else
#include <SDL_gfx/SDL_rotozoom.h>
#endif
#ifdef USE_OPENGL
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <GL/gl.h>
#endif
#if defined WIN32 || defined WINDOWS
#include <GL/glext.h>
#endif
#ifndef GL_BGR
#warning Odd OpenGL header. Defining GL_BGR to a 0.
#define GL_BGR 0
#endif
#endif
#include <sstream>
#include "debugprint.h"
#include "sprite.h"
#include "sprdata.h"
#include <math.h>
#include "gamecontent/creature.h"
#include "product.h"
#pragma pack(1)
typedef struct {
uint32_t signature;
uint16_t imgcount;
} picfileheader_t;
typedef struct {
uint8_t width, height;
uint8_t unk1, unk2, unk3; // FIXME (ivucica#4#) zerocoolz says this should be colorkey, according to http://otfans.net/showpost.php?p=840634&postcount=134
} picpicheader_t;
#pragma pack()
#include "engine.h"
Sprite::Sprite(int w, int h, const oRGBA& c)
{
// create blank sprite
#ifdef USE_OPENGL
m_pixelformat = GL_NONE;
#endif
m_image = NULL;
m_stretchimage = NULL;
m_coloredimage = NULL;
m_loaded = false;
m_smoothstretch = 0;
m_r = 1.f;
m_g = 1.f;
m_b = 1.f;
char spec[256];
sprintf(spec, "%d %d %g %g %g %g.blank", w,h,c.r,c.g,c.b,c.a);
m_filename = spec;
m_index = 0;
loadSurfaceFromFile(spec,0);
}
Sprite::Sprite(const std::string& filename, int index)
{
#ifdef USE_OPENGL
m_pixelformat = GL_NONE;
#endif
m_image = NULL;
m_stretchimage = NULL;
m_coloredimage = NULL;
m_loaded = false;
m_smoothstretch = 0;
m_filename = filename;
m_index = index;
m_r = 1.f;
m_g = 1.f;
m_b = 1.f;
loadSurfaceFromFile(filename, index);
}
Sprite::Sprite(const std::string& filename, int index, int x, int y, int w, int h)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
uint32_t rmask = 0xff000000;
uint32_t gmask = 0x00ff0000;
uint32_t bmask = 0x0000ff00;
uint32_t amask = 0x000000ff;
#else
uint32_t rmask = 0x000000ff;
uint32_t gmask = 0x0000ff00;
uint32_t bmask = 0x00ff0000;
uint32_t amask = 0xff000000;
#endif
#ifdef USE_OPENGL
m_pixelformat = GL_NONE;
#endif
m_image = NULL;
m_stretchimage = NULL;
m_coloredimage = NULL;
m_loaded = false;
m_smoothstretch = 1;
m_r = 1.f;
m_g = 1.f;
m_b = 1.f;
loadSurfaceFromFile(filename, index);
if(!m_image)
{
return;
}
SDL_Surface* ns = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h, 32, rmask, gmask, bmask, amask);
SDL_Rect src = {(Sint16)x,(Sint16)y,(Uint16)w,(Uint16)h};
SDL_Rect dst = {0,0,(Uint16)w,(Uint16)h};
SDL_BlitSurface(m_image, &src, ns, &dst);
SDL_FreeSurface(m_image);
SDL_FreeSurface(m_coloredimage);
m_image = ns;
m_coloredimage = SDL_CreateRGBSurface(SDL_HWSURFACE, m_image->w, m_image->h, 32, rmask, gmask, bmask, amask);
}
Sprite::~Sprite()
{
if(m_image){
SDL_FreeSurface(m_image);
}
if(m_stretchimage){
SDL_FreeSurface(m_stretchimage);
}
if(m_coloredimage){
SDL_FreeSurface(m_coloredimage);
}
}
#include "util.h" // REMOVE ME
void Sprite::loadSurfaceFromFile(const std::string& filename, int index) {
size_t extbegins = filename.rfind(".") + 1;
std::string extension;
if(extbegins != std::string::npos){
extension = filename.substr(extbegins, filename.length() - extbegins);
}
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
uint32_t rmask = 0xff000000;
uint32_t gmask = 0x00ff0000;
uint32_t bmask = 0x0000ff00;
uint32_t amask = 0x000000ff;
#else
uint32_t rmask = 0x000000ff;
uint32_t gmask = 0x0000ff00;
uint32_t bmask = 0x00ff0000;
uint32_t amask = 0xff000000;
#endif
// print loading status (useful for slow machines such as wince; on the other hand, flipping too often causes slowness, too)
#ifdef WINCE
std::stringstream loadingtext;
loadingtext << "Loading " << filename << "[" << index << "]...";
if (g_engine && index) {
g_engine->drawRectangle(0,0,240,10,oRGBA(0,0,0,255));
g_engine->drawText(loadingtext.str().c_str(), "minifont", 0, 0, 0xFF);
g_engine->Flip();
}
#endif
if(extension == "bmp"){
m_image = SDL_LoadBMP(filename.c_str());
if(!m_image){
DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_ERROR, "[Sprite::loadSurfaceFromFile] SDL_LoadBMP failed on file: %s\n", filename.c_str());
return;
}
#ifdef USE_OPENGL
m_pixelformat = GL_BGR;
#endif
m_loaded = true;
}
else if(extension == "spr"){
uint32_t signature; // TODO (ivucica#3#) signature should be perhaps read during logon?
uint16_t sprcount;
uint32_t where;
FILE *f = yatc_fopen(filename.c_str(), "rb");
if(!f){
DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY,DEBUGPRINT_ERROR,"[Sprite::loadSurfaceFromFile] Sprite file %s not found\n", filename.c_str());
return;
}
if (index < 1) {
if (index) DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY,DEBUGPRINT_ERROR, "[Sprite::loadSurfaceFromFile] Invalid index %d\n", index);
fclose(f);
goto loadFail;
}
yatc_fread(&signature, sizeof(signature), 1, f);
yatc_fread(&sprcount, sizeof(sprcount), 1, f);
if(index >= sprcount){// i can't do this, captain, there's not enough power
DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_ERROR, "[Sprite::loadSurfaceFromFile] Loading spr index %d while we have %d sprites in file.\n", index, sprcount);
goto loadFail; // she won't hold it much longer
}
// read the pointer to the real SPR data
fseek(f, (index-1)*4, SEEK_CUR);
yatc_fread(&where, sizeof(where), 1, f);
// create surface where we'll store data, and fill it with transparency
m_image = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, 32, 32, 32, rmask, gmask, bmask, amask);
if(!m_image){
DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY,DEBUGPRINT_ERROR, "[Sprite::loadSurfaceFromFile] Cant create SDL Surface.\n");
goto loadFail;
}
SDL_LockSurface(m_image);
// dont make static since if we change the rendering engine at runtime,
// this may change too
Uint32 magenta = SDL_MapRGBA(m_image->format, 255, 0, 255, 255);
SDL_FillRect(m_image, NULL, magenta);
// read the data
if (where) {
fseek(f, where, SEEK_SET);
fgetc(f); fgetc(f); fgetc(f); // FIXME (ivucica#4#) zerocoolz says this should be colorkey, according to http://otfans.net/showpost.php?p=840634&postcount=134
if (readSprData(f, m_image, 0, 0)) {
// error happened
DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_ERROR, "[Sprite::loadSurfaceFromFile] Problem in readSprData()\n");
SDL_FreeSurface(m_image);
m_image = NULL;
fclose(f);
goto loadFail;
}
}
fclose(f);
SDL_UnlockSurface(m_image);
SDL_UpdateRect(m_image, 0, 0, 32, 32);
#ifdef USE_OPENGL
m_pixelformat = GL_RGBA;
#endif
m_loaded = true;
}
else if(extension == "pic"){
FILE *f;
SDL_Surface *s = NULL;
picfileheader_t fh;
picpicheader_t ph;
uint32_t sprloc;
uint32_t magenta;
f = yatc_fopen(filename.c_str(), "rb");
if(!f){
DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_ERROR, "[Sprite::loadSurfaceFromFile] Picture file %s not found\n", filename.c_str());
goto loadFail;
}
yatc_fread(&fh, sizeof(fh), 1, f);
for(int i = 0; i < fh.imgcount && i <= index ; i++) {
yatc_fread(&ph, sizeof(ph), 1, f);
if(i == index){
s = SDL_CreateRGBSurface(SDL_SWSURFACE, ph.width*32, ph.height*32, 32, rmask, gmask, bmask, amask);
SDL_LockSurface(s);
if (!s) {
DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_ERROR, "Failed to create surface of size %dx%d\n", ph.width*32, ph.height*32);
fclose(f);
goto loadFail;
}
magenta = SDL_MapRGB(s->format, 255, 0, 255);
SDL_FillRect(s, NULL, magenta);
for(int j = 0; j < ph.height; j++){
for(int k = 0; k < ph.width; k++){
yatc_fread(&sprloc, sizeof(sprloc), 1, f);
int oldloc = ftell(f);
int r;
fseek(f, sprloc, SEEK_SET);
r = readSprData(f, s, k*32, j*32);
fseek(f, oldloc, SEEK_SET);
if(r){
SDL_FreeSurface(s);
fclose(f);
goto loadFail;
}
}
}
SDL_UnlockSurface(s);
break;
}
else{
fseek(f, sizeof(sprloc)*ph.height*ph.width, SEEK_CUR);
}
}
fclose(f);
m_image = s;
#ifdef USE_OPENGL
m_pixelformat = GL_RGBA;
#endif
m_loaded = true;
}
else if(extension=="blank"){
double r,g,b,a;
int w,h;
sscanf(m_filename.c_str(), "%d %d %lg %lg %lg %lg", &w,&h,&r,&g,&b,&a);
SDL_Surface *s = SDL_CreateRGBSurface(SDL_SWSURFACE, 256, 256, 32, rmask, gmask, bmask, amask);
Uint32 color = SDL_MapRGB(s->format, (int)r, (int)g, (int)b);
SDL_FillRect(s, NULL, color);
#ifdef USE_OPENGL
m_pixelformat = GL_RGBA;
#endif
m_image = s;
m_loaded = true;
}
else{
// m_image is already marked as NULL, so we're over
return;
}
m_filename = filename;
m_index = index;
m_coloredimage = SDL_CreateRGBSurface(SDL_SWSURFACE, m_image->w, m_image->h, 32, rmask, gmask, bmask, amask);
SDL_SetColorKey(m_image, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(m_image->format, 0xFF, 0, 0xFF)); // magenta is transparent
{
SDL_Surface *ns=SDL_DisplayFormatAlpha(m_image);
if (ns) {
SDL_FreeSurface(m_image);
m_image=ns;
}
}
return;
loadFail:
return;
}
void Sprite::templatedColorizePixel(uint8_t color, uint8_t &r, uint8_t &g, uint8_t &b)
{
uint8_t ro = (Creatures::OutfitLookupTable[color] & 0xFF0000) >> 16; // rgb outfit
uint8_t go = (Creatures::OutfitLookupTable[color] & 0xFF00) >> 8;
uint8_t bo = (Creatures::OutfitLookupTable[color] & 0xFF);
r = (uint8_t)(r * (ro / 255.f));
g = (uint8_t)(g * (go / 255.f));
b = (uint8_t)(b * (bo / 255.f));
}
void Sprite::templatedColorize(Sprite* templatespr, uint8_t head, uint8_t body, uint8_t legs, uint8_t feet)
{
// DONT uncomment these lines, it IS possible to get null as parameter and it should be ignored
if(!templatespr){
printf("!templatespr\n");
return;
}
if(!templatespr->getBasicImage()){
return;
}
if(!m_image){
printf("!m_image\n");
return;
}
#ifdef USE_OPENGL
// if(dynamic_cast<EngineGL*>(g_engine))
// gl engine is crashing on SDL_UnlockSurface.
// return;
#endif
templatespr->lockSurface();
if(SDL_MUSTLOCK(m_image)) SDL_LockSurface(m_image);
for(int i=0; i < m_image->h; i++){
for(int j=0; j < m_image->w; j++){
uint32_t pixel = getPixel(j,i,m_image);
uint32_t templatepixel = getPixel(j,i,templatespr->getBasicImage());
uint8_t rt, gt, bt; // rgb template
uint8_t ro, go, bo; // rgb original
SDL_GetRGB(templatepixel, templatespr->getBasicImage()->format, &rt, >, &bt);
SDL_GetRGB(pixel, m_image->format, &ro, &go, &bo);
if(rt && gt && !bt){ // yellow == head
templatedColorizePixel(head, ro, go, bo);
}
else if (rt && !gt && !bt){ // red == body
templatedColorizePixel(body, ro, go, bo);
}
else if (!rt && gt && !bt){ // green == legs
templatedColorizePixel(legs, ro, go, bo);
}
else if (!rt && !gt && bt){ // blue == feet
templatedColorizePixel(feet, ro, go, bo);
}
else{
continue; // if nothing changed, skip the change of pixel
}
putPixel(j, i, SDL_MapRGB(m_image->format, ro, go, bo), m_image);
}
}
if(SDL_MUSTLOCK(m_image)) SDL_UnlockSurface(m_image);
templatespr->unlockSurface();
rebuildSelf();
}
void Sprite::putPixel(int x, int y, uint32_t pixel, SDL_Surface *img)
{
if (!img)
img = m_image;
if (!img->pixels) {
//DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_WARNING, "Trying to write a pixel into a NIL array - %d, %d on a %dx%d image\n", x, y, img->w, img->h);
return;
}
int bpp = img->format->BytesPerPixel;
uint8_t *p = (uint8_t *)img->pixels + y * img->pitch + x * bpp;
if (x >= img->w || y >= img->h)
DEBUGPRINT(DEBUGPRINT_WARNING, DEBUGPRINT_LEVEL_OBLIGATORY, "Trying to write a pixel out of boundaries - %d, %d on a %dx%d image\n", x, y, img->w, img->h);
switch(bpp){
case 1:
*p = pixel;
break;
case 2:
*(uint16_t *)p = pixel;
break;
case 3:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
#else
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
#endif
break;
case 4:
*(uint32_t *)p = pixel;
break;
}
}
uint32_t Sprite::getPixel(int x, int y, SDL_Surface *img)
{
if (!img)
img = m_image;
int bpp = img->format->BytesPerPixel;
if (!img->pixels) {
//DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_WARNING, "Trying to read a pixel from a NIL array - %d, %d on a %dx%d image\n", x, y, img->w, img->h);
return 0;
}
/* Here p is the address to the pixel we want to retrieve */
uint8_t *p = (uint8_t *)img->pixels + y * img->pitch + x * bpp;
if (x >= img->w || y >= img->h)
DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_WARNING, "Trying to read a pixel out of boundaries - %d, %d on a %dx%d image\n", x, y, img->w, img->h);
switch(bpp){
case 1:
return *p;
case 2:
return *(uint16_t *)p;
case 3:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
return p[0] << 16 | p[1] << 8 | p[2];
#else
return p[0] | p[1] << 8 | p[2] << 16;
#endif
case 4:
return *(uint32_t *)p;
default:
return 0; /* shouldn't happen, but avoids warnings */
}
}
void Sprite::Stretch (float w, float h, int smooth, bool force)
{
SDL_Surface* img;
if(m_stretchimage && !force){
if(fabs(m_stretchimage->w - w) < 2.f && fabs(m_stretchimage->h - h) < 2.f){
return;
}
}
if(m_r == 1.f && m_g == 1.f && m_b == 1.f){
img = m_image;
}
else{
img = m_coloredimage;
}
if(smooth == -1){
smooth = m_smoothstretch;
}
else{
m_smoothstretch = smooth;
}
unStretch();
if (w == m_image->w && h == m_image->h)
return;
if (m_stretchimage && w == m_stretchimage->w && h == m_stretchimage->h)
return;
// DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Stretching to %g %g\n", w, h);
m_stretchimage = zoomSurface(img, w/img->w, h/img->h, smooth);
// DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "New size: %d %d\n", m_stretchimage->w, m_stretchimage->h);
}
void Sprite::addColor(float r, float g, float b)
{
register uint8_t ro, go, bo, ao; // old rgba
if (r > 1) r = 1;
if (g > 1) g = 1;
if (b > 1) b = 1;
if(r == m_r && g == m_g && b == m_b){
return;
}
SDL_LockSurface(m_image);
SDL_LockSurface(m_coloredimage);
for(register int i = 0; i < m_image->w; i++){
for(register int j =0; j < m_image->h; j++){
if (!getBasicImage()) {
printf("I don't have an image!\n");
}
if (!getBasicImage()->pixels) {
printf("I don't have image's pixels!\n");
}
SDL_GetRGBA(getPixel(i,j, getBasicImage()), getBasicImage()->format, &ro, &go, &bo, &ao);
if(ao){
putPixel(i, j, SDL_MapRGBA(m_coloredimage->format, (uint8_t)(ro*r), (uint8_t)(go*g), (uint8_t)(bo*b), ao), m_coloredimage);
}
}
}
SDL_UnlockSurface(m_image);
SDL_UnlockSurface(m_coloredimage);
m_r = r; m_g = g; m_b = b;
Stretch(getImage()->w, getImage()->h, -1, true);
}
void Sprite::setAsIcon()
{
#ifdef WINCE
return; // sdl for wince doesnt uspport runtime icons anyway
#endif
if(!m_image) {
std::stringstream s;
s << "Did not find source image for setting the icon. Probably " << PRODUCTSHORT << " did not find '" << m_filename << "'.";
NativeGUIError(s.str().c_str(), "Error");
}
SDL_WM_SetIcon(m_image, NULL);
}
SDL_Cursor* Sprite::createCursor(int topx, int topy, int w, int h, int hot_x, int hot_y)
{
int i, row, col;
Uint8 data[4*32];
Uint8 mask[4*32];
//int hot_x, hot_y;
i = -1;
for ( row=0; row<32; ++row ) {
for ( col=0; col<32; ++col ) {
if ( col % 8 ) {
data[i] <<= 1;
mask[i] <<= 1;
} else {
++i;
data[i] = mask[i] = 0;
}
if (col < w && row < h) {
uint32_t pv;
uint8_t r,g,b,a;
SDL_GetRGBA(pv=getPixel(topx+col, topy+row, m_image), m_image->format, &r, &g, &b, &a);
if(a == 0){
// transparent
} else if (r == 0 && g == 0 && b == 0) { // black
data[i] |= 0x01;
mask[i] |= 0x01;
} else { // white
mask[i] |= 0x01;
}
} else { // if out of boundaries, then leave
}
}
}
//sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
//hot_x = 16;
//hot_y = 16;
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
}
SDL_Surface* Sprite::lockSurface()
{
//printf("LOCK %p\n", m_image);
if(SDL_MUSTLOCK(m_image))
if(SDL_LockSurface(m_image)==-1)
return NULL;
return m_image;
}
void Sprite::unlockSurface()
{
//printf("UNLOCK %p\n", m_image);
if(SDL_MUSTLOCK(m_image)) SDL_UnlockSurface(m_image);
Stretch(getWidth(), getHeight(),m_smoothstretch,1); // when unlocking
rebuildSelf();
}