From c7a575d3fef907103a94ff444bb86c280e47148b Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 2 Apr 2021 11:11:44 +0530 Subject: add day 17 of devlog --- docs/posts/SDL2_devlog/index.html | 65 ++++++++++++++++++++++++++------------- docs/posts/index.html | 4 +-- 2 files changed, 45 insertions(+), 24 deletions(-) (limited to 'docs/posts') diff --git a/docs/posts/SDL2_devlog/index.html b/docs/posts/SDL2_devlog/index.html index 80cb297..6b5fd96 100644 --- a/docs/posts/SDL2_devlog/index.html +++ b/docs/posts/SDL2_devlog/index.html @@ -25,15 +25,15 @@ ">View Raw
- 01/04 — 2021 + 02/04 — 2021
- 93.51 + 105.89 cm   - 7.5 + 8.1 min
@@ -43,29 +43,50 @@

I have been working on an editor for the One Bit Image file format in Rust and SDL2. This entry in my blog follows my progress on the editor. The days are listed in reverse chronological order, begin from the bottom, if this is your first time on this page.

+

Day 17

+

I decided to give the text-only statusline a touch up, by adding a active color and dither level preview. Aligning the “widget” to the right of statusline involved a lot more than I thought, so I created a ghetto CSS-like rectangle placement system to position containers inside containers:

+
// roughly something like this
+let statusline = 
+    Container::new(Offset::Left(0), Offset::Bottom(40))
+    .width(Size::Max)
+    .height(Size::Absolute(20));
+    
+let mut primary = Container::uninit()
+    .width(Size::Absolute(16))
+    .height(Size::Absolute(16));
+
+container.place(
+    &mut padding_box,
+    HorAlign::Right,
+    VertAlign::Center
+);
+

The result (brush preview on the bottom right):

+
+ +

Day 16

The embedded lisp is coming along nicely, users can load a custom rc.lisp, which is evaluated on startup. To disable to grid on start, for example:

-
;;; rc.lisp
-(toggle-grid)
-

Some aliases to switch between brushes:

;;; rc.lisp
-(define (brush kind)
-  (cond
-    ((eq? kind 'f) (brush-fill))
-    ((eq? kind 'c) (brush-circle))
-    ((eq? kind 'l) (brush-line))
-    ((eq? kind 'l+) (brush-line-extend))
-    (else (brush-circle))))
+(toggle-grid)
+

Some aliases to switch between brushes:

+
;;; rc.lisp
+(define (brush kind)
+  (cond
+    ((eq? kind 'f) (brush-fill))
+    ((eq? kind 'c) (brush-circle))
+    ((eq? kind 'l) (brush-line))
+    ((eq? kind 'l+) (brush-line-extend))
+    (else (brush-circle))))

The following script draws a straight line along a given axis, at a given distance from the canvas boundary:

Day 15

I began writing a standard library for the lisp, in lisp. It includes basic list operations: car, cdr, null?, list, higher order functions: map, filter, fold:

-
(define (member? item ls)
-  (fold #f
-        (lambda (acc x) (or acc (eq? item x)))
-        ls))
+
(define (member? item ls)
+  (fold #f
+        (lambda (acc x) (or acc (eq? item x)))
+        ls))

Day 14

I attempted a small art piece using the editor, while it was largely usable, I felt a certain lack of feedback. The brushes just didn’t relay as much info as I’d have liked, for example, the approximate points of the line or the angle made by the line against the x-axis. Unfortunately, the existing infrastructure around brushes and line drawing didn’t easily allow for this either. I went ahead and reimplemented brushes, and added a new flood fill brush too:

@@ -98,11 +119,11 @@

Day 8

One of my favourite features of GIMP was symmetric editing. I added some coordinate geometry primitives to my pixmap abstraction, allowing for mirroring and reflecting figures about lines or points. The result was an ergonomic function that applies symmetry to any painting operation, (undo/redo works as expected):

-
let line = self.pixmap.get_line(start, end);
-let sym_line = self.symmetry.apply(&line);
-for point on line.extend(sym_line) {
-    // draw to window
-}
+
let line = self.pixmap.get_line(start, end);
+let sym_line = self.symmetry.apply(&line);
+for point on line.extend(sym_line) {
+    // draw to window
+}
diff --git a/docs/posts/index.html b/docs/posts/index.html index 697b522..8dcf25c 100644 --- a/docs/posts/index.html +++ b/docs/posts/index.html @@ -27,7 +27,7 @@
- 01/04 — 2021 + 02/04 — 2021
SDL2 Devlog @@ -35,7 +35,7 @@ - 7.5 + 8.1 min -- cgit v1.2.3