From 98a88c6ed20f4213f6e321d3657e53d27d3635b5 Mon Sep 17 00:00:00 2001 From: cxxxr Date: Sat, 23 Sep 2023 20:56:49 +0900 Subject: [PATCH] separate folder, icon and emoji objects from text objects --- frontends/sdl2/text-buffer-impl.lisp | 69 ++++++++++++++++++++-------- src/display-3.lisp | 22 ++++++--- 2 files changed, 66 insertions(+), 25 deletions(-) diff --git a/frontends/sdl2/text-buffer-impl.lisp b/frontends/sdl2/text-buffer-impl.lisp index 36a18443a..7913c3f0b 100644 --- a/frontends/sdl2/text-buffer-impl.lisp +++ b/frontends/sdl2/text-buffer-impl.lisp @@ -23,25 +23,44 @@ (attribute-font attribute)) (lem-sdl2::get-display-font lem-sdl2::*display* :type type :bold bold))) -(defun render-string (string attribute type) - (let ((foreground (lem-core::attribute-foreground-with-reverse attribute)) - (bold (and attribute (lem:attribute-bold attribute)))) +(defgeneric get-surface (drawing-object)) + +(defmethod get-surface :around (drawing-object) + (or (lem-core/display-3::text-object-surface drawing-object) + (setf (lem-core/display-3::text-object-surface drawing-object) + (call-next-method)))) + +(defmethod get-surface ((drawing-object lem-core/display-3::text-object)) + (let* ((attribute (lem-core/display-3::text-object-attribute drawing-object)) + (foreground (lem-core::attribute-foreground-with-reverse attribute))) + (cffi:with-foreign-string (c-string (lem-core/display-3::text-object-string drawing-object)) + (sdl2-ttf:render-utf8-blended + (get-font :attribute attribute + :type (lem-core/display-3::text-object-type drawing-object) + :bold (and attribute (lem:attribute-bold attribute))) + c-string + (lem:color-red foreground) + (lem:color-green foreground) + (lem:color-blue foreground) + 0)))) + +(defmethod get-surface ((drawing-object lem-core/display-3::icon-object)) + (let* ((string (lem-core/display-3::text-object-string drawing-object)) + (attribute (lem-core/display-3::text-object-attribute drawing-object)) + (font (lem-sdl2::icon-font (char (lem-core/display-3::text-object-string drawing-object) 0))) + (foreground (lem-core::attribute-foreground-with-reverse attribute))) (cffi:with-foreign-string (c-string string) - (sdl2-ttf:render-utf8-blended (get-font :attribute attribute - :type type - :bold bold) + (sdl2-ttf:render-utf8-blended font c-string (lem:color-red foreground) (lem:color-green foreground) (lem:color-blue foreground) 0)))) -(defmethod get-surface ((text-object lem-core/display-3::text-object)) - (or (lem-core/display-3::text-object-surface text-object) - (setf (lem-core/display-3::text-object-surface text-object) - (render-string (lem-core/display-3::text-object-string text-object) - (lem-core/display-3::text-object-attribute text-object) - (lem-core/display-3::text-object-type text-object))))) +(defmethod get-surface ((drawing-object lem-core/display-3::folder-object)) + (sdl2-image:load-image + (lem-sdl2::get-resource-pathname + "resources/open-folder.png"))) (defgeneric object-width (drawing-object)) @@ -49,9 +68,16 @@ 0) (defmethod object-width ((drawing-object lem-core/display-3::text-object)) - (if (eq :emoji (lem-core/display-3::text-object-type drawing-object)) - (* (lem-sdl2::char-width) 2 (length (lem-core/display-3::text-object-string drawing-object))) - (sdl2:surface-width (get-surface drawing-object)))) + (sdl2:surface-width (get-surface drawing-object))) + +(defmethod object-width ((drawing-object lem-core/display-3::icon-object)) + (sdl2:surface-width (get-surface drawing-object))) + +(defmethod object-width ((drawing-object lem-core/display-3::folder-object)) + (* 2 (lem-sdl2::char-width))) + +(defmethod object-width ((drawing-object lem-core/display-3::emoji-object)) + (* (lem-sdl2::char-width) 2 (length (lem-core/display-3::text-object-string drawing-object)))) (defmethod object-width ((drawing-object lem-core/display-3::eol-cursor-object)) 0) @@ -73,9 +99,16 @@ (lem-sdl2::char-height)) (defmethod object-height ((drawing-object lem-core/display-3::text-object)) - (if (eq :emoji (lem-core/display-3::text-object-type drawing-object)) - (lem-sdl2::char-height) - (sdl2:surface-height (get-surface drawing-object)))) + (sdl2:surface-height (get-surface drawing-object))) + +(defmethod object-height ((drawing-object lem-core/display-3::icon-object)) + (lem-sdl2::char-height)) + +(defmethod object-height ((drawing-object lem-core/display-3::folder-object)) + (lem-sdl2::char-height)) + +(defmethod object-height ((drawing-object lem-core/display-3::emoji-object)) + (lem-sdl2::char-height)) (defmethod object-height ((drawing-object lem-core/display-3::eol-cursor-object)) (lem-sdl2::char-height)) diff --git a/src/display-3.lisp b/src/display-3.lisp index ea6c399e6..4e03a95db 100644 --- a/src/display-3.lisp +++ b/src/display-3.lisp @@ -108,6 +108,10 @@ (type :initarg :type :reader text-object-type) (within-cursor :initform nil :initarg :within-cursor :reader text-object-within-cursor-p))) +(defclass icon-object (text-object) ()) +(defclass folder-object (text-object) ()) +(defclass emoji-object (text-object) ()) + (defclass eol-cursor-object (drawing-object) ((color :initarg :color :reader eol-cursor-object-color))) @@ -195,9 +199,13 @@ :attribute attribute :type type))) -(defun make-text-object (string attribute type) +(defun make-object-with-type (string attribute type) (let ((attribute (and attribute (lem-core:ensure-attribute attribute)))) - (make-instance 'text-object + (make-instance (case type + (:folder 'folder-object) + (:icon 'icon-object) + (:emoji 'emoji-object) + (otherwise 'text-object)) :string string :attribute attribute :type type @@ -235,7 +243,7 @@ (t (loop :for (type . string) :in (split-string-by-character-type string) :unless (alexandria:emptyp string) - :collect (make-text-object string attribute type)))))))) + :collect (make-object-with-type string attribute type)))))))) (defun create-drawing-objects (logical-line) (multiple-value-bind (items line-end-item) @@ -246,9 +254,9 @@ (create-drawing-object line-end-item))))) (defun make-letter-object (character attribute) - (make-text-object (string character) - attribute - (char-type character))) + (make-object-with-type (string character) + attribute + (char-type character))) (defun explode-object (text-object) (check-type text-object text-object) @@ -413,7 +421,7 @@ (redraw-lines window) (lem-core::update-screen-cache (lem-core:window-screen window) buffer)) -(defvar *v2* nil) +(defvar *v2* t) (defmethod lem-core::redraw-buffer (implementation (buffer lem-core:text-buffer) window force) (if *v2*