Guest User

Untitled

a guest
Feb 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. # rbGooey. -- Game GUI library to be used with rubygame
  2. # Copyright (C) 2006 Han 'kiba' Dao
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public
  15. # License along with this library; if not, write to the Free Software
  16. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17.  
  18. #Class TextMode handle texts setting and data and handle all classes of Text so everything a programmer need to do with one of the text class can access it here.
  19. class TextMode
  20. #Set up the class by using the Main class
  21. attr_accessor :main , :bgcolor , :fgcolor , :x , :y , :text , :size , :textrender , :omit , :textinput , :textsprite , :report
  22. def initialize main
  23. @main = main
  24. @textrender = textrender
  25. @textinput = textinput
  26. @textsprite = textsprite
  27. #@omit variable is used in render_text, which serve to determine wheather to omit the bgcolor or not from the font render agurement.
  28. @bgcolor = bgcolor
  29. @fgcolor = fgcolor
  30. @omit = omit
  31. #@x contain the x position of text
  32. @x = x
  33. #@y contain the y position of text
  34. @y = y
  35. #@text contain strings of text
  36. @text = text
  37. #@size contain the size of the text
  38. @size = size
  39. @report = report
  40. setup
  41. end
  42. def setup
  43. @bgcolor = @main.bgcolor
  44. @fgcolor = @main.fgcolor
  45. @x = []
  46. @y = []
  47. @text = []
  48. @size = []
  49. @report = []
  50. @omit = false
  51. @textrender = TextRender.new(@main, self)
  52. @textinput = TextInput.new(self)
  53. @textsprite = TextSprite.new(self)
  54. end
  55. #This method exist for the purpose of DRY or don't repeat yourself. It is mean to be used internally.
  56. def array_push
  57. @x.push(0)
  58. @y.push(0)
  59. @size.push(@main.size)
  60. @report.push(false)
  61. end
  62. def add text
  63. #Use this method to add new lines to the text array
  64. @text << text
  65. #This default to zero to prevent font size changing.
  66. #To activiate this setting for a particular index in the text array, please use method set_size after the particular index you wanted.
  67. array_push
  68. end
  69. def size=(size)
  70. #Set the font size for a part of the @text array. It only apply for a particular index you apply to.
  71. @size[-1] = size
  72. end
  73. def set_pos x , y = 0
  74. #Set position
  75. @x[-1] = x
  76. @y[-1] = y
  77. end
  78. def length=(length)
  79. #Set the length of how much text array element will follow the text's x position. For y, it will skip.
  80. length.times do
  81. @y << @y[-1]
  82. @x << @x[-1]
  83. end
  84. end
  85. def set_mutiple time
  86. #It is used in dir_nosub and dir. It make sure that all array objects are added for each
  87. time.times do
  88. array_push
  89. end
  90. end
  91. #Tag the particular text that been added last using the add method of this TextMode class.
  92. def active
  93. @report[-1] = 1
  94. end
  95. #Method clear is for the purpose of clearing every infomation accumulated during the usage of this class that are the screen, class Textsprite's rect, and instance variable such as @text, @size, @x, and @y. Useful for starting with a clean state.
  96. def clear
  97. @textrender.screen_clear()
  98. @textsprite.setup()
  99. @text = []
  100. @size = []
  101. @x = []
  102. @y = []
  103. end
  104. def dir location , enable = false
  105. #Use this to add directory items. Usage: Dir(location) => a string that should contain the location of the directory
  106. #change the enable variable to the value true. This if you want only the filename or the "basename".
  107. if enable == true
  108. @text += Dir.glob(location).map {|f| File.basename(f)}
  109. else
  110. @text += Dir.glob(location)
  111. end
  112. set_mutiple(Dir[location].size)
  113. end
  114. end
Add Comment
Please, Sign In to add comment