Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Commit

Permalink
Update windows.c
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinAlavik authored Feb 27, 2024
1 parent 6fee9d5 commit 8d39c59
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions src/system/wm/windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,51 @@ void spawn_window(window_t *window) {
}
}

#include "windows.h"

window_t windows[MAX_WINDOWS];
int num_windows = 0;

uint32_t w_old_pixels[MAX_WINDOWS][WIN_WIDTH][WIN_HEIGHT];
int old_window_x[MAX_WINDOWS];
int old_window_y[MAX_WINDOWS];
int last_updated_window_index = -1;

void spawn_window(window_t *window) {
if (num_windows < MAX_WINDOWS) {
window->buffer = malloc(window->width * window->height * sizeof(uint32_t));
window->old_buffer =
malloc(window->width * window->height * sizeof(uint32_t));
if (window->buffer == NULL || window->old_buffer == NULL) {
dprintf("Failed to allocate memory for window buffer\n");
return;
}

memset(window->buffer, 0xFFFFFFFF,
window->width * window->height * sizeof(uint32_t));
memcpy(window->old_buffer, window->buffer,
window->width * window->height * sizeof(uint32_t));

windows[num_windows] = *window;
num_windows++;

// // TODO: Make this not hardcoded to window id 0?
old_window_x[0] = window->x;
old_window_y[0] = window->y;
window->initialized = false;

render_window_gui(window);
update_window(window);
} else {
dprintf("Maximum number of windows reached\n");
}
}

void render_window_gui(window_t *window) {
int i, j;
uint32_t pixel;
bool buffer_changed = false;

for (i = 0; i < window->height; i++) {
for (j = 0; j < window->width; j++) {
for (int i = 0; i < window->height; i++) {
for (int j = 0; j < window->width; j++) {
if (window->buffer[i * window->width + j] !=
window->old_buffer[i * window->width + j]) {
buffer_changed = true;
Expand All @@ -57,9 +95,9 @@ void render_window_gui(window_t *window) {
}

if (!window->initialized || buffer_changed) {
for (i = 0; i < window->height; i++) {
for (j = 0; j < window->width; j++) {
pixel = window->buffer[i * window->width + j];
for (int i = 0; i < window->height; i++) {
for (int j = 0; j < window->width; j++) {
uint32_t pixel = window->buffer[i * window->width + j];
uint8_t alpha = (pixel & ALPHA_MASK) >> ALPHA_SHIFT;
uint8_t red = (pixel & RED_MASK) >> RED_SHIFT;
uint8_t green = (pixel & GREEN_MASK) >> GREEN_SHIFT;
Expand Down

0 comments on commit 8d39c59

Please sign in to comment.