shithub: blie

Download patch

ref: 1077381027fbb3b04aff7b5310f2fb744a8bf1fe
parent: 6772237407110a85e52893d91caba41969dad707
author: sirjofri <sirjofri@sirjofri.de>
date: Fri Aug 9 09:03:23 EDT 2024

adds editor initialization for static data

--- a/blie.c
+++ b/blie.c
@@ -16,6 +16,7 @@
 }
 
 int bliedebug = 0;
+int headless = 0;
 char Nlayers[] = "layers";
 char *root = nil;
 
@@ -427,6 +428,10 @@
 	if (memimageinit())
 		sysfatal("memimageinit: %r");
 	
+	headless = outputonly;
+	if (!headless)
+		if (initdraw(nil, nil, "blie") < 0)
+			sysfatal("initdraw: %r");
 	loadeditors();
 	
 	if (!loadfile())
@@ -436,9 +441,6 @@
 		outputcomposite();
 		exits(nil);
 	}
-	
-	if (initdraw(nil, nil, "blie") < 0)
-		sysfatal("initdraw: %r");
 	
 	einit(Emouse|Ekeyboard);
 	
--- a/blie.h
+++ b/blie.h
@@ -6,6 +6,7 @@
 extern Vdata vdata;
 extern Vstate vstate;
 extern int bliedebug;
+extern int headless;
 
 struct Layer {
 	char *name;
@@ -62,6 +63,7 @@
 
 struct Editor {
 	char *name;
+	void (*init)(void);
 	Memimage *(*composite)(Layer*, Memimage*);
 	Memimage *(*raw)(Layer*);
 	Memimage *(*mask)(Layer*);
--- a/editor.c
+++ b/editor.c
@@ -30,6 +30,8 @@
 	if (!firsteditor) {
 		firsteditor = mallocz(sizeof(Leditor), 1);
 		firsteditor->editor = ed;
+		if (ed->init)
+			ed->init();
 		return 1;
 	}
 	for (l = firsteditor; l->next; l = l->next)
@@ -37,6 +39,8 @@
 	l->next = mallocz(sizeof(Leditor), 1);
 	l = l->next;
 	l->editor = ed;
+	if (ed->init)
+		ed->init();
 	return 1;
 }
 
--- a/editor.txt
+++ b/editor.txt
@@ -5,6 +5,12 @@
 short name of the editor. Works as an identifier, must be unique!
 
 
+FUNCTION init (*)
+
+Initialize/load static data, like images and brushes.
+Will be called exactly once on startup.
+
+
 FUNCTION composite (*)
 
 param:  Layer*     Layer to work with
--- a/p9image.c
+++ b/p9image.c
@@ -39,6 +39,19 @@
 Tstate tstate;
 
 static void
+p9initialize()
+{
+	if (headless)
+		return;
+	
+	if (!tstate.circle) {
+		tstate.circle = allocimage(display, Rect(0, 0, 41, 41), RGBA32, 0, DTransparent);
+		ellipse(tstate.circle, Pt(20, 20), 19, 19, 0, display->white, ZP);
+		ellipse(tstate.circle, Pt(20, 20), 20, 20, 0, display->black, ZP);
+	}
+}
+
+static void
 p9init(Layer *l)
 {
 	int fd;
@@ -147,11 +160,6 @@
 	changecursor(nil, nil, ZP);
 	return 0;
 Mout:
-	if (!tstate.circle) {
-		tstate.circle = allocimage(display, Rect(0, 0, 41, 41), RGBA32, 0, DTransparent);
-		ellipse(tstate.circle, Pt(20, 20), 19, 19, 0, display->white, ZP);
-		ellipse(tstate.circle, Pt(20, 20), 20, 20, 0, display->black, ZP);
-	}
 	changecursor(&ccircle, tstate.circle, Pt(-20, -20));
 	if (!mi)
 		return 0;
@@ -221,6 +229,7 @@
 
 Editor p9image = {
 	.name = "p9img",
+	.init = p9initialize,
 	.raw = p9raw,
 	.mask = p9mask,
 	.overlay = p9overlay,