summaryrefslogtreecommitdiff
path: root/graphics.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2024-02-11 15:18:27 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2024-02-11 15:18:27 +0000
commit7aeae86d36a1a04e93bb4be2216cb735acfab714 (patch)
tree88d113a905ea73fb2f32cc43283bed3decae3e76 /graphics.c
parent7c6a945996a1d5510ff1412320ac7d07a0f82851 (diff)
More work
Diffstat (limited to 'graphics.c')
-rw-r--r--graphics.c81
1 files changed, 62 insertions, 19 deletions
diff --git a/graphics.c b/graphics.c
index 7339d8f..cb1127f 100644
--- a/graphics.c
+++ b/graphics.c
@@ -10,21 +10,56 @@
Mousectl *mouse;
Keyboardctl *keyboard;
Channel *updatechan;
+Channel *mkcolourchan;
+Channel *newcolourchan;
void
drawgui(GuiElement *g)
{
+ rlock(&g->lock);
GuiSpec spec = guispecs[g->type];
- spec.draw(g);
- for(int i = 0; i < g->nchildren; i++)
- drawgui(g->children[i]);
-}
-void
-drawnone(GuiElement *g)
-{
- Image *bg = getprop(g, Pbackground).colour->image;
- draw(screen, g->rect, bg, nil, ZP);
+ if(memcmp(&g->rect, &g->border, sizeof(Rectangle)) != 0 && Dx(g->border) > 0 && Dy(g->border) > 0){
+ /* draw the border first */
+ Image *bc = getprop(g, Pbordercolour).colour->image;
+ Rectangle r;
+
+ /* top part */
+ r.min.x = g->border.min.x;
+ r.min.y = g->border.min.y;
+ r.max.x = g->border.max.x;
+ r.max.y = g->rect.min.y;
+ draw(screen, r, bc, nil, ZP);
+
+ /* right part */
+ r.min.x = g->rect.max.x;
+ r.min.y = g->rect.min.y;
+ r.max.x = g->border.max.x;
+ r.max.y = g->border.max.y;
+ draw(screen, r, bc, nil, ZP);
+
+ /* bottom part */
+ r.min.x = g->border.min.x;
+ r.min.y = g->rect.max.y;
+ r.max.x = g->border.max.x;
+ r.max.y = g->border.max.y;
+ draw(screen, r, bc, nil, ZP);
+
+ /* left part */
+ r.min.x = g->border.min.x;
+ r.min.y = g->border.min.y;
+ r.max.x = g->rect.min.x;
+ r.max.y = g->border.max.y;
+ draw(screen, r, bc, nil, ZP);
+ }
+
+ if(Dx(g->rect) > 0 && Dy(g->rect) > 0){
+ spec.draw(g);
+
+ for(int i = 0; i < g->nchildren; i++)
+ drawgui(g->children[i]);
+ }
+ runlock(&g->lock);
}
void
@@ -37,13 +72,10 @@ drawcontainer(GuiElement *g)
Colour *
mkcolour(ulong c)
{
- lockdisplay(display);
- Colour *col = emalloc(sizeof(Colour));
- col->image = allocimage(display, Rect(0,0,1,1), screen->chan, 1, c);
- col->code = c;
- unlockdisplay(display);
-
- return col;
+ Colour *res = nil;
+ send(mkcolourchan, &c);
+ recv(newcolourchan, &res);
+ return res;
}
void
@@ -70,9 +102,9 @@ void
guiproc(void *)
{
int i;
+ ulong c;
if(initdraw(nil, nil, "guifs") < 0)
sysfatal("initdraw failed");
- display->locking = 1;
if((mouse = initmouse(nil, screen)) == nil)
sysfatal("initmouse failed");
@@ -83,6 +115,7 @@ guiproc(void *)
Aupdategui,
Aresize,
Amouse,
+ Amkcolour,
Aaltend,
};
Alt a[] = {
@@ -92,14 +125,14 @@ guiproc(void *)
{mouse->resizec, nil, CHANRCV},
[Amouse] =
{mouse->c, &mouse->Mouse, CHANRCV},
+ [Amkcolour] =
+ {mkcolourchan, &c, CHANRCV},
[Aaltend] =
{nil, nil, CHANEND},
};
while(1){
- unlockdisplay(display);
int which = alt(a);
- lockdisplay(display);
switch(which){
case Aupdategui:
@@ -110,6 +143,14 @@ guiproc(void *)
break;
case Amouse:
break;
+ case Amkcolour:
+ {
+
+ Colour *col = emalloc(sizeof(Colour));
+ col->image = allocimage(display, Rect(0,0,1,1), screen->chan, 1, c);
+ col->code = c;
+ send(newcolourchan, &col);
+ }
}
}
}
@@ -118,6 +159,8 @@ void
initgraphics(void)
{
updatechan = chancreate(sizeof(int), 0);
+ mkcolourchan = chancreate(sizeof(ulong), 0);
+ newcolourchan = chancreate(sizeof(Colour *), 0);
proccreate(guiproc, nil, mainstacksize);
updategui(1);
}