File: testkey.cpp

package info (click to toggle)
freej 0.10git20100110-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 32,080 kB
  • ctags: 22,705
  • sloc: cpp: 156,254; ansic: 25,531; sh: 13,538; perl: 4,624; makefile: 3,278; python: 2,889; objc: 1,284; asm: 1,125; ruby: 126
file content (81 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>

#include <slw.h>
#include <slw_console.h>


class TestKey : public SLangWidget {
  
public:
  TestKey() : SLangWidget() { set_name("testkey"); };
  ~TestKey() { };

  bool init() {
    if(!console) return false;
    // default widget behaviour
    initialized = true;
    visible = true;
    cursor = false;
    can_focus = true;
    border = false;

    refresh();
    return true;
  }

  // this function gets called every time a key is passed to the widget
  // so here we draw and change the displayed information accordingly
  bool feed(int key) {
    char msg[256];
    int len;
    if(key) { // if it's not null
      snprintf(msg, 256, "[ %c : %u ]                   ", key, key);
      len = strlen(msg);
      putnch((CHAR*)&msg, 0, 0, len);
    }
    return true;
  }

  bool refresh() {
    return true;
  }

};

SLangConsole con;
TestKey test;

int main(int argc, char **argv) {
  int key;
  bool quit;

  assert( con.init() );

  SLtt_set_cursor_visibility(0);

  assert( con.place(&test, (con.w/2)-5, (con.h/2)-5 ,con.w,con.h) );
  assert( test.init() );

  con.focused = &test;

  quit = false;

  while(!quit) {

    key = con.getkey();

    test.feed(key);

    if( ! con.refresh() ) quit = true;
  }

  con.close();

  exit(1);
}