mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[ION] Nicer FltkKbd
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
5
ion/drivers/fltkkbd/fltkkbdbutton.cpp
Normal file
5
ion/drivers/fltkkbd/fltkkbdbutton.cpp
Normal 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) {
|
||||
}
|
||||
15
ion/drivers/fltkkbd/fltkkbdbutton.h
Normal file
15
ion/drivers/fltkkbd/fltkkbdbutton.h
Normal 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
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -9,7 +9,7 @@ extern "C" {
|
||||
|
||||
typedef struct {
|
||||
FltkLCD * display;
|
||||
FltkKBD * keyboard;
|
||||
FltkKbd * keyboard;
|
||||
} platform_t;
|
||||
|
||||
extern platform_t Platform;
|
||||
|
||||
Reference in New Issue
Block a user