Exemplo n.º 1
0
void dashboard_window_t::render_progress()
{
	SDL_Rect r;
	int x, y, w, h;

	x = 0;
	w = (int)(_percent * 0.01f * width() + 0.5f);
	if(w < 4)
		w = 4;
	else if(w > width())
		w = width();

	h = 16;
	y = height() - h;

	r.x = x;
	r.y = y;
	r.w = w;
	r.h = h;

	foreground(map_rgb(0x000099));
	rectangle(x, y, w, h);

	++x;
	++y;
	w -= 2;
	h -= 2;
	foreground(map_rgb(0x0000cc));
	rectangle(x, y, w, h);

	++x;
	++y;
	w -= 2;
	h -= 2;
	foreground(map_rgb(0x0000ff));
	fillrect(x, y, w, h);
	
	r.x = 0;
	r.y = height() - 40;
	r.w = width();
	r.h = 12;
	foreground(map_rgb(0x000000));
	fillrect(r.x, r.y, r.w, r.h);
	if(_msg)
	{
		font(B_NORMAL_FONT);
		center(height() - 40, _msg);
	}
}
Exemplo n.º 2
0
void dashboard_window_t::refresh(SDL_Rect *r)
{
	switch(_mode)
	{
	  case DASHBOARD_OFF:
		break;
	  case DASHBOARD_BLACK:
		background(map_rgb(0x000000));
		clear();
		break;
	  case DASHBOARD_GAME:
		sprite(0, 0, B_SCREEN, 0);
		break;
	  case DASHBOARD_LOADING:
		background(map_rgb(0x000000));
		clear();
		sprite((width() - 250) / 2, 55, B_LOADING, 0);
		render_progress();
		break;
	}
}
Exemplo n.º 3
0
void bargraph_t::refresh(SDL_Rect *r)
{
	if(!_enabled)
	{
		clear();
		return;
	}
	float v = _value;
	int red, green, blue;
	if(v > 1.0f)
	{
		blue = 50 + (v - 1.0f) * 512;
		if(_redmax)
		{
			red = 255;
			green = blue / 2;
		}
		else
		{
			green = 255;
			red = blue / 2;
		}
		v = 1.0f;
	}
	else
	{
		if(_redmax)
		{
			red = (int)(v * 300.0);
			green = (int)((1.0 - v) * 400.0);
		}
		else
		{
			red = (int)((1.0 - v) * 300.0);
			green = (int)(v * 400.0);
		}
		blue = 50;
	}
	if(green > 180)
		green = 180;
	if(red > 230)
		red = 230;
	if(blue > 255)
		blue = 255;
	_y = (int)((height() - 2) * (1.0f - v));
	foreground(bgcolor);
	fillrect(0, 0, width(), height());
	foreground(map_rgb(red, green, blue));
	fillrect(1, _y + 1, width() - 2, height() - _y - 2);
}
Exemplo n.º 4
0
void screen_window_t::refresh(SDL_Rect *r)
{
	int x, y, w, h;
	foreground(map_rgb(0x000000));
	x = 0;
	y = 0;
	w = width();
	h = _top;
	fillrect(x, y, w, h);

	y = height() - _bottom;
	h = _bottom;
	fillrect(x, y, w, h);

	y = _top;
	w = _left;
	h = height() - _top - _bottom;
	fillrect(x, y, w, h);

	x = width() - _right;
	w = _right;
	fillrect(x, y, w, h);
}
Exemplo n.º 5
0
void dashboard_window_t::nibble(int tool)
{
	int i;
	int x[NIBBLE_TILES];
	int y[NIBBLE_TILES];

	mode(DASHBOARD_OFF);

	if(tool < 0)
		tool = (pubrand.get(20) + SDL_GetTicks()) % 5;

	/* Clear */
	for(i = 0; i < NIBBLE_TILES; ++i)
		x[i] = y[i] = -1;

	/* Fill in */
	int ind = 0;
	int xx = -NIBBLE_W / 2;
	int yy = -NIBBLE_H / 2;
	for(i = 0; i < NIBBLE_TILES; ++i)
	{
		ind = pubrand.get() % NIBBLE_TILES;
		if(ind >= NIBBLE_TILES)
			ind = 0;
		while(x[ind] != -1)
			if(++ind >= NIBBLE_TILES)
				ind = 0;
		x[ind] = xx;
		y[ind] = yy;
		xx += NIBBLE_W;
		if(xx >= SCREEN_WIDTH + NIBBLE_W / 2)
		{
			xx = -NIBBLE_W / 2;
			yy += NIBBLE_H;
		}
	}

	/* Clear 8000 tiles/second, until all are done. */
	foreground(map_rgb(0x000000));
	ind = 0;
	int last_index;
	int t = SDL_GetTicks();
	while(ind < NIBBLE_TILES)
	{
		int nt = SDL_GetTicks();
		int dt = nt - t;
		t = nt;
		last_index = ind;	/* For double buffer mode */
		for(i = 0; i < dt * 8; ++i)
		{
			if(ind >= NIBBLE_TILES)
				break;
			switch (tool)
			{
			  case 0:
				fillrect(x[ind] + NIBBLE_W / 2,
						y[ind] + NIBBLE_H / 2,
						NIBBLE_W, NIBBLE_H);
				break;
			  default:
				sprite(x[ind] - 8 + NIBBLE_W / 2,
						y[ind] - 8 +
						NIBBLE_H / 2, B_BRUSHES,
						tool - 1);
				break;
			}
			++ind;
		}
		gengine->invalidate();
		gengine->flip();
		if(gengine->doublebuffer())
		{
			for(i = 0; i < dt * 4; ++i)
			{
				if(last_index >= NIBBLE_TILES)
					break;
				switch (tool)
				{
				  case 0:
					fillrect(x[last_index] +
							NIBBLE_W / 2,
							y[last_index] +
							NIBBLE_H / 2,
							NIBBLE_W,
							NIBBLE_H);
					break;
				  default:
					sprite(x[last_index] - 8 +
							NIBBLE_W / 2,
							y[last_index] - 8 +
							NIBBLE_H / 2,
							B_BRUSHES,
							tool - 1);
					break;
				}
				++last_index;
			}
		}
	}
	mode(DASHBOARD_BLACK);
	gengine->flip();
}
Exemplo n.º 6
0
	bool mxSurface::createImageRaw(void *buffer)
	{

		
		long offset, size;
		short type, bitcount;
		u32 width, height;
		unsigned int i = 0;
		unsigned int x,q;
		int y=0;
	
		mxDataStream stream(buffer);

		stream.fRead(&type, sizeof(short));
		if(type != 0x4D42) {
			return false;
		}

		stream.fSeekSet(10);
		stream.fRead(&offset, sizeof(long));
		stream.fSeekFwd(4);
		stream.fRead(&width, sizeof(long));
		stream.fRead(&height, sizeof(long));
		stream.fSeekFwd(2);
		stream.fRead(&bitcount, sizeof(short));
		if(bitcount != 24) {
			return false;
		}
		stream.fSeekFwd(4);
		stream.fRead(&size, sizeof(long));
		stream.fSeekFwd(6);
		
		this->height = height;
		tw = alpha_LineSize(width);
		th = alpha_LineSize(height);
		data = malloc ( sizeof(u32) * (tw * th) );
	
		if(!data)
		{
			return false;
		}
	


		for(y = height-1; y > -1; y--)
		{	
			for(x = 0; x < width; x++)
			{
				q = x + y * width;
				u8 b,g,r,w;
				b = stream.fgetc();
				g = stream.fgetc();
				r = stream.fgetc();
				w = 255;
				{
					u32 *s;
					s = (u32*) data;
					s[x+(y*tw)] = map_rgb(r,g,b);
	
				}
	

			}
			for(i = 0; i <  width % 4; i++)
				stream.fgetc();
		}


		


		




		return true;

	}
Exemplo n.º 7
0
	bool mxSurface::loadImage(const char *source)
	{

		FILE *fptr = 0;
		long offset, size;
		short type, bitcount;
		u32 width, height;
		unsigned int i = 0;
		unsigned int x,q;
		int y=0;
	


		fptr = fopen(source,"rb");
		if(!fptr)
		return 0;
		fread(&type, sizeof(short), 1, fptr);
		if(type != 0x4D42) {
			fclose(fptr);
			return false;
		}

		fseek(fptr, 10, SEEK_SET);
		fread(&offset, sizeof(long), 1, fptr);
		fseek(fptr, 4, SEEK_CUR);
		fread(&width, sizeof(long), 1, fptr);
		fread(&height, sizeof(long), 1, fptr);
		fseek(fptr, 2, SEEK_CUR);
		fread(&bitcount, sizeof(short), 1, fptr);
		if(bitcount != 24) {
			fclose(fptr);
			return false;
		}
		fseek(fptr, 4, SEEK_CUR);
		fread(&size, sizeof(long), 1, fptr);
		fseek(fptr,16,SEEK_CUR);
		
		//surface = (Surface*) malloc ( sizeof(Surface) );
		//surface->w = width;
		//surface->h = height;
		this->width = width;
		this->height = height;
		tw = alpha_LineSize(width);
		th = alpha_LineSize(height);
		data = malloc ( sizeof(u32) * (tw * th) );
	
		if(!data)
		{
			fclose(fptr);
			return false;
		}
	


		for(y = height-1; y > -1; y--)
		{	
			for(x = 0; x < width; x++)
			{
				q = x + y * width;
				u8 b,g,r,w;
				b = fgetc(fptr);
				g = fgetc(fptr);
				r = fgetc(fptr);
				w = 255;
				{
					u32 *s;
					s = (u32*) data;
					s[x+(y*tw)] = map_rgb(r,g,b);
	
				}
	

			}
			for(i = 0; i <  width % 4; i++)
				fgetc(fptr);
		}


		fclose(fptr);

		return true;
	}
Exemplo n.º 8
0
void gui_show_listbox(gui_listbox *lb) {
	int i, item;
	SDL_Rect rect;
	
	if (lb == NULL)
		return;
	
	if (!lb->visible)
		return;
	
	/* draw the under area first */
	if (lb->trans_area == NULL) {
		SDL_Surface *area;
		SDL_Rect src, dest;
		
		area = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, lb->w - 17, lb->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
		assert(area);
		rect.x = 0;
		rect.y = 0;
		rect.w = area->w;
		rect.h = area->h;
		SDL_FillRect(area, &rect, SDL_MapRGB(area->format, 0, 0, 0));
		SDL_SetAlpha(area, SDL_SRCALPHA, 93);
		
		rect.x = lb->x;
		rect.y = lb->y;
		rect.w = area->w;
		rect.h = area->h;
		blit_surface(area, NULL, &rect, 0);
		
		SDL_FreeSurface(area);
		
		/* now that the trans area is drawn, back up that area there */
		lb->trans_area = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, lb->w - 17, lb->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
		src.x = lb->x;
		src.y = lb->y;
		src.w = lb->trans_area->w;
		src.h = lb->trans_area->h;
		dest.x = 0;
		dest.y = 0;
		dest.w = src.w;
		dest.h = src.h;
		
		SDL_BlitSurface(screen, &src, lb->trans_area, &dest);
	} else {
		rect.x = lb->x;
		rect.y = lb->y;
		rect.w = lb->trans_area->w;
		rect.h = lb->trans_area->h;
		
		blit_surface(lb->trans_area, NULL, &rect, 0);
	}
	
	if (lb->num_items == 0)
		return;
	
	/* now draw the items */
	/* set "item" to the first item for the top, as dedicated by the progress bar */
	item = (int)((float)lb->sb->progress * (float)(lb->num_items - 1));
	lb->top_scrolled = item;
	
	/* draw the top bar */
	rect.x = lb->x;
	rect.y = lb->y;
	rect.w = lb->w - 17;
	rect.h = 2;
	fill_rect(&rect, map_rgb(0, 93, 92));
	
	/* draw all the item borders and call the callback (if one exists) to draw what's inside each element */
	for (i = 0; (item < lb->num_items) && ((i * lb->item_h) < lb->h); i++) {
		if ((i + lb->top_scrolled) == lb->selected) {
			/* draw the selected bg */
			rect.x = lb->x;
			rect.y = lb->y + (i * lb->item_h) + 2;
			rect.w = lb->w - 17;
			rect.h = lb->item_h - 2;
			if ((rect.y + rect.h) > (lb->y + lb->h))
				rect.h = (lb->y + lb->h) - rect.y;
			
			fill_rect(&rect, map_rgb(0, 64, 65));
		}
		/* draw the bottom item bar */
		rect.x = lb->x;
		rect.y = lb->y + (i * lb->item_h) + lb->item_h;
		rect.w = lb->w - 17;
		rect.h = 2;
		if (rect.y < (lb->y + lb->h))
			fill_rect(&rect, map_rgb(0, 93, 92));
		
		if (lb->callback)
			(*lb->callback) (lb, rect.x, rect.y - lb->item_h, rect.w, lb->item_h, item);
		
		item++;
	}
}