Class Joyau::Danzeff
In: ruby/site_ruby/joyau/danzeff.rb
Parent: Joyau::Drawable

In the PSP’s world, a well known input method is the Danzeff keyboard. This class is not the same keyboard, but it allows to enter text the same way.

You can modifiy the characters displayed by the keyboard ( pages ), The color used for the text ( txt_color ), when focused ( :focus ), or usually ( :normal ).

You can also specify the background bg_color, which is either a color or a sprite ( which will be redimensionned ).

You may also change the keys used for controlling this object.

Methods

draw  

Attributes

bg_colors  [RW]  Like txt_colors, but for the background. Notice that a Sprite can be given too here.
border_col  [RW]  The border’s color.
h  [RW]  Keyboard’s geometry
keys  [RW]  A Hash where you can set the keys at which the keyboards should react. :next_page, :prev_page, :bottom, :up, :left, and :right are the valid keys.
page_id  [R]  Retuns the selected page’s id.
pages  [RW]  Three dimension array containing all the keys which are pressed by the user. Use it so : level[page_id][case_id][char_id].
str  [RW]  Contains the message entered by the user.
txt_colors  [RW]  A hash whose keys :normal and :focus are checked. The color You give there is set for the text which is either focused or not.
w  [RW]  Keyboard’s geometry

Public Instance methods

Draws the keyboard, and eventually update its string.

[Source]

# File ruby/site_ruby/joyau/danzeff.rb, line 152
    def draw
      @page_id += 1 if Pad.pressed? @keys[:next_page] and @pages[@page_id + 1]
      @page_id -= 1 if Pad.pressed? @keys[:prev_page] and @pages[@page_id - 1]

      focused_id = selected_id(Pad.stickX + 127, Pad.stickY + 127)
      str = pressed_str(focused_id)
      if str == -1
        @str[-1] = "" if @str[-1]
      elsif str
        @str += str
      end

      for id in 0..8
        point  = bloc_pos(id)
        width  = @w / 3
        height = @h / 3

        symbol = id == focused_id ? :focus : :normal
        Joyau.setTextColor(@txt_colors[symbol])
        
        rect = DrawableRect.new(point.x, point.y, 
                                point.x + width, point.y + height)

        # 1. Draw the backgroud
        if @bg_colors[symbol].is_a? Sprite
          @bg_colors[symbol].pos = point
          @bg_colors[symbol].setTile(0, 0, width, height)
          @bg_colors[symbol].draw
        else
          rect.color = @bg_colors[symbol]
          rect.draw
        end
        
        # 2. Draw the border
        rect.color = @border_col
        rect.filled = false
        rect.draw

        # 3. Draw the strings
        str = @pages[@page_id][id][0]
        str = "Del" if str == -1
        str = "Spc" if str == ' '

        str_x = point.x + (width / 2) - (Joyau.getLength(str) / 2)
        str_y = point.y + height - 9

        Joyau.drawText(str_x, str_y, str)
        
        str = @pages[@page_id][id][1]
        str = "Del" if str == -1
        str = "Spc" if str == ' '

        str_x = point.x + (width / 2) - (Joyau.getLength(str) / 2)
        str_y = point.y + 1

        Joyau.drawText(str_x, str_y, str)

        str = @pages[@page_id][id][2]
        str = "Del" if str == -1
        str = "Spc" if str == ' '

        str_x = point.x + 1
        str_y = point.y + (height / 2) - 5

        Joyau.drawText(str_x, str_y, str)

        str = @pages[@page_id][id][3]
        str = "Del" if str == -1
        str = "Spc" if str == ' '

        str_x = point.x + width - Joyau.getLength(str)
        str_y = point.y + (height / 2) - 5

        Joyau.drawText(str_x, str_y, str)
      end
    end

[Validate]