mirror of
https://github.com/gbowne1/ClassicOS.git
synced 2026-01-20 04:15:19 -08:00
Compare commits
2 Commits
gbowne1-ad
...
gbowne1-pa
| Author | SHA1 | Date | |
|---|---|---|---|
| 7adb798c17 | |||
| 43b5cacd09 |
66
kernel/gui.c
66
kernel/gui.c
@@ -0,0 +1,66 @@
|
|||||||
|
#include "gui.h"
|
||||||
|
#include "vga.h" // VGA functions for drawing and clearing screen
|
||||||
|
#include "framebuffer.h" // For pixel manipulation if needed
|
||||||
|
|
||||||
|
// Initialize the GUI (could set up any global state or variables here)
|
||||||
|
void gui_init(void) {
|
||||||
|
// Clear the screen with black or any color
|
||||||
|
gui_clear(vga_entry_color(VGA_COLOR_BLACK, VGA_COLOR_WHITE));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw a window (simple rectangle with a title)
|
||||||
|
void gui_draw_window(gui_window_t* window) {
|
||||||
|
// Draw the window's border
|
||||||
|
for (uint32_t y = 0; y < window->height; ++y) {
|
||||||
|
for (uint32_t x = 0; x < window->width; ++x) {
|
||||||
|
// Check if we are at the border
|
||||||
|
if (x == 0 || y == 0 || x == window->width - 1 || y == window->height - 1) {
|
||||||
|
vga_put_entry_at('#', vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK), window->x + x, window->y + y);
|
||||||
|
} else {
|
||||||
|
// Fill the inside of the window
|
||||||
|
vga_put_entry_at(' ', vga_entry_color(VGA_COLOR_BLACK, VGA_COLOR_BLACK), window->x + x, window->y + y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the title at the top
|
||||||
|
if (window->title) {
|
||||||
|
size_t i = 0;
|
||||||
|
while (window->title[i] != '\0' && i < window->width - 2) {
|
||||||
|
vga_put_entry_at(window->title[i], vga_entry_color(VGA_COLOR_WHITE, VGA_COLOR_BLACK), window->x + i + 1, window->y);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw a button (a simple rectangle with text in the middle)
|
||||||
|
void gui_draw_button(gui_button_t* button) {
|
||||||
|
for (uint32_t y = 0; y < button->height; ++y) {
|
||||||
|
for (uint32_t x = 0; x < button->width; ++x) {
|
||||||
|
// Check if we are at the border
|
||||||
|
if (x == 0 || y == 0 || x == button->width - 1 || y == button->height - 1) {
|
||||||
|
vga_put_entry_at('#', vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK), button->x + x, button->y + y);
|
||||||
|
} else {
|
||||||
|
// Fill the inside of the button
|
||||||
|
vga_put_entry_at(' ', vga_entry_color(VGA_COLOR_BLACK, VGA_COLOR_BLACK), button->x + x, button->y + y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the label in the center of the button
|
||||||
|
size_t label_len = 0;
|
||||||
|
while (button->label[label_len] != '\0') {
|
||||||
|
label_len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t start_x = button->x + (button->width - label_len) / 2;
|
||||||
|
size_t start_y = button->y + (button->height - 1) / 2;
|
||||||
|
for (size_t i = 0; i < label_len; ++i) {
|
||||||
|
vga_put_entry_at(button->label[i], vga_entry_color(VGA_COLOR_WHITE, VGA_COLOR_BLACK), start_x + i, start_y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the screen with a color
|
||||||
|
void gui_clear(uint32_t color) {
|
||||||
|
vga_clear(color); // Just clear the VGA screen with a solid color
|
||||||
|
}
|
||||||
|
|||||||
34
kernel/gui.h
34
kernel/gui.h
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef GUI_H
|
||||||
|
#define GUI_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#define GUI_WINDOW_WIDTH 80
|
||||||
|
#define GUI_WINDOW_HEIGHT 25
|
||||||
|
#define GUI_BUTTON_WIDTH 10
|
||||||
|
#define GUI_BUTTON_HEIGHT 3
|
||||||
|
|
||||||
|
// Window structure
|
||||||
|
typedef struct {
|
||||||
|
uint32_t x, y;
|
||||||
|
uint32_t width, height;
|
||||||
|
uint32_t color; // Background color
|
||||||
|
const char* title;
|
||||||
|
} gui_window_t;
|
||||||
|
|
||||||
|
// Button structure
|
||||||
|
typedef struct {
|
||||||
|
uint32_t x, y;
|
||||||
|
uint32_t width, height;
|
||||||
|
uint32_t color; // Background color
|
||||||
|
const char* label;
|
||||||
|
} gui_button_t;
|
||||||
|
|
||||||
|
// Function prototypes for GUI elements
|
||||||
|
void gui_init(void);
|
||||||
|
void gui_draw_window(gui_window_t* window);
|
||||||
|
void gui_draw_button(gui_button_t* button);
|
||||||
|
void gui_clear(uint32_t color);
|
||||||
|
|
||||||
|
#endif // GUI_H
|
||||||
|
|||||||
66
kernel/hid.c
66
kernel/hid.c
@@ -1,66 +0,0 @@
|
|||||||
#include "hid.h"
|
|
||||||
#include "usb.h"
|
|
||||||
#include "mouse.h"
|
|
||||||
#include "keyboard.h"
|
|
||||||
#include "print.h"
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
// Global variables
|
|
||||||
static bool hid_initialized = false;
|
|
||||||
|
|
||||||
void hid_init(void) {
|
|
||||||
if (hid_initialized) return;
|
|
||||||
hid_initialized = true;
|
|
||||||
|
|
||||||
// Initialize keyboard and mouse HID handling
|
|
||||||
keyboard_init();
|
|
||||||
// Assume USB mouse has been initialized and is connected.
|
|
||||||
usb_hid_init(); // Initializes USB HID for both keyboard and mouse
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_process_report(uint8_t* report, uint8_t length) {
|
|
||||||
// Process the HID report based on its type
|
|
||||||
if (length == 8) { // Assuming a standard 8-byte report for HID keyboard
|
|
||||||
keyboard_hid_report_t* k_report = (keyboard_hid_report_t*) report;
|
|
||||||
hid_process_keyboard_report(k_report);
|
|
||||||
} else if (length == 3) { // Assuming a standard 3-byte report for HID mouse
|
|
||||||
mouse_hid_report_t* m_report = (mouse_hid_report_t*) report;
|
|
||||||
hid_process_mouse_report(m_report);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle HID keyboard report
|
|
||||||
void hid_process_keyboard_report(const keyboard_hid_report_t* report) {
|
|
||||||
// Iterate over the keycodes and process key presses
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
uint8_t keycode = report->keycodes[i];
|
|
||||||
if (keycode != 0) {
|
|
||||||
char key = scancode_map[keycode];
|
|
||||||
if (key) {
|
|
||||||
keyboard_buffer_add(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle HID mouse report
|
|
||||||
void hid_process_mouse_report(const mouse_hid_report_t* report) {
|
|
||||||
// Process mouse movement and button clicks
|
|
||||||
mouse_data.x += report->x;
|
|
||||||
mouse_data.y += report->y;
|
|
||||||
mouse_data.left_button = (report->buttons & 0x01) != 0;
|
|
||||||
mouse_data.right_button = (report->buttons & 0x02) != 0;
|
|
||||||
|
|
||||||
// Print mouse movement for debugging
|
|
||||||
print_hex(mouse_data.x, 1, 1);
|
|
||||||
print_hex(mouse_data.y, 1, 1);
|
|
||||||
print_hex(report->buttons, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the HID descriptor (for parsing USB HID device descriptors)
|
|
||||||
bool hid_parse_descriptor(uint8_t* descriptor, uint32_t length) {
|
|
||||||
// HID descriptors are defined in the USB HID specification, we'll need to parse them here.
|
|
||||||
// For now, just return true assuming we have a valid descriptor.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
46
kernel/hid.h
46
kernel/hid.h
@@ -1,46 +0,0 @@
|
|||||||
#ifndef HID_H
|
|
||||||
#define HID_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
// HID Report types
|
|
||||||
#define HID_REPORT_INPUT 0x01
|
|
||||||
#define HID_REPORT_OUTPUT 0x02
|
|
||||||
#define HID_REPORT_FEATURE 0x03
|
|
||||||
|
|
||||||
// HID usage page constants (USB HID)
|
|
||||||
#define HID_USAGE_PAGE_GENERIC 0x01
|
|
||||||
#define HID_USAGE_KEYBOARD 0x06
|
|
||||||
#define HID_USAGE_MOUSE 0x02
|
|
||||||
|
|
||||||
// HID keyboard and mouse data
|
|
||||||
typedef struct {
|
|
||||||
uint8_t modifier; // Modifier keys (shift, ctrl, alt, etc.)
|
|
||||||
uint8_t reserved; // Reserved byte
|
|
||||||
uint8_t keycodes[6]; // Keycodes for keys pressed
|
|
||||||
} keyboard_hid_report_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint8_t buttons; // Mouse buttons (bitwise: 0x01 = left, 0x02 = right, 0x04 = middle)
|
|
||||||
int8_t x; // X axis movement
|
|
||||||
int8_t y; // Y axis movement
|
|
||||||
int8_t wheel; // Mouse wheel
|
|
||||||
} mouse_hid_report_t;
|
|
||||||
|
|
||||||
// Initialize the HID subsystem
|
|
||||||
void hid_init(void);
|
|
||||||
|
|
||||||
// Process an incoming HID report
|
|
||||||
void hid_process_report(uint8_t* report, uint8_t length);
|
|
||||||
|
|
||||||
// Process HID keyboard report
|
|
||||||
void hid_process_keyboard_report(const keyboard_hid_report_t* report);
|
|
||||||
|
|
||||||
// Process HID mouse report
|
|
||||||
void hid_process_mouse_report(const mouse_hid_report_t* report);
|
|
||||||
|
|
||||||
// USB HID report descriptor parsing
|
|
||||||
bool hid_parse_descriptor(uint8_t* descriptor, uint32_t length);
|
|
||||||
|
|
||||||
#endif // HID_H
|
|
||||||
Reference in New Issue
Block a user