mirror of
https://github.com/Alvin-Zilverstand/bob16.git
synced 2026-11-30 22:17:49 +01:00
;l
This commit is contained in:
1 parent
6dc841f956
commit
3d06f94e48
46 files changed
+5830
-543
No files matched your search
+64
-17
@@ -1,28 +1,75 @@
|
||||
#include "../bob64/app.h"
|
||||
#include "../bob64/gfx.h"
|
||||
|
||||
#define DISPLAY_LIMIT_WIDTH 1024u
|
||||
#define DISPLAY_LIMIT_HEIGHT 768u
|
||||
#define DEMO_WIDTH 640u
|
||||
#define DEMO_HEIGHT 400u
|
||||
|
||||
static u32 pixels[DISPLAY_LIMIT_WIDTH*DISPLAY_LIMIT_HEIGHT];
|
||||
static u32 pixels[DEMO_WIDTH*DEMO_HEIGHT];
|
||||
|
||||
static void draw_demo(BOB64_GFX *graphics) {
|
||||
u32 width=graphics->Width,height=graphics->Height;
|
||||
s32 margin=(s32)(width/40u);
|
||||
s32 header_height=(s32)(height/7u);
|
||||
s32 panel_y=(s32)(height/3u);
|
||||
u32 panel_width=(width-(u32)(margin*5))/4u;
|
||||
u32 panel_height=height/4u;
|
||||
bob64_gfx_fill_rect(graphics,0,0,width,height,0x101a2au);
|
||||
bob64_gfx_fill_rect(graphics,margin,margin,width-(u32)(margin*2),
|
||||
height-(u32)(margin*2),0x1b2b40u);
|
||||
bob64_gfx_fill_rect(graphics,margin,margin,width-(u32)(margin*2),
|
||||
(u32)header_height,0x345d89u);
|
||||
bob64_gfx_text(graphics,margin*2,margin*2,"BOB32 GRAPHICS DEMO",
|
||||
0x00ffffffu,3);
|
||||
bob64_gfx_line(graphics,margin,header_height+margin*2,
|
||||
(s32)width-margin,header_height+margin*2,0x00f0c879u);
|
||||
bob64_gfx_text(graphics,margin*2,panel_y-margin*2,
|
||||
"LINES RECTANGLES AND COLORS",0x00d7e5f5u,2);
|
||||
const u32 colors[]={0x00e85d75u,0x00edaa42u,0x004fc3a1u,0x005e8ee8u};
|
||||
for(u32 i=0;i<4;i++) {
|
||||
s32 x=margin+(s32)(i*(panel_width+(u32)margin));
|
||||
s32 y=panel_y;
|
||||
bob64_gfx_fill_rect(graphics,x,y,panel_width,panel_height,colors[i]);
|
||||
bob64_gfx_fill_rect(graphics,x+8,y+8,panel_width-16,
|
||||
panel_height-16,0x00223248u);
|
||||
bob64_gfx_line(graphics,x+14,y+panel_height-18,
|
||||
x+(s32)panel_width-14,y+18,colors[i]);
|
||||
bob64_gfx_line(graphics,x+14,y+18,
|
||||
x+(s32)panel_width-14,y+panel_height-18,colors[i]);
|
||||
}
|
||||
bob64_gfx_fill_rect(graphics,margin,panel_y+(s32)panel_height+margin,
|
||||
width-(u32)(margin*2),3,0x006d849fu);
|
||||
bob64_gfx_text(graphics,margin*2,
|
||||
(s32)height-margin*6,"PRESS X OR ESCAPE TO RETURN",0x00ffffffu,2);
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
u32 width,height;
|
||||
BOB64_GFX graphics;
|
||||
BOB64_EVENT event;
|
||||
u32 screen_width,screen_height;
|
||||
u64 window=0;
|
||||
s64 result=-1;
|
||||
if(!startup||startup->AbiVersion!=BOB64_APP_ABI_VERSION||
|
||||
bob64_app_query_abi()!=BOB64_SYSCALL_ABI_VERSION||
|
||||
bob64_app_get_display(&width,&height))return -1;
|
||||
if(!width||!height||width>DISPLAY_LIMIT_WIDTH||height>DISPLAY_LIMIT_HEIGHT)
|
||||
return -2;
|
||||
for(u32 y=0;y<height;y++)for(u32 x=0;x<width;x++) {
|
||||
u32 red=(x*180u)/width;
|
||||
u32 green=(y*120u)/height;
|
||||
pixels[(usize)y*width+x]=(red<<16)|(green<<8)|32u;
|
||||
}
|
||||
if(bob64_app_present(pixels,width,height)!=(s64)((u64)width*height))return -3;
|
||||
if(bob64_app_write("bob!",4)!=4)return -4;
|
||||
bob64_app_get_display(&screen_width,&screen_height)||
|
||||
screen_width<DEMO_WIDTH||screen_height<DEMO_HEIGHT)return -1;
|
||||
graphics.Pixels=pixels;graphics.Width=DEMO_WIDTH;graphics.Height=DEMO_HEIGHT;
|
||||
graphics.Capacity=DEMO_WIDTH*DEMO_HEIGHT;
|
||||
draw_demo(&graphics);
|
||||
window=bob64_app_window_create((s32)((screen_width-DEMO_WIDTH)/2u),
|
||||
(s32)((screen_height-DEMO_HEIGHT)/2u),DEMO_WIDTH,DEMO_HEIGHT);
|
||||
if(!window||(s64)window<0)return -2;
|
||||
if(bob64_app_window_focus(window)) {result=-3;goto cleanup;}
|
||||
result=bob64_app_window_present(window,pixels,DEMO_WIDTH,DEMO_HEIGHT);
|
||||
if(result!=(s64)(DEMO_WIDTH*DEMO_HEIGHT))goto cleanup;
|
||||
if(bob64_app_write("bob!",4)!=4) {result=-4;goto cleanup;}
|
||||
for(;;) {
|
||||
if(bob64_app_wait_event(&event))return -5;
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&event.Character==0x1b)break;
|
||||
if(bob64_app_wait_event(&event)) {result=-5;break;}
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
(event.Character=='x'||event.Character=='X'||event.Character==0x1b)) {
|
||||
result=0;break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
cleanup:
|
||||
if(bob64_app_window_destroy(window)&&result==0)result=-6;
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user