/* ------------ Local code */
static void add_overhead_thumbnail(
    FileSpecifier &File)
{
    PicHandle picture;
    PicHandle preview;
    RgnHandle clip_region;
    FontInfo info;
    short text_x, text_y;
    short text_length;
    Str255 temporary;
    GWorldPtr old_gworld;
    GDHandle old_device;
    struct overhead_map_data overhead_data;
    Rect bounds;
    AEDesc aeFileSpec;
    FSSpec *SpecPtr;

    // Skip all this if there's no nav services to install the preview
    if(!machine_has_nav_services() || NavLibraryVersion() < kNavServicesVersion_2_0)
        return;

    GetGWorld(&old_gworld, &old_device);
    SetGWorld(world_pixels, (GDHandle) NULL);

    // Note well. We're using world_pixels to create our thumbnail pict within.
    // If world_pixels is runing as a postage stamp (low-res + small display space)
    // Then it is actually smaller than the size we're looking to build a thumbnail
    // within. But seeing as we're generating pict images and using drawing commands
    // instead of bit-wise operations. It all works out.

    /* Create the bounding rectangle */
    SetRect(&bounds, 0, 0, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);

    /* Start recording.. */
    picture= OpenPicture(&bounds);

    PaintRect(&bounds);

    overhead_data.scale= OVERHEAD_MAP_MINIMUM_SCALE;
    overhead_data.origin.x= local_player->location.x;
    overhead_data.origin.y= local_player->location.y;
    overhead_data.half_width= RECTANGLE_WIDTH(&bounds)/2;
    overhead_data.half_height= RECTANGLE_HEIGHT(&bounds)/2;
    overhead_data.width= RECTANGLE_WIDTH(&bounds);
    overhead_data.height= RECTANGLE_HEIGHT(&bounds);
    overhead_data.mode= _rendering_saved_game_preview;

    _render_overhead_map(&overhead_data);

    RGBForeColor(&rgb_black);
    PenSize(1, 1);
    TextFont(0);
    TextFace(normal);
    TextSize(0);

    ClosePicture();

    // JTP: Add Nav Services style preview
    SetRect(&bounds, 0, 0, PREVIEW_WIDTH, PREVIEW_HEIGHT);
    preview= OpenPicture(&bounds);

    SetRect(&bounds, PREVIEW_IMAGE_X, PREVIEW_IMAGE_Y,
            THUMBNAIL_WIDTH + PREVIEW_IMAGE_X, THUMBNAIL_HEIGHT + PREVIEW_IMAGE_Y);
    clip_region= NewRgn();
    GetClip(clip_region);
    ClipRect(&bounds);
    DrawPicture(picture, &bounds);
    SetClip(clip_region);

    /* Center the text in the rectangle */
    // LP: Classic doesn't have this function
#ifdef TARGET_API_MAC_CARBON
    CopyCStringToPascal(static_world->level_name, temporary);
#else
    strncpy((char *)temporary,static_world->level_name,LEVEL_NAME_LENGTH);
    c2pstr((char *)temporary);
#endif
    // LP: fix to allow lengths more than 127 bytes (not really necessary, but...)
    text_length = *ptemporary;
    TruncText(PREVIEW_WIDTH, (char *)temporary+1, &text_length, smTruncEnd);
    *ptemporary = text_length;

    GetFontInfo(&info);
    text_y= PREVIEW_HEIGHT - info.descent;
    text_x= PREVIEW_LABEL_X + (PREVIEW_WIDTH-StringWidth(temporary))/2;
    MoveTo(text_x, text_y);
    DrawString(temporary);

    ClosePicture();

    // This requires NavServices 2.0, what's the inline check?
    // From FSS get a AEDesc
    OSStatus err;
    SpecPtr = &File.GetSpec();
    err = AECreateDesc(typeFSS, SpecPtr, sizeof(FSSpec), &aeFileSpec);

    HLock((Handle)preview);
    err = NavCreatePreview(&aeFileSpec, 'PICT', *preview, GetHandleSize((Handle)preview));
    HUnlock((Handle)preview);

    AEDisposeDesc(&aeFileSpec);
    KillPicture(preview);
    KillPicture(picture);
    DisposeRgn(clip_region);

    SetGWorld(old_gworld, old_device);
}
Example #2
0
/* This expects a cstring. Draws to the current port*/
void _draw_screen_text(
	char *text,
	screen_rectangle *destination,
	short flags,
	short font_id,
	short text_color)
{
	TextSpec old_font;
	short x, y;
	RGBColor old_color, new_color;
	char text_to_draw[256];

	assert(font_id>=0 && font_id<NUMBER_OF_INTERFACE_FONTS);
	
	GetFont(&old_font);
	SetFont(&interface_fonts.fonts[font_id]);

	GetForeColor(&old_color);
	_get_interface_color(text_color, &new_color);
	RGBForeColor(&new_color);

	/* Copy the text to draw.. */
	strcpy(text_to_draw, text);

	/* Check for wrapping, and if it occurs, be recursive... */
	if(flags & _wrap_text)
	{
/*ะตะตะต WHAT IS THE INTERNATIONALIZED WAY OF DETERMINING NON-PRINTING CHARACTERS? IE SPACES? */
		short last_non_printing_character;
		short text_width;
		short count= 0;

		text_width= 0;
		last_non_printing_character= 0;
		count= 0;
		while(count<strlen(text_to_draw) && text_width<RECTANGLE_WIDTH(destination))
		{
			text_width+= CharWidth(text_to_draw[count]);
			if(text_to_draw[count]==' ') last_non_printing_character= count;
			count++;
		}
		
		if(count!=strlen(text_to_draw))
		{
			char remaining_text_to_draw[256];
			screen_rectangle new_destination;
			
			/* If we ever have to wrap text, we can't also center vertically.  Sorry */
			flags &= ~_center_vertical;
			flags |= _top_justified;
			
			/* Pass the rest of it back in, recursively, on the next line.. */
			BlockMove(&text_to_draw[last_non_printing_character+1], remaining_text_to_draw,
				strlen(&text_to_draw[last_non_printing_character+1])+1);
	
			new_destination= *destination;
			new_destination.top+= interface_fonts.line_spacing[font_id];
			_draw_screen_text(remaining_text_to_draw, &new_destination, flags, font_id, text_color);
	
			/* now truncate our text to draw...*/
			text_to_draw[last_non_printing_character]= 0;
		}
	}

	/* Handle the horizontal stuff. */
	if(flags & _center_horizontal || flags & _right_justified)
	{
		short text_width;
		
		text_width= TextWidth(text_to_draw, 0, strlen(text_to_draw));
		
		if(text_width>RECTANGLE_WIDTH(destination))
		{
			short length;
			short trunc_code;
	
			/* Truncate the puppy.. */	
			x= destination->left;
			length= strlen(text);
			trunc_code= TruncText(RECTANGLE_WIDTH(destination), text_to_draw, &length, truncEnd);
			text_to_draw[length]= 0;

			/* Now recenter it.. */
			text_width= TextWidth(text_to_draw, 0, strlen(text_to_draw));
			if (flags & _center_horizontal)
				x= destination->left+(((destination->right-destination->left)-text_width)>>1);
			else