Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- #
- # Automatic Text Wrap (Sky00Valentines Updated Version)
- # To the best of my knowledge it is created by coolmariners98 (Atoria)
- # To my knowledge they also did not restrict use of this, so from
- # May 10, 2010 I will begin using it in conjuction with many scripts I
- # Write. Just so I have the quote from the header from where I go it from.
- #
- #
- # "Please do not copy and distribute claiming to have created this.
- # I would like full credit, even though this script is kind of crappy."
- # --------------------------------------------------------------------------
- # However I Sky00Valentine created all methods besides draw_wrap_text
- # with or without reference.
- #
- # also note that on boards I may say my version of Atoria's Auto Text
- # Wrap or SAATW.(Sky's Atoria's Auto Text Wrap) Because I have to let people
- # who use my script know what I am talking about as I use this a good bit.
- # I EDITED AN ALREADY EXISTING SCRIPT AND THE RESULT IS THIS.
- #==============================================================================
- class Bitmap
- def draw_wrap_text(x,y, width, height, text)
- array = text.split
- for i in array
- word = i + ' '
- word_width = text_size(word).width
- if x + word_width > width
- y += height
- x = 0
- end
- self.draw_text(x, y, 512, height, word)
- x += word_width
- end
- end
- #============================================================
- # New Method
- # Returns the height of a block of text that uses the
- # method draw_wrap_text.
- #============================================================
- def wrap_text_height(width,height,text = "",extra = true)
- array = text.split
- @extra_height = extra
- x = 0
- y = 0
- for i in array
- word = i + ' '
- word_width = text_size(word).width
- if x + word_width > width
- y += height
- x = 0
- end
- x += word_width
- end
- if @extra_height
- return y + height
- else
- return y
- end
- end
- def wrap_text_x(width,height,text = "")
- array = text.split
- x = 0
- y = 0
- for i in array
- word = i + ' '
- word_width = text_size(word).width
- if x + word_width > width
- y += height
- x = 0
- end
- x += word_width
- end
- return x - text_size(" ").width
- end
- def icon_text_right(y,width,height,text = "",iwidth = 24)
- array = text.split
- input_width = width
- for i in array.reverse
- if i.include?("/i[")
- num = i.delete("/i["+"]").to_i
- draw_icon(num,input_width - iwidth,y)
- input_width -= (iwidth + text_size(" ").width)
- else
- word_width = text_size(i).width
- draw_text(input_width - word_width,y,width,height,i)
- input_width -= (word_width + text_size(" ").width)
- end
- end
- end
- def icon_text(x,y,width,height,text = "",iwidth = 24)
- array = text.split
- input_x = x
- for i in array
- if i.include?("/i[")
- num = i.delete("i/i["+"]").to_i
- draw_icon(num,input_x,y)
- input_x += iwidth + text_size(" ").width
- else
- word_width = text_size(i).width
- draw_text(input_x,y,width,height,i)
- input_x += word_width + text_size(" ").width
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Icon
- # icon_index : Icon number
- # x : draw spot x-coordinate
- # y : draw spot y-coordinate
- # enabled : Enabled flag. When false, draw semi-transparently.
- #--------------------------------------------------------------------------
- def draw_icon(icon_index, x, y, enabled = true)
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- blt(x, y, bitmap, rect, enabled ? 255 : 128)
- end
- #==============================================================
- # New Method
- # For window's used only to show 1 line of text. It will
- # cut off any words that would make the line too long to
- # 'properly show'
- #==============================================================
- def draw_special_case(x,y,width, height, text)
- array = text.split
- for i in array
- word = i + ' '
- word_width = text_size(word).width
- self.draw_text(x, y, 512, height, word) unless word_width + x > width
- x += word_width
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement