Numworks Epsilon  1.4.1
Graphing Calculator Operating System
fltkkbd.cpp
Go to the documentation of this file.
1 #include <assert.h>
2 #include "../init.h"
3 #include "fltkkbd.h"
4 #include <FL/Fl_Repeat_Button.H>
5 #undef None // TODO: Remove me
6 
7 constexpr int KeyboardRows = 9;
8 constexpr int KeyboardColumns = 6;
9 
10 static const char* kCharForKey[Ion::Keyboard::NumberOfKeys] = {
11  "\u25c1", "\u25b3", "\u25bd", "\u25b7", "OK", "\u21ba",
12  "Home", "Power", "", "", "", "",
13  "shift", "alpha", "x,n,t", "var", "Toolbox", "\u232b",
14  "e\u02e3", "ln", "log", "i", ",", "x\u02b8",
15  "sin", "cos", "tan", "\u03c0", "\u221a\u203e\u203e", "x\u00b2",
16  "7", "8", "9", "(", ")", "",
17  "4", "5", "6", "\u00d7", "\u00f7", "",
18  "1", "2", "3", "+", "\u2212", "",
19  "0", ".", "\u00d710\u02e3", "Ans", "EXE", ""
20 };
21 
22 static const int kShortcutForKey[Ion::Keyboard::NumberOfKeys] = {
23  FL_Left, FL_Up, FL_Down, FL_Right, FL_Enter, FL_Escape,
24  FL_Home, 0, 0, 0, 0, 0,
25  0, 0, 'x', 0, 0, FL_BackSpace,
26  0, 0, 0, 'i', ',', 0,
27  0, 0, 0, 0, 0, 0,
28  '7', '8', '9', '(',')', 0,
29  '4', '5', '6', '*', '/', 0,
30  '1', '2', '3', '+', '-', 0,
31  '0', '.', 0, 0, FL_KP_Enter, 0
32 };
33 
34 static bool shouldRepeatKey(Ion::Keyboard::Key k) {
36 }
37 
38 static void keyHandler(Fl_Widget *, long key) {
44  }
45 }
46 
47 FltkKbd::FltkKbd(int x, int y, int w, int h) : Fl_Group(x, y, w, h) {
49  int key_width = w/KeyboardColumns;
50  int key_height = h/KeyboardRows;
51  for (int k=0; k<Ion::Keyboard::NumberOfKeys; k++) {
52  int key_x = x + (k%KeyboardColumns)*key_width;
53  int key_y = y + (k/KeyboardColumns)*key_height;
54  if (shouldRepeatKey((Ion::Keyboard::Key)k)) {
55  m_buttons[k] = new Fl_Repeat_Button(key_x, key_y, key_width, key_height, kCharForKey[k]);
56  } else {
57  m_buttons[k] = new Fl_Button(key_x, key_y, key_width, key_height, kCharForKey[k]);
58  }
59 #if defined(_WIN32) || defined(_WIN64)
60  m_buttons[k]->labelfont(FL_SYMBOL);
61 #endif
62  if (kCharForKey[k][0] == '\0') {
63  m_buttons[k]->deactivate();
64  } else {
65  m_buttons[k]->callback(keyHandler, k);
66  }
67  if (kShortcutForKey[k]) {
68  m_buttons[k]->shortcut(kShortcutForKey[k]);
69  }
70  m_buttons[k]->clear_visible_focus();
71  }
72  end();
73 }
74 
76  return m_buttons[(int)key]->value();
77 }
constexpr int KeyboardRows
Definition: fltkkbd.cpp:7
bool key_down(Ion::Keyboard::Key key)
Definition: fltkkbd.cpp:75
#define assert(e)
Definition: assert.h:9
void updateModifiersFromEvent(Event e)
constexpr Event None
Definition: events.h:215
constexpr int KeyboardColumns
Definition: fltkkbd.cpp:8
constexpr int NumberOfKeys
Definition: keyboard.h:33
Ion::Events::Event currentEvent
Definition: init.cpp:24
bool isAlphaActive()
bool isShiftActive()
FltkKbd(int x, int y, int w, int h)
Definition: fltkkbd.cpp:47