Expansión de las clases Bitmap y Font Para ambos maker en 1 script.
Bueno si bien he estado en las lindas ‘campañas’ anti-alias y blah blah blah, decidí hacer un script simple, y que por supuesto sea compatible con ambos makers sin modificar nada.
Asi nació este pequeño script que agrega unas cuantas funciones interesantes a las clases Font y Bitmap
-Muchos recordarán que las letras en RM2k3 eran degradas, bueno ahora es posible con gradient_draw_text
-Corrige el bug de la opcion vertical de VX y obiamente agrega «gradient_fill_rect» al XP.
#===========================================================================
# ** Expansión de las clases Bitmap y Font [RMVX/RMXP]
#—————————————————————————
# por Ramiro
# V 1.0
#————————————————————————–
# Notas:
# Si se usa demasiado por escena puede generar bastante lag(en especial
# la gradiente)
#————————————————————————–
# Algunos datos:
# bug de gradient_fill_rect corregido(VX)
# nuevós metodos:
#
# Font
# Font#outline=(booleano), permite lineas alrededor del texto(en VX desactiva
# Font#automáticamente la sombrapara una mejor visualización)
# Font#outline_color1=(Color) El color interior del borde
# Font#outline_color2=(Color) El color exterior del borde
#
# Bitmap
#
# Bitmap#gradient_fill_rect(*argumentos) #[Agregado en XP]
# Bitmap#gradient_draw_text(*argumentos) Revisar el método para saber su uso
#
# PROHIBIDO PARA USO COMERCIAL
#===========================================================================
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
# correción para que acepte «outline» simple y/o doble
#————————————————————————–
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
# los parmátros son identicos a Gradient_fill_rect de VX,
# cualquier duda referirse a su documentación
# (Se le ha agregado una corrección al bug de «vertical»)
#————————————————————————–
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
#
# Argumentos:
#
# Rect,name,color1,color2,aling,vertical
# x,y,width.height,text,color1,color2,aling,vertical
# Rect, x, y, width,height, text y aling funcionan igual que el draw_text
# convencional
#
# Datos que varian:
# color1 = Color inicial del degradado
# color2 = Color Final del degradado
# vertical: si es true el degrado es vertical, sino horizontal
#
# – Parametrtos por defecto:
#
# aling = 0
# vertical = false
#
#————————————————————————–
# ¡Atención!
#
# Requiere conocimientos básicos del Bitmap#draw_text del rpg maker.
#————————————————————————–
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
Soy bueno y les dejó un preview de lo que se puede lograr con este código, y sin mucho esfuerzo si sabes las bases de ruby:
Ultimos comentarios