Exemplo n.º 1
0
void _get_player_color(
	short color_index,
	RGBColor *color)
{
	assert(color_index>=0 && color_index<NUMBER_OF_PLAYER_COLORS);
	_get_interface_color(color_index+PLAYER_COLOR_BASE_INDEX, color);
}
Exemplo n.º 2
0
void _frame_rect(screen_rectangle *rectangle, short color_index)
{
	// Get color
	SDL_Color color;
	_get_interface_color(color_index, &color);
	uint32 pixel = SDL_MapRGB(draw_surface->format, color.r, color.g, color.b);

	// Draw rectangle
	SDL_Rect r = {rectangle->left, rectangle->top, rectangle->right - rectangle->left, rectangle->bottom - rectangle->top};
	draw_rectangle(draw_surface, &r, pixel);
}
Exemplo n.º 3
0
void _fill_screen_rectangle(
	screen_rectangle *rectangle, 
	short color_index)
{
	RGBColor old_color, new_color;

	GetForeColor(&old_color);
	_get_interface_color(color_index, &new_color);
	RGBForeColor(&new_color);
	PaintRect((Rect *) rectangle);
	RGBForeColor(&old_color);
}
Exemplo n.º 4
0
void _scroll_window(
	short dy, 
	short rectangle_id, 
	short background_color_index)
{
	Rect *destination= _get_interface_rect(rectangle_id);
	RgnHandle updateRgn;
	RGBColor old_color, new_color;

	GetBackColor(&old_color);
	_get_interface_color(background_color_index, &new_color);
	RGBBackColor(&new_color);

	updateRgn= NewRgn();
	ScrollRect(destination, 0, dy, updateRgn);
	DisposeRgn(updateRgn);

	RGBBackColor(&old_color);
}
Exemplo n.º 5
0
void _fill_rect(screen_rectangle *rectangle, short color_index)
{
	// Convert source rectangle
	SDL_Rect r;
	if (rectangle) {
		r.x = rectangle->left;
		r.y = rectangle->top;
		r.w = rectangle->right - rectangle->left;
		r.h = rectangle->bottom - rectangle->top;
	}

	// Get color
	SDL_Color color;
	_get_interface_color(color_index, &color);

	// Fill rectangle
	SDL_FillRect(draw_surface, rectangle ? &r : NULL, SDL_MapRGB(draw_surface->format, color.r, color.g, color.b));
	if (draw_surface == MainScreenSurface()) {
		if (rectangle)
			MainScreenUpdateRects(1, &r);
		else
			MainScreenUpdateRect(0, 0, 0, 0);
	}
}
Exemplo n.º 6
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
Exemplo n.º 7
0
void _draw_screen_text(const char *text, screen_rectangle *destination, short flags, short font_id, short text_color)
{
	int x, y;

	// Find font information
	assert(font_id >= 0 && font_id < NUMBER_OF_INTERFACE_FONTS);
	uint16 style = InterfaceFonts[font_id].Style;
	const font_info *font = InterfaceFonts[font_id].Info;
	if (font == NULL)
		return;

	// Get color
	SDL_Color color;
	_get_interface_color(text_color, &color);

	// Copy the text to draw
	char text_to_draw[256];
	strncpy(text_to_draw, text, 256);
	text_to_draw[255] = 0;

	// Check for wrapping, and if it occurs, be recursive
	if (flags & _wrap_text) {
		int last_non_printing_character = 0, text_width = 0;
		unsigned count = 0;
		while (count < strlen(text_to_draw) && text_width < RECTANGLE_WIDTH(destination)) {
			text_width += char_width(text_to_draw[count], font, style);
			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
			memcpy(remaining_text_to_draw, text_to_draw + last_non_printing_character + 1, strlen(text_to_draw + last_non_printing_character + 1) + 1);
	
			new_destination = *destination;
			new_destination.top += InterfaceFonts[font_id].LineSpacing;
			_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;
		}
	}

	// Truncate text if necessary
	int t_width = text_width(text_to_draw, font, style);
	if (t_width > RECTANGLE_WIDTH(destination)) {
		text_to_draw[trunc_text(text_to_draw, RECTANGLE_WIDTH(destination), font, style)] = 0;
		t_width = text_width(text_to_draw, font, style);
	}

	// Horizontal positioning
	if (flags & _center_horizontal)
		x = destination->left + (((destination->right - destination->left) - t_width) / 2);
	else if (flags & _right_justified)
		x = destination->right - t_width;
	else
		x = destination->left;

	// Vertical positioning
	int t_height = InterfaceFonts[font_id].Height;
	if (flags & _center_vertical) {
		if (t_height > RECTANGLE_HEIGHT(destination))
			y = destination->top;
		else {
			y = destination->bottom;
			int offset = RECTANGLE_HEIGHT(destination) - t_height;
			y -= (offset / 2) + (offset & 1) + 1;
		}
	} else if (flags & _top_justified) {
		if (t_height > RECTANGLE_HEIGHT(destination))
			y = destination->bottom;
		else
			y = destination->top + t_height;
	} else
		y = destination->bottom;

	// Now draw it
	draw_text(text_to_draw, x, y, SDL_MapRGB(draw_surface->format, color.r, color.g, color.b), font, style);
}