• R/O
  • SSH

rulp: 提交

The main repository for rulp in Mercurial


Commit MetaInfo

修订版f1cbf8d801a5acc3589a5a92c0bb19138831fc6d (tree)
时间2022-05-02 20:27:33
作者Giulio De Stasio <giuliods@user...>
CommiterGiulio De Stasio

Log Message

inverted rendering positions

更改概述

差异

diff -r 592642a7a3b1 -r f1cbf8d801a5 graphics/menu.lisp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/graphics/menu.lisp Mon May 02 13:27:33 2022 +0200
@@ -0,0 +1,51 @@
1+(in-package :graphics)
2+
3+(defparameter +menu-position+ nil)
4+(defparameter +menu-padding-x+ 300)
5+(defparameter +menu-padding-y+ 30)
6+
7+(defparameter +menu+ (list
8+ '(t "Toggle letters" (toggle-grid-letters))
9+ '(t "Toggle grid" (toggle-grid))
10+ '(+pointer+ "Move" nil)
11+ ))
12+
13+(defun display-menu (position)
14+ (when (null +menu-position+)
15+ (setf +menu-position+ position))
16+ (let ((menu-length (length +menu+)))
17+ (raylib:draw-rectangle-v +menu-position+
18+ (make-vector2 :x +menu-padding-x+ :y (* menu-length +menu-padding-y+))
19+ raylib:+white+)
20+ (loop :for e :in +menu+
21+ :for n :from 0 :to (length +menu+)
22+ :do
23+ (when (eval (car e))
24+ (raylib:draw-text (cadr e)
25+ (floor (raylib:vector2-x +menu-position+))
26+ (floor (+ (raylib:vector2-y +menu-position+) (* n +menu-padding-y+)))
27+ 30
28+ raylib:+black+)))
29+ ))
30+
31+(defun select-menu (position)
32+ (let* (;(position-x (raylib:vector2-x position))
33+ (position-y (raylib:vector2-y position))
34+ (relative-y (- position-y (raylib:vector2-y +menu-position+)))
35+ (value (floor (/ relative-y +menu-padding-y+)))
36+ )
37+ (when (and (> value -1) (< value (length +menu+)))
38+ (when (eval (car (nth value +menu+)))
39+ (eval (caddr (nth value +menu+)))))
40+ (setf +menu-position+ nil)
41+ (setf +mode+ '+normal-mode+)))
42+
43+;; The menu (kinda) works
44+;; There are two functions in this file: the display-menu function and the select-menu function.
45+;; The first is enabled when +menu-mode+ is active and display the menu with it's entries. Select-menu
46+;; on the other end check if select-menu is pressing something and eval the associated function.
47+;; in the +menu+ parameter it is possible to add everything in a specific pattern:
48+;;
49+;; The first is the condition, if this is t the option is displayed and usable
50+;; the second is the entry text, if the condition is t the entry text is displayed
51+;; the third is the eval expression, when pressed the entry this form is evaluated
Show on old repository browser