Ejemplo n.º 1
0
void menu_draw_buffer(menu_t *menu){
	if(menu->buffer == NULL){
		menu_create_buffer(menu);
	}

	SDL_Rect fill_rect;

	fill_rect.x = 0;
	fill_rect.y = 0;
	fill_rect.w = menu->buffer->w;
	fill_rect.h = menu->buffer->h;
	SDL_FillRect(menu->buffer, &fill_rect, 0x666666FF);

	fill_rect.x += 2;
	fill_rect.y += 2;
	fill_rect.w -= 4;
	fill_rect.h -= 4;
	SDL_FillRect(menu->buffer, &fill_rect, 0x333333FF);

	int x = 10;
	int y = 4;
	int h = font_get_height(menu->game->font);
	
	for(uint32_t i=0; i<MENU_MAX_OPTIONS; i++){
		if(menu->options[i] != NULL){
			font_draw_string(menu->game->font, menu->options[i]->label, x, y, menu->buffer);
		}
		if(i == menu->selection){
			font_draw_string(menu->game->font, ">", x-6, y, menu->buffer);
		}
		y += h;
	}
}
Ejemplo n.º 2
0
void draw_window(window_t *window, vga_screen *screen) {
  // draw window drop shadow
  vga_fill_rect(screen, window->x + WINDOW_SHADOW_OFFSET, window->y + WINDOW_SHADOW_OFFSET, 
    window->width, window->height, COLOR_BLACK);

  // draw window
  vga_fill_rect(screen, window->x, window->y, 
    window->width, window->height, COLOR_LIGHT_GRAY);

  // draw window decoration bar
  vga_fill_rect(screen, window->x, window->y, 
    window->width, WINDOW_TITLE_BAR_HEIGHT, COLOR_LIGHT_BLUE);

  // draw title text
  font_draw_string(screen, window->font,
    window->x + 2, window->y + 2,
    window->title);

  // draw all widgets
  for (uint i = 0; i < MAX_WIDGETS_PER_WINDOW; i++) {
    if (window->widgets[i] != NULL) {
      draw_widget(window->widgets[i], screen, 
        window->x + WINDOW_CONTENT_PADDING_X, 
        window->y + WINDOW_TITLE_BAR_HEIGHT + WINDOW_CONTENT_PADDING_Y);
    }
  }

  // draw special widgets
  draw_widget(window->close_button, screen, 
    window->x + WINDOW_CONTENT_PADDING_X, 
    window->y + WINDOW_TITLE_BAR_HEIGHT + WINDOW_CONTENT_PADDING_Y);
}
Ejemplo n.º 3
0
void broke_activate()
{
	lcd_blank_screen(RED);
	buttons_init();
	

	font_draw_string(20, 300, WHITE, RED, "GAME OVER");
	font_draw_string(50, 300, WHITE, RED, "You lost all your $$$");
	init_button("Try Again",
			120, 40,
			240, 50,
			2,
			WHITE, WHITE,
			BLACK, BLUE,
			balance_reset);

}
Ejemplo n.º 4
0
/* Draws the given string in the given font, centered at the specified (x,y) coordinates. */
void font_draw_string_centered(Font *f, SDL_Surface *surface, int x, int y, const char *string)
{
	int x_ofs;
	int y_ofs;

	x_ofs = x - ( ((int) strlen(string) * f->char_width) / 2);
	y_ofs = y - (f->char_height / 2);

	font_draw_string(f, surface, x_ofs, y_ofs, string);
}
Ejemplo n.º 5
0
/* Draws the given string with a black rectangle behind it and then updates the
   game's rectangle list for redrawing. */
void font_draw_string_opaque(Font *f, SDL_Surface *surface, int x, int y, const char *string)
{
  SDL_Rect r;

  /* Draw a black rectangle behind where the string is going to be drawn */
  r.x = x;
  r.y = y;
  r.w = (Uint16)(f->char_width*strlen(string));
  r.h = (Uint16) f->char_height;

  SDL_FillRect(surface, &r, 0);

  /* Draw the string */
  font_draw_string(f, surface, r.x, r.y, string);

  /* Add the rectangle of the area we just drew onto to the list of rects to redraw. */
  game_update_rect_add(&r);
}
Ejemplo n.º 6
0
/*==============================================================================
 * - _PUT()
 *
 * - draw a dir character on lcd,
 *   when user release touch screen, start recognise process
 */
static void _PUT (char dir)
{
#if 0
    static GUI_COOR ch_coor = {_BLANK_W, _BLANK_H};

    /* draw dir on the lcd */
    if (ch_coor.x >= gra_scr_w() - ICON_SIZE - _BLANK_W) {
        GUI_SIZE size = {gra_scr_w() - ICON_SIZE - 2 * _BLANK_W, GUI_FONT_HEIGHT};
        ch_coor.x = _BLANK_W;
        gra_rect (&ch_coor, &size, GUI_BG_COLOR);
    }
    font_draw_string (&ch_coor, GUI_COLOR_WHITE, (const uint8 *)&dir, 1);
    ch_coor.x += GUI_FONT_WIDTH;
#endif

    /* store this dir */
    _G_dirs[_G_dir_num++] = dir;
}
Ejemplo n.º 7
0
/**
 * Draw the parameter line text into the text buffer
 */
void
param_screen_draw_param_line
(
	const char	*param_string,
	char		*value,
	uint8_t		line_offset
)
{
	uint8_t buf[FONT_CHAR_WIDTH];
	int8_t string_len = strlen(param_string);

	/* Draw the parameter string, padding spaces, and parameter value seperately since
	 * the implementation of printf here doesn't support passing width as a parameter.
	 */
	sprintf ((char*)buf, "%-s:", param_string);
	memset ((char*)buf+string_len+1, ' ', FONT_CHAR_WIDTH-string_len-4);
	snprintf ((char*)buf+FONT_CHAR_WIDTH-4, 5, "%4s", value);

	//sprintf ((char*)buf, "%-*s: %*s", param_len, module_param_strings[param], FONT_CHAR_WIDTH - param_len - 1, value);
	//sprintf ((char*)buf, "%-*s:", 13, module_param_strings[param]);

	font_draw_string (buf, TXT2_ADDRESS + GFX_WIDTH*(line_offset-1), FONT_CHAR_WIDTH);
}
Ejemplo n.º 8
0
void mh_print(int x,int y,unsigned char *str, uint32_t col,int backcol,int fill) {
	unsigned char ch = 0,bef = 0;

    font_draw_string(x, y, col, str);

    return;

	while(*str != 0) {
		ch = *str++;
		if (bef!=0) {
			Draw_Char_Zenkaku(x,y,bef,ch,col,backcol,fill);

			x+=10;
			bef=0;
		} else {
			if (((ch>=0x80) && (ch<0xa0)) || (ch>=0xe0)) {
				bef = ch;
			} else {
				Draw_Char_Hankaku(x,y,ch,col,backcol,fill);
				x+=5;
			}
		}
	}
}
Ejemplo n.º 9
0
int main()
{
	char vita_ip[16];
	unsigned short int vita_port = 0;
	vita2d_init();
	vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF));
	clr_color = 0x000000FF;
	vita2d_texture* texture_splash = vita2d_load_JPEG_buffer(splash, size_splash);
	vita2d_start_drawing();
	vita2d_draw_texture(texture_splash, 0, 0);
	vita2d_end_drawing();
	vita2d_swap_buffers();
	sceKernelDelayThread(4000000);
	vita2d_start_drawing();
	vita2d_clear_screen();
	vita2d_end_drawing();
	vita2d_swap_buffers();
	vita2d_free_texture(texture_splash);
	SceCtrlData pad;
	SceCtrlData oldpad;
	while (1) {
		
		// Load main script
		SceUID id = sceIoDopen("cache0:/lpp");
		SceIoDirent entry;
		memset(&entry, 0, sizeof(SceIoDirent));
		while (sceIoDread(id, &entry) > 0){
			script_files++;
			memset(&entry, 0, sizeof(SceIoDirent));
		}
		sceIoDclose(id);
		if (script_files>1) errMsg = runScript((const char*)main_menu, true);
		else{
			SceUID main_file = sceIoOpen("cache0:/lpp/index.lua", PSP2_O_RDONLY, 0777);
			if (main_file < 0) errMsg = "index.lua not found.";
			else{
				SceOff size = sceIoLseek(main_file, 0, SEEK_END);
				if (size < 1) errMsg = "Invalid main script.";
				else{
					sceIoLseek(main_file, 0, SEEK_SET);
					script = (unsigned char*)malloc(size + 1);
					sceIoRead(main_file, script, size);
					script[size] = 0;
					sceIoClose(main_file);
					errMsg = runScript((const char*)script, true);
					free(script);
				}
			}
		}
		
		if (errMsg != NULL){
			if (strstr(errMsg, "lpp_shutdown")) break;
			else{
				int restore = 0;
				bool s = true;
				while (restore == 0){
					vita2d_start_drawing();
					vita2d_clear_screen();
					font_draw_string(10, 10, RGBA8(255, 255, 255, 255), "An error occurred:");
					font_draw_string(10, 30, RGBA8(255, 255, 255, 255), errMsg);
					font_draw_string(10, 70, RGBA8(255, 255, 255, 255), "Press X to restart.");
					font_draw_string(10, 90, RGBA8(255, 255, 255, 255), "Press O to enable/disable FTP.");
					if (vita_port != 0){
						font_draw_stringf(10, 150, RGBA8(255, 255, 255, 255), "PSVITA listening on IP %s , Port %u", vita_ip, vita_port);
					}
					vita2d_end_drawing();
					vita2d_swap_buffers();
					if (s){
						sceKernelDelayThread(800000);
						s = false;
					}
					sceCtrlPeekBufferPositive(0, &pad, 1);
					if (pad.buttons & PSP2_CTRL_CROSS) {
						errMsg = NULL;
						restore = 1;
						if (vita_port != 0){
							ftp_fini();
							vita_port = 0;
						}
						sceKernelDelayThread(800000);
					}else if ((pad.buttons & PSP2_CTRL_CIRCLE) && (!(oldpad.buttons & PSP2_CTRL_CIRCLE))){
						if (vita_port == 0) ftp_init(vita_ip, &vita_port);
						else{
							ftp_fini();
							vita_port = 0;
						}
					}
					oldpad = pad;
				}
			}
		}
	}

	vita2d_fini();
	sceKernelExitProcess(0);
	return 0;
}
Ejemplo n.º 10
0
int main()
{
	init_video();

	/* Enable analog stick */
	sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);

	/* Enable front touchscreen */
	sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, 1);

	/* FPS counting */
	SceUInt64 cur_micros = 0, delta_micros = 0, last_micros = 0;
	uint32_t frames = 0;
	float fps = 0.0f;

	/* Square variables */
	int w = 60;
	int h = 60;
	int x = SCREEN_W/2 - w/2;
	int y = SCREEN_H/2 - h/2;
	int speed = 2;
	uint32_t color = RGBA8(255, 0, 0, 255);

	/* Input variables */
	SceCtrlData pad;
	SceTouchData touch;
	signed char lx, ly, rx, ry;

	while (1) {
		clear_screen();

		/* Read controls and touchscreen */
		sceCtrlPeekBufferPositive(0, &pad, 1);
		sceTouchPeek(0, &touch, 1);

		if (pad.buttons & SCE_CTRL_START) {
			break;
		}

		font_draw_string(10, 10, RGBA8(0, 0, 255, 255), "PSVita sample by xerpi!");
		font_draw_stringf(SCREEN_W - 160, 10, RGBA8(0, 255, 0, 255), "FPS: %.2f", fps);
		font_draw_stringf(10, 30, RGBA8(255, 0, 0, 255),
			"(%3d, %3d) size: (%d, %d) speed: %d\n", x, y, w, h, speed);

		/* Move the rectangle */
		if (pad.buttons & SCE_CTRL_UP) {
			y -= speed;
		} else 	if (pad.buttons & SCE_CTRL_DOWN) {
			y += speed;
		}
		if (pad.buttons & SCE_CTRL_LEFT) {
			x -= speed;
		} else 	if (pad.buttons & SCE_CTRL_RIGHT) {
			x += speed;
		}

		if (pad.buttons & SCE_CTRL_LTRIGGER) {
			speed--;
			if (speed < 0) speed = 0;
		} else 	if (pad.buttons & SCE_CTRL_RTRIGGER) {
			speed++;
			if (speed > 100) speed = 100;
		}

		if (pad.buttons & SCE_CTRL_CROSS) {
			color = RGBA8(rand()%255, rand()%255, rand()%255, 255);
		}

		/* Update joystick values */
		lx = (signed char)pad.lx - 128;
		ly = (signed char)pad.ly - 128;
		rx = (signed char)pad.rx - 128;
		ry = (signed char)pad.ry - 128;

		/* Move using the left yoystick */
		if (abs(lx) > 50) {
			x += speed * lx/50.0f;
		}
		if (abs(ly) > 50) {
			y += speed * ly/50.0f;
		}

		/* Resize using the right yoystick */
		if (abs(rx) > 50) {
			w += rx/15.0f;
			if (w < 5) {
				w = 5;
			} else if (w > SCREEN_W) {
				w = SCREEN_W;
			}
		}
		if (abs(ry) > 50) {
			h += ry/15.0f;
			if (h < 5) {
				h = 5;
			} if (h > SCREEN_H) {
				h = SCREEN_H;
			}
		}

		/* Move using the touchscreen! */
		if (touch.reportNum > 0) {
			/* Front touchscreen: 1920x1088 */
			x = lerp(touch.report[0].x, 1920, SCREEN_W) - w/2;
			y = lerp(touch.report[0].y, 1088, SCREEN_H) - h/2;
		}

		/* Check left and right collisions */
		if (x < 0) {
			x = 0;
		} else if ((x + w) > SCREEN_W) {
			x = SCREEN_W - w;
		}

		/* Check top and bottom collisions */
		if (y < 0) {
			y = 0;
		} else if ((y + h) > SCREEN_H) {
			y = SCREEN_H - h;
		}

		/* Draw the rectangle */
		draw_rectangle(x, y, w, h, color);

		/* Draw a circle */
		draw_circle(SCREEN_W / 2, SCREEN_H / 2, 50, RGBA8(0,0,255,255));

		/* Calculate FPS */
		cur_micros = sceKernelGetProcessTimeWide();

		if (cur_micros >= (last_micros + 1000000)) {
			delta_micros = cur_micros - last_micros;
			last_micros = cur_micros;
			fps = (frames/(double)delta_micros)*1000000.0f;
			frames = 0;
		}

		swap_buffers();
		sceDisplayWaitVblankStart();
		frames++;
	}

	end_video();
	sceKernelExitProcess(0);
	return 0;
}
Ejemplo n.º 11
0
/*==============================================================================
 * - _PUT2()
 *
 * - draw recongised char on lcd
 */
static void _PUT2 (char ch, GUI_COLOR color)
{
    /* igno space */
    if (ch == ' ') {
        return ;
    }

    /* back */
    if ((ch == '<')) {
        if (_G_expr_len > 0) {
            _G_expr_len--;
            _G_expr_coor.x -= GUI_FONT_WIDTH;
            font_draw_string (&_G_expr_coor, color, (const uint8 *)&ch, 1);
        }
        return ;
    }

    /* new line */
    if (ch =='\n') {
        _G_expr_coor.x = gra_scr_w();
        return ;
    }

    /* print char */
    if (_G_expr_coor.x >= gra_scr_w() - ICON_SIZE - _BLANK_W) {
        _G_expr_coor.x = _BLANK_W;
        _G_expr_coor.y += GUI_FONT_HEIGHT;
        if (_G_expr_coor.y >= _EXPR_END_Y) {
            _G_expr_coor.y = _EXPR_START_Y;

            /* clear the expression panel */
            GUI_SIZE size = {gra_scr_w() - 2*_BLANK_W - ICON_SIZE, /* width */
                             _EXPR_LINE_NUM * GUI_FONT_HEIGHT};  /* height */
            gra_rect (&_G_expr_coor, &size, GUI_BG_COLOR);
        }

    }
    font_draw_string (&_G_expr_coor, color, (const uint8 *)&ch, 1);
    _G_expr_coor.x += GUI_FONT_WIDTH;

    /* store char or calculate the expression */
    if (ch != '=') {
        _G_expr[_G_expr_len++] = ch;
    } else {
        int  i = 0;
        CAL_TYPE  value;
        char val_str[20];

        _G_expr[_G_expr_len] = '\0';

        /* calculte and show */
        value = calculate (_G_expr);

        /* draw result value */
#ifdef CAL_TYPE_INT
        sprintf(val_str, "%d\n", value);
#else
        sprintf(val_str, "%f\n", value);
#endif
        while (val_str[i] != '\0') {
            _PUT2 (val_str[i], GUI_COLOR_MAGENTA);
            i++;
        }

        _G_expr_len = 0;
    }
}