summaryrefslogtreecommitdiff
path: root/source/core/core.c
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-03-29 23:09:33 +0200
committernasr <nsrddyn@gmail.com>2026-03-29 23:09:33 +0200
commit2380741bea16d5e3d54195c266e335cb131ac642 (patch)
tree27453c1b23bad00b3b5d751e50a04a0fe346dcb8 /source/core/core.c
parent444bfa2f41143aff7490e4fa21565947565b7d30 (diff)
feature: moving rectangle
Diffstat (limited to 'source/core/core.c')
-rw-r--r--source/core/core.c56
1 files changed, 27 insertions, 29 deletions
diff --git a/source/core/core.c b/source/core/core.c
index 43322de..fffcb47 100644
--- a/source/core/core.c
+++ b/source/core/core.c
@@ -64,63 +64,61 @@ int main()
64 p.value_mask, 64 p.value_mask,
65 &wa); 65 &wa);
66 66
67 Pixmap pixmap = XCreatePixmap(MainDisplay, window, dp_width, dp_heigth, 1);
68
69 XSetWindowBorder(MainDisplay, window, 60); 67 XSetWindowBorder(MainDisplay, window, 60);
70 68 XSelectInput(MainDisplay, window, ExposureMask | StructureNotifyMask | KeyReleaseMask | KeyPressMask);
71 // NOTE(nasr): type of input we want to handle
72 XSelectInput(MainDisplay, window, ExposureMask | StructureNotifyMask | KeyReleaseMask);
73
74 XMapWindow(MainDisplay, window); 69 XMapWindow(MainDisplay, window);
75 70 XEvent event;
76 double x = p.width / 2;
77 double y = p.height / 2;
78 71
79 u32 rect_width = 50; 72 u32 rect_width = 50;
80 u32 rect_height = 50; 73 u32 rect_height = 50;
74 i32 rect_x_position = p.width / 2;
75 i32 rect_y_position = p.height / 2;
81 76
82 u64 color = 0x0000ff00; 77 u64 color = 0x0000ff00;
83 78
84 GC gc = XCreateGC(MainDisplay, window, 0, NIL); 79 GC gc = XCreateGC(MainDisplay, window, 0, NIL);
85 XSetForeground(MainDisplay, gc, color); 80 XSetForeground(MainDisplay, gc, color);
86 81
87 double *pX = &x;
88 double *pY = &y;
89
90 XEvent event;
91 XNextEvent(MainDisplay, &event);
92
93 for (;running;) 82 for (;running;)
94 { 83 {
95 KeySym keysym = XLookupKeysym(event, 0); 84 XNextEvent(MainDisplay, &event);
85 KeySym keysym = XLookupKeysym(&event.xkey, 0);
96 86
97 switch (event.type) 87 switch (event.type)
98 { 88 {
99 case (KeyPress): 89 case (KeyPress):
100 { 90 {
101 if (keysym == XK_p || keysym == XK_P) 91 if(keysym == XK_h) rect_x_position -= 20;
92 else if(keysym == XK_l) rect_x_position += 20;
93 else if(keysym == XK_k)
102 { 94 {
103 XDrawRectangle(MainDisplay, screen, gc, 50, 50, 50, 50); 95 rect_y_position -= 20;
104 } 96 }
105 97 else if(keysym == XK_j)
106 break;
107 }
108 case (KeyRelease):
109 {
110 if (keysym == XK_p || keysym == XK_P)
111 { 98 {
112 XDrawRectangle(MainDisplay, screen, gc, 50, 50, 50, 50); 99 rect_y_position += 20;
113 } 100 }
101 else if(keysym == XK_s)
102 {
103
104 }
105 else if(keysym == XK_Escape || keysym == XK_q) goto exit;
106
107 XClearWindow(MainDisplay, window);
108 XDrawRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50);
109 XFillRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50);
114 110
115 break; 111 break;
116 } 112 }
117 default: 113 default:
118 { 114 {
115
119 116
120 } 117 }
121 118
122 } 119 }
123 } 120 }
121exit:
124 arena_clear(arena); 122 arena_clear(arena);
125 return 0; 123 return 0;
126} 124}