Would it be a good idea to create a Window_Selectable in the sprite class (Sprite_Selectable) instead since I'm not using any windowskins and since I've already turned most windows into sprites anyways?
One problem I run into is that the sprite class doesn't have the self.active method which would actually be a real issue.
You can implement both, but make sure that these lightweight windows don't turn out to consume more CPU power as the window class is optimized in C++ after all. Any Ruby implementation will be inferior so there is a limit to how much speed you can get even with a lightweight windowing system.
Luckly I found this in Ryex's Mouse_Window API script: :P
#==============================================================================
# Frame
#------------------------------------------------------------------------------
# Represents an advanced sprite class. It is lighter than a window and avoids
# usage of window specific additions that cannot be turned off. This class is
# abstract and should not be instanciated as such.
#==============================================================================
class Frame < Sprite
# constants
BORDER_COLOR = Color.new(255, 255, 255, 160)
BACK_COLOR = Color.new(0, 0, 0, 160)
# setting all accessible variables
attr_accessor :active
attr_reader :width
attr_reader :height
#----------------------------------------------------------------------------
# Initialization.
# x - x coordinate
# y - y coordinate
# width - width of the sprite
# height - height of the sprite
#----------------------------------------------------------------------------
def initialize(x, y, width, height)
# create the actual sprite
super()
# set dimensions
@width = width
@height = height
# create background sprite
create_background_sprite
# set position
self.x, self.y, self.z = x, y, 1000
# store variables
@active = true
end
#----------------------------------------------------------------------------
# Creates a background sprite.
#----------------------------------------------------------------------------
def create_background_sprite
# create background sprite
@background = Sprite.new
create_background_bitmap
end
#----------------------------------------------------------------------------
# Creates the background bitmap.
#----------------------------------------------------------------------------
def create_background_bitmap
@background.bitmap = Bitmap.new(@width, @height)
@background.bitmap.fill_rect(0, 0, @width, @height, BORDER_COLOR)
@background.bitmap.fill_rect(1, 1, @width - 2, @height - 2, BACK_COLOR)
end
#----------------------------------------------------------------------------
# Updates the background sprite.
#----------------------------------------------------------------------------
def update_background
@background.x, @background.y, @background.z = self.x, self.y, self.z - 100
end
#----------------------------------------------------------------------------
# Changes the sprite width.
# value - new width
#----------------------------------------------------------------------------
def width=(value)
# if width had changed
if @width != value
# delete old bitmap
@background.bitmap.dispose if @background.bitmap != nil
@width = value
# create new background bitmap
create_background_bitmap
end
end
#----------------------------------------------------------------------------
# Changes the sprite height.
# value - new height
#----------------------------------------------------------------------------
def height=(value)
# if width had changed
if @height != value
# delete old bitmap
@background.bitmap.dispose if @background.bitmap != nil
@height = value
# create new background bitmap
create_background_bitmap
end
end
#----------------------------------------------------------------------------
# Changes sprite x.
# value - new x coordinate
#----------------------------------------------------------------------------
def x=(value)
super
update_background
end
#----------------------------------------------------------------------------
# Changes sprite y.
# value - new y coordinate
#----------------------------------------------------------------------------
def y=(value)
super
update_background
end
#----------------------------------------------------------------------------
# Changes sprite z.
# value - new z coordinate
#----------------------------------------------------------------------------
def z=(value)
super
update_background
end
#----------------------------------------------------------------------------
# Refreshes the display. Abstract method.
#----------------------------------------------------------------------------
def refresh
end
#----------------------------------------------------------------------------
# Disposes the additional background sprite.
#----------------------------------------------------------------------------
def dispose
@background.dispose
super
end
end
#==============================================================================
# Frame
#------------------------------------------------------------------------------
# Represents an advanced sprite class. It is lighter than a window and avoids
# usage of window specific additions that cannot be turned off. This class is
# abstract and should not be instanciated as such.
#==============================================================================
class Frame < Sprite
attr_reader :viewport
# mod to add viewport handeling
alias viewport_addition_init initialize
def initialize(x, y, width, height, viewport = nil)
# create the actual sprite
if viewport.is_a?(Viewport)
super(viewport)
@viewport = viewport
@width = width
@height = height
# create background sprite
create_background_sprite
# set position
self.x, self.y, self.z = x, y, 1000
# store variables
else
viewport_addition_init(x, y, width, height)
end
end
alias viewport_addition_cbs create_background_sprite
def create_background_sprite
# create background sprite
if @viewport.is_a?(Viewport)
@background = Sprite.new(@viewport)
create_background_bitmap
else
viewport_addition_cbs
end
end
def visable=(value)
super
@background.visable = value if @background != nil && !@background.disposed?
end
end
This should work for what I'm doing. I guess the only way to consume less CPU power would be to create a dll file, which I don't really know how to do yet.
It's really not that hard, as long as you just want to work with bitmaps in the dll. Some source code is over on hbgames.