LESS CODE IS BETTER CODE
This commit is contained in:
parent
aa326c30df
commit
65663b9722
|
@ -1,19 +1,13 @@
|
|||
(fn attach-imstate [view]
|
||||
(set view.imstate {:x (love.mouse.getX) :y (love.mouse.getY)})
|
||||
(set view.imstate {})
|
||||
(local cls view.__index)
|
||||
(fn view.on_mouse_pressed [self button x y clicks]
|
||||
(tset self.imstate button :pressed)
|
||||
(set self.imstate.x x)
|
||||
(set self.imstate.y y)
|
||||
(cls.on_mouse_pressed self button x y clicks))
|
||||
(fn view.on_mouse_moved [self x y dx dy]
|
||||
(set self.imstate.x x)
|
||||
(set self.imstate.y y)
|
||||
(cls.on_mouse_moved self x y dx dy))
|
||||
(fn view.on_mouse_released [self button x y]
|
||||
(tset self.imstate button :released)
|
||||
(set self.imstate.x x)
|
||||
(set self.imstate.y y)
|
||||
(cls.on_mouse_released self button x y))
|
||||
(fn view.draw [self]
|
||||
(cls.draw self)
|
||||
|
@ -32,16 +26,17 @@
|
|||
:table (table.concat tag "::")
|
||||
_ (tostring tag)))
|
||||
|
||||
(fn mouse-inside [view x y w h]
|
||||
(and (>= view.imstate.x x) (<= view.imstate.x (+ x w)) (>= view.imstate.y y) (<= view.imstate.y (+ y h))))
|
||||
(fn mouse-inside [x y w h]
|
||||
(local (mx my) (values (love.mouse.getX) (love.mouse.getY)))
|
||||
(and (>= mx x) (<= mx (+ x w)) (>= my y) (<= my (+ y h))))
|
||||
|
||||
(fn activate [view tag x y w h]
|
||||
(when (and (= view.imstate.left :pressed) (mouse-inside view x y w h))
|
||||
(when (and (= view.imstate.left :pressed) (mouse-inside x y w h))
|
||||
(set view.imstate.active (make-tag tag))
|
||||
true))
|
||||
(fn active? [view tag] (= view.imstate.active (make-tag tag)))
|
||||
(fn button [view tag x y w h]
|
||||
(activate view tag x y w h)
|
||||
(and (active? view tag) (= view.imstate.left :released) (mouse-inside view x y w h)))
|
||||
(and (active? view tag) (= view.imstate.left :released) (mouse-inside x y w h)))
|
||||
|
||||
{: attach-imstate : mouse-inside : activate : active? : button}
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
(if (or (= bitx 0) (= bitx 15))
|
||||
(draw-bit-color bit px py)
|
||||
(draw-bit bit px py (= (% bitx 2) 1)))
|
||||
(when (and (active? self :tile) (mouse-inside self px py pixel-size pixel-size))
|
||||
(when (and (active? self :tile) (mouse-inside px py pixel-size pixel-size))
|
||||
(when (= self.bit nil) (set self.bit (not bit)))
|
||||
(when (not= self.bit bit)
|
||||
(self:update-tile (set-tile-bit tile ibyte ibit self.bit))))))
|
||||
|
|
Loading…
Reference in a new issue