Skip to content

Graphical text buffer#854

Merged
cxxxr merged 12 commits intomainfrom
refactor-redraw-functions
Jul 31, 2023
Merged

Graphical text buffer#854
cxxxr merged 12 commits intomainfrom
refactor-redraw-functions

Conversation

@cxxxr
Copy link
Member

@cxxxr cxxxr commented Jul 19, 2023

Added a text buffer that can display text and images of different sizes.

Change details

  • Added a new class called graphical-text-buffer, which inherits from the existing text-buffer.
  • Added a new drawing method for the class
  • If the attribute contains a font or image value, it is displayed.
  • Not enabled by default because there are still some unimplemented features in graphical-text-buffer
    • Display on the left side of the screen, e.g line numbers
    • horizontal scroll
    • There is a process that assumes fixed-width characters in several places in the lem.

How to Activate

Change the class of the specified buffer to graphical-text-buffer to activate it.

For example

(change-class (lem:get-buffer "*tmp*") 'lem-sdl2::graphical-text-buffer)

Demo

(defvar *h1-font*
  (sdl2-ttf:open-font (lem-sdl2/resource:get-resource-pathname
                       "resources/fonts/FreeMono.ttf")
                      100))

(defvar *h2-font*
  (sdl2-ttf:open-font (lem-sdl2/resource:get-resource-pathname
                       "resources/fonts/FreeMono.ttf")
                      80))

(defvar *h3-font*
  (sdl2-ttf:open-font (lem-sdl2/resource:get-resource-pathname
                       "resources/fonts/FreeMono.ttf")
                      60))

(defvar *h4-font*
  (sdl2-ttf:open-font (lem-sdl2/resource:get-resource-pathname
                       "resources/fonts/FreeMono.ttf")
                      40))

(defvar *h1-attribute*
  (make-attribute :plist (list 'lem-sdl2::font *h1-font*)))

(defvar *h2-attribute*
  (make-attribute :plist (list 'lem-sdl2::font *h2-font*)))

(defvar *h3-attribute*
  (make-attribute :plist (list 'lem-sdl2::font *h3-font*)))

(defvar *h4-attribute*
  (make-attribute :plist (list 'lem-sdl2::font *h4-font*)))

(define-command demo () ()
  (let* ((buffer (make-buffer "*Demo*"))
         (point (buffer-point buffer)))
    (change-class buffer 'lem-sdl2::graphical-text-buffer)
    (let ((image (sdl2-image:load-image 
                  (asdf:system-relative-pathname :lem "frontends/sdl2/resources/icon.png"))))
      (insert-string point 
                     " "
                     :attribute (make-attribute :plist (list 'lem-sdl2::image image))))
    (insert-character point #\newline)
    (insert-string point (format nil "Hello World~%") :attribute *h1-attribute*)
    (insert-string point (format nil "Hello World~%") :attribute *h2-attribute*)
    (insert-string point (format nil "Hello World~%") :attribute *h3-attribute*)
    (insert-string point (format nil "Hello World~%") :attribute *h4-attribute*)
    (insert-string point (format nil "Hello World~%"))))

image

@cxxxr cxxxr force-pushed the refactor-redraw-functions branch 12 times, most recently from 2cce094 to 3887f7f Compare July 28, 2023 14:34
@cxxxr cxxxr force-pushed the refactor-redraw-functions branch from 3887f7f to 7387f0d Compare July 29, 2023 09:48
@cxxxr cxxxr force-pushed the refactor-redraw-functions branch from a70ec8c to c92b4d8 Compare July 30, 2023 07:02
@cxxxr cxxxr force-pushed the refactor-redraw-functions branch from 561e6e5 to f53ca60 Compare July 30, 2023 15:33
@cxxxr cxxxr changed the title Refactor redraw functions Graphical text buffer Jul 31, 2023
@cxxxr cxxxr marked this pull request as ready for review July 31, 2023 15:14
@cxxxr cxxxr merged commit 4fe17c8 into main Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant