aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-12-03 13:56:14 +0100
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-12-03 13:56:14 +0100
commit4aec2e1331650cabb966bbf24ed83f76cbbe9912 (patch)
tree3d88f426d7bcfb44f448a0bf56adb5cb7db18232
parent083a6363e0b7d5be9850eef56df35d5f1e13f720 (diff)
checkpoint
-rw-r--r--box.c48
-rw-r--r--box_test.c27
2 files changed, 68 insertions, 7 deletions
diff --git a/box.c b/box.c
index af836ed..3c22aad 100644
--- a/box.c
+++ b/box.c
@@ -14,7 +14,7 @@
#include <locale.h>
#ifdef DEBUG
-#define Assert(expr) if (!expr) \
+#define Assert(expr) if (!(expr)) \
{ \
tb_shutdown(); \
*(u8*)0 = 0; \
@@ -101,6 +101,38 @@ IsInRect(rect Rect, u32 X, u32 Y)
return False;
}
+void
+ScrollLeft(rect Text, u32 *TextOffset, u32 Left)
+{
+ u32 TextSurface = Text.H * Text.W;
+
+ if (global.cursor_x - Left >= Text.X)
+ {
+ global.cursor_x -= Left;
+ }
+ else
+ {
+ global.cursor_x += Text.W - 1;
+
+ if (global.cursor_y > Text.Y)
+ {
+ global.cursor_y--;
+ }
+ else
+ {
+ global.cursor_y = Text.Y + Text.H - 1;
+ if (*TextOffset < TextSurface)
+ {
+ *TextOffset = 0;
+ }
+ else
+ {
+ *TextOffset -= TextSurface;
+ }
+ }
+ }
+}
+
int
main(void)
{
@@ -112,7 +144,7 @@ main(void)
u32 InputLen = 0;
wchar_t Input[MAX_INPUT_LEN] = {0};
-#if 0
+#if 1
wchar_t *t = L"This is some text that no one would want to know, but you could.";
u32 Len = wcslen(t);
for (u32 At = 0; At < Len; At++) Input[At] = t[At];
@@ -193,7 +225,10 @@ main(void)
if (InputPos == 0) break;
Delete(Input, InputPos - 1);
InputLen--;
- global.cursor_x--;
+ // TODO: scrolling
+
+ ScrollLeft(Text, &TextOffset, 1);
+
} break;
// Delete character forwards
case TB_KEY_CTRL_D:
@@ -285,15 +320,14 @@ main(void)
}
}
-
// Insert new character in Input at InputPos
else if (ev.ch && InputLen < MAX_INPUT_LEN)
{
if (InputPos < InputLen)
{
- memmove(Input + InputPos + 1,
- Input + InputPos,
- (InputLen - InputPos - 1) * sizeof(*Input));
+ memmove(Input + InputPos,
+ Input + InputPos - 1,
+ (InputLen - InputPos + 1) * sizeof(*Input));
}
Input[InputPos] = ev.ch;
InputLen++;
diff --git a/box_test.c b/box_test.c
new file mode 100644
index 0000000..57663f9
--- /dev/null
+++ b/box_test.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <stdbool.h>
+
+#define Assert(expr) if (!(expr)) return false;
+
+char
+DrawingTest()
+{
+ Assert(2 == 3);
+
+ return true;
+}
+
+char
+FooTest()
+{
+ return false;
+}
+
+
+int
+main(int Argc, char* Argv[])
+{
+ char *i(void);
+ i = &DrawingTest;
+
+}