diff --git a/include/arm11/acf.h b/include/arm11/acf.h index f6e921a..95e431c 100644 --- a/include/arm11/acf.h +++ b/include/arm11/acf.h @@ -30,7 +30,7 @@ typedef const char * acf_text_t; typedef uint16_t acf_counter_t; typedef void (*acf_visitor_t)( - INPUT(acf_callerdata_t) some_data_provide_by_caller, + INPUT(acf_callerdata_t) some_data_provided_by_caller, INPUT(acf_position_t) position_x_of_canvas, INPUT(acf_position_t) position_y_of_canvas, INPUT(acf_color_t) color_in_position_xy_of_canvas diff --git a/include/arm11/acf_cfg.h b/include/arm11/acf_cfg.h deleted file mode 100644 index 38b48da..0000000 --- a/include/arm11/acf_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef _ANOD_COMPILED_FONT_CFG_ -#define _ANOD_COMPILED_FONT_CFG_ - -#include "acf_dev.h" -#define ACF_CANVAS ACFDEV_OPENAGB - -#endif//_ANOD_COMPILED_FONT_CFG_ \ No newline at end of file diff --git a/include/arm11/acf_dev.h b/include/arm11/acf_dev.h deleted file mode 100644 index 88414d3..0000000 --- a/include/arm11/acf_dev.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef _ANOD_COMPILED_FONT_DEVICE_H_ -#define _ANOD_COMPILED_FONT_DEVICE_H_ - -#define ACFDEV_U8GBITMAP 0x00000001 -#define ACFDEV_OPENAGB 0x00000002 - -#endif//_ANOD_COMPILED_FONT_DEVICE_H_ \ No newline at end of file diff --git a/include/arm11/atp.h b/include/arm11/atp.h new file mode 100644 index 0000000..1a483c0 --- /dev/null +++ b/include/arm11/atp.h @@ -0,0 +1,71 @@ +#ifndef _ANOD_TEXT_PAGE_ +#define _ANOD_TEXT_PAGE_ + +#include + +#define INPUT(type) type +#define OUTPUT(type) type* + +typedef uint32_t atp_counter_t; +typedef int32_t atp_itemval_t; +typedef const char* atp_text_t; +typedef uint8_t atp_boolean_t; +typedef uint8_t atp_pageopt_t; +typedef uint8_t atp_color_t; +typedef uint8_t atp_error_t; +typedef void * atp_callerdata_t; + +// error type +#define ATP_SUCCESS 0 +#define ATP_POWER_OFF 1 +#define ATP_INDEX_OUTOFRANGE 2 + +// color type SAME AS console +#define ATP_COLOR_BLACK 0 +#define ATP_COLOR_RED 1 +#define ATP_COLOR_GREEN 2 +#define ATP_COLOR_YELLOW 3 +#define ATP_COLOR_BLUE 4 +#define ATP_COLOR_MAGENTA 5 +#define ATP_COLOR_CYAN 6 +#define ATP_COLOR_WHITE 7 + +// page option +#define ATP_PAGE_NOOPTION 0 +#define ATP_PAGE_UPDATE 1 // UPDATE THE CURSOR ROW +#define ATP_PAGE_REFRESH 2 // UPDATE THE WHOLE PAGE + +typedef atp_error_t (*atp_lineinfo_t)( + INPUT(atp_callerdata_t) some_data_provided_by_caller, + INPUT(atp_counter_t) line_index_of_this_page, + OUTPUT(atp_text_t) line_text_of_this_line, + OUTPUT(atp_itemval_t) option_value_of_this_item, + OUTPUT(atp_color_t) value_of_atp_color +); + +typedef atp_pageopt_t (*atp_keyhandler_t)( + INPUT(atp_callerdata_t) some_data_provided_by_caller, + INPUT(atp_boolean_t) is_x_key_down, + INPUT(atp_boolean_t) is_y_key_down, + INPUT(atp_boolean_t) is_start_key_down, + INPUT(atp_boolean_t) is_select_key_down +); + +extern atp_error_t atp_show( + INPUT(atp_counter_t) line_count_of_this_page, + INPUT(atp_lineinfo_t) line_information_provider, + INPUT(atp_callerdata_t) some_data_from_caller +); + +extern atp_itemval_t atp_select( + INPUT(atp_text_t) tips_for_this_select_page, + INPUT(atp_counter_t) item_count_exclude_title_of_this_select_page, + INPUT(atp_lineinfo_t) item_information_provider, + INPUT(atp_keyhandler_t) extra_key_handler, + INPUT(atp_callerdata_t) some_data_from_caller +); + +#undef INPUT +#undef OUTPUT + +#endif//_ANOD_TEXT_PAGE_ \ No newline at end of file diff --git a/source/arm11/acf.c b/source/arm11/acf.c index 4994099..9b56da2 100644 --- a/source/arm11/acf.c +++ b/source/arm11/acf.c @@ -7,7 +7,6 @@ #include "arm11/acf.h" #include "arm11/console.h" -#include "arm11/fmt.h" #include "fs.h" typedef struct diff --git a/source/arm11/atp.c b/source/arm11/atp.c new file mode 100644 index 0000000..3110231 --- /dev/null +++ b/source/arm11/atp.c @@ -0,0 +1,114 @@ +#include "arm11/atp.h" +#include "arm11/acf.h" +#include "arm11/drivers/hid.h" +#include "drivers/gfx.h" + +//--------------------------------------------------- +// basic print helper +/* +static void set_screen_color( acf_callerdata_t data, acf_position_t tx, acf_position_t ty, acf_color_t b ) +{ + if( b == 0 ) return; + + int *draw_data = data; + u16 *frame = consoleGet()->frameBuffer; + + int x = tx + draw_data[0]; + int y = ty + draw_data[1]; + if( 0 <= x && x < draw_data[2] && 0 <= y && y < draw_data[3] ){ + frame[ x*draw_data[3] + (draw_data[3]-1-y) ] = (u16)draw_data[4]; + } +} + +static const char *acf_draw(int x, int y, int width, int height, int maxwidth, u16 color, const char* text) +{ + uint8_t draw_data[sizeof(int)*5]; + + int *draw_data_int = (int*)&draw_data; + draw_data_int[0] = x; + draw_data_int[1] = y; + draw_data_int[2] = width; + draw_data_int[3] = height; + draw_data_int[4] = color; + + const char *retval = text; + acf_canvas_t canvas = acf_get_canvas(maxwidth, text, NULL, NULL, &retval); + if( !canvas ) return retval; + acf_recycle( acf_use_canvas(canvas, set_screen_color, draw_data) ); + return retval; +} +*/ +extern const char *acf_draw(int x, int y, int width, int height, int maxwidth, u16 color, const char* text) +//--------------------------------------------------- + +#define CONTAINER_LEFTTOP_X 20u +#define CONTAINER_LEFTTOP_Y 15u +#define CONTAINER_RECT_WIDTH 282u +#define CONTAINER_MAX_LINES 13u +#define WINDOW_WIDTH 320u +#define WINDOW_HEIGHT 240u + +#define FONT_HEIGHT 15u + +#define screen_clean + +// wait key pressed, if power key is pressed, return 0 +static uint32_t waitKey() +{ + uint32_t ek, down; + do{ + GFX_waitForVBlank0(); + hidScanInput(); + ek = hidGetExtraKeys(0); + if( ek & (KEY_POWER_HELD | KEY_POWER) ) + return 0; + + down = hidKeysDown(); + }while ( down == 0 ); + + return down; +} + +static void paint_one_line( atp_lineinfo_t provider, acf_callerdata_t data, int idx, int row ) +{ + atp_text_t text; + atp_color_t color = ATP_COLOR_WHITE; + atp_error_t err = provider( data, idx, &text, NULL, &color ); + if( !err ){ + acf_draw( + CONTAINER_LEFTTOP_X, + CONTAINER_LEFTTOP_Y + row*FONT_HEIGHT, + WINDOW_WIDTH, + WINDOW_HEIGHT, + CONTAINER_RECT_WIDTH, + consoleGetRGB565Color(color > ATP_COLOR_WHITE ? ATP_COLOR_WHITE : color), + text + ); + } +} + +static void container_paint( atp_lineinfo_t provider, atp_callerdata_t data, atp_counter_t nlines, int top ) +{ + int end = top + CONTAINER_MAX_LINES; + if( end > nlines ) end = nlines; + for( int n = top; n < end; ++n ){ + paint_one_line( provider, data, n, n-top ); + } +} + +atp_error_t atp_show( atp_counter_t cnt, atp_lineinfo_t provider, atp_callerdata_t data ) +{ + int idx_top = 0; + + while( 1 ){ + screen_clean(); + container_paint( provider, data, cnt, idx_top ); + + u32 kDown = waitKey(); + + if( kDown == 0 ) return ATP_POWER_OFF; + if( kDown == KEY_B || kDown == KEY_A ) + return ATP_SUCCESS; + } +} + diff --git a/source/arm11/filebrowser.c b/source/arm11/filebrowser.c index b51d5e0..fbfdef1 100644 --- a/source/arm11/filebrowser.c +++ b/source/arm11/filebrowser.c @@ -27,6 +27,7 @@ #include "arm11/fmt.h" #include "drivers/gfx.h" #include "arm11/acf.h" +#include "arm11/atp.h" #define screenClean() memset(consoleGet()->frameBuffer, 0, CWIDTH*CHEIGHT*sizeof(uint16_t)) @@ -90,6 +91,22 @@ const char *acf_draw(int x, int y, int width, int height, int maxwidth, u16 colo return retval; } +static const char *page[] = { + "是这里吗?", + "我不知道呢", + "能再看一遍吗?", + "原来是这样啊" +}; + +static atp_error_t test_show( atp_callerdata_t data, atp_counter_t idx, atp_text_t *ptext, atp_itemval_t *pval, atp_color_t *c ) +{ + if( idx < sizeof(page) ){ + *ptext = page[idx]; + return ATP_SUCCESS; + } + else return ATP_INDEX_OUTOFRANGE; +} + int dlistCompare(const void *a, const void *b) { const char *entA = *(char**)a; @@ -285,6 +302,10 @@ Result browseFiles(const char *const basePath, char selected[512]) cursorPos = oldCursorPos = windowPos = 0; showDirList(dList, 0); } + + if( kDown & KEY_X ){ + atp_show( 4, test_show, NULL ); + } } end: diff --git a/source/arm11/open_agb_firm.c b/source/arm11/open_agb_firm.c index 1b3d226..b9a25b2 100644 --- a/source/arm11/open_agb_firm.c +++ b/source/arm11/open_agb_firm.c @@ -533,7 +533,7 @@ static void gbaGfxHandler(void *args) GFX_waitForPPF(); GFX_swapFramebufs(); - if(hidKeysDown() == (KEY_Y | KEY_SELECT)) dumpFrameTex(); + //if(hidKeysDown() == (KEY_Y | KEY_SELECT)) dumpFrameTex(); } taskExit();