Horz/vert lines and boxes.

This commit is contained in:
Simon Forman 2023-02-26 18:07:47 -08:00
parent c385ad096b
commit d8e20c0ce9
2 changed files with 43 additions and 15 deletions

View File

@ -1,5 +1,9 @@
#include <stddef.h>
#define RED 0xFF_00_00
#define GREEN 0x00_FF_00
#define WHITE 0xFF_FF_FF
void
draw_background(u32* buffer, size_t w, size_t h)
{
@ -18,15 +22,13 @@ void
carefree_alpha_blend_blit(u32* dest, u32* source, size_t dest_stride, u64 dest_x, u64 dest_y, u64 w, u64 h)
{
u32* d = dest + dest_stride * dest_y + dest_x;
for (u64 x = 0; x < w; ++x) {
for (u64 y = 0; y < h; ++y) {
u32* pix_ptr = d + x + dest_stride * y;
for (u64 y = 0; y < h; ++y) {
for (u64 x = 0; x < w; ++x) {
u32* spix_ptr = source + x + w * y;
u32 pixel = *spix_ptr;
u8 alpha = pixel >> 24;
if (!alpha) { // no alpha
continue;
}
if (!alpha) continue;
u32* pix_ptr = d + x + dest_stride * y;
if (0xFF == alpha) {
*pix_ptr = pixel;
continue;
@ -42,3 +44,35 @@ carefree_alpha_blend_blit(u32* dest, u32* source, size_t dest_stride, u64 dest_x
}
void
carefree_draw_horizontal_line(u32* dest, size_t dest_stride, u64 x, u64 y, u64 w, u32 color)
{
u32* d = dest + dest_stride * y + x;
for (u64 i = 0; i < w; ++i) {
*d = color;
d = d + 1;
}
}
void
carefree_draw_vertical_line(u32* dest, size_t dest_stride, u64 x, u64 y, u64 h, u32 color)
{
u32* d = dest + dest_stride * y + x;
for (u64 i = 0; i < h; ++i) {
*d = color;
d = d + dest_stride;
}
}
void
carefree_draw_box(u32* dest, size_t dest_stride, u64 y, u64 x, u64 w, u64 h, u32 color)
{
carefree_draw_horizontal_line(dest, dest_stride, x, y, w, color);
carefree_draw_horizontal_line(dest, dest_stride, x, y + h, w, color);
carefree_draw_vertical_line( dest, dest_stride, x, y, h, color);
carefree_draw_vertical_line( dest, dest_stride, x + w, y, h, color);
}

View File

@ -4,9 +4,6 @@
#include "/home/sforman/src/Joypy/implementations/uvm-ncc/font/font.h"
#include "/home/sforman/src/Joypy/implementations/uvm-ncc/graphics.h"
#define RED 0xFF_00_00
#define GREEN 0x00_FF_00
size_t FRAME_WIDTH = 768;
size_t FRAME_HEIGHT = 512;
u32 frame_buffer[393216];
@ -42,12 +39,6 @@ draw_char(u8 ch, u64 dest_x, u64 dest_y)
void
keydown(u64 window_id, u16 keycode)
{
if (KEY_TAB == keycode) {
print_str("bye! ");
print_i64(keycode);
print_endl();
exit(0);
}
if (KEY_BACKSPACE == keycode) {
} else if (KEY_TAB == keycode) {
} else if (KEY_RETURN == keycode) {
@ -110,6 +101,9 @@ main()
128 + (ch / 26) * font_Inconsolata_22_height
);
}
u64 w = 3 + 26 * font_Inconsolata_22_width;
u64 h = 4 + 4 * font_Inconsolata_22_height;
carefree_draw_box(frame_buffer, FRAME_WIDTH, 126, 126, w, h, WHITE);
window_draw_frame(wid, frame_buffer);
window_on_keydown(wid, keydown);
window_on_mousedown(wid, mousedown);