Skip to content

Commit

Permalink
separate folder, icon and emoji objects from text objects
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed Sep 25, 2023
1 parent 7371238 commit 73ae424
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 25 deletions.
69 changes: 51 additions & 18 deletions frontends/sdl2/text-buffer-impl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,61 @@
(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))

(defmethod object-width ((drawing-object lem-core/display-3::void-object))
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)
Expand All @@ -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))
Expand Down
22 changes: 15 additions & 7 deletions src/display-3.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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*
Expand Down

0 comments on commit 73ae424

Please sign in to comment.