Report abuse


			
#  rbGooey. -- Game GUI library to be used with rubygame
#  Copyright (C) 2006  Han 'kiba' Dao
#
#  This library is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2.1 of the License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#The class Text_input deal with text input system. It also inherit much of TextRender class's properties.

class Text_input
  def initialize main
    @text = TextRender.new(main)
  end
  def last_add text
    #Use this if you want to add something to the last text array
    @text.last << "#{text}"
    render_text
  end
  def input_delete
    #Use this for deleting the end of the string one at a time.
    @text.last.chop!
    unless @text.last.length == 0
      render_text
    else
      @text.pop
      @text.render_text
      @text.push("")
    end
  end
  def input
    #This is the input system. for typing in text. Use the return value to do the things you want. It have a limitation for not allowing other things going on.
    #Activitating this function will stop the program whatever it is doing and wait for the users to press enter or return. It render the text as it go. It can only do lowercase letters and a period.
    q = Queue.instance()
    @text.push(input = "")
    array_push
    while (1)
      update
      q.get.each do |event|
        case event
          when Rubygame::QuitEvent
            exit
          when Rubygame::KeyDownEvent
            case event.key    
              when Rubygame::K_A
                last_add("a")
              when Rubygame::K_B
                last_add("b")
              when Rubygame::K_C
                last_add("c")
              when Rubygame::K_D
                last_add("d")
              when Rubygame::K_E
                last_add("e")
              when Rubygame::K_F
                last_add("f")
              when Rubygame::K_G
                last_add("g")
              when Rubygame::K_H
                last_add("h")
              when Rubygame::K_I
                last_add("i")
              when Rubygame::K_J
                last_add("j")
              when Rubygame::K_K
                last_add("k")
              when Rubygame::K_L
                last_add("l")
              when Rubygame::K_M
                last_add("m")
              when Rubygame::K_N
                last_add("n")
              when Rubygame::K_O
                last_add("o")
              when Rubygame::K_P
                last_add("p")
              when Rubygame::K_Q
                last_add("q")
              when Rubygame::K_R
                last_add("r")
              when Rubygame::K_S
                last_add("s")
              when Rubygame::K_T
                last_add("t")
              when Rubygame::K_U
                last_add("u")
              when Rubygame::K_V
                last_add("v")
              when Rubygame::K_W
                last_add("w")
              when Rubygame::K_X
                last_add("x")
              when Rubygame::K_Y
                last_add("y")
              when Rubygame::K_Z
                last_add("z")
              when Rubygame::K_0
                last_add("0")
              when Rubygame::K_1
                last_add("1")
              when Rubygame::K_2
                last_add("2")
              when Rubygame::K_3
                last_add("3")
              when Rubygame::K_4
                last_add("4")
              when Rubygame::K_5
                last_add("5")
              when Rubygame::K_6
                last_add("6")
              when Rubygame::K_7
                last_add("7")
              when Rubygame::K_8
                last_add("8")
              when Rubygame::K_9
                last_add("9")
              #TODO: Make a bugfix for this some time in the future. For now, a workaround is in place.
              when Rubygame::K_MINUS
                last_add("_")
              when Rubygame::K_SLASH
                last_add("/")
              when Rubygame::K_QUOTE
                last_add("\'")
              when Rubygame::K_RETURN
                if @text.last.empty? == false
                  return @text.last
                end
              when Rubygame::K_PERIOD
                last_add(".")
              when Rubygame::K_ESCAPE
                exit
              when Rubygame::K_BACKSPACE
                input_delete
            end
        end
      end
    end
  end
end