Remove SpriteWindowCursorRect & fix WindowCursorRect (#85)

* Remove SpriteWindowCursorRect
* Fix WindowCursorRect
- Use super
- Don't overwrite getters for x, y etc.
- Use self.x instead of @x, etc.
* Fix needs_update? using zeroes
* Rename WindowCursorRect#isEmpty? to #empty?
This commit is contained in:
Joni Savolainen
2021-02-01 21:57:54 +02:00
committed by GitHub
parent 9fe14395c0
commit 923844fdc7
2 changed files with 29 additions and 92 deletions

View File

@@ -1,59 +1,55 @@
class WindowCursorRect < Rect
def initialize(window)
@window=window
@x=0
@y=0
@width=0
@height=0
super(0, 0, 0, 0)
@window = window
end
attr_reader :x,:y,:width,:height
def empty
needupdate=@x!=0 || @y!=0 || @width!=0 || @height!=0
if needupdate
@x=0
@y=0
@width=0
@height=0
@window.width=@window.width
end
return unless needs_update?(0, 0, 0, 0)
set(0, 0, 0, 0)
end
def isEmpty?
return @x==0 && @y==0 && @width==0 && @height==0
def empty?
return self.x == 0 && self.y == 0 && self.width == 0 && self.height == 0
end
def set(x,y,width,height)
needupdate=@x!=x || @y!=y || @width!=width || @height!=height
if needupdate
@x=x
@y=y
@width=width
@height=height
@window.width=@window.width
end
def set(x, y, width, height)
return unless needs_update?(x, y, width, height)
super(x, y, width, height)
@window.width = @window.width
end
def height=(value)
@height=value; @window.width=@window.width
super(value)
@window.width = @window.width
end
def width=(value)
@width=value; @window.width=@window.width
super(value)
@window.width = @window.width
end
def x=(value)
@x=value; @window.width=@window.width
super(value)
@window.width = @window.width
end
def y=(value)
@y=value; @window.width=@window.width
super(value)
@window.width = @window.width
end
private
def needs_update?(x, y, width, height)
return self.x != x || self.y != y || self.width != width || self.height != height
end
end
class Window
attr_reader :tone
attr_reader :color
@@ -309,7 +305,7 @@ class Window
@cursoropacity+=8
@cursorblink=0 if @cursoropacity>=255
end
mustchange=true if !@cursor_rect.isEmpty?
mustchange=true if !@cursor_rect.empty?
else
mustchange=true if @cursoropacity!=128
@cursoropacity=128

View File

@@ -1,62 +1,3 @@
#===============================================================================
#
#===============================================================================
class SpriteWindowCursorRect < Rect
def initialize(window)
@window=window
@x=0
@y=0
@width=0
@height=0
end
attr_reader :x,:y,:width,:height
def empty
needupdate=@x!=0 || @y!=0 || @width!=0 || @height!=0
if needupdate
@x=0
@y=0
@width=0
@height=0
@window.width=@window.width
end
end
def isEmpty?
return @x==0 && @y==0 && @width==0 && @height==0
end
def set(x,y,width,height)
needupdate=@x!=x || @y!=y || @width!=width || @height!=height
if needupdate
@x=x
@y=y
@width=width
@height=height
@window.width=@window.width
end
end
def height=(value)
@height=value; @window.width=@window.width
end
def width=(value)
@width=value; @window.width=@window.width
end
def x=(value)
@x=value; @window.width=@window.width
end
def y=(value)
@y=value; @window.width=@window.width
end
end
#===============================================================================
# SpriteWindow is a class based on Window which emulates Window's functionality.
# This class is necessary in order to change the viewport of windows (with
@@ -156,7 +97,7 @@ class SpriteWindow < Window
@blend_type=0
@contents_blend_type=0
@contents_opacity=255
@cursor_rect=SpriteWindowCursorRect.new(self)
@cursor_rect=WindowCursorRect.new(self)
@cursorblink=0
@cursoropacity=255
@pause=false