Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===========================================================================
- # ** 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
- 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]
- align = args[2] if args[2]
- else
- x = args[0]
- y = args[1]
- w = args[2]
- h = args[3]
- text = args[4]
- align = args[5] if args[5]
- end
- align = 0 if !align
- if font.outline
- color = font.color.clone
- font.color = Color.new(0,0,0)
- org_draw_text(x-1,y-1,w,h,text,align)
- org_draw_text(x,y-1,w,h,text,align)
- org_draw_text(x-1,y,w,h,text,align)
- org_draw_text(x+1,y+1,w,h,text,align)
- org_draw_text(x-1,y+1,w,h,text,align)
- org_draw_text(x+1,y-1,w,h,text,align)
- org_draw_text(x+1,y,w,h,text,align)
- org_draw_text(x,y+1,w,h,text,align)
- font.color = color.clone\
- 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,align,vertical
- # x,y,width.height,text,color1,color2,align,vertical
- # Rect, x, y, width,height, text y align 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:
- #
- # align = 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]
- align = 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]
- align = args[7] if args[7]
- vertical = args[8] if args[8]
- end
- align = 0 if !align
- 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,align)
- 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,align)
- blt(x,y,text_bmp,Rect.new(0,0,w,h))
- end
- end
Add Comment
Please, Sign In to add comment