Module: DXRubyEditor::Core::KeyInput

Defined in:
lib/dxruby_editor/core/key_input.rb

Constant Summary collapse

@@_old_keys =
[]
@@_record_pressed_key =
[
  # key(num), tick
  nil, 0
]
@@_keys =
{
  # keycode: [str, str(+shift)]
  "1": ['1', '!'],
  "2": ['2', '"'],
  "3": ['3', '#'],
  "4": ['4', '$'],
  "5": ['5', '%'],
  "6": ['6', '&'],
  "7": ['7', "'"],
  "8": ['8', '('],
  "9": ['9', ')'],
  "0": ['0', nil],
  "MINUS": ['-', '='],
  "PREVTRACK": ['^', '~'],
  "YEN": ['\\', '|'],
  "AT": ['@', '`'],
  "LBRACKET": ['[', '{'],
  "RBRACKET": [']', '}'],
  "SEMICOLON": [';', '+'],
  "COLON": [':', '*'],
  "COMMA": [',', '<'],
  "PERIOD": ['.', '>'],
  "SLASH": ['/', '?'],
  "BACKSLASH": ['\\', '_'],
  "SPACE": [' ', ' ']
}
@@_int2keycode =
{}
@@_keycode2int =
{}

Class Method Summary collapse

Class Method Details

.K_#{key}Object

.update_cursor(context) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/dxruby_editor/core/key_input.rb', line 123

def update_cursor(context)
  # TODO: Ctrl で単語ごとに移動
  # if Input.key_down?(K_LCONTROL) || Input.key_down?(K_RCONTROL)
  # end

  if pressed?(K_RIGHT)
    context.cursor_x += 1
    if context.cursor_x >= context.text[context.cursor_y - 1].length + 2 &&
       context.cursor_y != context.text.length
      context.cursor_x = 0
      context.cursor_y += 1
    end
  end
  if pressed?(K_LEFT)
    context.cursor_x -= 1
    if context.cursor_x <= 0 && context.cursor_y > 1
      context.cursor_x = context.text[context.cursor_y - 2].length + 1
      context.cursor_y -= 1
    end
  end
  if pressed?(K_DOWN)
    context.cursor_y += 1
    if context.cursor_y > context.text.length
      context.cursor_x = context.text[context.cursor_y - 2].length + 1
    end
  end
  if pressed?(K_UP)
    context.cursor_y -= 1
    context.cursor_x = 0 if context.cursor_y < 1
  end

  context.cursor_y = [[1, context.cursor_y].max, context.text.length].min
  context.cursor_x = [[1, context.cursor_x].max, context.text[context.cursor_y - 1].length + 1].min
end