Development Libraries
Overview
FreeWorld OS provides comprehensive development libraries for building applications with GUI, database, network, and graphics capabilities. These libraries abstract the kernel interfaces and provide high-level APIs for application development.
GUI Framework Library
The GUI Framework Library provides a high-level interface for creating graphical user interfaces with windows, controls, dialogs, and message loops.
Features
- ✅ Window creation and management
- ✅ Control creation (buttons, textboxes, labels, listboxes, etc.)
- ✅ Text and property management
- ✅ Position and size management
- ✅ Window show/hide
- ✅ Message loop handling
- ✅ Message boxes and dialogs
- ✅ Event handling
API Functions
; Window management
gui_create_window(title, width, height, style) -> window_handle
gui_show_window(window_handle) -> status
gui_hide_window(window_handle) -> status
gui_destroy_window(window_handle) -> status
; Control management
gui_create_control(parent, type, x, y, width, height, text) -> control_handle
gui_set_text(control_handle, text) -> status
gui_get_text(control_handle, buffer) -> status
gui_set_position(control_handle, x, y) -> status
gui_set_size(control_handle, width, height) -> status
; Message handling
gui_message_loop(window_handle) -> status
gui_show_messagebox(title, message, type) -> result
gui_show_dialog(dialog_handle) -> result
Database Library
The Database Library provides a unified interface for accessing various database systems including SQLite, MySQL, PostgreSQL, and MongoDB.
Features
- ✅ Multiple database type support (SQLite, MySQL, PostgreSQL, MongoDB)
- ✅ SQL execution
- ✅ Prepared statements
- ✅ Parameter binding
- ✅ Result set handling
- ✅ Transaction support (BEGIN, COMMIT, ROLLBACK)
- ✅ Connection management
API Functions
; Connection management
db_open(path, db_type) -> db_handle
db_close(db_handle) -> status
; SQL execution
db_execute(db_handle, sql_statement) -> status
db_prepare(db_handle, sql_statement) -> statement_handle
db_bind(statement_handle, param_index, value, value_type) -> status
db_step(statement_handle) -> result_code
db_finalize(statement_handle) -> status
db_get_column(statement_handle, column_index, buffer, buffer_size) -> status
; Transactions
db_transaction_begin(db_handle) -> status
db_transaction_commit(db_handle) -> status
db_transaction_rollback(db_handle) -> status
Network Library
The Network Library provides high-level networking functions for TCP/UDP sockets, DNS resolution, and network configuration.
Features
- ✅ Socket creation (TCP, UDP, Raw)
- ✅ Address binding and listening
- ✅ Connection management
- ✅ Data transmission (send, recv, sendto, recvfrom)
- ✅ DNS resolution (getaddrinfo, getnameinfo)
- ✅ Hostname management
- ✅ IPv4 and IPv6 support
API Functions
; Socket management
net_socket(domain, type, protocol) -> socket_fd
net_bind(socket_fd, address, address_len) -> status
net_listen(socket_fd, backlog) -> status
net_accept(socket_fd, address, address_len) -> new_socket_fd
net_connect(socket_fd, address, address_len) -> status
net_close(socket_fd) -> status
; Data transmission
net_send(socket_fd, buffer, length, flags) -> bytes_sent
net_recv(socket_fd, buffer, length, flags) -> bytes_received
net_sendto(socket_fd, buffer, length, flags, address, address_len) -> bytes_sent
net_recvfrom(socket_fd, buffer, length, flags, address, address_len) -> bytes_received
; DNS and hostname
net_getaddrinfo(node, service, hints, result) -> status
net_getnameinfo(address, address_len, node, node_size, service, service_size) -> status
net_gethostname(buffer, buffer_size) -> status
net_sethostname(hostname, length) -> status
Graphics Library
The Graphics Library provides high-level graphics functions for drawing primitives, text, and images in application windows.
Features
- ✅ Graphics context management
- ✅ Drawing primitives (points, lines, rectangles, circles, ellipses, polygons)
- ✅ Fill operations (solid, gradient, pattern)
- ✅ Text rendering with font support
- ✅ Image loading and rendering
- ✅ Color management
- ✅ Double buffering support
API Functions
; Context management
gfx_create_context(window_handle) -> context
gfx_destroy_context(context) -> status
gfx_set_color(context, color) -> status
gfx_set_font(context, font_name, font_size) -> status
; Drawing primitives
gfx_draw_point(context, x, y) -> status
gfx_draw_line(context, x1, y1, x2, y2) -> status
gfx_draw_rectangle(context, x, y, width, height) -> status
gfx_draw_circle(context, center_x, center_y, radius) -> status
gfx_draw_ellipse(context, x, y, width, height) -> status
gfx_draw_polygon(context, points, point_count) -> status
gfx_draw_text(context, x, y, text) -> status
gfx_draw_image(context, x, y, image) -> status
; Fill operations
gfx_fill_rectangle(context, x, y, width, height) -> status
gfx_fill_circle(context, center_x, center_y, radius) -> status
gfx_fill_ellipse(context, x, y, width, height) -> status
gfx_fill_polygon(context, points, point_count) -> status
; Buffer management
gfx_clear(context) -> status
gfx_flush(context) -> status
; Image operations
gfx_load_image(path) -> image_handle
gfx_save_image(image_handle, path) -> status
Build System
Development libraries are built using the Makefile in usr/lib/development/:
cd usr/lib/development
make
This produces static libraries:
lib/libgui.a- GUI Frameworklib/libdatabase.a- Database Librarylib/libnetwork.a- Network Librarylib/libgraphics.a- Graphics Library
Applications can link against these libraries:
gcc -o app app.c -Llib -lgui -ldatabase -lnetwork -lgraphics
Usage Examples
GUI Application
; Create window
mov rdi, window_title
mov rsi, 800 ; Width
mov rdx, 600 ; Height
mov rcx, WINDOW_STYLE_NORMAL
call gui_create_window
mov [window], rax
; Create button
mov rdi, [window]
mov rsi, CONTROL_BUTTON
mov rdx, 100 ; X
mov rcx, 100 ; Y
mov r8, 100 ; Width
mov r9, 30 ; Height
push button_text
call gui_create_control
; Message loop
mov rdi, [window]
call gui_message_loop
Database Application
; Open database
mov rdi, database_path
mov rsi, DB_TYPE_SQLITE
call db_open
mov [db], rax
; Execute SQL
mov rdi, [db]
mov rsi, sql_statement
call db_execute
; Prepare statement
mov rdi, [db]
mov rsi, prepared_sql
call db_prepare
mov [stmt], rax
; Bind parameter and execute
mov rdi, [stmt]
mov rsi, 1 ; Parameter index
mov rdx, value
mov rcx, VALUE_TYPE_INTEGER
call db_bind
mov rdi, [stmt]
call db_step