03-08-2010, 04:07 AM
(This post was last modified: 09-02-2024, 05:39 PM by DerVVulfman.)
Bitmap & Font expansion.
Description:
Well this scripts it's a nice one, it can work with XP and VX without any change. It makes new adds to Bitmap and Font Classes.
Its an scripter´s tool, not a 'plug & play' Script
Script:
Content Hidden
Code:
#===========================================================================
# ** Font & Bitmap Expansion [RMVX/RMXP]
#---------------------------------------------------------------------------
# by Ramiro
# V 1.0
#--------------------------------------------------------------------------
# Notes:
# may cause lag if you use it too mutch per scene
#--------------------------------------------------------------------------
# Sime tips:
# bug in gradient_fill_rect fixed(VX)
# new methods:
#
# Font
# Font#outline=(boolean), draw outline text (auto font shadow killer in VX for better look)
# Font#outline_color1=(Color) Internal outline color
# Font#outline_color2=(Color)External outline color
#
# Bitmap
#
# Bitmap#gradient_fill_rect(*arguments) #[New in XP]
# Bitmap#gradient_draw_text(*arguments) Take a look in gradient_draw_text method here for more info
#
# NOT FOR COMERTIAL USAGE
#===========================================================================
class Font
attr_accessor :outline
attr_accessor :outline_color1
attr_accessor :outline_color2
alias fond_expand_initialize initialize
def initialize
fond_expand_initialize
@outline = true
@outline_color1 = Color.new(0,0,0)
@outline_color2 = Color.new(0,0,0,0)
end
end
class Bitmap
#--------------------------------------------------------------------------
# Bitmap#draw_text
# for an "outline" look
#--------------------------------------------------------------------------
alias org_draw_text draw_text if !method_defined?('org_draw_text')
def draw_text(*args)
if args[0].is_a?(Rect)
x = args[0].x
y = args[0].y
w = args[0].width
h = args[0].height
text = args[1]
aling = args[2] if args[2]
else
x = args[0]
y = args[1]
w = args[2]
h = args[3]
text = args[4]
aling = args[5] if args[5]
end
aling = 0 if !aling
if font.outline
if font.respond_to?("shadow")
shval = font.shadow
font.shadow = false
end
color = font.color.clone
font.color = font.outline_color2
org_draw_text(x-2,y-2,w,h,text,aling)
org_draw_text(x,y-2,w,h,text,aling)
org_draw_text(x-2,y,w,h,text,aling)
org_draw_text(x+2,y+2,w,h,text,aling)
org_draw_text(x-2,y+2,w,h,text,aling)
org_draw_text(x+2,y-2,w,h,text,aling)
org_draw_text(x+2,y,w,h,text,aling)
org_draw_text(x,y+2,w,h,text,aling)
font.color = font.outline_color1
org_draw_text(x-1,y-1,w,h,text,aling)
org_draw_text(x,y-1,w,h,text,aling)
org_draw_text(x-1,y,w,h,text,aling)
org_draw_text(x+1,y+1,w,h,text,aling)
org_draw_text(x-1,y+1,w,h,text,aling)
org_draw_text(x+1,y-1,w,h,text,aling)
org_draw_text(x+1,y,w,h,text,aling)
org_draw_text(x,y+1,w,h,text,aling)
font.color = color.clone
font.shadow = shval if shval
end
org_draw_text(*args)
end
#--------------------------------------------------------------------------
# Bitmap#Gradient Fill Rect
# Its the same method than RMVX,
# if you need more info take a look at
# the RMVX manual
#--------------------------------------------------------------------------
def gradient_fill_rect(*args)
if args[0].is_a?(Rect)
x = args[0].x
y = args[0].y
w = args[0].width
h = args[0].height
c1 = args[1]
c2 = args[2]
v = args[3]
else
x = args[0]
y = args[1]
w = args[2]
h = args[3]
c1 = args[4]
c2 = args[5]
v = args[6]
end
v = false if !v
color_tones = []
if v
for i in 0...h
r = c1.red * (h - i) / h + c2.red * i / h
g = c1.green * (h - i) / h + c2.green * i / h
b = c1.blue * (h - i) / h + c2.blue * i / h
a = c1.alpha * (h - i) / h + c2.alpha * i / h
fill_rect(Rect.new(x,y+i,w,1),Color.new(r,g,b,a))
end
else
for i in 0...w
r = c1.red * (w - i) / w + c2.red * i / w
g = c1.green * (w - i) / w + c2.green * i / w
b = c1.blue * (w - i) / w + c2.blue * i / w
a = c1.alpha * (w - i) / w + c2.alpha * i / w
fill_rect(Rect.new(x+i,y,1,h),Color.new(r,g,b,a))
end
end
end
#--------------------------------------------------------------------------
# Bitmap#gradient_draw_text
#
# Arguments:
#
# Rect,name,color1,color2,aling,vertical
# x,y,width.height,text,color1,color2,aling,vertical
# Rect, x, y, width,height, text y aling wors exactly equal as the draw_text_method
#
# New Arguments:
# color1 = Initial gradient color
# color2 = End gradient color
# vertical: put it true if you want the gradient vertical
#
# - Default arguments:
#
# aling = 0
# vertical = false
#
#--------------------------------------------------------------------------
# ¡Atentio!
#
# If you want to use this please read about draw_text method
#--------------------------------------------------------------------------
def gradient_draw_text(*args)
if args[0].is_a?(Rect)
x = args[0].x
y = args[0].y
w = args[0].width
h = args[0].height
text = args[1]
color1 = args[2]
color2 = args[3]
aling = args[4] if args[4]
vertical = args[5] if args[5]
else
x = args[0]
y = args[1]
w = args[2]
h = args[3]
text = args[4]
color1 = args[5]
color2 = args[6]
aling = args[7] if args[7]
vertical = args[8] if args[8]
end
aling = 0 if !aling
vertical = false if !vertical
text_bmp = Bitmap.new(w,h)
text_bmp.font.name = font.name
text_bmp.font.size = font.size
text_bmp.font.shadow = false if text_bmp.font.respond_to?("shadow")
text_bmp.font.outline = false if text_bmp.font.respond_to?("outline")
text_bmp.font.border = false if text_bmp.font.respond_to?("border")
text_bmp.font.bold = font.bold
text_bmp.font.italic = font.italic
text_bmp.draw_text(0,0,w,h,text,aling)
gradient_bmp = Bitmap.new(w,h)
gradient_bmp.gradient_fill_rect(0, 0, w, h, color1, color2, vertical)
for x2 in 0...w
for y2 in 0...h
alpha_txt = text_bmp.get_pixel(x2,y2).alpha
if alpha_txt > 0
c = gradient_bmp.get_pixel(x2,y2)
c.alpha = alpha_txt
text_bmp.set_pixel(x2,y2,c)
end
end
end
draw_text(x,y,w,h,text,aling)
blt(x,y,text_bmp,Rect.new(0,0,w,h))
end
end
Screens:
Here there is a preview of what you can make with this
And the code for that:
Code:
class Window_Base
#--------------------------------------------------------------------------
# * Draw Name
# actor : actor
# x : draw spot x-coordinate
# y : draw spot y-coordinate
#--------------------------------------------------------------------------
def draw_actor_name(actor, x, y)
contents.gradient_draw_text(x,y,108,WLH,actor.name,Color.new(255,0,0),Color.new(0,255,0),0,false)
end
end
crédits:
Me of course
FAQ
- I don't have any.
Ok I hope you'll like it, see ya!