Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2011
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.47 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # Automatic Text Wrap (Sky00Valentines Updated Version)
  4. # To the best of my knowledge it is created by coolmariners98 (Atoria)
  5. # To my knowledge they also did not restrict use of this, so from
  6. # May 10, 2010 I will begin using it in conjuction with many scripts I
  7. # Write. Just so I have the quote from the  header from where I go it from.
  8. #
  9. #
  10. #  "Please do not copy and distribute claiming to have created this.
  11. #  I would like full credit, even though this script is kind of crappy."
  12. # --------------------------------------------------------------------------
  13. # However I Sky00Valentine created all methods besides draw_wrap_text
  14. # with or without reference.
  15. #
  16. # also note that on boards I may say my version of Atoria's Auto Text
  17. # Wrap or SAATW.(Sky's Atoria's Auto Text Wrap) Because I have to let people
  18. # who use my script know what I am talking about as I use this a good bit.
  19. # I EDITED AN ALREADY EXISTING SCRIPT AND THE RESULT IS THIS.
  20. #==============================================================================
  21.  
  22. class Bitmap
  23.   def draw_wrap_text(x,y, width, height, text)
  24.     array = text.split
  25.     for i in array
  26.       word = i + ' '
  27.       word_width = text_size(word).width
  28.       if x + word_width > width
  29.         y += height
  30.         x = 0
  31.       end
  32.       self.draw_text(x, y, 512, height, word)
  33.       x += word_width
  34.     end
  35.   end
  36.  
  37. #============================================================
  38. # New Method
  39. # Returns the height of a block of text that uses the
  40. # method draw_wrap_text.
  41. #============================================================
  42.  
  43.   def wrap_text_height(width,height,text = "",extra = true)
  44.     array = text.split
  45.     @extra_height = extra
  46.     x = 0
  47.     y = 0
  48.     for i in array
  49.       word = i + ' '
  50.       word_width = text_size(word).width
  51.       if x + word_width > width
  52.         y += height
  53.         x = 0
  54.       end
  55.       x += word_width
  56.     end
  57.     if @extra_height
  58.       return y + height
  59.     else
  60.       return y
  61.     end
  62.   end
  63.  
  64.   def wrap_text_x(width,height,text = "")
  65.     array = text.split
  66.     x = 0
  67.     y = 0
  68.     for i in array
  69.       word = i + ' '
  70.       word_width = text_size(word).width
  71.       if x + word_width > width
  72.         y += height
  73.         x = 0
  74.       end
  75.       x += word_width
  76.     end
  77.     return x - text_size(" ").width
  78.   end
  79.  
  80.   def icon_text_right(y,width,height,text = "",iwidth = 24)
  81.     array = text.split
  82.     input_width = width
  83.     for i in array.reverse
  84.       if i.include?("/i[")
  85.         num = i.delete("/i["+"]").to_i
  86.         draw_icon(num,input_width - iwidth,y)
  87.         input_width -= (iwidth + text_size(" ").width)
  88.       else
  89.         word_width = text_size(i).width
  90.         draw_text(input_width - word_width,y,width,height,i)
  91.         input_width -= (word_width + text_size(" ").width)
  92.       end
  93.     end
  94.   end
  95.  
  96.  
  97.   def icon_text(x,y,width,height,text = "",iwidth = 24)
  98.     array = text.split
  99.     input_x = x
  100.     for i in array
  101.       if i.include?("/i[")
  102.         num = i.delete("i/i["+"]").to_i
  103.         draw_icon(num,input_x,y)
  104.         input_x += iwidth + text_size(" ").width
  105.       else
  106.         word_width = text_size(i).width
  107.         draw_text(input_x,y,width,height,i)
  108.         input_x += word_width + text_size(" ").width
  109.       end
  110.     end
  111.   end
  112.  
  113.    #--------------------------------------------------------------------------
  114.    # * Draw Icon
  115.    #     icon_index : Icon number
  116.    #     x     : draw spot x-coordinate
  117.    #     y     : draw spot y-coordinate
  118.    #     enabled    : Enabled flag. When false, draw semi-transparently.
  119.    #--------------------------------------------------------------------------
  120.    def draw_icon(icon_index, x, y, enabled = true)
  121.      bitmap = Cache.system("Iconset")
  122.      rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  123.      blt(x, y, bitmap, rect, enabled ? 255 : 128)
  124.    end
  125.  
  126. #==============================================================
  127. # New Method
  128. # For window's used only to show 1 line of text.   It will
  129. # cut off any words that would make the line too long to
  130. # 'properly show'
  131. #==============================================================
  132.   def draw_special_case(x,y,width, height, text)
  133.     array = text.split
  134.     for i in array
  135.       word = i + ' '
  136.       word_width = text_size(word).width
  137.       self.draw_text(x, y, 512, height, word) unless word_width + x > width
  138.       x += word_width
  139.     end
  140.   end
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement