Rewrote parts of blesses...

This commit is contained in:
Ognjen Milan Robovic 2023-11-30 14:50:42 -05:00
parent 3677286554
commit e19ac322d8
4 changed files with 69 additions and 57 deletions

View File

@ -11,31 +11,28 @@ It is distributed in the hope that it will be useful or harmful, it really depen
#include "chapter_5.h"
#define BLESSES_FONT_WIDTH (8)
#define BLESSES_FONT_HEIGHT (8)
#define BLESSES_FONT_WIDTH (8)
#define BLESSES_FONT_HEIGHT (8)
#define BLESSES_FONT_TABULATOR (4)
char * blesses_window_title = "xolatile";
int blesses_window_width = 1800;
int blesses_window_height = 900;
int blesses_active = 1;
int blesses_cursor_x = 0;
int blesses_cursor_y = 0;
int blesses_signal = 0;
int * blesses_sub_framebuffer = NULL;
int * blesses_framebuffer = NULL;
#define BLESSES_SIGNAL_COUNT (144)
void (* blesses_action [BLESSES_SIGNAL_COUNT]) (void) = { NULL };
static char * blesses_window_title = "xolatile";
static int blesses_window_width = 1800;
static int blesses_window_height = 900;
static int * blesses_sub_framebuffer = NULL;
static int * blesses_framebuffer = NULL;
xcb_window_t blesses_window = 0;
xcb_gcontext_t blesses_context = 0;
xcb_pixmap_t blesses_pixmap = 0;
xcb_connection_t * blesses_connection = NULL;
xcb_screen_t * blesses_screen = NULL;
xcb_image_t * blesses_image = NULL;
static void (* blesses_action [BLESSES_SIGNAL_COUNT]) (void) = { NULL };
void blesses_initialize (void) {
static xcb_window_t blesses_window = 0;
static xcb_gcontext_t blesses_context = 0;
static xcb_pixmap_t blesses_pixmap = 0;
static xcb_connection_t * blesses_connection = NULL;
static xcb_screen_t * blesses_screen = NULL;
static xcb_image_t * blesses_image = NULL;
static void blesses_initialize (void) {
unsigned int window_flags [2] = {
0,
XCB_EVENT_MASK_NO_EVENT |
@ -50,6 +47,10 @@ void blesses_initialize (void) {
unsigned short int window_width = (unsigned short int) blesses_window_width;
unsigned short int window_height = (unsigned short int) blesses_window_height;
if (blesses_active == TRUE) {
return;
}
blesses_connection = xcb_connect (NULL, NULL);
fatal_failure (blesses_connection == NULL, "blesses : blesses_initialize : XCB connection is null pointer.");
@ -67,7 +68,7 @@ void blesses_initialize (void) {
xcb_map_window (blesses_connection, blesses_window);
xcb_change_property (blesses_connection, XCB_PROP_MODE_REPLACE, blesses_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, string_length (blesses_window_title), blesses_window_title);
xcb_change_property (blesses_connection, XCB_PROP_MODE_REPLACE, blesses_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, (unsigned int) string_length (blesses_window_title), blesses_window_title);
xcb_create_pixmap (blesses_connection, blesses_screen->root_depth, blesses_pixmap, blesses_window, window_width, window_height);
@ -80,7 +81,7 @@ void blesses_initialize (void) {
blesses_framebuffer = allocate (blesses_window_width * blesses_window_height * (int) sizeof (* blesses_framebuffer));
}
void blesses_deinitialize (void) {
static void blesses_deinitialize (void) {
blesses_sub_framebuffer = deallocate (blesses_sub_framebuffer);
blesses_framebuffer = deallocate (blesses_framebuffer);
@ -93,9 +94,23 @@ void blesses_deinitialize (void) {
xcb_disconnect (blesses_connection);
}
int blesses_active = FALSE;
int blesses_cursor_x = 0;
int blesses_cursor_y = 0;
int blesses_signal = 0;
void blesses_configure (void) {
blesses_initialize ();
blesses_active = TRUE;
}
void blesses_synchronize (void) {
int i = 0;
unsigned short int window_width = (unsigned short int) blesses_window_width;
unsigned short int window_height = (unsigned short int) blesses_window_height;
xcb_generic_event_t * generic_event = NULL;
/*
for (i = 0; i != blesses_window_width * blesses_window_height; i++) {
@ -108,15 +123,15 @@ void blesses_synchronize (void) {
blesses_sub_framebuffer = deallocate (blesses_sub_framebuffer);
blesses_image = xcb_image_create_native (blesses_connection, blesses_window_width, blesses_window_height, XCB_IMAGE_FORMAT_Z_PIXMAP, blesses_screen->root_depth,
blesses_framebuffer, (unsigned int) (blesses_window_width * blesses_window_height * (int) sizeof (* blesses_framebuffer)),
blesses_image = xcb_image_create_native (blesses_connection, window_width, window_height, XCB_IMAGE_FORMAT_Z_PIXMAP, blesses_screen->root_depth,
blesses_framebuffer, (unsigned int) (window_width * window_height * (int) sizeof (* blesses_framebuffer)),
(unsigned char *) blesses_framebuffer);
xcb_image_put (blesses_connection, blesses_pixmap, blesses_context, blesses_image, 0, 0, 0);
xcb_image_destroy (blesses_image);
xcb_copy_area (blesses_connection, blesses_pixmap, blesses_window, blesses_context, 0, 0, 0, 0, blesses_window_width, blesses_window_height);
xcb_copy_area (blesses_connection, blesses_pixmap, blesses_window, blesses_context, 0, 0, 0, 0, window_width, window_height);
blesses_framebuffer = NULL;
@ -129,7 +144,7 @@ void blesses_synchronize (void) {
case XCB_KEY_PRESS: {
blesses_signal = (int) ((xcb_key_press_event_t *) generic_event)->detail;
if (blesses_signal == 24) {
blesses_active = 0;
blesses_active = FALSE;
}
} break;
default: {
@ -143,6 +158,10 @@ void blesses_synchronize (void) {
blesses_sub_framebuffer = allocate (blesses_window_width * blesses_window_height * (int) sizeof (* blesses_sub_framebuffer));
blesses_framebuffer = allocate (blesses_window_width * blesses_window_height * (int) sizeof (* blesses_framebuffer));
}
if (blesses_active == FALSE) {
blesses_deinitialize ();
}
}
void blesses_render_background_colour (int background) {
@ -150,7 +169,7 @@ void blesses_render_background_colour (int background) {
for (y = 0; y != blesses_window_height/* / 2*/; ++y) {
for (x = 0; x != blesses_window_width/* / 2*/; ++x) {
blesses_sub_framebuffer [y * (blesses_window_width/* / 2*/) + x] = 0XFF000000 | colour;
blesses_sub_framebuffer [y * (blesses_window_width/* / 2*/) + x] = (int) (0XFF000000 | (unsigned int) background);
}
}
}

View File

@ -19,30 +19,13 @@ It is distributed in the hope that it will be useful or harmful, it really depen
#include "chapter_3.h"
#include "chapter_4.h"
#define BLESSES_SIGNAL_COUNT (144)
extern int blesses_active;
extern int blesses_cursor_x;
extern int blesses_cursor_y;
extern int blesses_signal;
extern char * blesses_window_title;
extern int blesses_window_width;
extern int blesses_window_height;
extern int blesses_active;
extern int blesses_cursor_x;
extern int blesses_cursor_y;
extern int blesses_signal;
extern int * blesses_sub_framebuffer;
extern int * blesses_framebuffer;
extern void (* blesses_action [BLESSES_SIGNAL_COUNT]) (void);
extern xcb_window_t blesses_window;
extern xcb_gcontext_t blesses_context;
extern xcb_pixmap_t blesses_pixmap;
extern xcb_connection_t * blesses_connection;
extern xcb_screen_t * blesses_screen;
extern xcb_image_t * blesses_image;
extern void blesses_initialize (void);
extern void blesses_deinitialize (void);
extern void blesses_synchronize (void);
extern void blesses_configure (void);
extern void blesses_synchronize (void);
extern void blesses_render_background_colour (int background);

View File

@ -2,19 +2,19 @@
set -xe
clang -DSTATIC_SOURCE -g -Weverything -O0 -o xhartae xhartae.c
clang -DSTATIC_SOURCE -g -Weverything -O0 -o xhartae xhartae.c -lxcb -lxcb-image
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_0.o chapter/chapter_0.c
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_1.o chapter/chapter_1.c
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_2.o chapter/chapter_2.c
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_3.o chapter/chapter_3.c
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_4.o chapter/chapter_4.c
#~gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_5.o chapter/chapter_5.c
#~gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_6.o chapter/chapter_6.c
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_5.o chapter/chapter_5.c
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_6.o chapter/chapter_6.c
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o xhartae.o xhartae.c
gcc -o xhartae xhartae.o chapter/chapter_0.o chapter/chapter_1.o chapter/chapter_2.o chapter/chapter_3.o chapter/chapter_4.o #chapter/chapter_5.o chapter/chapter_6.o
gcc -o xhartae xhartae.o chapter/chapter_0.o chapter/chapter_1.o chapter/chapter_2.o chapter/chapter_3.o chapter/chapter_4.o chapter/chapter_5.o chapter/chapter_6.o -lxcb -lxcb-image
gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -o program/program_0 program/program_0.c
gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -o program/program_1 program/program_1.c

View File

@ -12,7 +12,7 @@ It is distributed in the hope that it will be useful or harmful, it really depen
#include "chapter/chapter_2.c"
#include "chapter/chapter_3.c"
#include "chapter/chapter_4.c"
//~#include "chapter/chapter_5.c"
#include "chapter/chapter_5.c"
//~#include "chapter/chapter_6.c"
#else
#include "chapter/chapter_0.h"
@ -20,7 +20,7 @@ It is distributed in the hope that it will be useful or harmful, it really depen
#include "chapter/chapter_2.h"
#include "chapter/chapter_3.h"
#include "chapter/chapter_4.h"
//~#include "chapter/chapter_5.h"
#include "chapter/chapter_5.h"
//~#include "chapter/chapter_6.h"
#endif
@ -133,7 +133,17 @@ int main (int argc, char * * argv) {
(void) argc;
(void) argv;
preview_c_file ("program/example.c", 0, 0);
preview_c_file ("program/program_1.c", 0, 0);
blesses_configure ();
while (blesses_active) {
blesses_render_string ("Heyo world!", 0XFF0000, 0XFF, 0, 0);
blesses_synchronize ();
}
preview_c_file ("program/program_2.c", 0, 0);
return (EXIT_SUCCESS);
}