move entire window on arrow keys instead of just the cursor
This commit is contained in:
parent
b676363db8
commit
755aca3e30
1 changed files with 13 additions and 28 deletions
41
nboard
41
nboard
|
@ -14,10 +14,14 @@ def main(stdscr):
|
||||||
k='NOU'
|
k='NOU'
|
||||||
height, width = stdscr.getmaxyx()
|
height, width = stdscr.getmaxyx()
|
||||||
vx = vy = tx = ty = 0
|
vx = vy = tx = ty = 0
|
||||||
|
|
||||||
cx = width // 2
|
cx = width // 2
|
||||||
cy = height // 2
|
cy = height // 2
|
||||||
|
|
||||||
stdscr.move(cy,cx)
|
stdscr.move(cy,cx)
|
||||||
while True:
|
while True:
|
||||||
|
cx = width // 2
|
||||||
|
cy = height // 2
|
||||||
|
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
|
|
||||||
|
@ -25,32 +29,13 @@ def main(stdscr):
|
||||||
|
|
||||||
# detect where to move cursor
|
# detect where to move cursor
|
||||||
if k == 'KEY_UP':
|
if k == 'KEY_UP':
|
||||||
cy += -1
|
vy += -1
|
||||||
if k == 'KEY_DOWN':
|
if k == 'KEY_DOWN':
|
||||||
cy += 1
|
vy += 1
|
||||||
if k == 'KEY_LEFT':
|
if k == 'KEY_LEFT':
|
||||||
cx += -1
|
vx += -1
|
||||||
if k == 'KEY_RIGHT':
|
if k == 'KEY_RIGHT':
|
||||||
cx += 1
|
vx += 1
|
||||||
|
|
||||||
# enter view move mode
|
|
||||||
if k == '&':
|
|
||||||
stdscr.addstr(height-1, 0, 'Welcome to switch view mode. press an arrow key to move the view or a if you wanted a &'[:width-1])
|
|
||||||
k = stdscr.getkey()
|
|
||||||
if k == 'a':
|
|
||||||
k = '&'
|
|
||||||
if k == 'KEY_UP':
|
|
||||||
vy += -1
|
|
||||||
cy = height
|
|
||||||
if k == 'KEY_DOWN':
|
|
||||||
vy += 1
|
|
||||||
cy = 0
|
|
||||||
if k == 'KEY_LEFT':
|
|
||||||
vx += -1
|
|
||||||
cx = width
|
|
||||||
if k == 'KEY_RIGHT':
|
|
||||||
vx += 1
|
|
||||||
cx = 0
|
|
||||||
|
|
||||||
# make sure the cursor is on the screen
|
# make sure the cursor is on the screen
|
||||||
# this is not nessesary for the view as it is infinite
|
# this is not nessesary for the view as it is infinite
|
||||||
|
@ -61,8 +46,8 @@ def main(stdscr):
|
||||||
cy = min(height-2, cy)
|
cy = min(height-2, cy)
|
||||||
|
|
||||||
# calculate true position
|
# calculate true position
|
||||||
tx = cx + (vx * width) - width // 2
|
tx = cx + (vx) - width // 2
|
||||||
ty = cy + (vy * height) - (height-1) // 2
|
ty = cy + (vy) - (height-1) // 2
|
||||||
|
|
||||||
# get json data
|
# get json data
|
||||||
with open(dataPath, 'r') as openfile:
|
with open(dataPath, 'r') as openfile:
|
||||||
|
@ -71,10 +56,10 @@ def main(stdscr):
|
||||||
# if valid key pressed, write it
|
# if valid key pressed, write it
|
||||||
if k in allowedChars:
|
if k in allowedChars:
|
||||||
data[str((ty,tx))] = k
|
data[str((ty,tx))] = k
|
||||||
cx = min(width-1, cx+1)
|
vx = vx+1
|
||||||
with open(dataPath, 'w') as outfile:
|
with open(dataPath, 'w') as outfile:
|
||||||
json.dump(data, outfile)
|
json.dump(data, outfile)
|
||||||
tx = cx + (vx * width) - width // 2
|
tx = cx + (vx) - width // 2
|
||||||
|
|
||||||
# draw the screen
|
# draw the screen
|
||||||
stdscr.move(0, 0)
|
stdscr.move(0, 0)
|
||||||
|
@ -85,7 +70,7 @@ def main(stdscr):
|
||||||
|
|
||||||
|
|
||||||
# display some info
|
# display some info
|
||||||
stdscr.addstr(height-1, 0, 'x: {}, y: {}, arrow keys to move, & key to move to the next pane'.format(tx, ty)[:width-1])
|
stdscr.addstr(height-1, 0, 'x: {}, y: {}, arrow keys to move'.format(tx, ty)[:width-1])
|
||||||
|
|
||||||
|
|
||||||
# move the cursor where its actually supposed to be
|
# move the cursor where its actually supposed to be
|
||||||
|
|
Loading…
Reference in a new issue