Bladeren bron

Added optional zooming for blesses...

master
Ognjen Milan Robovic 5 maanden geleden
bovenliggende
commit
91e17f32c6
2 gewijzigde bestanden met toevoegingen van 37 en 25 verwijderingen
  1. +36
    -25
      chapter/chapter_5.c
  2. +1
    -0
      chapter/chapter_5.h

+ 36
- 25
chapter/chapter_5.c Bestand weergeven

@@ -47,10 +47,6 @@ static 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.");
@@ -76,9 +72,13 @@ static void blesses_initialize (void) {

xcb_flush (blesses_connection);

/*blesses_sub_framebuffer = allocate (blesses_window_width * blesses_window_height * (int) sizeof (* blesses_sub_framebuffer) / 4);*/
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_zoom == TRUE) {
blesses_sub_framebuffer = allocate (blesses_window_width * blesses_window_height * (int) sizeof (* blesses_sub_framebuffer) / 4);
} else {
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));
}

static void blesses_deinitialize (void) {
@@ -98,11 +98,12 @@ int blesses_active = FALSE;
int blesses_cursor_x = 0;
int blesses_cursor_y = 0;
int blesses_signal = 0;
int blesses_zoom = TRUE;

void blesses_configure (void) {
blesses_initialize ();

blesses_active = TRUE;

blesses_initialize ();
}

void blesses_synchronize (void) {
@@ -112,13 +113,15 @@ void blesses_synchronize (void) {
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++) {
blesses_framebuffer [i] = blesses_sub_framebuffer [((i / blesses_window_width) / 2) * (blesses_window_width / 2) + (i % blesses_window_width) / 2];
}
*/
for (i = 0; i != blesses_window_width * blesses_window_height; i++) {
blesses_framebuffer [i] = blesses_sub_framebuffer [i];

if (blesses_zoom == TRUE) {
for (i = 0; i != blesses_window_width * blesses_window_height; i++) {
blesses_framebuffer [i] = blesses_sub_framebuffer [((i / blesses_window_width) / 2) * (blesses_window_width / 2) + (i % blesses_window_width) / 2];
}
} else {
for (i = 0; i != blesses_window_width * blesses_window_height; i++) {
blesses_framebuffer [i] = blesses_sub_framebuffer [i];
}
}

blesses_sub_framebuffer = deallocate (blesses_sub_framebuffer);
@@ -154,9 +157,15 @@ void blesses_synchronize (void) {
generic_event = deallocate (generic_event);

if ((blesses_sub_framebuffer == NULL) && (blesses_framebuffer == NULL)) {
/*blesses_sub_framebuffer = allocate (blesses_window_width * blesses_window_height * (int) sizeof (* blesses_sub_framebuffer) / 4);*/
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_zoom == TRUE) {
blesses_sub_framebuffer = allocate (blesses_window_width * blesses_window_height * (int) sizeof (* blesses_sub_framebuffer) / 4);
} else {
blesses_sub_framebuffer = allocate (blesses_window_width * blesses_window_height * (int) sizeof (* blesses_sub_framebuffer));
}

// blesses_sub_framebuffer = allocate ((blesses_window_width * blesses_window_height * (int) sizeof (* blesses_sub_framebuffer)) / ((blesses_zoom == TRUE) * 4));

blesses_framebuffer = allocate (blesses_window_width * blesses_window_height * (int) sizeof (* blesses_framebuffer));
}

if (blesses_active == FALSE) {
@@ -167,9 +176,9 @@ void blesses_synchronize (void) {
void blesses_render_background_colour (int background) {
int x, y;

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] = (int) (0XFF000000 | (unsigned int) background);
for (y = 0; y != blesses_window_height / ((blesses_zoom == TRUE) * 2); ++y) {
for (x = 0; x != blesses_window_width / ((blesses_zoom == TRUE) * 2); ++x) {
blesses_sub_framebuffer [y * (blesses_window_width / ((blesses_zoom == TRUE) * 2)) + x] = (int) (0XFF000000 | (unsigned int) background);
}
}
}
@@ -192,8 +201,8 @@ void blesses_render_character (char character, int foreground, int background, i

int offset;

if ((x <= -1) || (x >= blesses_window_width/* / 2*/ - BLESSES_FONT_WIDTH)) return;
if ((y <= -1) || (y >= blesses_window_height/* / 2*/ - BLESSES_FONT_HEIGHT)) return;
if ((x <= -1) || (x >= blesses_window_width / ((blesses_zoom == TRUE) * 2) - BLESSES_FONT_WIDTH)) return;
if ((y <= -1) || (y >= blesses_window_height / ((blesses_zoom == TRUE) * 2) - BLESSES_FONT_HEIGHT)) return;

fatal_failure (blesses_sub_framebuffer == NULL, "blesses : render_character : Sub framebuffer was not allocated.");
fatal_failure (blesses_framebuffer == NULL, "blesses : render_character : Framebuffer was not allocated.");
@@ -207,7 +216,9 @@ void blesses_render_character (char character, int foreground, int background, i
int u = offset / BLESSES_FONT_WIDTH + y;
int v = offset % BLESSES_FONT_WIDTH + x;

blesses_sub_framebuffer [u * (blesses_window_width/* / 2*/) + v] = ((font_code [(int) (character - ' ')] >> offset) % 2) ? foreground : background;
blesses_sub_framebuffer [u * (blesses_window_width / ((blesses_zoom == TRUE) * 2)) + v] = ((font_code [(int) (character - ' ')] >> offset) % 2)
? foreground
: background;
}
}



+ 1
- 0
chapter/chapter_5.h Bestand weergeven

@@ -23,6 +23,7 @@ extern int blesses_active;
extern int blesses_cursor_x;
extern int blesses_cursor_y;
extern int blesses_signal;
extern int blesses_zoom;

extern void blesses_configure (void);
extern void blesses_synchronize (void);


Laden…
Annuleren
Opslaan