Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commonization of graphical text buffer #1054

Merged
merged 39 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bcdc61b
split files/packages
cxxxr Aug 29, 2023
9ca21df
fix rendering process
cxxxr Sep 22, 2023
8de31e3
extract function
cxxxr Sep 22, 2023
a7a4bff
tweak method specializers
cxxxr Sep 22, 2023
4d9b30a
add v2 rendering flag
cxxxr Sep 22, 2023
c8235a1
separate folder, icon and emoji objects from text objects
cxxxr Sep 23, 2023
dfdec60
Support for display of control characters
cxxxr Sep 28, 2023
718a328
fix
cxxxr Sep 28, 2023
3e66eba
fix
cxxxr Sep 29, 2023
cad3e77
add assertion
cxxxr Sep 29, 2023
1457e7d
log:info -> log:error
cxxxr Sep 29, 2023
ff401f3
export attribute-foreground-color and attribute-background-color
cxxxr Sep 30, 2023
da78e5d
remove unused functions
cxxxr Sep 30, 2023
88dafde
export attribute-equal
cxxxr Sep 30, 2023
01cd4ec
change %render-line to lem-if:render-line
cxxxr Oct 1, 2023
40f4fd3
fix rendering cache
cxxxr Oct 1, 2023
89e8f84
refactor cursor drawing
cxxxr Oct 2, 2023
2da9ac3
explode
cxxxr Oct 2, 2023
4125298
export compute-left-display-area-content
cxxxr Oct 2, 2023
4694dd9
remove unused logical-line-equal
cxxxr Oct 3, 2023
d4e07d9
inline function
cxxxr Oct 3, 2023
f77f853
change to flet
cxxxr Oct 3, 2023
b4dab59
change file structure
cxxxr Oct 4, 2023
644427f
remove unused functions and slots
cxxxr Oct 4, 2023
38fec5c
set left-width
cxxxr Oct 4, 2023
d3403a2
remove unused slots
cxxxr Oct 4, 2023
6a1be5b
move modeline-elements in screen to window
cxxxr Oct 4, 2023
c92b575
move last-print-cursor in screen to window
cxxxr Oct 4, 2023
40c12f7
merge screen into window
cxxxr Oct 4, 2023
433ed79
export symbols
cxxxr Oct 4, 2023
daf2680
fix
cxxxr Oct 4, 2023
b96f9a2
rename overlay classes
cxxxr Oct 4, 2023
b980eab
rename object-equal to drawing-object-equal
cxxxr Oct 4, 2023
a2e7de6
remove unused class
cxxxr Oct 4, 2023
741d679
merge package
cxxxr Oct 4, 2023
8fb9a73
change redraw-display parameter to keyword
cxxxr Oct 6, 2023
0745a92
Change attempt to split string on wrap to binary search
cxxxr Oct 9, 2023
a0fcf84
fix argument
cxxxr Oct 9, 2023
675bf35
Forgive me for comment out a test that is failing
cxxxr Oct 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/lisp-mode/eval.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
(background-attribute
(make-attribute :background (compute-evaluated-background-color))))
(let ((popup-overlay
(make-overlay-line-endings
(make-line-endings-overlay
start
end
(or attribute
Expand Down
2 changes: 1 addition & 1 deletion extensions/vi-mode/visual.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
(defmethod state-setup ((state visual-line))
(apply-region-lines *start-point* (current-point)
(lambda (p)
(push (make-overlay-line p 'region)
(push (make-line-overlay p 'region)
*visual-overlays*))))

(defmethod state-setup ((state visual-block))
Expand Down
3 changes: 2 additions & 1 deletion frontends/ncurses/lem-ncurses.asd
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
(:file "clipboard")
(:file "style")
(:file "key")
(:file "ncurses")))
(:file "ncurses")
(:file "text-buffer-impl")))
5 changes: 3 additions & 2 deletions frontends/ncurses/ncurses.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@
bits))

(defun attribute-to-bits (attribute-or-name)
(let ((attribute (ensure-attribute attribute-or-name nil))
(cursorp (eq attribute-or-name 'cursor)))
(let* ((attribute (ensure-attribute attribute-or-name nil))
(cursorp (or (eq attribute-or-name 'cursor)
(and attribute (lem-core:attribute-value attribute :cursor)))))
(when (and lem-if:*background-color-of-drawing-window* (null attribute))
(setf attribute (make-attribute :background lem-if:*background-color-of-drawing-window*)))
(if (null attribute)
Expand Down
133 changes: 133 additions & 0 deletions frontends/ncurses/text-buffer-impl.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
(defpackage :lem-ncurses/text-buffer-impl
(:use :cl)
(:import-from :lem-core
:control-character-object
:cursor-attribute-p
:emoji-object
:eol-cursor-object
:eol-cursor-object-color
:extend-to-eol-object
:extend-to-eol-object-color
:folder-object
:icon-object
:image-object
:image-object-height
:image-object-image
:image-object-width
:line-end-object
:line-end-object-offset
:text-object
:text-object-attribute
:text-object-string
:text-object-surface
:text-object-type
:void-object
:window-view-height
:window-view-width
:text-object))
(in-package :lem-ncurses/text-buffer-impl)

(defgeneric object-width (drawing-object))

(defmethod object-width ((drawing-object void-object))
0)

(defmethod object-width ((drawing-object text-object))
(lem-core:string-width (text-object-string drawing-object)))

(defmethod object-width ((drawing-object eol-cursor-object))
0)

(defmethod object-width ((drawing-object extend-to-eol-object))
0)

(defmethod object-width ((drawing-object line-end-object))
0)

(defmethod object-width ((drawing-object image-object))
0)

(defmethod lem-if:view-width ((implementation lem-ncurses::ncurses) view)
(lem-ncurses::ncurses-view-width view))

(defmethod lem-if:view-height ((implementation lem-ncurses::ncurses) view)
(lem-ncurses::ncurses-view-height view))

(defgeneric draw-object (object x y window))

(defmethod draw-object ((object void-object) x y window)
(values))

(defmethod draw-object ((object text-object) x y window)
(let ((string (text-object-string object))
(attribute (text-object-attribute object)))
(when (and attribute (cursor-attribute-p attribute))
(lem-core::set-last-print-cursor window x y))
(lem-if:print (lem-core:implementation)
(lem-core::window-view window)
x
y
string
attribute)))

(defun color-to-hex-string (color)
(format nil "#~2,'0X~2,'0X~2,'0X"
(lem:color-red color)
(lem:color-green color)
(lem:color-blue color)))

(defmethod draw-object ((object eol-cursor-object) x y window)
(lem-core::set-last-print-cursor window x y)
(lem-if:print (lem:implementation)
(lem:window-view window)
x
y
" "
(lem:make-attribute :foreground
(color-to-hex-string (eol-cursor-object-color object)))))

(defmethod draw-object ((object extend-to-eol-object) x y window)
(lem-if:print (lem:implementation)
(lem:window-view window)
x
y
(make-string (- (lem:window-width window) x) :initial-element #\space)
(lem:make-attribute :background
(color-to-hex-string (extend-to-eol-object-color object)))))

(defmethod draw-object ((object line-end-object) x y window)
(let ((string (text-object-string object))
(attribute (text-object-attribute object)))
(lem-if:print (lem-core:implementation)
(lem-core::window-view window)
(+ x (line-end-object-offset object))
y
string
attribute)))

(defmethod draw-object ((object image-object) x y window)
(values))

(defmethod lem-if:render-line ((implementation lem-ncurses::ncurses) window x y objects height)
(let ((view (lem:window-view window)))
(charms/ll:wmove (lem-ncurses::ncurses-view-scrwin view) y x)
(charms/ll:wclrtoeol (lem-ncurses::ncurses-view-scrwin view))
(loop :for object :in objects
:do (draw-object object x y window)
(incf x (object-width object)))))

(defmethod lem-if:object-width ((implementation lem-ncurses::ncurses) drawing-object)
(object-width drawing-object))

(defmethod lem-if:object-height ((implementation lem-ncurses::ncurses) drawing-object)
1)

(defmethod lem-if:clear-to-end-of-window ((implementation lem-ncurses::ncurses) window y)
(let* ((view (lem-core::window-view window))
(win (lem-ncurses::ncurses-view-scrwin view)))
(unless (= y (lem-if:view-height (lem:implementation) view))
(charms/ll:wmove win y 0)
(charms/ll:wclrtobot win))))

(defmethod lem-if:get-char-width ((implementation lem-ncurses::ncurses))
1)
2 changes: 1 addition & 1 deletion frontends/sdl2/lem-sdl2.asd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(:file "font")
(:file "icon")
(:file "main")
(:file "text-buffer")
(:file "text-buffer-impl")
(:file "image-buffer")
(:file "tree")))

Expand Down
61 changes: 32 additions & 29 deletions frontends/sdl2/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@
(font-config-size (display-font-config *display*)))))))))

(defmethod get-display-font ((display display) &key type bold character)
(check-type type (member :latin :cjk :braille :emoji :icon))
(cond ((eq type :icon)
(check-type type lem-core::char-type)
(cond ((eq type :control)
(display-latin-font display))
((eq type :icon)
(or (and character (icon-font character))
(display-emoji-font display)))
((eq type :emoji)
Expand Down Expand Up @@ -243,14 +245,10 @@
(lem:update-on-display-resized))))

(defun attribute-foreground-color (attribute)
(or (and attribute
(lem:parse-color (lem:attribute-foreground attribute)))
(display-foreground-color *display*)))
(lem-core:attribute-foreground-color attribute))

(defun attribute-background-color (attribute)
(or (and attribute
(lem:parse-color (lem:attribute-background attribute)))
(display-background-color *display*)))
(lem-core:attribute-background-color attribute))

(defun render-fill-rect-to-current-texture (x y width height &key color)
(let ((x (* x (char-width)))
Expand Down Expand Up @@ -278,21 +276,23 @@
:dest-rect dest-rect
:flip (list :none))))

(defun cjk-char-code-p (display code)
(and (typep code '(UNSIGNED-BYTE 16))
(not (eql 0
(sdl2-ffi.functions:ttf-glyph-is-provided (display-cjk-normal-font display)
code)))))
(defun cjk-char-code-p (code)
(or (<= #x4E00 code #x9FFF)
(<= #x3040 code #x309F)
(<= #x30A0 code #x30FF)
(<= #xAC00 code #xD7A3)))

(defun latin-char-code-p (display code)
(and (typep code '(UNSIGNED-BYTE 16))
(not (eql 0
(sdl2-ffi.functions:ttf-glyph-is-provided (display-latin-font display)
code)))))
(defun latin-char-code-p (code)
(or (<= #x0000 code #x007F)
(<= #x0080 code #x00FF)
(<= #x0100 code #x017F)
(<= #x0180 code #x024F)))

(defun emoji-char-code-p (display code)
(and (typep code '(UNSIGNED-BYTE 16))
(not (eql 0 (sdl2-ffi.functions:ttf-glyph-is-provided (display-emoji-font display) code)))))
(defun emoji-char-code-p (code)
(or (<= #x1F300 code #x1F6FF)
(<= #x1F900 code #x1F9FF)
(<= #x1F600 code #x1F64F)
(<= #x1F700 code #x1F77F)))

(defun braille-char-code-p (code)
(<= #x2800 code #x28ff))
Expand Down Expand Up @@ -342,30 +342,29 @@
(sdl2:free-surface image)
(sdl2:destroy-texture texture)))

(defun guess-font-type (display code)
(cond #+windows
((eql code #x1f4c1)
;; sdl2_ttf.dllでなぜか絵文字を表示できないので代わりにフォルダの画像を使う
(defun guess-font-type (code)
(cond ((eql code #x1f4c1)
;; sdl2_ttf.dllでなぜか絵文字を表示できない環境があるので代わりにフォルダの画像を使う
:folder)
((<= code 128)
:latin)
((icon-char-code-p code)
:icon)
((braille-char-code-p code)
:braille)
((cjk-char-code-p display code)
((cjk-char-code-p code)
:cjk)
((latin-char-code-p display code)
((latin-char-code-p code)
:latin)
((emoji-char-code-p display code)
((emoji-char-code-p code)
:emoji)
(t
:emoji)))

(defun render-character (character x y &key color bold)
(handler-case
(let* ((code (char-code character))
(type (guess-font-type *display* code)))
(type (guess-font-type code)))
(case type
(:folder
(render-folder-icon x y)
Expand Down Expand Up @@ -886,6 +885,10 @@
(with-debug ("lem-if:get-background-color")
(display-background-color *display*)))

(defmethod lem-if:get-foreground-color ((implementation sdl2))
(with-debug ("lem-if:get-foreground-color")
(display-foreground-color *display*)))

(defmethod lem-if:update-foreground ((implementation sdl2) color)
(with-debug ("lem-if:update-foreground" color)
(setf (display-foreground-color *display*) (lem:parse-color color))))
Expand Down
Loading