int gr_lock_screen() { if ( screen_locked ) return 1 ; screen_locked = 1 ; if ( scale_resolution != -1 ) { if ( SDL_MUSTLOCK( scale_screen ) ) SDL_LockSurface( scale_screen ) ; } else { if ( SDL_MUSTLOCK( screen ) ) SDL_LockSurface( screen ) ; } if ( enable_scale || scale_mode != SCALE_NONE ) { if ( scrbitmap && ( scrbitmap->info_flags & GI_EXTERNAL_DATA ) ) { bitmap_destroy( scrbitmap ) ; scrbitmap = NULL ; } if ( !scrbitmap ) { scrbitmap = bitmap_new( 0, screen->w / 2, screen->h / 2, sys_pixel_format->depth ) ; bitmap_add_cpoint( scrbitmap, 0, 0 ) ; } } else { if ( !scrbitmap || !( scrbitmap->info_flags & GI_EXTERNAL_DATA ) ) { if ( scrbitmap ) bitmap_destroy( scrbitmap ) ; scrbitmap = bitmap_new_ex( 0, screen->w, screen->h, screen->format->BitsPerPixel, screen->pixels, screen->pitch ); bitmap_add_cpoint( scrbitmap, 0, 0 ) ; } } return 1 ; }
GRAPH * gr_text_bitmap( int fontid, const char * text, int alignment ) { GRAPH * gr ; int x, y ; FONT * f ; // Splinter if ( !text || !*text ) return NULL; if ( fontid < 0 || fontid >= MAX_FONTS || !fonts[fontid] ) return NULL; // Incorrect font type f = fonts[fontid] ; /* Un refresco de paleta en mitad de gr_text_put puede provocar efectos * desagradables al modificar el tipo de letra del sistema */ if ( palette_changed ) gr_refresh_palette() ; gr = bitmap_new_syslib( gr_text_width( fontid, ( const unsigned char * ) text ), gr_text_height( fontid, ( const unsigned char * ) text ), sys_pixel_format->depth ) ; if ( !gr ) return NULL; gr_clear( gr ) ; if ( !gr_text_put( gr, 0, fontid, 0, -gr_text_margintop( fontid, ( const unsigned char * ) text ), ( const unsigned char * ) text ) ) { bitmap_destroy( gr ); return NULL; } switch ( alignment ) { case ALIGN_TOP_LEFT: // 0 case ALIGN_TOP: // 1 case ALIGN_TOP_RIGHT: // 2 y = 0 ; break ; case ALIGN_CENTER_LEFT: // 3 case ALIGN_CENTER: // 4 case ALIGN_CENTER_RIGHT:// 5 y = gr->height / 2 ; break ; default: y = gr->height - 1 ; break ; } switch ( alignment ) { case ALIGN_TOP_LEFT: // 0 case ALIGN_CENTER_LEFT: // 3 case ALIGN_BOTTOM_LEFT: // 6 x = 0 ; break ; case ALIGN_TOP: // 1 case ALIGN_CENTER: // 4 case ALIGN_BOTTOM: // 7 x = gr->width / 2 ; break ; default: x = gr->width - 1 ; break ; } bitmap_add_cpoint( gr, x, y ) ; return gr ; }
static int grproc_get_real_point( INSTANCE * my, int * params ) { GRAPH * b ; int x, y, r, centerx, centery, px = 0, py = 0, rx = 0, ry = 0 ; int _angle = 0, angle = 0; b = instance_graph( my ) ; if ( !b ) return 0 ; /* Point 0 is the graphic center, but it may be not defined */ if ( params[0] == 0 && ( b->ncpoints == 0 || b->cpoints[0].x == CPOINT_UNDEFINED ) ) { if ( b->ncpoints == 0 ) bitmap_add_cpoint( b, b->width / 2, b->height / 2 ); else { b->cpoints[0].x = b->width / 2; b->cpoints[0].y = b->height / 2; } } else if (( uint32_t )params[0] >= b->ncpoints || params[0] < 0) return 0 ; if ( b->cpoints[params[0]].x == CPOINT_UNDEFINED && b->cpoints[params[0]].y == CPOINT_UNDEFINED ) return 0; r = LOCINT32( mod_grproc, my, REGIONID ) ; if ( r < 0 || r > 31 ) r = 0 ; if ( b->cpoints[0].x != CPOINT_UNDEFINED && b->cpoints[0].y != CPOINT_UNDEFINED ) { centerx = b->cpoints[0].x ; centery = b->cpoints[0].y ; } else { centerx = b->width / 2 ; centery = b->height / 2 ; } if ( LOCINT32( mod_grproc, my, ANGLE ) != 0 && !LOCDWORD( mod_grproc, my, XGRAPH ) ) { _angle = angle = LOCINT32( mod_grproc, my, ANGLE ) ; } /* if ( b->cpoints[params[0]].x >= 0 ) { if ( LOCDWORD( mod_grproc, my, FLAGS ) & B_HMIRROR ) px = centerx - b->cpoints[params[0]].x - 1 ; else px = b->cpoints[params[0]].x - centerx ; if ( LOCDWORD( mod_grproc, my, FLAGS ) & B_VMIRROR ) py = centery - b->cpoints[params[0]].y - 1 ; else py = b->cpoints[params[0]].y - centery ; } else px = py = 0 ; */ if ( params[0] > 0 ) { px = b->cpoints[params[0]].x - centerx ; py = b->cpoints[params[0]].y - centery ; if ( LOCDWORD( mod_grproc, my, FLAGS ) & B_HMIRROR ) { if (_angle) { py = (centery - b->cpoints[params[0]].y) ; angle = 90000 + ( 90000 - angle ); } else px = (centerx - b->cpoints[params[0]].x) ; } if ( LOCDWORD( mod_grproc, my, FLAGS ) & B_VMIRROR ) { if (_angle) { px = (centerx - b->cpoints[params[0]].x) ; angle = 360000 + ( 180000 - angle ); } else py = (centery - b->cpoints[params[0]].y) ; } } if ( LOCINT32( mod_grproc, my, GRAPHSIZEX ) == 100 && LOCINT32( mod_grproc, my, GRAPHSIZEY ) == 100 ) { if ((( int )LOCINT32( mod_grproc, my, GRAPHSIZE ) ) > 0 ) { // Corrected a bug from the casting that rounded to 0 px = ( int )( px * ( LOCINT32( mod_grproc, my, GRAPHSIZE ) / 100.0F ) ) ; py = ( int )( py * ( LOCINT32( mod_grproc, my, GRAPHSIZE ) / 100.0F ) ) ; } } else { // Adding size_x/size_y control if ( LOCINT32( mod_grproc, my, GRAPHSIZEX ) > 0 ) px = ( int )( px * ( LOCINT32( mod_grproc, my, GRAPHSIZEX ) / 100.0F ) ) ; if ( LOCINT32( mod_grproc, my, GRAPHSIZEY ) > 0 ) py = ( int )( py * ( LOCINT32( mod_grproc, my, GRAPHSIZEY ) / 100.0F ) ) ; } if ( angle ) { float cos_angle = ( float ) cos( angle * M_PI / -180000.0 ); float sin_angle = ( float ) sin( angle * M_PI / -180000.0 ); rx = ( int )(( double )px * cos_angle - ( double )py * sin_angle ) ; ry = ( int )(( double )px * sin_angle + ( double )py * cos_angle ) ; px = rx ; py = ry ; } x = LOCINT32( mod_grproc, my, COORDX ) ; y = LOCINT32( mod_grproc, my, COORDY ) ; RESOLXY( mod_grproc, my, x, y ); rx = x + px ; ry = y + py ; if ( LOCINT32( mod_grproc, my, RESOLUTION ) > 0 ) { rx *= LOCINT32( mod_grproc, my, RESOLUTION ); ry *= LOCINT32( mod_grproc, my, RESOLUTION ); } else if ( LOCINT32( mod_grproc, my, RESOLUTION ) < 0 ) { rx /= -LOCINT32( mod_grproc, my, RESOLUTION ); ry /= -LOCINT32( mod_grproc, my, RESOLUTION ); } *( int * )params[1] = rx ; *( int * )params[2] = ry ; return 1 ; }
static int gr_font_loadfrom( file * fp ) { char header[8]; int bpp; int types, i, id; uint32_t y; FONT * f; PALETTE * pal = NULL; struct { int width ; int height ; int yoffset ; int fileoffset ; } oldchardata[256]; _chardata chardata[256] ; if ( font_count == MAX_FONTS ) return -1 ; /* Read the file header */ if ( !file_read( fp, header, 8 ) ) return -1; if ( memcmp( header, FNT_MAGIC, 7 ) != 0 && memcmp( header, FNX_MAGIC, 7 ) != 0 ) { return -1; } bpp = header[7]; if ( bpp == 0 ) bpp = 8; /* Read or ignore the palette */ if ( bpp == 8 && !( pal = gr_read_pal_with_gamma( fp ) ) ) return -1 ; /* Read the character data (detect old format) */ if ( header[2] == 'x' ) { if ( !file_readSint32( fp, &types ) ) { pal_destroy( pal ); return -1 ; } if ( !file_read( fp, chardata, sizeof( chardata ) ) ) { pal_destroy( pal ); return -1 ; } for ( i = 0 ; i < 256 ; i++ ) { ARRANGE_DWORD( &chardata[i].width ); ARRANGE_DWORD( &chardata[i].height ); ARRANGE_DWORD( &chardata[i].xadvance ); ARRANGE_DWORD( &chardata[i].yadvance ); ARRANGE_DWORD( &chardata[i].xoffset ); ARRANGE_DWORD( &chardata[i].yoffset ); ARRANGE_DWORD( &chardata[i].fileoffset ); } } else { if ( !file_readSint32( fp, &types ) ) { pal_destroy( pal ); return -1 ; } if ( !file_read( fp, oldchardata, sizeof( oldchardata ) ) ) { pal_destroy( pal ); return -1 ; } for ( i = 0 ; i < 256 ; i++ ) { ARRANGE_DWORD( &oldchardata[i].width ); ARRANGE_DWORD( &oldchardata[i].height ); ARRANGE_DWORD( &oldchardata[i].yoffset ); ARRANGE_DWORD( &oldchardata[i].fileoffset ); chardata[i].width = oldchardata[i].width; chardata[i].height = oldchardata[i].height; chardata[i].xoffset = 0; chardata[i].yoffset = oldchardata[i].yoffset; chardata[i].xadvance = oldchardata[i].width; chardata[i].yadvance = oldchardata[i].height + oldchardata[i].yoffset; chardata[i].fileoffset = oldchardata[i].fileoffset; } } /* Create the font */ if ( header[2] == 'x' ) id = gr_font_new( types, header[7] ) ; else id = gr_font_new( CHARSET_CP850, 8 ) ; if ( id == -1 ) { pal_destroy( pal ); return -1 ; } f = fonts[id]; if ( !f ) { gr_font_destroy( id ); pal_destroy( pal ); return -1 ; } /* Load the character bitmaps */ for ( i = 0 ; i < 256 ; i++ ) { GRAPH * gr; uint8_t * ptr; f->glyph[i].xadvance = chardata[i].xadvance ; f->glyph[i].yadvance = chardata[i].yadvance ; if ( chardata[i].fileoffset == 0 || chardata[i].width == 0 || chardata[i].height == 0 ) continue ; f->glyph[i].xoffset = chardata[i].xoffset ; f->glyph[i].yoffset = chardata[i].yoffset ; file_seek( fp, chardata[i].fileoffset, SEEK_SET ) ; f->glyph[i].bitmap = gr = bitmap_new( i, chardata[i].width, chardata[i].height, f->bpp ) ; if ( !gr ) { gr_font_destroy( id ); pal_destroy( pal ); return -1 ; } bitmap_add_cpoint( gr, 0, 0 ) ; gr->format->palette = pal; pal_use( pal ); for ( y = 0, ptr = gr->data; y < gr->height; y++, ptr += gr->pitch ) { if ( !file_read( fp, ptr, gr->widthb ) ) break ; if ( gr->format->depth == 16 ) { ARRANGE_WORDS( ptr, ( int )gr->width ); } else if ( gr->format->depth == 32 ) { ARRANGE_DWORDS( ptr, ( int )gr->width ); } } f->glyph[i].yoffset = chardata[i].yoffset ; } if ( f->glyph[32].xadvance == 0 ) f->glyph[32].xadvance = f->glyph['j'].xadvance ; pal_destroy( pal ); // Elimino la instancia inicial return id ; }