Class: Newt::Screen

Inherits:
Object
  • Object
show all
Defined in:
ext/ruby_newt/ruby_newt.c

Class Method Summary collapse

Class Method Details

.bellObject



460
461
462
463
464
465
# File 'ext/ruby_newt/ruby_newt.c', line 460

static VALUE rb_ext_Screen_Bell(VALUE self)
{
  INIT_GUARD();
  newtBell();
  return Qnil;
}

.centered_window(width, height, title) ⇒ Object



241
242
243
244
245
# File 'ext/ruby_newt/ruby_newt.c', line 241

static VALUE rb_ext_Screen_CenteredWindow(VALUE self, VALUE width, VALUE height, VALUE title)
{
  INIT_GUARD();
  return INT2NUM(newtCenteredWindow(NUM2INT(width), NUM2INT(height), StringValuePtr(title)));
}

.clear_keybufferObject



226
227
228
229
230
231
# File 'ext/ruby_newt/ruby_newt.c', line 226

static VALUE rb_ext_Screen_ClearKeyBuffer()
{
  INIT_GUARD();
  newtClearKeyBuffer();
  return Qnil;
}

.clsObject



205
206
207
208
209
210
# File 'ext/ruby_newt/ruby_newt.c', line 205

static VALUE rb_ext_Screen_Cls()
{
  INIT_GUARD();
  newtCls();
  return Qnil;
}

.cursor_offObject



467
468
469
470
471
472
# File 'ext/ruby_newt/ruby_newt.c', line 467

static VALUE rb_ext_Screen_CursorOff(VALUE self)
{
  INIT_GUARD();
  newtCursorOff();
  return Qnil;
}

.cursor_onObject



474
475
476
477
478
479
# File 'ext/ruby_newt/ruby_newt.c', line 474

static VALUE rb_ext_Screen_CursorOn(VALUE self)
{
  INIT_GUARD();
  newtCursorOn();
  return Qnil;
}

.draw_roottext(col, row, text) ⇒ Object



431
432
433
434
435
436
# File 'ext/ruby_newt/ruby_newt.c', line 431

static VALUE rb_ext_Screen_DrawRootText(VALUE self, VALUE col, VALUE row, VALUE text)
{
  INIT_GUARD();
  newtDrawRootText(NUM2INT(col), NUM2INT(row), StringValuePtr(text));
  return Qnil;
}

.finishObject



212
213
214
215
216
217
# File 'ext/ruby_newt/ruby_newt.c', line 212

static VALUE rb_ext_Screen_Finished()
{
  newtFinished();
  initialized = Qfalse;
  return Qnil;
}

.help_callback(cb) ⇒ Object



675
676
677
678
679
680
681
682
683
# File 'ext/ruby_newt/ruby_newt.c', line 675

static VALUE rb_ext_Screen_HelpCallback(VALUE self, VALUE cb)
{
  INIT_GUARD();
  cb = rb_struct_new(rb_ext_sCallback, Qnil, rb_binding_new(), cb, Qnil, NULL);
  rb_obj_freeze(cb);
  rb_cvar_set(self, CVAR_HELP_CALLBACK, cb);
  newtSetHelpCallback(rb_ext_Screen_help_callback_function);
  return Qnil;
}

.initObject



187
188
189
190
191
192
193
194
195
196
# File 'ext/ruby_newt/ruby_newt.c', line 187

static VALUE rb_ext_Screen_Init()
{
  if (initialized == Qtrue)
    return Qnil;

  newtInit();
  memcpy(&newtColors, &newtDefaultColorPalette, sizeof(struct newtColors));
  initialized = Qtrue;
  return Qnil;
}

.newObject



198
199
200
201
202
203
# File 'ext/ruby_newt/ruby_newt.c', line 198

static VALUE rb_ext_Screen_new()
{
  rb_ext_Screen_Init();
  newtCls();
  return Qnil;
}

.open_window(left, top, width, height, title) ⇒ Object



233
234
235
236
237
238
239
# File 'ext/ruby_newt/ruby_newt.c', line 233

static VALUE rb_ext_Screen_OpenWindow(VALUE self, VALUE left, VALUE top,
    VALUE width, VALUE height, VALUE title)
{
  INIT_GUARD();
  return INT2NUM(newtOpenWindow(NUM2INT(left), NUM2INT(top), NUM2INT(width),
                                NUM2INT(height), StringValuePtr(title)));
}

.pop_helplineObject



453
454
455
456
457
458
# File 'ext/ruby_newt/ruby_newt.c', line 453

static VALUE rb_ext_Screen_PopHelpLine(VALUE self)
{
  INIT_GUARD();
  newtPopHelpLine();
  return Qnil;
}

.pop_windowObject



247
248
249
250
251
252
# File 'ext/ruby_newt/ruby_newt.c', line 247

static VALUE rb_ext_Screen_PopWindow(VALUE self)
{
  INIT_GUARD();
  newtPopWindow();
  return Qnil;
}

.push_helpline(text) ⇒ Object



438
439
440
441
442
443
444
# File 'ext/ruby_newt/ruby_newt.c', line 438

static VALUE rb_ext_Screen_PushHelpLine(VALUE self, VALUE text)
{
  INIT_GUARD();
  newtPushHelpLine(StringValuePtr(text));

  return Qnil;
}

.redraw_helplineObject



446
447
448
449
450
451
# File 'ext/ruby_newt/ruby_newt.c', line 446

static VALUE rb_ext_Screen_RedrawHelpLine(VALUE self)
{
  INIT_GUARD();
  newtRedrawHelpLine();
  return Qnil;
}

.refreshObject



424
425
426
427
428
429
# File 'ext/ruby_newt/ruby_newt.c', line 424

static VALUE rb_ext_Screen_Refresh()
{
  INIT_GUARD();
  newtRefresh();
  return Qnil;
}

.resumeObject



410
411
412
413
414
415
# File 'ext/ruby_newt/ruby_newt.c', line 410

static VALUE rb_ext_Screen_Resume()
{
  INIT_GUARD();
  newtResume();
  return Qnil;
}

.set_color(colorset, fg, bg) ⇒ Object



403
404
405
406
407
408
# File 'ext/ruby_newt/ruby_newt.c', line 403

static VALUE rb_ext_Screen_SetColor(VALUE self, VALUE colorset, VALUE fg, VALUE bg)
{
  INIT_GUARD();
  newtSetColor(NUM2INT(colorset), StringValuePtr(fg), StringValuePtr(bg));
  return Qnil;
}

.set_colors(colors) ⇒ Object



393
394
395
396
397
398
399
400
401
# File 'ext/ruby_newt/ruby_newt.c', line 393

static VALUE rb_ext_Screen_SetColors(VALUE self, VALUE colors)
{
  Check_Type(colors, T_HASH);
  rb_hash_foreach(colors, rb_ext_Colors_callback_function, (VALUE) &newtColors);

  INIT_GUARD();
  newtSetColors(newtColors);
  return Qnil;
}

.sizeObject



481
482
483
484
485
486
487
488
# File 'ext/ruby_newt/ruby_newt.c', line 481

static VALUE rb_ext_Screen_Size(VALUE self)
{
  int cols, rows;

  INIT_GUARD();
  newtGetScreenSize(&cols, &rows);
  return rb_ary_new_from_args(2, INT2NUM(cols), INT2NUM(rows));
}

.suspendObject



417
418
419
420
421
422
# File 'ext/ruby_newt/ruby_newt.c', line 417

static VALUE rb_ext_Screen_Suspend()
{
  INIT_GUARD();
  newtSuspend();
  return Qnil;
}

.suspend_callback(*args) ⇒ Object



657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'ext/ruby_newt/ruby_newt.c', line 657

static VALUE rb_ext_Screen_SuspendCallback(int argc, VALUE *argv, VALUE self)
{
  VALUE cb, data = Qnil;

  if (argc < 1 || argc > 2)
    ARG_ERROR(argc, "1 or 2");

  INIT_GUARD();
  if (argc == 2)
    data = argv[1];

  cb = rb_struct_new(rb_ext_sCallback, self, rb_binding_new(), argv[0], data, NULL);
  rb_obj_freeze(cb);
  rb_cvar_set(self, CVAR_SUSPEND_CALLBACK, cb);
  newtSetSuspendCallback(rb_ext_Screen_suspend_callback_function, (void *) cb);
  return Qnil;
}

.wait_for_keyObject



219
220
221
222
223
224
# File 'ext/ruby_newt/ruby_newt.c', line 219

static VALUE rb_ext_Screen_WaitForKey()
{
  INIT_GUARD();
  newtWaitForKey();
  return Qnil;
}

.win_choice(title, button1, button2, text) ⇒ Object



497
498
499
500
501
502
503
504
505
# File 'ext/ruby_newt/ruby_newt.c', line 497

static VALUE rb_ext_Screen_WinChoice(VALUE self, VALUE title, VALUE button1, VALUE button2, VALUE text)
{
  int result;

  INIT_GUARD();
  result = newtWinChoice(StringValuePtr(title), StringValuePtr(button1),
                         StringValuePtr(button2), StringValuePtr(text));
  return INT2NUM(result);
}

.win_entries(args) ⇒ Object



544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'ext/ruby_newt/ruby_newt.c', line 544

static VALUE rb_ext_Screen_WinEntries(VALUE self, VALUE args)
{
  VALUE ary;
  struct newtWinEntry *items;
  char *title, *text, *button1, *button2;
  int len, i;
  int width, flexDown, flexUp, dataWidth;
  char *entries[10];

  len = RARRAY_LENINT(args);
  if (len < 8 || len > 9)
    ARG_ERROR(len, "8..9");

  INIT_GUARD();
  title = StringValuePtr(RARRAY_PTR(args)[0]);
  text = StringValuePtr(RARRAY_PTR(args)[1]);
  width = NUM2INT(RARRAY_PTR(args)[2]);
  flexDown = NUM2INT(RARRAY_PTR(args)[3]);
  flexUp = NUM2INT(RARRAY_PTR(args)[4]);
  dataWidth = NUM2INT(RARRAY_PTR(args)[5]);
  button1 = StringValuePtr(RARRAY_PTR(args)[7]);
  button2 = (len == 9) ? StringValuePtr(RARRAY_PTR(args)[8]) : NULL;

  Check_Type(RARRAY_PTR(args)[6], T_ARRAY);
  len = RARRAY_LENINT(RARRAY_PTR(args)[6]);
  if (len > 8) ARG_ERROR(len, "8 or less");
  memset(entries, 0, sizeof(entries));
  items = ALLOCA_N(struct newtWinEntry, len + 1);
  for (i = 0; i < len; i++) {
    Check_Type(RARRAY_PTR(RARRAY_PTR(args)[6])[i], T_STRING);
    items[i].text = StringValuePtr(RARRAY_PTR(RARRAY_PTR(args)[6])[i]);
    items[i].value = entries + i;
    items[i].flags = 0;
  }
  items[len].text = NULL;
  items[len].value = NULL;
  items[len].flags = 0;

  ary = rb_ary_new();
  newtWinEntries(title, text, width, flexDown, flexUp, dataWidth, items, button1, button2, NULL);
  for (i = 0; i < len; i++) { rb_ary_push(ary, rb_str_new2(entries[i])); }
  return ary;
}

.win_menu(args) ⇒ Object



507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'ext/ruby_newt/ruby_newt.c', line 507

static VALUE rb_ext_Screen_WinMenu(VALUE self, VALUE args)
{
  char **cptr;
  char *title, *text, *button1, *button2;

  int len, i, listItem;
  int width, flexDown, flexUp, maxHeight;

  len = RARRAY_LENINT(args);
  if (len < 8 || len > 9)
    ARG_ERROR(len, "8..9");

  INIT_GUARD();
  title = StringValuePtr(RARRAY_PTR(args)[0]);
  text = StringValuePtr(RARRAY_PTR(args)[1]);
  width = NUM2INT(RARRAY_PTR(args)[2]);
  flexDown = NUM2INT(RARRAY_PTR(args)[3]);
  flexUp = NUM2INT(RARRAY_PTR(args)[4]);
  maxHeight = NUM2INT(RARRAY_PTR(args)[5]);

  Check_Type(RARRAY_PTR(args)[6], T_ARRAY);

  len = RARRAY_LENINT(RARRAY_PTR(args)[6]);
  cptr = ALLOCA_N(char*, len + 1);
  for (i = 0; i < len; i++) {
    Check_Type(RARRAY_PTR(RARRAY_PTR(args)[6])[i], T_STRING);
    cptr[i] = StringValuePtr(RARRAY_PTR(RARRAY_PTR(args)[6])[i]);
  }
  cptr[len] = NULL;

  button1 = StringValuePtr(RARRAY_PTR(args)[7]);
  button2 = (len == 9) ? StringValuePtr(RARRAY_PTR(args)[8]) : NULL;

  newtWinMenu(title, text, width, flexDown, flexUp, maxHeight, cptr, &listItem, button1, button2, NULL);
  return INT2NUM(listItem);
}

.win_message(title, button, text) ⇒ Object



490
491
492
493
494
495
# File 'ext/ruby_newt/ruby_newt.c', line 490

static VALUE rb_ext_Screen_WinMessage(VALUE self, VALUE title, VALUE button, VALUE text)
{
  INIT_GUARD();
  newtWinMessage(StringValuePtr(title), StringValuePtr(button), StringValuePtr(text));
  return Qnil;
}