Guest User

Untitled

a guest
Feb 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 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
  22. def initialize main
  23. @main = main
  24. @textrender = textrender
  25. @textinput = textinput
  26. #@omit variable is used in render_text, which serve to determine wheather to omit the bgcolor or not from the font render agurement.
  27. @bgcolor = bgcolor
  28. @fgcolor = fgcolor
  29. @omit = omit
  30. #@x contain the x position of text
  31. @x = x
  32. #@y contain the y position of text
  33. @y = y
  34. #@text contain strings of text
  35. @text = text
  36. #@size contain the size of the text
  37. @size = size
  38. setup
  39. end
  40. def setup
  41. @bgcolor = @main.bgcolor
  42. @fgcolor = @main.fgcolor
  43. @x = []
  44. @y = []
  45. @text = []
  46. @size = []
  47. @omit = false
  48. @textrender = TextRender.new(@main, self)
  49. @textinput = TextInput.new(self)
  50. end
  51. def array_push
  52. #This method exist for the purpose of DRY or don't repeat yourself
  53. @x.push 0
  54. @y.push 0
  55. @size.push @main.size
  56. end
  57. def add text
  58. #Use this method to add new lines to the text array
  59. @text << text
  60. #This default to zero to prevent font size changing.
  61. #To activiate this setting for a particular index in the text array, please use method set_size after the particular index you wanted.
  62. array_push
  63. end
  64. def set_size size
  65. #Set the font size for a part of the @text array. It only apply for a particular index you apply to.
  66. @size[-1] = size
  67. end
  68. def set_pos x , y = 0
  69. #Set position
  70. @x[-1] = x
  71. @y[-1] = y
  72. end
  73. def length length
  74. #Set the length of how much text array element will follow the text's x position. For y, it will skip.
  75. length.times do
  76. @y << @y[-1]
  77. @x << @x[-1]
  78. end
  79. end
  80. def set_mutiple time
  81. #It is used in dir_nosub and dir. It make sure that all array objects are added for each
  82. time.times do
  83. array_push
  84. end
  85. end
  86. def clear
  87. #Use this to clear arrays which are @text, @size, and @x and @y
  88. @textrender.screen_clear
  89. @text = []
  90. @size = []
  91. @x = []
  92. @y = []
  93. end
  94. def dir location , enable = false
  95. #Use this to add directory items. Usage: Dir(location) => a string that should contain the location of the directory
  96. #change the enable variable to the value true. This if you want only the filename or the "basename".
  97. if enable == true
  98. @text += Dir.glob(location).map {|f| File.basename(f)}
  99. else
  100. @text += Dir.glob(location)
  101. end
  102. set_mutiple(Dir[location].size)
  103. end
  104. end
Add Comment
Please, Sign In to add comment