diff options
Diffstat (limited to 'source/core/core.c')
| -rw-r--r-- | source/core/core.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/source/core/core.c b/source/core/core.c new file mode 100644 index 0000000..43322de --- /dev/null +++ b/source/core/core.c | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | #define TB_IMPLEMENTATION | ||
| 2 | #include "core.h" | ||
| 3 | #include "../base/base_include.h" | ||
| 4 | #include "../platform/platform_include.h" | ||
| 5 | |||
| 6 | int main() | ||
| 7 | { | ||
| 8 | b32 running = 1; | ||
| 9 | |||
| 10 | Display *MainDisplay = XOpenDisplay(0); | ||
| 11 | mem_arena *arena = arena_create(MiB(8)); | ||
| 12 | |||
| 13 | Window root = XDefaultRootWindow(MainDisplay); | ||
| 14 | int screen = DefaultScreen(MainDisplay); | ||
| 15 | |||
| 16 | Visual *v = DefaultVisual(MainDisplay, screen); | ||
| 17 | |||
| 18 | XSetWindowAttributes wa = { | ||
| 19 | .background_pixmap = None, | ||
| 20 | .background_pixel = BlackPixel(MainDisplay, DefaultScreen(MainDisplay)), | ||
| 21 | .border_pixmap = CopyFromParent, | ||
| 22 | .border_pixel = 0, | ||
| 23 | .bit_gravity = ForgetGravity, | ||
| 24 | .win_gravity = NorthWestGravity, | ||
| 25 | .backing_store = NotUseful, | ||
| 26 | .backing_planes = 1, | ||
| 27 | .backing_pixel = 0, | ||
| 28 | .save_under = False, | ||
| 29 | .event_mask = 0, | ||
| 30 | .do_not_propagate_mask = 0, | ||
| 31 | .override_redirect = False, | ||
| 32 | .colormap = CopyFromParent, | ||
| 33 | .cursor = None | ||
| 34 | }; | ||
| 35 | |||
| 36 | i32 dp_heigth = DisplayHeight(MainDisplay, screen); | ||
| 37 | i32 dp_width = DisplayWidth(MainDisplay, screen); | ||
| 38 | |||
| 39 | WindowProperties p = { | ||
| 40 | |||
| 41 | .x = dp_width / 2, | ||
| 42 | .y = dp_heigth / 2, | ||
| 43 | .height = (u32)800, | ||
| 44 | .width = (u32)1200, | ||
| 45 | .border_width = 0, | ||
| 46 | .window_depth = CopyFromParent, | ||
| 47 | .window_class = CopyFromParent, | ||
| 48 | .value_mask = CWBackPixel, | ||
| 49 | |||
| 50 | }; | ||
| 51 | |||
| 52 | Window window = | ||
| 53 | XCreateWindow( | ||
| 54 | MainDisplay, | ||
| 55 | root, | ||
| 56 | p.x, | ||
| 57 | p.y, | ||
| 58 | p.width, | ||
| 59 | p.height, | ||
| 60 | p.border_width, | ||
| 61 | p.window_depth, | ||
| 62 | p.window_class, | ||
| 63 | v, | ||
| 64 | p.value_mask, | ||
| 65 | &wa); | ||
| 66 | |||
| 67 | Pixmap pixmap = XCreatePixmap(MainDisplay, window, dp_width, dp_heigth, 1); | ||
| 68 | |||
| 69 | XSetWindowBorder(MainDisplay, window, 60); | ||
| 70 | |||
| 71 | // NOTE(nasr): type of input we want to handle | ||
| 72 | XSelectInput(MainDisplay, window, ExposureMask | StructureNotifyMask | KeyReleaseMask); | ||
| 73 | |||
| 74 | XMapWindow(MainDisplay, window); | ||
| 75 | |||
| 76 | double x = p.width / 2; | ||
| 77 | double y = p.height / 2; | ||
| 78 | |||
| 79 | u32 rect_width = 50; | ||
| 80 | u32 rect_height = 50; | ||
| 81 | |||
| 82 | u64 color = 0x0000ff00; | ||
| 83 | |||
| 84 | GC gc = XCreateGC(MainDisplay, window, 0, NIL); | ||
| 85 | XSetForeground(MainDisplay, gc, color); | ||
| 86 | |||
| 87 | double *pX = &x; | ||
| 88 | double *pY = &y; | ||
| 89 | |||
| 90 | XEvent event; | ||
| 91 | XNextEvent(MainDisplay, &event); | ||
| 92 | |||
| 93 | for (;running;) | ||
| 94 | { | ||
| 95 | KeySym keysym = XLookupKeysym(event, 0); | ||
| 96 | |||
| 97 | switch (event.type) | ||
| 98 | { | ||
| 99 | case (KeyPress): | ||
| 100 | { | ||
| 101 | if (keysym == XK_p || keysym == XK_P) | ||
| 102 | { | ||
| 103 | XDrawRectangle(MainDisplay, screen, gc, 50, 50, 50, 50); | ||
| 104 | } | ||
| 105 | |||
| 106 | break; | ||
| 107 | } | ||
| 108 | case (KeyRelease): | ||
| 109 | { | ||
| 110 | if (keysym == XK_p || keysym == XK_P) | ||
| 111 | { | ||
| 112 | XDrawRectangle(MainDisplay, screen, gc, 50, 50, 50, 50); | ||
| 113 | } | ||
| 114 | |||
| 115 | break; | ||
| 116 | } | ||
| 117 | default: | ||
| 118 | { | ||
| 119 | |||
| 120 | } | ||
| 121 | |||
| 122 | } | ||
| 123 | } | ||
| 124 | arena_clear(arena); | ||
| 125 | return 0; | ||
| 126 | } | ||
