Advertisement
Mithran

VXA Draw Text Test 2.0

Mar 27th, 2012
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. # Text Tester
  2. # By Mithran
  3.  
  4. # change the options at the top of the script to test various text drawing
  5. # situations
  6.  
  7. # while in the tester:
  8.  
  9. # q/w add/subtract string width
  10. # a/s add/subtract buffer width
  11. # Enter: Center bitmap
  12. # left/right scroll bitmap left/right, hold ctrl for faster scroll
  13.  
  14. Font.default_name = "Verdana" # for comparison to VX
  15. Font.default_size = 20 # for comparison to VX
  16. #Font.default_outline = true
  17. #Font.default_italic = true
  18. #Font.default_shadow = true
  19. #Font.default_bold = true
  20.  
  21. class Scene_DrawTextTest < Scene_Base
  22. ON = true # change to false to disable this text tester
  23. TEST_TEXT = "The quick brown fox jumps over the lazy dog, and lands in a fox trap?!"
  24. "The green area is the rect given by Bitmap#text_size." +
  25. " And this is just an extra optional line that can be added to the above to demonstrate the error."
  26. # the green area is the rect given by Bitmap#text_size for the above string,
  27. # and the text is drawn to this rect
  28. # by definition, the text should be of approximately the same size as the rect
  29. # and should not shift if alignment is changed, but neither is true
  30.  
  31. # if you make the above string really long (as in, for horizonally scrolling text)
  32. # the draw text will collapse over itself (uncomment the plus to see)
  33. ALIGN = 0# text_size issue is really ovbious when aligned left
  34. # but try center with longer text, to show text drawing over itself for no reason
  35. # to make matters worse, it doesnt even properly center when this happens
  36.  
  37. BUFFER = 0 # how much wider the bitmap is than the text drawn to it
  38.  
  39. def start
  40. @text = TEST_TEXT
  41. create_sprite
  42. end
  43.  
  44. def create_sprite
  45. @sprite = Sprite_Base.new
  46. @buffer = BUFFER
  47. @align = ALIGN
  48. create_bitmap
  49. center_sprite(@sprite)
  50. end
  51.  
  52. def create_bitmap
  53. rect = Cache.empty_bitmap.text_size(@text)
  54. rect.width += @buffer
  55. @sprite.bitmap = Bitmap.new(rect.width, rect.height)
  56. @sprite.bitmap.fill_rect(rect, Color.new(0, 128, 0))
  57. @sprite.bitmap.draw_text(rect, @text, @align)
  58. end
  59.  
  60. def update
  61. super
  62. @sprite.update
  63. if Input.press?(:ALT)
  64. @align = 0 if Input.trigger?(:LEFT)
  65. @align = 1 if Input.trigger?(:DOWN)
  66. @align = 2 if Input.trigger?(:RIGHT)
  67. elsif Input.press?(:RIGHT)
  68. @sprite.ox -= 1
  69. @sprite.ox -= 3 if Input.press?(:CTRL)
  70. elsif Input.press?(:LEFT)
  71. @sprite.ox += 1
  72. @sprite.ox += 3 if Input.press?(:CTRL)
  73. elsif Input.repeat?(:R)
  74. @text += (rand(90) + 32).chr
  75. @sprite.bitmap.dispose
  76. create_bitmap
  77. elsif Input.repeat?(:L)
  78. @text.chop!
  79. @sprite.bitmap.dispose
  80. create_bitmap
  81. elsif Input.repeat?(:X)
  82. @buffer -= 1
  83. @buffer -= 3 if Input.press?(:CTRL)
  84. @sprite.bitmap.dispose
  85. create_bitmap
  86. elsif Input.repeat?(:Y)
  87. @buffer += 1
  88. @buffer += 3 if Input.press?(:CTRL)
  89. @sprite.bitmap.dispose
  90. create_bitmap
  91. elsif Input.trigger?(:F5)
  92. msgbox_p( "Buffer Ratio: #{(@buffer / Cache.empty_bitmap.text_size(@text).width.to_f) + 1}" )
  93. elsif Input.trigger?(:F6)
  94. msgbox_p "Bitmap Width: #{@sprite.bitmap.width}"
  95. end
  96. center_sprite(@sprite) if Input.trigger?(:C)
  97. SceneManager.exit if Input.trigger?(:B)
  98. end
  99.  
  100. def center_sprite(sprite)
  101. sprite.ox = sprite.bitmap.width / 2
  102. sprite.oy = sprite.bitmap.height / 2
  103. sprite.x = Graphics.width / 2
  104. sprite.y = Graphics.height / 2
  105. end
  106.  
  107. def terminate
  108. destroy_sprite
  109. end
  110.  
  111. def destroy_sprite
  112. @sprite.bitmap.dispose
  113. @sprite.dispose
  114. end
  115.  
  116. end
  117.  
  118.  
  119. module SceneManager
  120. if Scene_DrawTextTest::ON
  121. def self.first_scene_class
  122. Scene_DrawTextTest
  123. end
  124. end
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement