2012-01-30 03:05:42 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
*/
|
2012-02-04 05:47:36 +04:00
|
|
|
#ifndef LIB_GRAPHICS_H
|
|
|
|
#define LIB_GRAPHICS_H
|
|
|
|
|
2012-01-30 03:05:42 +04:00
|
|
|
#include <syscall.h>
|
|
|
|
#include <stdint.h>
|
2012-02-04 05:47:36 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-01-30 03:05:42 +04:00
|
|
|
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
#define GFX_W(ctx) ((ctx)->width) /* Display width */
|
|
|
|
#define GFX_H(ctx) ((ctx)->height) /* Display height */
|
|
|
|
#define GFX_B(ctx) ((ctx)->depth / 8) /* Display byte depth */
|
2012-01-30 03:05:42 +04:00
|
|
|
|
|
|
|
#define _RED(color) ((color & 0x00FF0000) / 0x10000)
|
|
|
|
#define _GRE(color) ((color & 0x0000FF00) / 0x100)
|
|
|
|
#define _BLU(color) ((color & 0x000000FF) / 0x1)
|
2012-02-20 08:35:20 +04:00
|
|
|
#define _ALP(color) ((color & 0xFF000000) / 0x1000000)
|
2012-01-30 03:05:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros make verything easier.
|
|
|
|
*/
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
#define GFX(ctx,x,y) *((uint32_t *)&((ctx)->backbuffer)[(GFX_W(ctx) * (y) + (x)) * GFX_B(ctx)])
|
EXPERIMENTAL: Rotating windows.
* Dumb bounding box top_at logic replaced with select buffer
* Select buffer rendered through cairo with AA disabled
Using rectangles for window shapes - this should easily
be expandable to 1bpp bitmaps. Currently, the select buffer
is very inefficient, using twice the space it needs (plus,
it's double buffered, so in reality, 4x the space needed),
however, it's also very accurate and fast, and I like that.
* Window rotation is controlled through Ctrl+Shift+{z,x,c} where
z = rotate 1 degree left
x = rotate 1 degree right
c = reset rotation
* Input is remapped based on window rotation, so you *can* use the
draw app, and it is totally epic.
2013-04-02 12:26:32 +04:00
|
|
|
#define GFXR(ctx,x,y) *((uint32_t *)&((ctx)->buffer)[(GFX_W(ctx) * (y) + (x)) * GFX_B(ctx)])
|
2012-02-04 05:47:36 +04:00
|
|
|
#define SPRITE(sprite,x,y) sprite->bitmap[sprite->width * (y) + (x)]
|
|
|
|
#define SMASKS(sprite,x,y) sprite->masks[sprite->width * (y) + (x)]
|
|
|
|
|
|
|
|
typedef struct sprite {
|
|
|
|
uint16_t width;
|
|
|
|
uint16_t height;
|
|
|
|
uint32_t * bitmap;
|
|
|
|
uint32_t * masks;
|
|
|
|
uint32_t blank;
|
|
|
|
uint8_t alpha;
|
|
|
|
} sprite_t;
|
2012-01-30 03:05:42 +04:00
|
|
|
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
typedef struct context {
|
|
|
|
uint16_t width;
|
|
|
|
uint16_t height;
|
|
|
|
uint16_t depth;
|
|
|
|
uint32_t size;
|
|
|
|
char * buffer;
|
|
|
|
char * backbuffer;
|
|
|
|
} gfx_context_t;
|
2012-01-30 03:05:42 +04:00
|
|
|
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
gfx_context_t * init_graphics_fullscreen();
|
|
|
|
gfx_context_t * init_graphics_fullscreen_double_buffer();
|
2012-02-04 05:47:36 +04:00
|
|
|
|
2012-09-14 09:12:47 +04:00
|
|
|
#define ALPHA_OPAQUE 0
|
|
|
|
#define ALPHA_MASK 1
|
|
|
|
#define ALPHA_EMBEDDED 2
|
|
|
|
#define ALPHA_INDEXED 3
|
|
|
|
|
2012-01-30 03:05:42 +04:00
|
|
|
uint32_t rgb(uint8_t r, uint8_t g, uint8_t b);
|
2012-09-14 10:22:38 +04:00
|
|
|
uint32_t rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
2012-01-30 03:05:42 +04:00
|
|
|
uint32_t alpha_blend(uint32_t bottom, uint32_t top, uint32_t mask);
|
2012-09-14 09:12:47 +04:00
|
|
|
uint32_t alpha_blend_rgba(uint32_t bottom, uint32_t top);
|
2012-02-04 05:47:36 +04:00
|
|
|
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
void flip(gfx_context_t * ctx);
|
|
|
|
void clear_buffer(gfx_context_t * ctx);
|
2012-02-04 05:47:36 +04:00
|
|
|
|
2012-10-16 10:04:33 +04:00
|
|
|
gfx_context_t * init_graphics_sprite(sprite_t * sprite);
|
|
|
|
sprite_t * create_sprite(size_t width, size_t height, int alpha);
|
|
|
|
|
|
|
|
void blur_context(gfx_context_t * _dst, gfx_context_t * _src, double amount);
|
2014-04-02 08:23:22 +04:00
|
|
|
void blur_context_no_vignette(gfx_context_t * _dst, gfx_context_t * _src, double amount);
|
2014-06-01 12:33:25 +04:00
|
|
|
void blur_context_box(gfx_context_t * _src, int radius);
|
2012-10-16 10:04:33 +04:00
|
|
|
void sprite_free(sprite_t * sprite);
|
|
|
|
|
2012-02-04 05:47:36 +04:00
|
|
|
void load_sprite(sprite_t * sprite, char * filename);
|
2012-09-13 09:10:10 +04:00
|
|
|
int load_sprite_png(sprite_t * sprite, char * file);
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
void draw_sprite(gfx_context_t * ctx, sprite_t * sprite, int32_t x, int32_t y);
|
2012-04-17 23:25:03 +04:00
|
|
|
void draw_line(gfx_context_t * ctx, int32_t x0, int32_t x1, int32_t y0, int32_t y1, uint32_t color);
|
|
|
|
void draw_line_thick(gfx_context_t * ctx, int32_t x0, int32_t x1, int32_t y0, int32_t y1, uint32_t color, char thickness);
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
void draw_fill(gfx_context_t * ctx, uint32_t color);
|
|
|
|
|
2012-11-17 06:37:12 +04:00
|
|
|
void draw_sprite_scaled(gfx_context_t * ctx, sprite_t * sprite, int32_t x, int32_t y, uint16_t width, uint16_t height);
|
2015-04-05 08:19:14 +03:00
|
|
|
void draw_sprite_scaled_alpha(gfx_context_t * ctx, sprite_t * sprite, int32_t x, int32_t y, uint16_t width, uint16_t height, float alpha);
|
2012-11-17 06:37:12 +04:00
|
|
|
|
2012-10-08 11:17:50 +04:00
|
|
|
void context_to_png(FILE * file, gfx_context_t * ctx);
|
2012-02-04 05:47:36 +04:00
|
|
|
|
2013-03-29 11:34:12 +04:00
|
|
|
uint32_t premultiply(uint32_t color);
|
|
|
|
|
|
|
|
|
2012-02-04 05:47:36 +04:00
|
|
|
#endif
|