Advertisement
Guest User

Scroll-bar-problem

a guest
Nov 3rd, 2019
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 24.00 KB | None | 0 0
  1. ;; Load up cl-utilities, lispbuilder-sdl and lispbuilder-sdl-ttf  in quicklisp before loading this file!
  2. ;; (ql:quickload :cl-utilities)
  3. ;; (ql:quickload :lispbuilder-sdl)
  4. ;; (ql:quickload :lispbuilder-sdl-ttf)
  5.  
  6. ;; in main change the string containing the path to the font, to where you have the font ( c:/te/ in my case)
  7.  
  8.  
  9. (defparameter *scroll-boxes-list* nil) ; List of scroll boxes for the use of emptying when not clicked
  10. (defparameter *colors* `((white ,(sdl:color :r 255 :g 255 :b 255))
  11.              (black ,(sdl:color :r 0 :g 0 :b 0))
  12.              (darkgray ,(sdl:color :r 50 :g 50 :b 50))
  13.              (gray ,(sdl:color :r 160 :g 160 :b  160))
  14.              (lightgray ,(sdl:color :r 211 :g 211 :b 211))
  15.              (green ,(sdl:color :r 0 :g 255 :b 0))
  16.              (red ,(sdl:color :r 255 :g 0 :b 0))
  17.              (blue ,(sdl:color :r 0 :g 0 :b 255))
  18.              (cyan ,(sdl:color :r 0 :g 255 :b 255))
  19.              (yellow ,(sdl:color :r 255 :g 255 :b 0))))
  20.  
  21. (defclass pos ()
  22.   ((x :initarg :x :accessor x)
  23.    (y :initarg :y :accessor y))
  24.   (:documentation "Positions of an object, used as a super class for circle and rect"))
  25.  
  26. (defclass circle (pos)
  27.   ((radius :initarg :r :accessor r :documentation "The circle's radius"))
  28.   (:documentation "A cirlce"))
  29.  
  30. (defclass rect (pos)
  31.   ((w :initarg :w :accessor w)
  32.    (h :initarg :h :accessor h))
  33.   (:documentation "A rectangle"))
  34.  
  35.  
  36. (defun pixel-rect-collision-check (x y w h px py)
  37.   "pixel collision detection between pixel point and a rect"
  38.   (if (and (<= px (+ x w))
  39.        (>= px x)
  40.        (<= py (+ y h))
  41.        (>= py y))
  42.       t
  43.       nil))
  44.  
  45. (defmethod mouse-collision-check ((object rect))
  46.   (if (pixel-rect-collision-check (x object) (y object) (w object) (h object) (sdl:mouse-x) (sdl:mouse-y))
  47.       object
  48.       nil))
  49.  
  50. (defclass text-field (rect)
  51.   ((surface :accessor get-surface
  52.         :initarg :surface)
  53.    (text :accessor get-text
  54.           :initarg :text
  55.           :documentation "text to be used on the text-field")
  56.    (text-x :accessor get-text-x
  57.        :initarg :text-x)
  58.    (text-y :accessor get-text-y
  59.        :initarg :text-y)
  60.    (state :accessor get-text-field-state
  61.       :initarg :state)
  62.    (color :accessor get-box-color
  63.       :initarg :color)
  64.    (alpha :accessor get-alpha
  65.       :initarg :alpha)
  66.    (font :accessor get-text-font
  67.      :initarg :font
  68.      :Documentation "Font used by the textfield")
  69.    (background :accessor text-field-background
  70.            :initarg :background)
  71.    (amount-of-lines :accessor get-line-amount
  72.             :Documentation "The amount of lines the text-field hold"
  73.             :initarg :line-amount)
  74.    (hitbox :accessor get-hitbox
  75.        :initarg :hitbox)))
  76.  
  77.  
  78. (defclass scroll-box (rect)
  79.   ((surface :accessor get-surface
  80.         :initarg :surface)
  81.    (color :accessor get-box-color
  82.       :initarg :color)
  83.    (direction :accessor get-box-dir
  84.           :initarg :dir
  85.           :documentation "what cordinate to scroll")
  86.    (hitbox :accessor get-hitbox
  87.        :initarg :hitbox)
  88.    (active :accessor is-active-box?
  89.        :initform nil
  90.        :documentation "if the mouse is currently engaged in this box")))
  91.  
  92.  
  93. (defclass scroll-bar (rect)
  94.   ((surface :accessor get-surface
  95.         :initarg :surface)
  96.    (show :accessor show-scroll-bar?
  97.      :initarg :show)
  98.    (scroll-box :accessor get-scroll-box :initarg :scroll-box)
  99.    (hitbox :accessor get-hitbox :initarg :hitbox)
  100.    (bar-color :accessor get-bar-color :initarg :bar-color)
  101.    (box-color :accessor get-box-color :initarg :box-color)))
  102.  
  103.  
  104. (defgeneric change-surface (object &key alpha))
  105.  
  106.  
  107.  
  108. (defmethod change-surface ((object text-field) &key alpha)
  109.   (let* ((old-surface (get-surface object))
  110.      (surface (sdl:create-surface (sdl:width old-surface) (sdl:height old-surface) :alpha alpha)))
  111.    
  112.     ;; Ensures the textbox box-field is drawn on the surface before anything else
  113.     (when (text-field-background object)
  114.       (sdl:draw-box-* 0 0 (w object) (h object) :surface surface
  115.               :color (text-field-background object)))
  116.   (setf (get-surface object) surface)))
  117.  
  118. (defmethod change-surface ((object scroll-bar) &key alpha)
  119.   (let* ((old-surface (get-surface object))
  120.      (surface (sdl:create-surface (sdl:width old-surface) (sdl:height old-surface) :alpha alpha)))
  121.  
  122.     ;; Surface for the scroll-box is the same as the scroll-bar
  123.     (setf (get-surface (get-scroll-box object)) surface)
  124.     (setf (get-surface object) surface)))
  125.  
  126.  
  127.  
  128. (defun get-scrollbox-hitbox (scroll-bar)
  129.   (get-hitbox (get-scroll-box scroll-bar)))
  130.  
  131. (defmacro add-color (color &key (r 0) (g 0) (b 0))
  132.   "Add a color to the *colors* list"
  133.   `(push (list ',color (sdl:color :r ,r :g ,g :b ,b)) *colors*))
  134.  
  135. (defun find-color (color)
  136.   "helper function for get-color"
  137.   (cadr (assoc color *colors* :test #'string=)))
  138.  
  139. (defmacro get-color (color)
  140.   "Returns a chosen color from the list of SDL colors found in *colors*"
  141.   `(find-color ',color))
  142.  
  143. (defun get-rgb (&key (r 0) (g 0) (b 0))
  144.   "Get an SDL color object from passed R,G,B"
  145.   (sdl:color :r r :g g :b b))
  146.  
  147.  
  148. (defun get-font (&key (font (first *fonts*)) (size 15))
  149.   "Creates and initialise a font instance"
  150.   (sdl:initialise-font (make-instance 'sdl:ttf-font-definition :size size :filename (merge-pathnames font *font-path*))))
  151.  
  152. (defun draw-text (string point &key (color (get-color white)) (font sdl:*default-font*))
  153.   "Draw a text string on screen"
  154.   (sdl:draw-string-solid string point :color color :font font))
  155.  
  156.  
  157. (defun line-wraping (strings cordinate color boundry-x surface font start-x-pos start-y-pos
  158.              &aux (start-pos 0) (x-pos) (y-pos)
  159.                (space (sdl:get-font-size " " :size :w :font font))
  160.                (height (sdl:get-font-size " " :size :h :font font)))
  161. "Returns a vector with first value being the line amount, and second value the height of individual lines"
  162.  
  163.   (setf boundry-x (cond (boundry-x boundry-x)
  164.             (surface (sdl:width surface))
  165.             (t *width*))
  166.     start-pos (cond (start-x-pos start-x-pos)
  167.             (surface 0)
  168.             (t (elt cordinate 0)))
  169.     x-pos start-x-pos
  170.     y-pos (cond (start-y-pos start-y-pos)
  171.             (surface 0)
  172.             (t (elt cordinate 1))))
  173.  
  174.   (loop for i from 0 to (1- (length strings))
  175.     with line-amount = 1   
  176.     finally (return (vector line-amount height))
  177.     do
  178.    
  179.     (let* ((word (elt strings i))
  180.            (word-size (sdl:get-font-size word :size :w :font font)))
  181.      
  182.       ;; Check if the new word's positon will exceed the boundry set, if it does move it down one cordinate
  183.       (when (and (>= (+ x-pos word-size) boundry-x) (> i 0))
  184.         (incf line-amount)
  185.         (setf x-pos start-pos
  186.           y-pos (+ y-pos height)))
  187.  
  188.       ;; Only draws what can be seen
  189.       (when (and (>  y-pos  (- (sdl:y surface)  height)) (<  y-pos (sdl:height surface)))
  190.         (sdl:draw-string-solid word (vector x-pos y-pos) :color color :font font :surface surface))
  191.      
  192.       ;; Get the next position for the new word
  193.       (incf x-pos (+ word-size space)))))
  194.  
  195. (defgeneric draw-text-with-line-wrap (sentence cordinates
  196.                       &key color boundry-x surface font start-x start-y)
  197.   (:documentation "Draws either a text string, or a sequence of strings that wraps when it goes beyond the chosen bounds(boundry-x)"))
  198.  
  199. (defmethod draw-text-with-line-wrap ((sentence string) cordinates
  200.                      &key  (color (get-color white)) (boundry-x nil) surface
  201.                        (font sdl:*default-font*) start-x start-y)
  202.   (line-wraping (cl-utilities:split-sequence #\space sentence) cordinates  color boundry-x surface font start-x start-y))
  203.  
  204. ;; Change words to do subseq of sentence
  205. (defmethod draw-text-with-line-wrap ((sentence sequence) cordinates
  206.                      &key (color (get-color white)) (boundry-x nil) surface
  207.                        (font sdl:*default-font*) start-x start-y)
  208.  
  209.   (line-wraping sentence cordinates color  boundry-x surface font start-x start-y))
  210.  
  211.  
  212.  
  213. (defun draw-text-with-lines (words surface &key (font sdl:*default-font*)
  214.                          (color (get-color white))
  215.                          (height (sdl:get-font-size " " :size :h :font font))
  216.                          (x-pos 0) (y-pos 0)
  217.                          (start-line 0)
  218.                          (end-line (1- (length words))))
  219.  
  220.   (loop for i from start-line to end-line do
  221.        (let* ((word (elt words i)))
  222.       ;; Only draws what can be seen
  223.      (when (and (> y-pos (- (sdl:y surface) height)) (< y-pos (sdl:height surface)))
  224.        (sdl:draw-string-solid word (vector x-pos y-pos) :surface surface :font font :color color)))
  225.  
  226.     ;; Exit loop when we exceed what will be visible
  227.    
  228.     ;; Draw next line one down
  229.     (incf y-pos height)))
  230.  
  231. (defun list-to-string-list (list)
  232.   "Converts a list of strings into a single string as list"
  233.   (list (string-right-trim '(#\space) (format nil "~{~a ~}" list))))
  234.  
  235. (defun line-wrap-calc (words boundry font space start-pos)
  236.   "Seperate a list of words into lines of words based on maximum line-length allowed to be drawn(for use with draw-lines function)"
  237.  ; (unless space (setf space (sdl:get-font-size " " :size :w :font font)))
  238.   (let ((line-size start-pos)
  239.     (line-amount 1)
  240.     (first-loop t) ; Dont do boundry calculation on first loop
  241.     (line-list nil)
  242.     (current-line nil))
  243.  
  244.     (dolist (word words)
  245.       (let ((word-size (sdl:get-font-size word :size :w :font font)))
  246.  
  247.     ;; Check if our line exceeds the maximum line size
  248.     (if (and (>= (+ word-size line-size) boundry) (not first-loop))
  249.      ; (format t "yes! word = ~a~%" word)
  250.         (progn
  251.           (setf line-list (append line-list (list-to-string-list current-line)))
  252.           (setf line-size start-pos
  253.             current-line nil)
  254.           (incf line-amount)))
  255.    
  256.           (incf line-size (+ space word-size))
  257.     (setf first-loop nil) ; Turns off first-loop checky
  258.     (setf current-line (append current-line (list word)))))
  259.  
  260.     ;; Adds last line to list
  261.     (setf line-list (append line-list (list-to-string-list current-line)))
  262.  
  263.     ;; Returns the list of strings as an array, also the amount of lines and the font height as values
  264.     (values (make-array (length line-list) :initial-contents line-list)
  265.         line-amount
  266.         (sdl:get-font-size " " :size :h :font font))))
  267.  
  268.  
  269. (defgeneric line-wrapping (string boundry &key font space))
  270.  
  271. (defmethod line-wrapping ((string string) boundry &key (font sdl:*default-font*)
  272.                             (space (sdl:get-font-size " " :size :w :font font))
  273.                             (start-pos 0))
  274.   (line-wrap-calc (cl-utilities:split-sequence #\space string) boundry font space start-pos))
  275.  
  276. (defmethod line-wrapping ((string sequence) boundry  &key (font sdl:*default-font*)
  277.                                (space (sdl:get-font-size " " :size :w :font font))
  278.                                (start-pos 0))
  279.   (line-wrap-calc string boundry font space start-pos))
  280.  
  281.  
  282. (defun draw-debug-text (string point &key (color (get-color white)))
  283.   "Draws text that will only show up if debug is true"
  284.   (when *debug*
  285.     (sdl:draw-string-solid string point :color color)))
  286.  
  287.  
  288. (defun is-keys (&rest keys)
  289.   "Takes a list of keys and check if it's been pressed(through shf's global variable)"
  290.   (find-if #'(lambda (key) (member key *key-pressed-state*)) keys))
  291.  
  292. (defun get-pressed-key (&aux (key *key-pressed-code*))
  293.   "Get the current pressed key as character"
  294.   (unless key (setf key 0))
  295.    ; (unless (is-keys :sdl-key-up :sdl-key-down :sdl-key-left :sdl-key-right :sdl-key-lshift :sdl-key-rshift)
  296.       (code-char key))
  297.  
  298. (defun check-key (char)
  299.   "checks if passed char is the pressed key"
  300.   (when *key-pressed-code*
  301.     (if (equalp char (code-char *key-pressed-code*))
  302.     (code-char *key-pressed-code*)
  303.     nil)))
  304.  
  305. (defun change-default-font (font sdl:*default-font*)
  306.   "changes default font to passed font"
  307.   (unless (and (not (null font)) (sdl:initialise-default-font font))
  308.     (error "Cannot initialize the default font.")))
  309.  
  310. ;; Make it support image and transperancy
  311. (defun create-text-field (&key (x 0) (y 0) (w *width*) (h *height*) state
  312.                 (background (get-color white))
  313.                 (font sdl:*default-font*)
  314.                 text
  315.                 (text-x 0)
  316.                 (text-y 0)
  317.                 (hitbox-color background)
  318.                 (alpha 255)
  319.                 line-amount)
  320.   "Rewrite to create a text-field based on height\width parameters, and optional background,
  321. also create collision detection for mouse
  322.  
  323. Get the x,y,width,height, create a surface with width\height and draw it"
  324.  
  325.   (let ((surface (sdl:create-surface w h :alpha alpha)))
  326.     (when background
  327.       (sdl:draw-box-* 0 0 w h :surface surface
  328.               :color background))
  329.     (make-instance 'text-field :surface surface :x x :y y :w w :h h :state state
  330.            :background background :line-amount line-amount :font font
  331.            :text text :text-x text-x :text-y text-y
  332.  
  333.            ;; Unsure about hitbox for text-field, might not have one
  334.            :hitbox (make-instance 'rect :x x :y y :w w :h h)
  335.            )))
  336.  
  337.  
  338. (defun draw-text-on-text-field (textfield &key text (color (get-color white)))
  339.   "draws lines of text ontop of a text field"
  340.   (draw-text-with-lines  (if text text (get-text textfield))
  341.                  (get-surface textfield)
  342.                  :x-pos (get-text-x textfield) :y-pos (get-text-y textfield)
  343.                  :font (get-text-font textfield) :color color))
  344.  
  345. (defun draw-text-field (textfield)
  346.   "Draws the text field onto the screen"
  347.   (sdl:draw-surface-at-* (get-surface textfield) (x textfield) (y textfield)))
  348.  
  349. (defun draw-text-field-with-text (textfield &key text  (color (get-color white)))
  350.   "Draws both the lines of text ontop of a text field, and the text field itself onto the screen"
  351.   (draw-text-on-text-field textfield :text text :color color)
  352.   (draw-text-field textfield))
  353.  
  354. (defun add-to-scroll-box-list (scroll-box-instance)
  355.   (setf *scroll-boxes-list* (cons scroll-box-instance *scroll-boxes-list*))
  356.   scroll-box-instance)
  357.  
  358. (defun create-scroll-box (surface bar-x bar-y box-x box-y box-w box-h direction color hb-color)
  359.   "Creates the box used for scrolling in a scrollbar"
  360.   (add-to-scroll-box-list (make-instance 'scroll-box :surface surface :w box-w :h box-h :x box-x :y box-y :color color :dir direction
  361.                      :hitbox (make-instance 'rect :x bar-x :y bar-y :w box-w :h box-h))))
  362.  
  363.  
  364.  
  365. (defun create-scroll-bar (x y w h &key  (show t) (bar-color (get-color darkgray)) (alpha 255)
  366.                     (sb-x 0) (sb-y 0) (sb-w w) (sb-h h) (direction :y)
  367.                     (sb-color (get-color lightgray)) (sb-hitbox-color sb-color))
  368.   "Creates a scroll-bar"
  369.   (let* ((surface (sdl:create-surface w h :alpha alpha)))
  370.     (make-instance 'scroll-bar :surface surface :w w :h h :x x :y y :bar-color bar-color  :show show
  371.            :scroll-box (create-scroll-box surface x y sb-x sb-y sb-w sb-h direction sb-color sb-hitbox-color)))) ;:box-color box-color)))
  372.  
  373.  
  374. (defun draw-bar (scroll-bar)
  375.   (sdl:draw-box-* 0 0 (w scroll-bar) (h scroll-bar) :surface (get-surface scroll-bar) :color (get-bar-color scroll-bar)))
  376.  
  377. (defun draw-scroll-box (scroll-box)
  378.   "Draws the scroll-box"
  379.  
  380.   (sdl:draw-box-* (x scroll-box)
  381.           (y scroll-box) (w scroll-box) (h scroll-box)
  382.           :surface (get-surface scroll-box)
  383.           :color (get-box-color scroll-box)))
  384.  
  385. (defun draw-scroll-bar (scroll-bar) ;scroll-box)
  386.   "Draw the scroll-bar and scroll-box boxes to the scroll-bar surface, then draws the surface to screen"
  387.     (draw-bar scroll-bar)
  388.     (draw-scroll-box (get-scroll-box scroll-bar))
  389.    
  390.   (when (show-scroll-bar? scroll-bar)
  391.     (sdl:draw-surface-at-* (get-surface scroll-bar) (x scroll-bar) (y scroll-bar))))
  392.  
  393.  
  394. (defun calculate-scroll-box-height (scroll-bar text-height line-amount &key (min-size 5))
  395.   ""
  396.       (let* ((max (round (/ (h scroll-bar) text-height )))
  397.          (hidden-lines (- line-amount max))
  398.          (height (if (<= hidden-lines 0)
  399.              0
  400.             (round (/ (h scroll-bar)
  401.                  
  402.                   ;; Allows scrolling if only one line is hidden
  403.                   (if (= hidden-lines 1) 2 hidden-lines))))))
  404.           ;; If there are no lines hidden from view, make the scroll-box an height of 0
  405.     (values (if (< height min-size) min-size height)
  406.         max)))
  407.  
  408.  
  409. (defun scroll-box-active-mouse? (scroll-box )
  410.   "Changes the active state of the scroll-box if mouse is clicked on it"
  411.   (and (mouse-collision-check (get-hitbox scroll-box)) (sdl:mouse-left-p)
  412.        (setf (is-active-box? scroll-box) t)))
  413.  
  414.  
  415. (defun out-of-bounds? (box-pos box-size bar-size)
  416.   "Checks if the scroll box is out of bound of the bar"
  417.   (cond ((<= box-pos 0)
  418.      'start)
  419.     ((>= (+ box-size box-pos) bar-size)
  420.      'end)))
  421.  
  422. (defun get-new-scroll-box-pos (mouse-pos bar-pos bar-size box-pos  box-size)
  423.   "Returns the new position of the scroll box and it's hitbox in relative to the mouse position"
  424.   (let ((bounds (out-of-bounds? box-pos box-size bar-size)))
  425.     (cond ((and (string-equal bounds 'start) (< mouse-pos (+ bar-pos (round (/ box-size 2)))))
  426.        (values 0 bar-pos))
  427.       ((and (string-equal bounds 'end) (> mouse-pos (- (+ bar-size bar-pos) (round (/ box-size 2)))))
  428.        (values (- bar-size box-size)
  429.            (+ bar-pos box-pos)))
  430.       (t (values (- (- mouse-pos bar-pos) (round (/ box-size 2)))
  431.              (- mouse-pos (round (/ box-size 2))))))))
  432.  
  433.  
  434. (defun scrolling (scroll-bar &aux (scroll-box (get-scroll-box scroll-bar))
  435.                    (hitbox (get-hitbox scroll-box)))
  436.   "Call to automatically check for, and cause scrolling.
  437. Destructivly change the positions of scroll-bar, scroll-box(and it's hitbox)"
  438.   (scroll-box-active-mouse? scroll-box)
  439.   (when (is-active-box? scroll-box)
  440.     (cond ((string-equal (get-box-dir scroll-box) :y)
  441.        (setf (values (y scroll-box) (y hitbox))
  442.          (get-new-scroll-box-pos (sdl:mouse-y) (y scroll-bar)  (h scroll-bar)
  443.                      (y scroll-box) (h scroll-box))))
  444.      
  445.       ((string-equal (get-box-dir scroll-box) :x)
  446.        (setf (values (x scroll-box) (x hitbox))
  447.          (get-new-scroll-box-pos (sdl:mouse-x) (y scroll-bar) (w scroll-bar)
  448.                      (x scroll-box) (w scroll-box)))))))
  449.  
  450.  
  451.  
  452.  
  453. (defun text-field-shown-lines (text-field)
  454.   (floor (/ (h text-field) (sdl:get-font-size " " :size :h :font (get-text-font text-field)))))
  455.  
  456.  
  457. (defun line-pixels (text-field)
  458.   (* (- (get-line-amount text-field) (text-field-shown-lines text-field)) (sdl:get-font-size " " :size :h :font (get-text-font text-field))))
  459.  
  460. (defun get-max-box-pos (scroll-bar)
  461.   (- (h scroll-bar) (h (get-scroll-box scroll-bar))))
  462.  
  463. (defun get-movement-rate (text-field scroll-bar &aux (scroll-box (get-scroll-box scroll-bar)))
  464.   (let* ((max-box-pos (get-max-box-pos scroll-bar)))
  465.     (ceiling (/ (line-pixels text-field) (if (= max-box-pos 0) 1 max-box-pos)))))
  466.  
  467.  
  468. (defun hidden-lines (text-field)
  469.   (- (get-line-amount text-field) (text-field-shown-lines text-field)))
  470.  
  471.  
  472. (defun text-scrolling (text-field scroll-bar texts &key (color (get-color black))
  473.                &aux (scroll-box (get-scroll-box scroll-bar))
  474.              (fh (sdl:get-font-size " " :size :h :font (get-text-font text-field))))
  475.   (scrolling scroll-bar)
  476.  
  477.     ;; This is where the issue is!
  478.     (setf (get-text-y text-field) (-(* (get-movement-rate text-field scroll-bar) (y scroll-box)))))
  479.  
  480.  
  481. (defmacro with-window (width height fps title font-path def-font
  482.                &body body
  483.              &aux (font (gensym)))
  484.   `(sdl:with-init ()
  485.      ;;(init ,width ,height ,fps ,capture-mouse ,default-font)
  486.  
  487.  
  488.      (sdl:init-video)
  489.      (sdl:enable-unicode)
  490.      ;; Attempts to initialize the default font
  491.      (let ((,font (make-instance 'sdl:ttf-font-definition
  492.                  :size 10
  493.                  :filename  (merge-pathnames ,def-font ,font-path))))
  494.        (sdl:initialise-default-font ,font))
  495.      
  496.      
  497.      (sdl:window ,width ,height :title-caption ,title)
  498.      
  499.      (setf (sdl:frame-rate) ,fps)
  500.      ,@body))
  501.      
  502.  
  503.  
  504. (defun main ()
  505.     (with-window 500 500 60 "scroll-test" "c:/te/" "Vera.ttf"
  506.    
  507.         (let ((string "hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and ext string a text string and stuff for the purpose of testing hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string  and stuff like that and such hello there this is a text string a text string and stuff for the purpose of testing hello there this is a text string andr the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string is a text string for that and such hello there this is a textsuch hello there this is a text such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello such hello there this is a text there this is a text string for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing hello there this is a text string and stuff for the purpose of testing  that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string and stuff for the purpose of testing and stuff like that and such hello there this is a text string this is the end")
  508.               (text-field nil)
  509.               (scroll-bar nil)
  510.               (lines nil)
  511.               (tf-w 150)
  512.               (tf-h 150)
  513.               (tf-x 200)
  514.               (tf-y 50))
  515.           (setf (values string lines) (line-wrapping string tf-w))
  516.           (setf text-field (create-text-field :x tf-x :y tf-y :w tf-w :h tf-h :text string :line-amount lines))
  517.           (setf scroll-bar (create-scroll-bar (+ tf-x tf-w) tf-y  5 tf-h :sb-h 31 :direction :y ))
  518.           ;; Event Loops
  519.  
  520.                (sdl:with-events ()
  521.              (:quit-event () t)
  522.              (:mouse-button-up-event ()
  523.                          (dolist (sb *scroll-boxes-list*)
  524.                            (setf (is-active-box? sb) nil)))
  525.  
  526.              (:idle ()
  527.                 (sdl:clear-display (get-color black))
  528.        
  529.                 (te text-field scroll-bar)
  530.                 (draw-scroll-bar scroll-bar)
  531.                 (scrolling scroll-bar)
  532.                 (text-scrolling text-field scroll-bar string :color (get-color blue))
  533.                 (draw-text-field-with-text text-field :color (get-color blue))
  534.                 ;; Update display
  535.                 (sdl:update-display)
  536.                 )))))
  537.  
  538. (defun te (tf sb)
  539.   (change-surface tf :alpha 225)
  540.   (change-surface sb :alpha 225))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement