[ION] Nicer FltkKbd

This commit is contained in:
Romain Goyet
2015-09-02 13:47:25 +02:00
parent 5c95ee85cb
commit ece318c454
8 changed files with 62 additions and 14 deletions

View File

@@ -1,9 +1,34 @@
#include "fltkkbd.h"
#include "fltkkbdbutton.h"
#include <stdio.h>
FltkKBD::FltkKBD(int x, int y, int w, int h) :
Fl_Group(x, y, w, h) {
void FltkKbdButtonCallback(Fl_Widget * w, void * context) {
FltkKbd * kbd = (FltkKbd *)context;
FltkKbdButton * button = (FltkKbdButton *)w;
kbd->register_key_state(button->m_key, button->value());
printf("Register state %d at %d\n", button->m_key, button->value());
}
bool FltkKBD::scankey(ion_key_t key) {
return false;
FltkKbd::FltkKbd(int x, int y, int w, int h) : Fl_Group(x, y, w, h) {
m_keyState = new bool[ION_NUMBER_OF_KEYS];
for (int i=0; i<ION_NUMBER_OF_KEYS; i++) {
m_keyState[i] = false;
}
for (int k=0; k<ION_NUMBER_OF_KEYS; k++) {
FltkKbdButton * b = new FltkKbdButton(x+(k*w)/ION_NUMBER_OF_KEYS, y, w/ION_NUMBER_OF_KEYS, h);
b->m_key = (ion_key_t)k;
b->when(FL_WHEN_CHANGED);
b->callback(FltkKbdButtonCallback, (void *)this);
}
end();
}
// FIXME: Destructor: delete[] m_keyState
bool FltkKbd::scankey(ion_key_t key) {
return m_keyState[key];
}
void FltkKbd::register_key_state(ion_key_t key, bool active) {
m_keyState[key] = active;
}

View File

@@ -6,10 +6,14 @@ extern "C" {
#include <ion/keyboard.h>
}
class FltkKBD : public Fl_Group {
public:
FltkKBD(int x, int y, int w, int h);
bool scankey(ion_key_t key);
class FltkKbd : public Fl_Group {
friend void FltkKbdButtonCallback(Fl_Widget * w, void * context);
public:
FltkKbd(int x, int y, int w, int h);
bool scankey(ion_key_t key);
private:
bool * m_keyState;
void register_key_state(ion_key_t key, bool active);
};
#endif

View File

@@ -0,0 +1,5 @@
#include "fltkkbdbutton.h"
FltkKbdButton::FltkKbdButton(int x, int y, int w, int h, const char * label) :
Fl_Button(x, y, w, h, label) {
}

View File

@@ -0,0 +1,15 @@
#ifndef ION_FLTK_KBD_BUTTON
#define ION_FLTK_KBD_BUTTON
#include <FL/Fl_Button.H>
extern "C" {
#include <ion/keyboard.h>
}
class FltkKbdButton : public Fl_Button {
public:
FltkKbdButton(int x, int y, int w, int h, const char * label = 0);
ion_key_t m_key;
};
#endif

View File

@@ -7,7 +7,8 @@ typedef enum {
ION_KEY_1,
ION_KEY_2,
ION_KEY_PLUS,
ION_KEY_MINUS
ION_KEY_MINUS,
ION_NUMBER_OF_KEYS // Should be defined last
} ion_key_t;
bool ion_scankey(ion_key_t key);

View File

@@ -1,5 +1,5 @@
objs += $(addprefix ion/platform/simulator/, init.o keyboard.o platform.o)
objs += $(addprefix ion/drivers/, fltklcd/fltklcd.o fltkkbd/fltkkbd.o)
objs += $(addprefix ion/drivers/, fltklcd/fltklcd.o fltkkbd/fltkkbd.o fltkkbd/fltkkbdbutton.o)
#SFLAGS += -I/usr/local/Cellar/fltk/1.3.3/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT
LDFLAGS += -L/usr/local/Cellar/fltk/1.3.3/lib -lfltk -lpthread -framework Cocoa

View File

@@ -7,7 +7,6 @@ extern "C" {
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <ion/drivers/fltklcd/fltklcd.h>
#include <ion/drivers/fltkkbd/fltkkbd.h>
@@ -21,10 +20,9 @@ void ion_init() {
Platform.display = lcd;
PlatformFramebuffer = lcd->m_framebuffer;
FltkKBD * kbd = new FltkKBD(0,0,100,100);
FltkKbd * kbd = new FltkKbd(0,0,100,100);
Platform.keyboard = kbd;
Fl_Button *button = new Fl_Button(margin, ION_FRAMEBUFFER_HEIGHT+2*margin+margin, 40, 40, "A");
window->end();
window->show(NULL, NULL);

View File

@@ -9,7 +9,7 @@ extern "C" {
typedef struct {
FltkLCD * display;
FltkKBD * keyboard;
FltkKbd * keyboard;
} platform_t;
extern platform_t Platform;