Advertisement
TheSixth

Image Descriptions

Apr 12th, 2017
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.27 KB | None | 0 0
  1. =begin
  2.  
  3. This little snippet will let you add images to any text which is processed with
  4. the draw_text_ex method in any windows (such as the description texts).
  5.  
  6. To display an image, use this message code:
  7.  
  8.   \IMG[filename]
  9.  
  10. Replace filename with the name of the image you want to display.
  11. The image must be in the project's "Graphics/Pictures/" folder!
  12.  
  13. Additionally, you can use another message code to set the X position of the
  14. text manually. Whenever a new line starts in your text, it will start on this
  15. X position instead of starting from the top-left side like it does by default.
  16. The message code for this:
  17.  
  18.   \LX[value]
  19.  
  20. Replace value with the line's starting X position in pixels.
  21.  
  22. Made by: Sixth
  23.  
  24. =end
  25.  
  26. class Window_Base < Window
  27.  
  28.   alias add_iimgs8825 process_escape_character
  29.   def process_escape_character(code, text, pos)
  30.     case code.upcase
  31.     when 'IMG'
  32.       text.sub!(/\[(.*?)\]/i,"")
  33.       draw_img($1,pos)
  34.     when 'LX'
  35.       text.sub!(/\[(.*?)\]/i,"")
  36.       pos[:new_x] = $1.to_i
  37.     else
  38.       add_iimgs8825(code, text, pos)
  39.     end
  40.   end
  41.    
  42.   def draw_img(img,pos)
  43.     bmp = Cache.picture(img)
  44.     rct = Rect.new(0,0,bmp.width,bmp.height)
  45.     contents.blt(pos[:x],pos[:y],bmp,rct,255)
  46.     pos[:x] += bmp.width
  47.   end
  48.  
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement