-
Notifications
You must be signed in to change notification settings - Fork 0
/
tool.rkt
119 lines (98 loc) · 3.6 KB
/
tool.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#lang racket/base
(require drracket/tool
racket/class
racket/gui/base
racket/unit
mrlib/switchable-button)
(require brick-snip)
(provide tool@)
(define secret-key "egg")
(define to-insert "easter egg")
(define tool@
(unit
(import drracket:tool^)
(export drracket:tool-exports^)
#;(define easter-egg-mixin
(mixin ((class->interface text%)) ()
(inherit begin-edit-sequence
end-edit-sequence
insert
get-text)
(define/augment (on-insert start len)
(begin-edit-sequence))
(define/augment (after-insert start len)
(check-range (max 0 (- start (string-length secret-key)))
(+ start len))
(end-edit-sequence))
(define/augment (on-delete start len)
(begin-edit-sequence))
(define/augment (after-delete start len)
(check-range (max 0 (- start (string-length secret-key)))
start)
(end-edit-sequence))
(define/private (check-range start stop)
(let/ec k
(for ((x (in-range start stop)))
(define after-x
(get-text x (+ x (string-length secret-key))))
(when (string=? after-x secret-key)
(define before-x
(get-text (max 0 (- x (string-length to-insert))) x))
(unless (string=? before-x to-insert)
(insert to-insert x x)
(k (void)))))))
(super-new)))
(define reverse-button-mixin
(mixin (drracket:unit:frame<%>) ()
(super-new)
(inherit get-button-panel
get-definitions-text)
(inherit register-toolbar-button)
(let ((btn
(new switchable-button%
(label "New Brick")
(callback (λ (button)
(reverse-content
(get-definitions-text))))
(parent (get-button-panel))
(bitmap reverse-content-bitmap))))
(register-toolbar-button btn #:number 11)
(send (get-button-panel) change-children
(λ (l)
(cons btn (remq btn l)))))))
(define reverse-content-bitmap
(let* ((bmp (make-bitmap 16 16))
(bdc (make-object bitmap-dc% bmp)))
(send bdc erase)
(send bdc set-smoothing 'smoothed)
(send bdc set-pen "black" 1 'transparent)
(send bdc set-brush "blue" 'solid)
(send bdc draw-ellipse 2 2 8 8)
(send bdc set-brush "red" 'solid)
(send bdc draw-ellipse 6 6 8 8)
(send bdc set-bitmap #f)
bmp))
(define (reverse-content text)
(define start (box (send text last-position)))
(send text get-position start)
(send text insert (new brick-snip%) (unbox start) 0)
#;(
(for ((x (in-range 1 (send text last-position))))
(send text split-snip x))
(define snips
(let loop ((snip (send text find-first-snip)))
(if snip
(cons snip (loop (send snip next)))
'())))
(define released-snips
(for/list ((snip (in-list snips))
#:when (send snip release-from-owner))
snip))
(for ((x (in-list released-snips)))
(send text insert x 0 0))
)
)
(define (phase1) (void))
(define (phase2) (void))
#;(drracket:get/extend:extend-definitions-text easter-egg-mixin)
(drracket:get/extend:extend-unit-frame reverse-button-mixin)))