53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/cdk/mixins/movement.rb', line 53
def position(win)
parent = @screen.window
orig_x = win.getbegx
orig_y = win.getbegy
beg_x = parent.getbegx
beg_y = parent.getbegy
end_x = beg_x + @screen.window.getmaxx
end_y = beg_y + @screen.window.getmaxy
while !([CDK::KEY_RETURN, Ncurses::KEY_ENTER].include?(
key = self.getch([])))
case key
when Ncurses::KEY_UP, '8'.ord
if win.getbegy > beg_y
self.move(0, -1, true, true)
else
CDK.Beep
end
when Ncurses::KEY_DOWN, '2'.ord
if (win.getbegy + win.getmaxy) < end_y
self.move(0, 1, true, true)
else
CDK.Beep
end
when Ncurses::KEY_LEFT, '4'.ord
if win.getbegx > beg_x
self.move(-1, 0, true, true)
else
CDK.Beep
end
when Ncurses::KEY_RIGHT, '6'.ord
if (win.getbegx + win.getmaxx) < end_x
self.move(1, 0, true, true)
else
CDK.Beep
end
when '7'.ord
if win.getbegy > beg_y && win.getbegx > beg_x
self.move(-1, -1, true, true)
else
CDK.Beep
end
when '9'.ord
if (win.getbegx + win.getmaxx) < end_x && win.getbegy > beg_y
self.move(1, -1, true, true)
else
CDK.Beep
end
when '1'.ord
if win.getbegx > beg_x && (win.getbegy + win.getmaxy) < end_y
self.move(-1, 1, true, true)
else
CDK.Beep
end
when '3'.ord
if (win.getbegx + win.getmaxx) < end_x &&
(win.getbegy + win.getmaxy) < end_y
self.move(1, 1, true, true)
else
CDK.Beep
end
when '5'.ord
self.move(CDK::CENTER, CDK::CENTER, false, true)
when 't'.ord
self.move(win.getbegx, CDK::TOP, false, true)
when 'b'.ord
self.move(win.getbegx, CDK::BOTTOM, false, true)
when 'l'.ord
self.move(CDK::LEFT, win.getbegy, false, true)
when 'r'.ord
self.move(CDK::RIGHT, win.getbegy, false, true)
when 'c'.ord
self.move(CDK::CENTER, win.getbegy, false, true)
when 'C'.ord
self.move(win.getbegx, CDK::CENTER, false, true)
when CDK::REFRESH
@screen.erase
@screen.refresh
when CDK::KEY_ESC
self.move(orig_x, orig_y, false, true)
else
CDK.Beep
end
end
end
|