ref: d7926bf6057714eb34c81b378c6e87e899406fea
parent: d92a4578490a554a34b3e81dd16129c6c96f3dcc
parent: 24b0ed8ccf3ea37334d4fc2d4c60d40c30d2c7a1
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Tue Aug 24 10:13:22 EDT 2021
Merge commit '24b0ed8ccf3ea37334d4fc2d4c60d40c30d2c7a1'
--- a/microui/LICENSE
+++ b/microui/LICENSE
@@ -1,5 +1,5 @@
Copyright (c) 2018-2019 rxi
-Copyright (c) 2020 ftrvxmtrx
+Copyright (c) 2020-2021 Sigrid Solveig Haflínudóttir
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
--- a/microui/demo/plan9.c
+++ b/microui/demo/plan9.c
@@ -16,6 +16,7 @@
char *s;
Biobuf *snarf;
Keyboardctl *kctl;
+ int redraw;
Rune key;
Mouse m;
Alt a[] = {
@@ -50,11 +51,13 @@
process_frame();
oldbuttons = 0;
+ redraw = 0;
for (;;) {
process_frame();
- if (mu_render())
+ if (mu_render(redraw))
flushimage(display, 1);
+ redraw = 0;
gotevent = 1;
switch (alt(a)) {
case 0: /* mouse */
@@ -79,6 +82,7 @@
case 1: /* resize */
getwindow(display, Refnone);
+ redraw = 1;
break;
case 2: /* keyboard */
--- a/microui/microui.c
+++ b/microui/microui.c
@@ -278,7 +278,7 @@
}
/* 32bit fnv-1a hash */
-#define HASH_INITIAL 2166136261
+#define HASH_INITIAL 2166136261U
static void
hash(mu_Id *hash, const void *data, int size)
@@ -516,10 +516,12 @@
mu_draw_rect(mu_Rect rect, Image *color)
{
mu_Command *cmd;
- rect = clip_rect(rect, mu_get_clip_rect());
+ mu_Rect clipped;
+ clipped = clip_rect(rect, mu_get_clip_rect());
if (rect.w > 0 && rect.h > 0) {
cmd = mu_push_command(MU_COMMAND_RECT);
- cmd->rect.rect = rect;
+ cmd->rect.rect = clipped;
+ cmd->rect.position = subpt(Pt(clipped.x, clipped.y), Pt(rect.x, rect.y));
cmd->rect.color = color;
}
}
@@ -1436,12 +1438,12 @@
}
int
-mu_render(void)
+mu_render(int force)
{
mu_Command *cmd;
mu_Rect r, iconr;
- if (memcmp(&mu_ctx.screen, &screen->r, sizeof(mu_ctx.screen)) != 0)
+ if (force || !eqrect(mu_ctx.screen, screen->r) != 0)
mu_ctx.screen = screen->r;
else if (mu_ctx.oldcmdsnum == mu_ctx.cmdsnum && memcmp(mu_ctx.oldcmds, mu_ctx.cmds, mu_ctx.cmdsnum*sizeof(mu_Command)) == 0)
if (mu_ctx.oldstrnum == mu_ctx.strnum && memcmp(mu_ctx.oldstr, mu_ctx.str, mu_ctx.strnum) == 0)
@@ -1470,7 +1472,7 @@
case MU_COMMAND_RECT:
if (cmd->rect.color != nil)
- draw(screen, screenrect(cmd->rect.rect), cmd->rect.color, nil, ZP);
+ draw(screen, screenrect(cmd->rect.rect), cmd->rect.color, nil, cmd->rect.position);
break;
case MU_COMMAND_ICON:
--- a/microui/microui.h
+++ b/microui/microui.h
@@ -1,6 +1,6 @@
#pragma lib "libmicroui.a"
-typedef unsigned mu_Id;
+typedef u32int mu_Id;
typedef struct mu_Command mu_Command;
typedef struct mu_Container mu_Container;
@@ -133,6 +133,7 @@
struct
{
Image *color;
+ Point position;
mu_Rect rect;
}rect;
@@ -253,7 +254,7 @@
Image *mu_color(u8int r, u8int g, u8int b, u8int a);
void mu_init(void);
-int mu_render(void);
+int mu_render(int force);
void mu_begin(void);
void mu_end(void);
void mu_set_focus(mu_Id id);
@@ -278,8 +279,8 @@
mu_Command *mu_push_command(int type);
void mu_set_clip(mu_Rect rect);
-void mu_draw_rect(mu_Rect rect, Image *color);
-void mu_draw_box(mu_Rect rect, Image *color);
+void mu_draw_rect(mu_Rect rect, Image *image);
+void mu_draw_box(mu_Rect rect, Image *image);
void mu_draw_text(Font *font, const char *str, int len, Point pos, Image *color);
void mu_draw_icon(int id, mu_Rect rect);