Method: CDK::CDKOBJS#position

Defined in:
lib/cdk/cdk_objs.rb

#position(win) ⇒ Object

This allows the user to use the cursor keys to adjust the postion of the widget.



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/cdk/cdk_objs.rb', line 376

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

  # Let them move the widget around until they hit return.
  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