📄 newscr.c
字号:
};
void blit_hline ( BITMAP *source, BITMAP *dest, int sx, int sy, int dx, int dy, int sw, int dw ) {
if ( !source ) source = ScreenContext;
if ( !dest ) dest = ScreenContext;
if ( !source->w || !source->h ) return;
sx %= source->w;
sy %= source->h;
sw = min(source->w-sx, min(sw, dw));
while ( dw ) {
blit(source, dest, sx, sy, dx, dy, sw, 1);
sx = 0;
dx += sw;
dw -= sw;
sw = min(source->w, dw);
};
};
/* blit_ellipsefill:
* Draws a blit filled circle. Without trying to use any hardware feature on the card - pity.
*/
void blit_circlefill(BITMAP *source, BITMAP *dest, int sx, int sy, int dx, int dy, int sw, int radius)
{
int cx = 0;
int cy = radius;
int df = 1 - radius;
int d_e = 3;
int d_se = -2 * radius + 5;
int vx = (dx-radius)-sx;
int vy = (dy-radius)-sy;
if ( !source ) source = ScreenContext;
if ( !dest ) dest = ScreenContext;
do {
__blit_hline(source, dest, (dx-cy)-vx, (dy-cx)-vy, dx-cy, dy-cx, sw, dx+cy-(dx-cy));
if (cx)
__blit_hline(source, dest, (dx-cy)-vx, (dy+cx)-vy, dx-cy, dy+cx, sw, dx+cy-(dx-cy));
if (df < 0) {
df += d_e;
d_e += 2;
d_se += 2;
}
else {
if (cx != cy) {
__blit_hline(source, dest, (dx-cx)-vx, (dy-cy)-vy, dx-cx, dy-cy, sw, dx+cx-(dx-cx));
if (cy)
__blit_hline(source, dest, (dx-cx)-vx, (dy+cy)-vy, dx-cx, dy+cy, sw, dx+cx-(dx-cx));
}
df += d_se;
d_e += 2;
d_se += 4;
cy--;
}
cx++;
} while (cx <= cy);
}
/* blit_ellipsefill:
* Draws a blit filled ellipse. without using hardware - shame.
*/
void blit_ellipsefill(BITMAP *source, BITMAP *dest, int sx, int sy, int dx, int dy, int sw, int rx, int ry)
{
int x, y;
int a, b, c, d;
int da, db, dc, dd;
int na, nb, nc, nd;
int vx = (dx-rx)-sx, vy = (dy-ry)-sy;
if ( !source ) source = ScreenContext;
if ( !dest ) dest = ScreenContext;
if (rx < 1)
rx = 1;
if (ry < 1)
ry = 1;
if (rx > ry) {
dc = -1;
dd = 0xFFFF;
x = 0;
y = rx * 64;
na = 0;
nb = (y + 32) >> 6;
nc = 0;
nd = (nb * ry) / rx;
do {
a = na;
b = nb;
c = nc;
d = nd;
x = x + (y / rx);
y = y - (x / rx);
na = (x + 32) >> 6;
nb = (y + 32) >> 6;
nc = (na * ry) / rx;
nd = (nb * ry) / rx;
if ((c > dc) && (c < dd)) {
__blit_hline(source, dest, (dx-b)-vx, (dy+c)-vy, dx-b, dy+c, sw, dx+b-(dx-b));
if (c)
__blit_hline(source, dest, (dx-b)-vx, (dy-c)-vy, dx-b, dy-c, sw, dx+b-(dx-b));
dc = c;
}
if ((d < dd) && (d > dc)) {
__blit_hline(source, dest, (dx-a)-vx, (dy+d)-vy, dx-a, dy+d, sw, dx+a-(dx-a));
__blit_hline(source, dest, (dx-a)-vx, (dy-d)-vy, dx-a, dy-d, sw, dx+a-(dx-a));
dd = d;
}
} while(b > a);
}
else {
da = -1;
db = 0xFFFF;
x = 0;
y = ry * 64;
na = 0;
nb = (y + 32) >> 6;
nc = 0;
nd = (nb * rx) / ry;
do {
a = na;
b = nb;
c = nc;
d = nd;
x = x + (y / ry);
y = y - (x / ry);
na = (x + 32) >> 6;
nb = (y + 32) >> 6;
nc = (na * rx) / ry;
nd = (nb * rx) / ry;
if ((a > da) && (a < db)) {
__blit_hline(source, dest, (dx-d)-vx, (dy+a)-vy, dx-d, dy+a, sw, dx+d-(dx-d));
if (a)
__blit_hline(source, dest, (dx-d)-vx, (dy-a)-vy, dx-d, dy-a, sw, dx+d-(dx-d));
da = a;
}
if ((b < db) && (b > da)) {
__blit_hline(source, dest, (dx-c)-vx, (dy+b)-vy, dx-c, dy+b, sw, dx+c-(dx-c));
__blit_hline(source, dest, (dx-c)-vx, (dy-b)-vy, dx-c, dy-b, sw, dx+c-(dx-c));
db = b;
}
} while(b > a);
}
}
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef ulong
#define ulong unsigned long
#endif
#define lrgb long
#define sizeuchar 1
#define sizeint 2
#define sizelrgb 3
#define sizelong 4
BITMAP *gen_neg ( int depth, BITMAP *src ) { // if depth == 0 create standard bitmap
#define loop_neg(d,s,rgb1,rgb2) \
while ( w-- ) { \
ssdat = *((s*)sdat); \
rcol = getr##rgb2(ssdat); \
gcol = getg##rgb2(ssdat); \
bcol = getb##rgb2(ssdat); \
\
rcol = 255-rcol; \
gcol = 255-gcol; \
bcol = 255-bcol; \
\
*((d*)bdat) = (d)makecol##rgb1(rcol, gcol, bcol); \
sdat += size##s; \
bdat += size##d; \
}
int y = 0;
int w = src->w, h = src->h;
int ssdat = 0;
unsigned char *sdat, *bdat;
unsigned char rcol, gcol, bcol;
BITMAP *bmp = NULL;
if ( depth ) bmp = create_bitmap_ex(depth, src->w, src->h);
else bmp = create_bitmap(src->w, src->h);
if ( !bmp ) return NULL;
h = min(h, bmp->h);
while ( h-- ) {
sdat = src->line[y];
bdat = bmp->line[y];
switch ( bmp->vtable->color_depth ) {
case 8: switch ( src->vtable->color_depth ) {
case 8 : loop_neg(uchar, uchar, 8, 8); break;
case 15: loop_neg(uchar, int, 8, 15); break;
case 16: loop_neg(uchar, int, 8, 16); break;
case 24: loop_neg(uchar, lrgb, 8, 24); break;
case 32: loop_neg(uchar, long, 8, 32); break;
}; break;
case 15: switch ( src->vtable->color_depth ) {
case 8 : loop_neg(int, uchar, 15, 8); break;
case 15: loop_neg(int, int, 15, 15); break;
case 16: loop_neg(int, int, 15, 16); break;
case 24: loop_neg(int, lrgb, 15, 24); break;
case 32: loop_neg(int, long, 15, 32); break;
}; break;
case 16: switch ( src->vtable->color_depth ) {
case 8 : loop_neg(int, uchar, 16, 8); break;
case 15: loop_neg(int, int, 16, 15); break;
case 16: loop_neg(int, int, 16, 16); break;
case 24: loop_neg(int, lrgb, 16, 24); break;
case 32: loop_neg(int, long, 16, 32); break;
}; break;
case 24: switch ( src->vtable->color_depth ) {
case 8 : loop_neg(lrgb, uchar, 24, 8); break;
case 15: loop_neg(lrgb, int, 24, 15); break;
case 16: loop_neg(lrgb, int, 24, 16); break;
case 24: loop_neg(lrgb, lrgb, 24, 24); break;
case 32: loop_neg(lrgb, long, 24, 32); break;
}; break;
case 32: switch ( src->vtable->color_depth ) {
case 8 : loop_neg(long, uchar, 32, 8); break;
case 15: loop_neg(long, int, 32, 15); break;
case 16: loop_neg(long, int, 32, 16); break;
case 24: loop_neg(long, lrgb, 32, 24); break;
case 32: loop_neg(long, long, 32, 32); break;
}; break;
};
y++;
w = min(src->w, bmp->w);
};
return bmp;
};
BITMAP *gen_emboss ( int depth, BITMAP *src ) { // if depth == 0 create standard bitmap
#define loop_print(d,s,rgb1,rgb2) \
while ( w-- ) { \
ssdat = *((s*)sdat); \
dddat = *((s*)ddat); \
rcol = getr##rgb2(ssdat); \
gcol = getg##rgb2(ssdat); \
bcol = getb##rgb2(ssdat); \
\
drcol = getr##rgb2(dddat); \
dgcol = getg##rgb2(dddat); \
dbcol = getb##rgb2(dddat); \
\
rcol = (rcol+(255-drcol))>>1; \
gcol = (gcol+(255-dgcol))>>1; \
bcol = (bcol+(255-dbcol))>>1; \
\
*((d*)bdat) = (d)makecol##rgb1(rcol, gcol, bcol); \
sdat += size##s; \
ddat += size##s; \
bdat += size##d; \
}
int y = 0;
int w = src->w-1, h = src->h-1;
int ssdat = 0;
int dddat = 0;
unsigned char *sdat, *ddat, *bdat;
unsigned char rcol, gcol, bcol, drcol, dgcol, dbcol;
BITMAP *bmp = NULL;
if ( depth ) bmp = create_bitmap_ex(depth, src->w, src->h);
else bmp = create_bitmap(src->w, src->h);
if ( !bmp ) return NULL;
clear(bmp);
h = min(h, bmp->h-1);
if ( (w > 1) && (h > 1) )
while ( h-- ) {
sdat = src->line[y];
ddat = src->line[y+1]+2;
bdat = bmp->line[y];
switch ( bmp->vtable->color_depth ) {
case 8: switch ( src->vtable->color_depth ) {
case 8 : loop_print(uchar, uchar, 8, 8); break;
case 15: loop_print(uchar, int, 8, 15); break;
case 16: loop_print(uchar, int, 8, 16); break;
case 24: loop_print(uchar, lrgb, 8, 24); break;
case 32: loop_print(uchar, long, 8, 32); break;
}; break;
case 15: switch ( src->vtable->color_depth ) {
case 8 : loop_print(int, uchar, 15, 8); break;
case 15: loop_print(int, int, 15, 15); break;
case 16: loop_print(int, int, 15, 16); break;
case 24: loop_print(int, lrgb, 15, 24); break;
case 32: loop_print(int, long, 15, 32); break;
}; break;
case 16: switch ( src->vtable->color_depth ) {
case 8 : loop_print(int, uchar, 16, 8); break;
case 15: loop_print(int, int, 16, 15); break;
case 16: loop_print(int, int, 16, 16); break;
case 24: loop_print(int, lrgb, 16, 24); break;
case 32: loop_print(int, long, 16, 32); break;
}; break;
case 24: switch ( src->vtable->color_depth ) {
case 8 : loop_print(lrgb, uchar, 24, 8); break;
case 15: loop_print(lrgb, int, 24, 15); break;
case 16: loop_print(lrgb, int, 24, 16); break;
case 24: loop_print(lrgb, lrgb, 24, 24); break;
case 32: loop_print(lrgb, long, 24, 32); break;
}; break;
case 32: switch ( src->vtable->color_depth ) {
case 8 : loop_print(long, uchar, 32, 8); break;
case 15: loop_print(long, int, 32, 15); break;
case 16: loop_print(long, int, 32, 16); break;
case 24: loop_print(long, lrgb, 32, 24); break;
case 32: loop_print(long, long, 32, 32); break;
}; break;
};
y++;
w = min(src->w-1, bmp->w-1);
};
return bmp;
};
BITMAP *conv_to_skipcolor_bitmap ( BITMAP *ctx, int r, int g, int b ) {
int x, y = 0;
l_color skip = makecol(r,g,b);
if ( !ctx || (ctx == screen) ) return NULL;
if ( skip == ctx->vtable->mask_color ) return ctx;
for ( y = 0; y < ctx->h; y++ )
for ( x = 0; x < ctx->w; x++ ) {
l_color c = getpixel(ctx, x, y);
if ( skip == c )
putpixel(ctx, x, y, ctx->vtable->mask_color);
if ( c == ctx->vtable->mask_color )
if ( !ctx->vtable->mask_color )
putpixel(ctx, x, y, makecol(0,36,0));
else
putpixel(ctx, x, y, makecol(255,36,255));
};
return ctx;
};
DATAFILE *conv_to_skipcolor_data ( DATAFILE *f, int r, int g, int b ) {
int c = 0;
if ( f )
for (c=0; f[c].type != DAT_END; c++) {
if ( f[c].type == DAT_BITMAP )
f[c].dat = (BITMAP*)conv_to_skipcolor_bitmap((BITMAP*)(f[c].dat), r, g, b);
else
if ( f[c].type == DAT_FILE )
conv_to_skipcolor_data((DATAFILE*)(f[c].dat), r, g, b);
};
return f;
};
ICONLIBRARY *load_icon_library ( char *filename, int r, int g, int b )
{
DATAFILE *dat = load_skip_datafile ( filename, r, g, b );
return convert_to_icon_library ( dat );
};
void unload_icon_library ( ICONLIBRARY *icl )
{
while ( icl ) {
ICONLIBRARY *i = icl->next;
if ( icl->datfile ) unload_datafile(icl->datfile);
_free(icl);
icl = i;
};
};
BITMAP *get_icon_from_library ( ICONLIBRARY *icl, int id, int size )
{
while ( icl ) {
if ( icl->id == id ) {
if ( size == ICON_32 ) {
if ( icl->icon32 ) return icl->icon32;
else return icl->icon16;
} else
if ( icl->icon16 ) return icl->icon16;
else return icl->icon32;
return icl->icon32;
};
icl = icl->next;
};
return NULL;
};
static ICONLIBRARY *_convert_to_icon_library ( DATAFILE *f, ICONLIBRARY *icl, int id )
{
int c = 0;
int h = 0;
if ( f ) {
ICONLIBRARY *i = NULL;
if ( id ) {
i = (ICONLIBRARY*)_malloc(sizeof(ICONLIBRARY));
memset(i, 0, sizeof(ICONLIBRARY));
if ( !icl ) i->datfile = f;
i->id = id-1;
};
for (c=0; f[c].type != DAT_END; c++) {
if ( i && (f[c].type == DAT_BITMAP) && (h < 2) ) {
if ( h == 1 ) i->icon16 = (BITMAP*)(f[c].dat);
else
if ( h == 0 ) i->icon32 = (BITMAP*)(f[c].dat);
h++;
} else
if ( f[c].type == DAT_FILE ) {
ICONLIBRARY *t;
id++;
t = _convert_to_icon_library ( (DATAFILE*)(f[c].dat), i, id );
t->next = i;
i = t;
};
};
return i;
};
return NULL;
};
ICONLIBRARY *convert_to_icon_library ( DATAFILE *f )
{
return _convert_to_icon_library(f, NULL, 0);
};
void *get_datafile_object ( DATAFILE *dat, int obj_num )
{
int c = 0;
if ( dat )
for (c=0; dat[c].type != DAT_END; c++) {
if ( c == obj_num ) return dat[c].dat;
};
return NULL;
};
DATAFILE *load_skip_datafile ( char *filename, int r, int g, int b ) {
DATAFILE *f = load_datafile(filename);
f = conv_to_skipcolor_data(f, r, g, b);
return f;
};
int _gr_setmode ( int _s, int _w, int _h, int _v_w, int _v_h, char _depth )
{
/* new allegro insists on 8 15 16 24 or 32 (in debug mode) */
set_color_depth((_depth<8)?8:_depth);
if ( set_gfx_mode(_s, _w, _h, _v_w, _v_h) ) {
return 0;
};
if ( (_depth < 15) && (_s >= 0) ) {
PALLETE pal;
generate_332_palette(pal);
pal[0].r = 0;
pal[0].g = 0;
pal[0].b = 0;
set_pallete(pal);
};
return 1;
};
extern FONT* load_ttf_font_ex (const char* filename, const int points_w, const int points_h, const int smooth);
extern l_int font_smooth;
extern FONT *load_font(char *f);
static void *_seal_load_font ( char *_filename, char *xxname, int w, int h, int from, int to ) {
/* you shouldnt make an 8 point font anything but 8 point anyhow */
void *f=NULL;
if(_filename){
/* f=load_font(_filename);
if ( !f )*/ f = (void*)load_ttf_font_ex2(GetFile(_filename), w, h, 32, 255, font_smooth);
}
return f;
};
static void _destroy_font ( void *f ) {
destroy_font((FONT*)f);
};
void *(*seal_load_font)(char* _filename, char *xxname, int w, int h, int from, int to) = &_seal_load_font;
void (*unload_font)(void *f) = &_destroy_font;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -