mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 09:35:23 -04:00
WIP moving more drawing/dirty tracking into LBackend
This commit is contained in:
parent
9dcc41f4f1
commit
f0583c32ca
@ -201,6 +201,11 @@ IOS_FLAGS="-s -O1 -fvisibility=hidden -rdynamic -funwind-tables"
|
|||||||
build_ios() {
|
build_ios() {
|
||||||
echo "Building ios.."
|
echo "Building ios.."
|
||||||
$IOS_CC *.c interop_ios.m $IOS_FLAGS $IOS_LIBS -o cc-ios
|
$IOS_CC *.c interop_ios.m $IOS_FLAGS $IOS_LIBS -o cc-ios
|
||||||
|
mkdir -p Payload/ClassiCube.app
|
||||||
|
cp cc-ios Payload/ClassiCube.app/ClassiCube
|
||||||
|
# https://askubuntu.com/questions/681949/plutil-equivalent-in-ubuntu
|
||||||
|
plistutil -i $ROOT_DIR/ios/Info.plist -o Payload/ClassiCube.app/Info.plist -f bin
|
||||||
|
zip -r cc.ipa Payload
|
||||||
}
|
}
|
||||||
|
|
||||||
# ----------------------------- driver
|
# ----------------------------- driver
|
||||||
|
@ -23,7 +23,15 @@
|
|||||||
#include "LScreens.h"
|
#include "LScreens.h"
|
||||||
#include "Input.h"
|
#include "Input.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
struct FontDesc titleFont, textFont, hintFont;
|
struct FontDesc titleFont, textFont, hintFont;
|
||||||
|
static struct LScreen* activeScreen;
|
||||||
|
static cc_uint8 pendingRedraw;
|
||||||
|
extern Rect2D dirty_rect;
|
||||||
|
|
||||||
|
#define REDRAW_ALL 0x02
|
||||||
|
#define REDRAW_SOME 0x01
|
||||||
|
|
||||||
static int xBorder, xBorder2, xBorder3, xBorder4;
|
static int xBorder, xBorder2, xBorder3, xBorder4;
|
||||||
static int yBorder, yBorder2, yBorder3, yBorder4;
|
static int yBorder, yBorder2, yBorder3, yBorder4;
|
||||||
@ -34,6 +42,7 @@ static int hdrYOffset, hdrYPadding, rowYOffset, rowYPadding;
|
|||||||
static int cellXOffset, cellXPadding, cellMinWidth;
|
static int cellXOffset, cellXPadding, cellMinWidth;
|
||||||
static int flagXOffset, flagYOffset;
|
static int flagXOffset, flagYOffset;
|
||||||
|
|
||||||
|
static void HookEvents(void);
|
||||||
void LBackend_Init(void) {
|
void LBackend_Init(void) {
|
||||||
xBorder = Display_ScaleX(1); xBorder2 = xBorder * 2; xBorder3 = xBorder * 3; xBorder4 = xBorder * 4;
|
xBorder = Display_ScaleX(1); xBorder2 = xBorder * 2; xBorder3 = xBorder * 3; xBorder4 = xBorder * 4;
|
||||||
yBorder = Display_ScaleY(1); yBorder2 = yBorder * 2; yBorder3 = yBorder * 3; yBorder4 = yBorder * 4;
|
yBorder = Display_ScaleY(1); yBorder2 = yBorder * 2; yBorder3 = yBorder * 3; yBorder4 = yBorder * 4;
|
||||||
@ -65,6 +74,7 @@ void LBackend_Init(void) {
|
|||||||
Drawer2D_MakeFont(&titleFont, 16, FONT_FLAGS_BOLD);
|
Drawer2D_MakeFont(&titleFont, 16, FONT_FLAGS_BOLD);
|
||||||
Drawer2D_MakeFont(&textFont, 14, FONT_FLAGS_NONE);
|
Drawer2D_MakeFont(&textFont, 14, FONT_FLAGS_NONE);
|
||||||
Drawer2D_MakeFont(&hintFont, 12, FONT_FLAGS_NONE);
|
Drawer2D_MakeFont(&hintFont, 12, FONT_FLAGS_NONE);
|
||||||
|
HookEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_Free(void) {
|
void LBackend_Free(void) {
|
||||||
@ -73,33 +83,91 @@ void LBackend_Free(void) {
|
|||||||
Font_Free(&hintFont);
|
Font_Free(&hintFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawBoxBounds(BitmapCol col, int x, int y, int width, int height) {
|
void LBackend_SetScreen(struct LScreen* s) { activeScreen = s; }
|
||||||
Drawer2D_Clear(&Launcher_Framebuffer, col,
|
void LBackend_CloseScreen(struct LScreen* s) { activeScreen = NULL; }
|
||||||
|
|
||||||
|
void LBackend_WidgetRepositioned(struct LWidget* w) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Marks the entire window as needing to be redrawn. */
|
||||||
|
static CC_NOINLINE void MarkAllDirty(void) {
|
||||||
|
dirty_rect.X = 0; dirty_rect.Width = Launcher_Framebuffer.width;
|
||||||
|
dirty_rect.Y = 0; dirty_rect.Height = Launcher_Framebuffer.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*------------------------------------------------------Base drawing-------------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
|
static void DrawBoxBounds(BitmapCol color, int x, int y, int width, int height) {
|
||||||
|
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
||||||
x, y,
|
x, y,
|
||||||
width, yBorder);
|
width, yBorder);
|
||||||
Drawer2D_Clear(&Launcher_Framebuffer, col,
|
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
||||||
x, y + height - yBorder,
|
x, y + height - yBorder,
|
||||||
width, yBorder);
|
width, yBorder);
|
||||||
Drawer2D_Clear(&Launcher_Framebuffer, col,
|
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
||||||
x, y,
|
x, y,
|
||||||
xBorder, height);
|
xBorder, height);
|
||||||
Drawer2D_Clear(&Launcher_Framebuffer, col,
|
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
||||||
x + width - xBorder, y,
|
x + width - xBorder, y,
|
||||||
xBorder, height);
|
xBorder, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBackend_WidgetRepositioned(struct LWidget* w) { }
|
static CC_NOINLINE void RedrawAll(void) {
|
||||||
void LBackend_SetScreen(struct LScreen* s) { }
|
struct LScreen* s = activeScreen;
|
||||||
void LBackend_CloseScreen(struct LScreen* s) { }
|
|
||||||
|
|
||||||
void LBackend_RedrawScreen(struct LScreen* s) {
|
|
||||||
int i;
|
int i;
|
||||||
s->DrawBackground(s, &Launcher_Framebuffer);
|
s->DrawBackground(s, &Launcher_Framebuffer);
|
||||||
|
|
||||||
for (i = 0; i < s->numWidgets; i++) {
|
for (i = 0; i < s->numWidgets; i++) {
|
||||||
LWidget_Draw(s->widgets[i]);
|
LWidget_Draw(s->widgets[i]);
|
||||||
}
|
}
|
||||||
Launcher_MarkAllDirty();
|
MarkAllDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LBackend_Redraw(void) {
|
||||||
|
pendingRedraw = REDRAW_ALL;
|
||||||
|
MarkAllDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LBackend_Tick(void) {
|
||||||
|
activeScreen->Tick(activeScreen);
|
||||||
|
if (!dirty_rect.Width) return;
|
||||||
|
|
||||||
|
if (pendingRedraw & REDRAW_ALL) {
|
||||||
|
RedrawAll();
|
||||||
|
pendingRedraw = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Window_DrawFramebuffer(dirty_rect);
|
||||||
|
dirty_rect.X = 0; dirty_rect.Width = 0;
|
||||||
|
dirty_rect.Y = 0; dirty_rect.Height = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*-----------------------------------------------------Event handling------------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
|
static void ReqeustRedraw(void* obj) { LBackend_Redraw(); }
|
||||||
|
|
||||||
|
static void OnPointerDown(void* obj, int idx) {
|
||||||
|
activeScreen->MouseDown(activeScreen, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OnPointerUp(void* obj, int idx) {
|
||||||
|
activeScreen->MouseUp(activeScreen, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OnPointerMove(void* obj, int idx) {
|
||||||
|
if (!activeScreen) return;
|
||||||
|
activeScreen->MouseMove(activeScreen, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void HookEvents(void) {
|
||||||
|
Event_Register_(&WindowEvents.Redraw, NULL, ReqeustRedraw);
|
||||||
|
Event_Register_(&PointerEvents.Down, NULL, OnPointerDown);
|
||||||
|
Event_Register_(&PointerEvents.Up, NULL, OnPointerUp);
|
||||||
|
Event_Register_(&PointerEvents.Moved, NULL, OnPointerMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -753,7 +821,7 @@ void LBackend_TableDraw(struct LTable* w) {
|
|||||||
LTable_DrawHeaders(w);
|
LTable_DrawHeaders(w);
|
||||||
LTable_DrawRows(w);
|
LTable_DrawRows(w);
|
||||||
LTable_DrawScrollbar(w);
|
LTable_DrawScrollbar(w);
|
||||||
Launcher_MarkAllDirty();
|
MarkAllDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,10 +17,13 @@ struct LTable;
|
|||||||
|
|
||||||
void LBackend_Init(void);
|
void LBackend_Init(void);
|
||||||
void LBackend_Free(void);
|
void LBackend_Free(void);
|
||||||
void LBackend_WidgetRepositioned(struct LWidget* w);
|
|
||||||
void LBackend_SetScreen(struct LScreen* s);
|
void LBackend_SetScreen(struct LScreen* s);
|
||||||
void LBackend_CloseScreen(struct LScreen* s);
|
void LBackend_CloseScreen(struct LScreen* s);
|
||||||
void LBackend_RedrawScreen(struct LScreen* s);
|
|
||||||
|
/* Resets pixels to default, then draws widgets of current screen over it */
|
||||||
|
void LBackend_Redraw(void);
|
||||||
|
void LBackend_Tick(void);
|
||||||
|
void LBackend_WidgetRepositioned(struct LWidget* w);
|
||||||
|
|
||||||
void LBackend_ButtonInit(struct LButton* w, int width, int height);
|
void LBackend_ButtonInit(struct LButton* w, int width, int height);
|
||||||
void LBackend_ButtonUpdate(struct LButton* w);
|
void LBackend_ButtonUpdate(struct LButton* w);
|
||||||
|
@ -395,7 +395,7 @@ static void ColoursScreen_TextChanged(struct LInput* w) {
|
|||||||
|
|
||||||
*color = BitmapCol_Make(r, g, b, 255);
|
*color = BitmapCol_Make(r, g, b, 255);
|
||||||
Launcher_SaveTheme();
|
Launcher_SaveTheme();
|
||||||
Launcher_Redraw();
|
LBackend_Redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ColoursScreen_AdjustSelected(struct LScreen* s, int delta) {
|
static void ColoursScreen_AdjustSelected(struct LScreen* s, int delta) {
|
||||||
@ -439,7 +439,7 @@ static void ColoursScreen_KeyDown(struct LScreen* s, int key, cc_bool was) {
|
|||||||
static void ColoursScreen_ToggleBG(struct LCheckbox* w) {
|
static void ColoursScreen_ToggleBG(struct LCheckbox* w) {
|
||||||
Launcher_Theme.ClassicBackground = w->value;
|
Launcher_Theme.ClassicBackground = w->value;
|
||||||
Launcher_SaveTheme();
|
Launcher_SaveTheme();
|
||||||
Launcher_Redraw();
|
LBackend_Redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ColoursScreen_Init(struct LScreen* s_) {
|
static void ColoursScreen_Init(struct LScreen* s_) {
|
||||||
@ -1604,7 +1604,7 @@ static struct LWidget* themes_widgets[] = {
|
|||||||
static void ThemesScreen_Set(const struct LauncherTheme* theme) {
|
static void ThemesScreen_Set(const struct LauncherTheme* theme) {
|
||||||
Launcher_Theme = *theme;
|
Launcher_Theme = *theme;
|
||||||
Launcher_SaveTheme();
|
Launcher_SaveTheme();
|
||||||
Launcher_Redraw();
|
LBackend_Redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ThemesScreen_Modern(void* w) {
|
static void ThemesScreen_Modern(void* w) {
|
||||||
|
@ -23,12 +23,11 @@
|
|||||||
|
|
||||||
/* The area/region of the window that needs to be redrawn and presented to the screen. */
|
/* The area/region of the window that needs to be redrawn and presented to the screen. */
|
||||||
/* If width is 0, means no area needs to be redrawn. */
|
/* If width is 0, means no area needs to be redrawn. */
|
||||||
static Rect2D dirty_rect;
|
Rect2D dirty_rect;
|
||||||
|
|
||||||
static struct LScreen* activeScreen;
|
static struct LScreen* activeScreen;
|
||||||
struct Bitmap Launcher_Framebuffer;
|
struct Bitmap Launcher_Framebuffer;
|
||||||
struct FontDesc Launcher_LogoFont;
|
struct FontDesc Launcher_LogoFont;
|
||||||
static cc_bool pendingRedraw;
|
|
||||||
|
|
||||||
cc_bool Launcher_ShouldExit, Launcher_ShouldUpdate;
|
cc_bool Launcher_ShouldExit, Launcher_ShouldUpdate;
|
||||||
static char hashBuffer[STRING_SIZE], userBuffer[STRING_SIZE];
|
static char hashBuffer[STRING_SIZE], userBuffer[STRING_SIZE];
|
||||||
@ -62,7 +61,7 @@ void Launcher_SetScreen(struct LScreen* screen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LBackend_SetScreen(screen);
|
LBackend_SetScreen(screen);
|
||||||
Launcher_Redraw();
|
LBackend_Redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher_DisplayHttpError(cc_result res, int status, const char* action, cc_string* dst) {
|
void Launcher_DisplayHttpError(cc_result res, int status, const char* action, cc_string* dst) {
|
||||||
@ -176,19 +175,12 @@ cc_bool Launcher_ConnectToServer(const cc_string* hash) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------------Event handler---------------------------------------------------*
|
*---------------------------------------------------------Event handler---------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static void ReqeustRedraw(void* obj) {
|
|
||||||
/* We may get multiple Redraw events in short timespan */
|
|
||||||
/* So we just request a redraw at next launcher tick */
|
|
||||||
pendingRedraw = true;
|
|
||||||
Launcher_MarkAllDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnResize(void* obj) {
|
static void OnResize(void* obj) {
|
||||||
Window_FreeFramebuffer(&Launcher_Framebuffer);
|
Window_FreeFramebuffer(&Launcher_Framebuffer);
|
||||||
InitFramebuffer();
|
InitFramebuffer();
|
||||||
|
|
||||||
if (activeScreen) activeScreen->Layout(activeScreen);
|
if (activeScreen) activeScreen->Layout(activeScreen);
|
||||||
Launcher_Redraw();
|
LBackend_Redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
static cc_bool IsShutdown(int key) {
|
static cc_bool IsShutdown(int key) {
|
||||||
@ -219,47 +211,18 @@ static void OnMouseWheel(void* obj, float delta) {
|
|||||||
activeScreen->MouseWheel(activeScreen, delta);
|
activeScreen->MouseWheel(activeScreen, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnPointerDown(void* obj, int idx) {
|
|
||||||
activeScreen->MouseDown(activeScreen, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnPointerUp(void* obj, int idx) {
|
|
||||||
activeScreen->MouseUp(activeScreen, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnPointerMove(void* obj, int idx) {
|
|
||||||
if (!activeScreen) return;
|
|
||||||
activeScreen->MouseMove(activeScreen, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------------Main body-----------------------------------------------------*
|
*-----------------------------------------------------------Main body-----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static void Launcher_Display(void) {
|
|
||||||
if (pendingRedraw) {
|
|
||||||
Launcher_Redraw();
|
|
||||||
pendingRedraw = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Window_DrawFramebuffer(dirty_rect);
|
|
||||||
dirty_rect.X = 0; dirty_rect.Width = 0;
|
|
||||||
dirty_rect.Y = 0; dirty_rect.Height = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Launcher_Init(void) {
|
static void Launcher_Init(void) {
|
||||||
Event_Register_(&WindowEvents.Resized, NULL, OnResize);
|
Event_Register_(&WindowEvents.Resized, NULL, OnResize);
|
||||||
Event_Register_(&WindowEvents.StateChanged, NULL, OnResize);
|
Event_Register_(&WindowEvents.StateChanged, NULL, OnResize);
|
||||||
Event_Register_(&WindowEvents.Redraw, NULL, ReqeustRedraw);
|
|
||||||
|
|
||||||
Event_Register_(&InputEvents.Down, NULL, OnInputDown);
|
Event_Register_(&InputEvents.Down, NULL, OnInputDown);
|
||||||
Event_Register_(&InputEvents.Press, NULL, OnKeyPress);
|
Event_Register_(&InputEvents.Press, NULL, OnKeyPress);
|
||||||
Event_Register_(&InputEvents.Wheel, NULL, OnMouseWheel);
|
Event_Register_(&InputEvents.Wheel, NULL, OnMouseWheel);
|
||||||
Event_Register_(&InputEvents.TextChanged, NULL, OnTextChanged);
|
Event_Register_(&InputEvents.TextChanged, NULL, OnTextChanged);
|
||||||
|
|
||||||
Event_Register_(&PointerEvents.Down, NULL, OnPointerDown);
|
|
||||||
Event_Register_(&PointerEvents.Up, NULL, OnPointerUp);
|
|
||||||
Event_Register_(&PointerEvents.Moved, NULL, OnPointerMove);
|
|
||||||
|
|
||||||
Utils_EnsureDirectory("texpacks");
|
Utils_EnsureDirectory("texpacks");
|
||||||
Utils_EnsureDirectory("audio");
|
Utils_EnsureDirectory("audio");
|
||||||
@ -323,8 +286,7 @@ void Launcher_Run(void) {
|
|||||||
Window_ProcessEvents();
|
Window_ProcessEvents();
|
||||||
if (!WindowInfo.Exists || Launcher_ShouldExit) break;
|
if (!WindowInfo.Exists || Launcher_ShouldExit) break;
|
||||||
|
|
||||||
activeScreen->Tick(activeScreen);
|
LBackend_Tick();
|
||||||
if (dirty_rect.Width) Launcher_Display();
|
|
||||||
Thread_Sleep(10);
|
Thread_Sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -561,10 +523,6 @@ void Launcher_ResetArea(int x, int y, int width, int height) {
|
|||||||
Launcher_MarkDirty(x, y, width, height);
|
Launcher_MarkDirty(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher_Redraw(void) {
|
|
||||||
LBackend_RedrawScreen(activeScreen);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Launcher_MarkDirty(int x, int y, int width, int height) {
|
void Launcher_MarkDirty(int x, int y, int width, int height) {
|
||||||
int x1, y1, x2, y2;
|
int x1, y1, x2, y2;
|
||||||
if (!Drawer2D_Clamp(&Launcher_Framebuffer, &x, &y, &width, &height)) return;
|
if (!Drawer2D_Clamp(&Launcher_Framebuffer, &x, &y, &width, &height)) return;
|
||||||
@ -584,9 +542,4 @@ void Launcher_MarkDirty(int x, int y, int width, int height) {
|
|||||||
dirty_rect.X = x; dirty_rect.Width = width;
|
dirty_rect.X = x; dirty_rect.Width = width;
|
||||||
dirty_rect.Y = y; dirty_rect.Height = height;
|
dirty_rect.Y = y; dirty_rect.Height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher_MarkAllDirty(void) {
|
|
||||||
dirty_rect.X = 0; dirty_rect.Width = Launcher_Framebuffer.width;
|
|
||||||
dirty_rect.Y = 0; dirty_rect.Height = Launcher_Framebuffer.height;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -65,13 +65,8 @@ void Launcher_DrawBackgroundAll(struct Bitmap* bmp);
|
|||||||
/* Redraws the specified region with the background pixels. */
|
/* Redraws the specified region with the background pixels. */
|
||||||
/* Also marks that area as neeing to be redrawn. */
|
/* Also marks that area as neeing to be redrawn. */
|
||||||
void Launcher_ResetArea(int x, int y, int width, int height);
|
void Launcher_ResetArea(int x, int y, int width, int height);
|
||||||
/* Resets pixels to default, then draws widgets of current screen over it. */
|
|
||||||
/* Marks the entire window as needing to be redrawn. */
|
|
||||||
void Launcher_Redraw(void);
|
|
||||||
/* Marks the given area/region as needing to be redrawn. */
|
/* Marks the given area/region as needing to be redrawn. */
|
||||||
CC_NOINLINE void Launcher_MarkDirty(int x, int y, int width, int height);
|
CC_NOINLINE void Launcher_MarkDirty(int x, int y, int width, int height);
|
||||||
/* Marks the entire window as needing to be redrawn. */
|
|
||||||
CC_NOINLINE void Launcher_MarkAllDirty(void);
|
|
||||||
|
|
||||||
/* Sets currently active screen/menu, freeing old one. */
|
/* Sets currently active screen/menu, freeing old one. */
|
||||||
void Launcher_SetScreen(struct LScreen* screen);
|
void Launcher_SetScreen(struct LScreen* screen);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user