summaryrefslogtreecommitdiff
path: root/source/core/core.c
blob: 43322de9b224047296b3ac0f666123999bf5ca4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#define TB_IMPLEMENTATION
#include "core.h"
#include "../base/base_include.h"
#include "../platform/platform_include.h"

int main()
{
    b32 running = 1;

    Display *MainDisplay = XOpenDisplay(0);
    mem_arena *arena = arena_create(MiB(8));

    Window root = XDefaultRootWindow(MainDisplay);
    int screen = DefaultScreen(MainDisplay);

    Visual *v = DefaultVisual(MainDisplay, screen);

    XSetWindowAttributes wa = {
        .background_pixmap = None,
        .background_pixel = BlackPixel(MainDisplay, DefaultScreen(MainDisplay)),
        .border_pixmap = CopyFromParent,
        .border_pixel = 0,
        .bit_gravity = ForgetGravity,
        .win_gravity = NorthWestGravity,
        .backing_store = NotUseful,
        .backing_planes = 1,
        .backing_pixel = 0,
        .save_under = False,
        .event_mask = 0,
        .do_not_propagate_mask = 0,
        .override_redirect = False,
        .colormap = CopyFromParent,
        .cursor = None
    };

    i32 dp_heigth = DisplayHeight(MainDisplay, screen);
    i32 dp_width = DisplayWidth(MainDisplay, screen);

    WindowProperties p = {

        .x = dp_width / 2,
        .y = dp_heigth / 2,
        .height = (u32)800,
        .width = (u32)1200,
        .border_width = 0,
        .window_depth = CopyFromParent,
        .window_class = CopyFromParent,
        .value_mask = CWBackPixel,

    };

    Window window =
        XCreateWindow(
                      MainDisplay,
                      root,
                      p.x,
                      p.y,
                      p.width,
                      p.height,
                      p.border_width,
                      p.window_depth,
                      p.window_class,
                      v,
                      p.value_mask,
                      &wa);

    Pixmap pixmap = XCreatePixmap(MainDisplay, window, dp_width, dp_heigth, 1);

    XSetWindowBorder(MainDisplay, window, 60);

	// NOTE(nasr): type of input we want to handle
    XSelectInput(MainDisplay, window, ExposureMask | StructureNotifyMask | KeyReleaseMask);

    XMapWindow(MainDisplay, window);

    double x = p.width / 2;
    double y = p.height / 2;

    u32 rect_width = 50;
    u32 rect_height = 50;

    u64 color = 0x0000ff00;

    GC gc = XCreateGC(MainDisplay, window, 0, NIL);
    XSetForeground(MainDisplay, gc, color);

    double *pX = &x;
    double *pY = &y;

    XEvent event;
    XNextEvent(MainDisplay, &event);

    for (;running;)
    {
        KeySym keysym = XLookupKeysym(event, 0);

        switch (event.type)
		{
            case (KeyPress):
		        {
                    if (keysym == XK_p || keysym == XK_P) 
                    {
                        XDrawRectangle(MainDisplay, screen, gc, 50, 50, 50, 50);
                    }

			        break;
		        }
            case (KeyRelease):
		        {
                    if (keysym == XK_p || keysym == XK_P) 
                    {
                        XDrawRectangle(MainDisplay, screen, gc, 50, 50, 50, 50);
                    }

			        break;
		        }
            default:
                {

                }

		}
	}
    arena_clear(arena);
    return 0;
}