setos

拙OS
Log | Files | Refs | LICENSE

draw.h (1686B)


      1 // #include <libc.h>
      2 // #include <uefi.h>
      3 
      4 // low 8 bits represent alpha, next low 8 bits represent blue,
      5 // the next 8bits green, and the last red.
      6 // red is 0xff000000, green: 0x00ff0000, blue: 0x0000ff00.
      7 typedef unsigned int RGBA32;
      8 
      9 typedef struct Window Window;
     10 extern Window root_window;
     11 
     12 typedef struct Point {
     13 	int x, y;
     14 } Point;
     15 
     16 typedef struct Rectangle {
     17 	Point min; // upper left
     18 	Point max; // lower right
     19 } Rectangle;
     20 
     21 typedef struct Image {
     22 	Window    *window;
     23 	Rectangle r;
     24 } Image;
     25 
     26 #define MAX_CHILD_WIN 16 // TODO: dynamically allocate.
     27 typedef struct Window {
     28 	uint32    *fb;  // for the root window only. TODO: I think children need fb for optimization.
     29 	int       ppsl;
     30 	RGBA32    fg;
     31 	RGBA32    bg;
     32 	Window    *parent;
     33 	Point     pos;  // in parent cordinate system in pixels. TODO: should this be hidden?
     34 	Point     size;
     35 	Window    **children;
     36 	int       nchildren;
     37 } Window;
     38 
     39 typedef struct Mouse {
     40 	Point  size;
     41 	Point  pos;
     42 	RGBA32 *hidden;
     43 	RGBA32 *img;
     44 } Mouse;
     45 
     46 int init_root_window(uint32 *fb_base, int hres, int vres, int ppsl, EFI_GRAPHICS_PIXEL_FORMAT pf);
     47 extern void (* pixel)(Window *dst, Point p, RGBA32 col);
     48 extern RGBA32 (* get_pixel)(Window *win, Point at);
     49 void line(Window *dst, Point p0, Point p1, RGBA32 col);
     50 // i is the thickness of the border.
     51 // i = 0: one pixel line, i > 0: inside the border, i < 0: outside the border.
     52 void border(Window *dst, Rectangle r, int i, RGBA32 col);
     53 void fill(Window *dst, Rectangle r, RGBA32 col);
     54 void clear(Window *dst);
     55 int make_window(Window *parent, Window *child, Point at, Point size, RGBA32 fg, RGBA32 bg);
     56 void draw_mouse(Window *dst, Mouse *mouse);
     57 void clear_mouse(Window *dst, Mouse *mouse);