-
Notifications
You must be signed in to change notification settings - Fork 0
/
component.rkt
51 lines (35 loc) · 1.19 KB
/
component.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
#lang racket
(provide component%)
(define component%
(class object%
(init-field color)
(field [x 0] [y 0] [width 0] [height 0])
(define/public (get-x)
x)
(define/public (get-y)
y)
(define/public (set-x! new-x)
(set! x new-x))
(define/public (set-y! new-y)
(set! y new-y))
(define/public (set-width! new-width)
(set! width new-width))
(define/public (set-height! new-height)
(set! height new-height))
(define/public (set-size! width height)
(send this set-width! width)
(send this set-height! height))
(define/public (set-position! x y)
(send this set-x! x)
(send this set-y! y))
(define/public (contains-x? x)
(<= (send this get-x) x (+ (send this get-x) (send this get-width))))
(define/public (contains-y? y)
(<= (send this get-y) y (+ (send this get-y) (send this get-height))))
(define/public (contains? x y)
(and (send this contains-x? x)
(send this contains-y? y)))
(define/public (draw dc)
(send dc set-brush color 'solid)
(send dc draw-rectangle x y width height))
(super-new)))