Skip to content

Commit

Permalink
User editor threads
Browse files Browse the repository at this point in the history
  • Loading branch information
joexbayer committed Jan 23, 2024
1 parent b46bd6e commit 62fcbe4
Show file tree
Hide file tree
Showing 3 changed files with 531 additions and 466 deletions.
73 changes: 69 additions & 4 deletions apps/users/users.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,69 @@
#include <utils/Graphics.hpp>
#include <utils/StdLib.hpp>
#include <utils/Widgets.hpp>
#include <utils/Thread.hpp>
#include <libc.h>
#include <colors.h>

class UserEditor : public Window {

public:
UserEditor(int width, int height) : Window(200, 200, "User Editor", 1) {
this->width = width;
this->height = height;

/* Create widgets */
widgets = new WidgetManager();
widgets->addWidget(new Button(10, 10, 100, 12, "Button", []() {
printf("Button pressed!\n");
}));
}

int eventHandler(struct gfx_event* event) {
switch (event->event)
{
case GFX_EVENT_RESOLUTION:
/* update screensize */
break;
case GFX_EVENT_EXIT:
delete widgets;
return -1;
case GFX_EVENT_KEYBOARD:
widgets->Keyboard(event->data);
/* keyboard event in e.data */
break;
case GFX_EVENT_MOUSE:
widgets->Mouse(event->data, event->data2);
break;
}
return 0;
}

void draw() {
/* Clear screen */
drawRect(0, 0, width, height, 30);
/* Draw widgets */
widgets->draw(this);
}

private:
int width;
int height;
WidgetManager* widgets;
};

void editorEntry(void* arg) {
UserEditor t(200, 200);

struct gfx_event e;
while (1){
gfx_get_event(&e, GFX_EVENT_BLOCKING); /* alt: GFX_EVENT_NONBLOCKING */
if(t.eventHandler(&e) == -1) break;
t.draw();
}
return;
}

class Users : public Window {
public:
Users(int width, int height) : Window(200, 200, "Users", 1) {
Expand All @@ -15,8 +75,11 @@ class Users : public Window {
widgets->addWidget(new Button(10, 10, 100, 12, "Button", []() {
printf("Button pressed!\n");
}));
widgets->addWidget(new Button(10, 30, 100, 12, "Button 2", []() {
printf("Button 2 pressed!\n");
widgets->addWidget(new Button(10, 30, 100, 12, "Start Edit", []() {

Thread* editor = new Thread(editorEntry, 0);
editor->start(0);

}));

Input* input = new Input(10, 50, 100, 12, "Input");
Expand All @@ -34,8 +97,10 @@ class Users : public Window {
/* update screensize */
break;
case GFX_EVENT_EXIT:
delete widgets;
exit();
/* exit */
return 0;
return -1;
case GFX_EVENT_KEYBOARD:
widgets->Keyboard(event->data);
/* keyboard event in e.data */
Expand Down Expand Up @@ -67,7 +132,7 @@ int main()
struct gfx_event e;
while (1){
gfx_get_event(&e, GFX_EVENT_BLOCKING); /* alt: GFX_EVENT_NONBLOCKING */
t.eventHandler(&e);
if(t.eventHandler(&e) == -1) break;
t.draw();
}
return 0;
Expand Down
24 changes: 12 additions & 12 deletions graphics/windowserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,19 @@ static int ws_set_background(struct windowserver* ws, color_t color)
WS_VALIDATE(ws);

memset(ws->background, color, VBE_SIZE());
int j, i;
for (i = 0; i < 640; i++) {
for (j = 0; j < 480; j++) {
/* Checkered pattern */
int size = 10;
int spacing = 10;
int dot_size = 2;

DIAMONDS();
// int j, i;
// for (i = 0; i < 640; i++) {
// for (j = 0; j < 480; j++) {
// /* Checkered pattern */
// int size = 30;
// int spacing = 10;
// int dot_size = 2;

// DIAMONDS();

vesa_put_pixel(ws->background, i, j, color);
}
}
// vesa_put_pixel(ws->background, i, j, color);
// }
// }



Expand Down
Loading

0 comments on commit 62fcbe4

Please sign in to comment.