1 #include "lcd-window.hh"
2 #include "badge_worker.hh"
3 #include "mock/event.h"
5 #include <gtkmm/main.h>
8 lcd_drawingarea::lcd_drawingarea(BaseObjectType
*cobject
,
9 Glib::RefPtr
<Gtk::Builder
> const &)
10 : Gtk::DrawingArea(cobject
)
12 sig_redraw_
.connect(sigc::mem_fun(*this, &lcd_drawingarea::force_redraw
));
13 badge_framebuffer_clear(&framebuffer_
);
16 lcd_drawingarea::~lcd_drawingarea() { }
18 void lcd_drawingarea::push_framebuffer(badge_framebuffer
const &fb
) {
23 void lcd_drawingarea::force_redraw() {
24 Glib::RefPtr
<Gdk::Window
> win
= get_window();
26 win
->invalidate(true);
30 bool lcd_drawingarea::on_draw(Cairo::RefPtr
<Cairo::Context
> const &cr
) {
31 Gtk::Allocation alloc
= get_allocation();
32 double w_width
= alloc
.get_width ();
33 double w_height
= alloc
.get_height();
35 double c_width
= w_width
/ BADGE_DISPLAY_WIDTH
;
36 double c_height
= w_height
/ BADGE_DISPLAY_HEIGHT
;
40 for(int i
= 0; i
< BADGE_DISPLAY_WIDTH
; ++i
) {
41 for(int j
= 0; j
< BADGE_DISPLAY_HEIGHT
; ++j
) {
42 if(badge_framebuffer_pixel(&framebuffer_
, i
, j
)) {
43 cr
->rectangle(c_width
* i
, c_height
* j
,
55 ///////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////
57 ///////////////////////////////////////////////////////
59 lcd_window::lcd_window(BaseObjectType
*cobject
, Glib::RefPtr
<Gtk::Builder
> const &glade
)
60 : Gtk::Window(cobject
),
63 glade
->get_widget_derived("canvas", canvas_
);
65 Glib::signal_timeout().connect(sigc::mem_fun(*this, &lcd_window::on_game_tick
), 11);
66 sig_close_
.connect(sigc::mem_fun(*this, &lcd_window::hide
));
69 lcd_window::~lcd_window() { }
71 void lcd_window::push_framebuffer(badge_framebuffer
const &fb
) {
72 canvas_
->push_framebuffer(fb
);
75 void lcd_window::request_close() {
79 bool lcd_window::on_key_press_event (GdkEventKey
* event
) {
80 uint8_t new_state
= key_state_
;
82 switch(event
->keyval
) {
83 case GDK_KEY_e
: new_state
|= BADGE_EVENT_KEY_UP
; break;
84 case GDK_KEY_s
: new_state
|= BADGE_EVENT_KEY_LEFT
; break;
85 case GDK_KEY_d
: new_state
|= BADGE_EVENT_KEY_DOWN
; break;
86 case GDK_KEY_f
: new_state
|= BADGE_EVENT_KEY_RIGHT
; break;
87 case GDK_KEY_a
: new_state
|= BADGE_EVENT_KEY_CENTER
; break;
88 case GDK_KEY_j
: new_state
|= BADGE_EVENT_KEY_BTN_A
; break;
89 case GDK_KEY_k
: new_state
|= BADGE_EVENT_KEY_BTN_B
; break;
92 badge_event_push(badge_event_new(BADGE_EVENT_USER_INPUT
, key_state_
, new_state
));
93 key_state_
= new_state
;
98 bool lcd_window::on_key_release_event(GdkEventKey
* event
) {
99 uint8_t new_state
= key_state_
;
101 switch(event
->keyval
) {
102 case GDK_KEY_e
: new_state
&= ~BADGE_EVENT_KEY_UP
; break;
103 case GDK_KEY_s
: new_state
&= ~BADGE_EVENT_KEY_LEFT
; break;
104 case GDK_KEY_d
: new_state
&= ~BADGE_EVENT_KEY_DOWN
; break;
105 case GDK_KEY_f
: new_state
&= ~BADGE_EVENT_KEY_RIGHT
; break;
106 case GDK_KEY_a
: new_state
&= ~BADGE_EVENT_KEY_CENTER
; break;
107 case GDK_KEY_j
: new_state
&= ~BADGE_EVENT_KEY_BTN_A
; break;
108 case GDK_KEY_k
: new_state
&= ~BADGE_EVENT_KEY_BTN_B
; break;
111 badge_event_push(badge_event_new(BADGE_EVENT_USER_INPUT
, key_state_
, new_state
));
112 key_state_
= new_state
;
117 bool lcd_window::on_game_tick() {
118 badge_event_push(badge_event_new(BADGE_EVENT_GAME_TICK
, key_state_
, key_state_
));
123 void lcd_window::on_show() {
124 Gtk::Window::on_show();
128 Glib::Thread::create(sigc::mem_fun(worker_
, &badge_worker::run
));
This page took 0.054424 seconds and 5 git commands to generate.