mirror of https://github.com/ClassiCube/ClassiCube
NDS: On-screen dialog now mostly works
This commit is contained in:
parent
db4ed0301a
commit
45ec826517
|
|
@ -72,6 +72,7 @@ enum InputButtons {
|
|||
|
||||
extern const char* const Input_StorageNames[INPUT_COUNT];
|
||||
extern const char* Input_DisplayNames[INPUT_COUNT];
|
||||
typedef cc_bool (*Input_DownHook)(int btn, struct InputDevice* device);
|
||||
|
||||
extern struct _InputState {
|
||||
/* Pressed state of each input button. Use Input_Set to change */
|
||||
|
|
@ -81,7 +82,7 @@ extern struct _InputState {
|
|||
/* Sources available for input (Mouse/Keyboard, Gamepad) */
|
||||
cc_uint8 Sources;
|
||||
/* Function that can override all normal input handling (e.g. for virtual keyboard) */
|
||||
cc_bool (*DownHook)(int btn, struct InputDevice* device);
|
||||
Input_DownHook DownHook;
|
||||
} Input;
|
||||
|
||||
/* Sets Input_Pressed[key] to true and raises InputEvents.Down */
|
||||
|
|
|
|||
|
|
@ -4,11 +4,54 @@
|
|||
#include "Utils.h"
|
||||
#include "LBackend.h"
|
||||
#include "Window.h"
|
||||
#include "SystemFonts.h"
|
||||
|
||||
static void VirtualDialog_Show(const char* title, const char* message) {
|
||||
static cc_bool dlg_close;
|
||||
/* Prevent normal input handling from seeing next button press */
|
||||
static cc_bool VirtualDialog_InputHook(int key, struct InputDevice* device) { return true; }
|
||||
|
||||
static void VirtualDialog_OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* device) {
|
||||
Platform_LogConst("AAAA");
|
||||
dlg_close = true;
|
||||
}
|
||||
|
||||
struct LogPosition { struct Bitmap* bmp; int x, y; };
|
||||
#define BEG_X 10
|
||||
|
||||
static void PlotOnscreen(int x, int y, void* ctx) {
|
||||
struct LogPosition* pos = ctx;
|
||||
x += pos->x;
|
||||
y += pos->y;
|
||||
if (x >= pos->bmp->width || y >= pos->bmp->height) return;
|
||||
|
||||
BitmapCol* row = Bitmap_GetRow(pos->bmp, y);
|
||||
row[x] = BITMAPCOLOR_WHITE;
|
||||
}
|
||||
|
||||
static int DrawText(const char* msg, struct Bitmap* bmp, int y) {
|
||||
struct LogPosition pos;
|
||||
pos.bmp = bmp;
|
||||
pos.x = BEG_X;
|
||||
pos.y = y;
|
||||
|
||||
while (*msg)
|
||||
{
|
||||
if (pos.x + 20 >= bmp->width) {
|
||||
pos.x = BEG_X;
|
||||
pos.y += 20;
|
||||
}
|
||||
|
||||
pos.x += FallbackFont_Plot((cc_uint8)*msg, PlotOnscreen, 1, &pos);
|
||||
msg++;
|
||||
}
|
||||
return pos.y;
|
||||
}
|
||||
|
||||
#define DLG_TICK_INTERVAL 50
|
||||
static void VirtualDialog_Show(const char* title, const char* msg) {
|
||||
struct Bitmap bmp;
|
||||
Platform_LogConst(title);
|
||||
Platform_LogConst(message);
|
||||
Platform_LogConst(msg);
|
||||
|
||||
if (!LBackend_FB.bmp.scan0) {
|
||||
Window_AllocFramebuffer(&bmp, Window_Main.Width, Window_Main.Height);
|
||||
|
|
@ -18,18 +61,42 @@ static void VirtualDialog_Show(const char* title, const char* message) {
|
|||
|
||||
struct Context2D ctx;
|
||||
Context2D_Wrap(&ctx, &bmp);
|
||||
Context2D_Clear(&ctx, BitmapCol_Make(200, 200, 200, 255),
|
||||
Context2D_Clear(&ctx, BitmapCol_Make(50, 50, 50, 255),
|
||||
0, 0, bmp.width, bmp.height);
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
const char* ipt_msg = "Press any button to continue";
|
||||
dlg_close = false;
|
||||
int y = 30;
|
||||
|
||||
y = DrawText(title, &bmp, y);
|
||||
y = DrawText(msg, &bmp, y + 20);
|
||||
DrawText(ipt_msg, &bmp, bmp.height - 30);
|
||||
|
||||
Input_DownHook old_hook = Input.DownHook;
|
||||
Input.DownHook = VirtualDialog_InputHook;
|
||||
Event_Register_(&InputEvents.Down2, NULL, VirtualDialog_OnInputDown);
|
||||
|
||||
Rect2D rect = { 0, 0, bmp.width, bmp.height };
|
||||
|
||||
while (Window_Main.Exists && !dlg_close)
|
||||
{
|
||||
Window_ProcessEvents(1.0f / DLG_TICK_INTERVAL);
|
||||
Gamepads_Process( 1.0f / DLG_TICK_INTERVAL);
|
||||
|
||||
Window_DrawFramebuffer(rect, &bmp);
|
||||
Thread_Sleep(50);
|
||||
Thread_Sleep(DLG_TICK_INTERVAL);
|
||||
}
|
||||
|
||||
Context2D_Clear(&ctx, BitmapCol_Make(40, 40, 40, 255),
|
||||
0, 0, bmp.width, bmp.height);
|
||||
Window_DrawFramebuffer(rect, &bmp);
|
||||
|
||||
if (!LBackend_FB.bmp.scan0) {
|
||||
Window_FreeFramebuffer(&bmp);
|
||||
} else {
|
||||
LBackend_Redraw();
|
||||
}
|
||||
|
||||
Input.DownHook = old_hook;
|
||||
Event_Unregister_(&InputEvents.Down2, NULL, VirtualDialog_OnInputDown);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,12 +81,6 @@ void Gfx_Create(void) {
|
|||
Gfx_ClearColor(PackedCol_Make(0, 120, 80, 255));
|
||||
Gfx_SetViewport(0, 0, 256, 192);
|
||||
|
||||
vramSetBankA(VRAM_A_TEXTURE);
|
||||
vramSetBankB(VRAM_B_TEXTURE);
|
||||
vramSetBankC(VRAM_C_TEXTURE);
|
||||
vramSetBankD(VRAM_D_TEXTURE);
|
||||
vramSetBankE(VRAM_E_TEX_PALETTE);
|
||||
|
||||
Gfx_SetFaceCulling(false);
|
||||
Gfx.NonPowTwoTexturesSupport = GFX_NONPOW2_UPLOAD;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "../Errors.h"
|
||||
#include "../ExtMath.h"
|
||||
#include "../Camera.h"
|
||||
#include "../VirtualDialog.h"
|
||||
|
||||
#include <nds.h>
|
||||
#include <fat.h>
|
||||
|
|
@ -154,6 +155,12 @@ static void SetupVideo(cc_bool is3D) {
|
|||
vramSetBankI(VRAM_I_SUB_BG_0x06208000);
|
||||
|
||||
videoSetMode(MODE_0_3D);
|
||||
|
||||
vramSetBankA(VRAM_A_TEXTURE);
|
||||
vramSetBankB(VRAM_B_TEXTURE);
|
||||
vramSetBankC(VRAM_C_TEXTURE);
|
||||
vramSetBankD(VRAM_D_TEXTURE);
|
||||
vramSetBankE(VRAM_E_TEX_PALETTE);
|
||||
}
|
||||
|
||||
Console_Init(is3D);
|
||||
|
|
@ -181,7 +188,6 @@ void Window_Init(void) {
|
|||
|
||||
Window_Main.SoftKeyboard = SOFT_KEYBOARD_RESIZE;
|
||||
Input_SetTouchMode(true);
|
||||
Window_ShowDialog("AC", "DE");
|
||||
}
|
||||
|
||||
void Window_Free(void) { }
|
||||
|
|
@ -308,6 +314,7 @@ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) {
|
|||
|
||||
bg_id = bgInitSub(2, BgType_Bmp16, BgSize_B16_256x256, 2, 0);
|
||||
bg_ptr = bgGetGfxPtr(bg_id);
|
||||
SetupVideo(false);
|
||||
}
|
||||
|
||||
void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) {
|
||||
|
|
@ -330,6 +337,7 @@ void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) {
|
|||
|
||||
void Window_FreeFramebuffer(struct Bitmap* bmp) {
|
||||
Mem_Free(bmp->scan0);
|
||||
SetupVideo(true);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -385,9 +393,7 @@ void OnscreenKeyboard_Close(void) {
|
|||
*-------------------------------------------------------Misc/Other--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void Window_ShowDialog(const char* title, const char* msg) {
|
||||
Platform_LogConst(title);
|
||||
Platform_LogConst(message);
|
||||
// TODO
|
||||
VirtualDialog_Show(title, msg);
|
||||
}
|
||||
|
||||
cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue