Commit 12f7e2ec authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

UI experiments

parent c8653c95
OBJS=gfx.o ui.o ui_pc.o font_helv17.o font_luct38.o font_xm16x25b.o digital_watch.o font_helv38b.o font_helv29.o font_helv22b.o font_xm4x6.o font_xm5x8.o
CFLAGS=`sdl-config --cflags` -I.
LDFLAGS =`sdl-config --libs`
all: $(OBJS)
gcc -o pc-ui $(OBJS) $(LDFLAGS)
clean:
rm $(OBJS) pc-ui
\ No newline at end of file
#include "ui.h"
static int dw_h, dw_min, dw_cycles;
static void digital_watch_redraw(struct ui_widget *w)
{
char buf[20];
sprintf(buf,"%02d:%02d", dw_h, dw_min);
gfx_clear(&w->dc, 0);
gfx_text(&w->dc, &font_helv38b, 0, 0, buf);
sprintf(buf,"%02d.%01d", dw_cycles * 12 / 10, (dw_cycles * 12) % 10);
gfx_text(&w->dc, &font_helv22b, 84, 14, buf);
}
static void digital_watch_event(struct ui_widget *w, struct ui_event event)
{
switch(event.type)
{
case EVT_NEXT_CYCLE:
{
dw_cycles = event.data % 50;
event.data /= 50;
dw_min = event.data % 60;
event.data /= 60;
dw_h = event.data % 24;
w->flags |= WF_DIRTY;
break;
}
default:
break;
}
}
struct ui_widget digital_watch = {
digital_watch_redraw,
digital_watch_event,
{ 0, 20, 127, 59 },
0,
WF_ACTIVE | WF_VISIBLE
};
void digtal_watch_create()
{
ui_add_widget ( &digital_watch );
}
struct pls_cycle {
uint8_t current;
uint8_t ramp;
uint8_t flat_top;
uint8_t ejection;
char *name;
};
static struct pls_cycle cycles[] = {
{ 20, 8, 5, 3, "TOF" },
{ 22, 4, 14, 3, "EAST1" },
{ 10, 2, 2, 5, "SFTPRO" },
{ 6, 2, 20, 5, "LHCINDIV" },
{ 30, 8, 5, 3, "MD6" },
{ 0, 4, 14, 3, "ZERO" },
{ 0, 2, 2, 5, "ZERO" },
{ 15, 5, 2, 5, "ISOGPS" }
};
static int pls_current = 0, pls_total = 8;
static void pls_redraw(struct ui_widget *w)
{
gfx_clear(&w->dc, 0);
// fprintf(stderr, "PLS_redraw!");
/*gfx_line(&w->dc, 64, 0, 127, 0, 1);
gfx_line(&w->dc, 64, 30, 127, 30, 1);
gfx_line(&w->dc, 64, 0, 64, 30, 1);
gfx_line(&w->dc, 127, 0, 127, 30, 1);*/
#define PERIOD 30
int n = -((sys_get_tics() / UI_TICK_RATE ) / 2) % PERIOD;
int x = n, y = 0, yn, xn, x0;
int i;
//printf("x0 %d\n", x);
printf("pls_current %d\n", pls_current);
if(n == PERIOD - 1)
pls_current++;
if(pls_current == pls_total)
pls_current = 0;
i = pls_current;
gfx_set_clip(&w->dc, 70, 0, 127, 30);
while(1)
{
yn = y;
x0 = x;
xn = x;
//printf("x %d y %d xn %d yn %d\n", x, y, xn, yn);
gfx_line(&w->dc, 30+x, 30-y, 30+xn, 30-yn, 1);x=xn;y=yn;
gfx_line(&w->dc, 30+x, 30-y, 30+xn, 30-yn, 1);x=xn;y=yn;
xn = x+cycles[i].ramp;
yn = y+cycles[i].current;
gfx_line(&w->dc, 30+x, 30-y, 30+xn, 30-yn, 1);x=xn;y=yn;
xn = x+cycles[i].flat_top;
gfx_line(&w->dc, 30+x, 30-y, 30+xn, 30-yn, 1);x=xn;y=yn;
xn = x+cycles[i].ejection;
yn = 0;
gfx_line(&w->dc, 30+x, 30-y, 30+xn, 30-yn, 1);x=xn;y=yn;
xn= x0 + 30;
gfx_line(&w->dc, 30+x, 30-y, 30+xn, 30-yn, 1);x=xn;y=yn;
i++;
if(i == pls_total)
i = 0;
if(i == pls_current)
break;
}
gfx_reset_clip(&w->dc);
gfx_line(&w->dc, 68, 0, 68, 30, 1);
i = pls_current - 3;
if (i < 0)
i += pls_total;
for(n=0;n<4;n++)
{
struct pls_cycle *cyc = &cycles[i];
char buf[10];
sprintf(buf,"%-02d %s", i + 1, cyc->name);
gfx_text(&w->dc, &font_xm5x8, 0, n * 8, buf);
if(n == 3)
gfx_box(&w->dc, 0, n*8-1, 60, n*8+7, COLOR_TOGGLE);
i++; i %= pls_total;
}
}
static void pls_event(struct ui_widget *w, struct ui_event event)
{
switch(event.type)
{
case EVT_TICK:
{
if(event.data % 3 == 0) // 15 refreshes/second
w->flags |= WF_DIRTY;
break;
}
default:
break;
}
}
struct ui_widget pls_viewer = {
pls_redraw,
pls_event,
{ 0, 60, 127, 120 },
0,
WF_ACTIVE | WF_VISIBLE
};
void pls_viewer_create()
{
ui_add_widget ( &pls_viewer );
}
/*
* Copyright (C) 2014 Julian Lewis
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Basic drawing library.
*/
#ifndef FONT_H
#define FONT_H
#include <stdint.h>
struct font
{
uint8_t min_char, max_char, height;
const uint8_t *width_table;
const uint16_t *offset_table;
const uint8_t *glyph_data;
};
// List of available fonts
extern const struct font font_helv11;
extern const struct font font_helv17;
extern const struct font font_helv38b;
extern const struct font font_helv29;
extern const struct font font_helv17b;
extern const struct font font_helv22b;
extern const struct font font_xm4x5;
extern const struct font font_xm4x6;
extern const struct font font_luct38;
extern const struct font font_xm16x25b;
extern const struct font font_xm5x8;
#endif /* FONT_H */
/*
* Copyright (C) 2014 Julian Lewis
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Font glyphs defintion.
*/
#include "font.h"
static const uint8_t _gw[] = { 2,2,4,5,6,7,6,2,3,3,4,6,2,6,2,3,5,5,5,5,5,5,5,5,5,5,2,2,5,4,5,5,9,6,6,6,6,6,6,6,6,2,4,6,5,7,6,6,6,6,6,6,4,6,6,8,6,6,6,3,2,2,5,5,2,5,5,4,5,4,4,5,5,2,2,4,2,6,5,5,5,5,4,4,4,4,5,6,5,5,4,3,2,3,6};
static const uint16_t _go[] = { 0,11,22,33,44,55,66,77,88,99,110,121,132,143,154,165,176,187,198,209,220,231,242,253,264,275,286,297,308,319,330,341,352,374,385,396,407,418,429,440,451,462,473,484,495,506,517,528,539,550,561,572,583,594,605,616,627,638,649,660,671,682,693,704,715,726,737,748,759,770,781,792,803,814,825,836,847,858,869,880,891,902,913,924,935,946,957,968,979,990,1001,1012,1023,1034,1045};
static const uint8_t _gd[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x00,0x40,0x00,0x00,
0x00,0x00,0x00,0x50,0x50,0x50,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x50,0xf8,0x50,0xf8,0x50,0x00,0x00,
0x00,0x00,0x00,0x08,0x1c,0x20,0x18,0x04,0x38,0x10,0x00,
0x00,0x00,0x00,0x74,0x54,0x68,0x16,0x2a,0x2e,0x00,0x00,
0x00,0x00,0x00,0x20,0x50,0x24,0x54,0x58,0x2c,0x00,0x00,
0x00,0x00,0x00,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x00,
0x00,0x00,0x00,0x40,0x20,0x20,0x20,0x20,0x20,0x40,0x00,
0x00,0x00,0x00,0x00,0x20,0x70,0x20,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x10,0x10,0x7c,0x10,0x10,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,
0x00,0x00,0x00,0x20,0x20,0x20,0x40,0x40,0x40,0x40,0x00,
0x00,0x00,0x00,0x30,0x48,0x48,0x48,0x48,0x30,0x00,0x00,
0x00,0x00,0x00,0x10,0x30,0x10,0x10,0x10,0x10,0x00,0x00,
0x00,0x00,0x00,0x30,0x48,0x08,0x10,0x20,0x78,0x00,0x00,
0x00,0x00,0x00,0x30,0x08,0x30,0x08,0x08,0x30,0x00,0x00,
0x00,0x00,0x00,0x10,0x10,0x30,0x78,0x10,0x10,0x00,0x00,
0x00,0x00,0x00,0x38,0x20,0x30,0x08,0x08,0x30,0x00,0x00,
0x00,0x00,0x00,0x38,0x40,0x70,0x48,0x48,0x30,0x00,0x00,
0x00,0x00,0x00,0x78,0x08,0x10,0x20,0x20,0x20,0x00,0x00,
0x00,0x00,0x00,0x30,0x48,0x30,0x48,0x48,0x30,0x00,0x00,
0x00,0x00,0x00,0x30,0x48,0x48,0x38,0x08,0x30,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x40,0x40,0x80,
0x00,0x00,0x00,0x00,0x10,0x20,0x40,0x20,0x10,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x70,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x20,0x10,0x08,0x10,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x30,0x08,0x10,0x00,0x10,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,0x20,0x80,0x4c,0x80,0x52,0x80,0x4f,0x00,0x40,0x00,0x3c,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x10,0x28,0x38,0x44,0x44,0x00,0x00,
0x00,0x00,0x00,0x38,0x24,0x38,0x24,0x24,0x38,0x00,0x00,
0x00,0x00,0x00,0x38,0x44,0x40,0x40,0x44,0x38,0x00,0x00,
0x00,0x00,0x00,0x78,0x44,0x44,0x44,0x44,0x78,0x00,0x00,
0x00,0x00,0x00,0x3c,0x20,0x38,0x20,0x20,0x3c,0x00,0x00,
0x00,0x00,0x00,0x3c,0x20,0x38,0x20,0x20,0x20,0x00,0x00,
0x00,0x00,0x00,0x38,0x40,0x4c,0x44,0x44,0x38,0x00,0x00,
0x00,0x00,0x00,0x44,0x44,0x7c,0x44,0x44,0x44,0x00,0x00,
0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,
0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x50,0x20,0x00,0x00,
0x00,0x00,0x00,0x24,0x28,0x30,0x38,0x24,0x24,0x00,0x00,
0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x38,0x00,0x00,
0x00,0x00,0x00,0x22,0x36,0x2a,0x2a,0x2a,0x2a,0x00,0x00,
0x00,0x00,0x00,0x44,0x64,0x54,0x54,0x4c,0x44,0x00,0x00,
0x00,0x00,0x00,0x38,0x44,0x44,0x44,0x44,0x38,0x00,0x00,
0x00,0x00,0x00,0x38,0x24,0x24,0x38,0x20,0x20,0x00,0x00,
0x00,0x00,0x00,0x38,0x44,0x44,0x44,0x44,0x38,0x10,0x08,
0x00,0x00,0x00,0x38,0x24,0x24,0x38,0x24,0x24,0x00,0x00,
0x00,0x00,0x00,0x1c,0x20,0x38,0x04,0x04,0x38,0x00,0x00,
0x00,0x00,0x00,0x70,0x20,0x20,0x20,0x20,0x20,0x00,0x00,
0x00,0x00,0x00,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,
0x00,0x00,0x00,0x24,0x24,0x24,0x24,0x28,0x10,0x00,0x00,
0x00,0x00,0x00,0x49,0x49,0x49,0x36,0x24,0x24,0x00,0x00,
0x00,0x00,0x00,0x24,0x24,0x18,0x18,0x24,0x24,0x00,0x00,
0x00,0x00,0x00,0x64,0x24,0x24,0x18,0x10,0x10,0x00,0x00,
0x00,0x00,0x00,0x3c,0x04,0x08,0x10,0x20,0x3c,0x00,0x00,
0x00,0x00,0x00,0x60,0x40,0x40,0x40,0x40,0x40,0x60,0x00,
0x00,0x00,0x00,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x00,
0x00,0x00,0x00,0xc0,0x40,0x40,0x40,0x40,0x40,0xc0,0x00,
0x00,0x00,0x00,0x00,0x20,0x50,0x88,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x00,
0x00,0x00,0x00,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x60,0x10,0x70,0x50,0x68,0x00,0x00,
0x00,0x00,0x40,0x40,0x70,0x48,0x48,0x48,0x70,0x00,0x00,
0x00,0x00,0x00,0x00,0x30,0x40,0x40,0x40,0x30,0x00,0x00,
0x00,0x00,0x08,0x08,0x38,0x48,0x48,0x48,0x38,0x00,0x00,
0x00,0x00,0x00,0x00,0x20,0x50,0x70,0x40,0x30,0x00,0x00,
0x00,0x00,0x10,0x20,0x70,0x20,0x20,0x20,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x38,0x48,0x48,0x38,0x08,0x30,0x00,
0x00,0x00,0x40,0x40,0x70,0x48,0x48,0x48,0x48,0x00,0x00,
0x00,0x00,0x40,0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00,
0x00,0x00,0x40,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x80,
0x00,0x00,0x40,0x40,0x50,0x60,0x60,0x50,0x50,0x00,0x00,
0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x78,0x54,0x54,0x54,0x54,0x00,0x00,
0x00,0x00,0x00,0x00,0x70,0x48,0x48,0x48,0x48,0x00,0x00,
0x00,0x00,0x00,0x00,0x30,0x48,0x48,0x48,0x30,0x00,0x00,
0x00,0x00,0x00,0x00,0x70,0x48,0x48,0x48,0x70,0x40,0x00,
0x00,0x00,0x00,0x00,0x38,0x48,0x48,0x48,0x38,0x08,0x00,
0x00,0x00,0x00,0x00,0x50,0x60,0x40,0x40,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x30,0x40,0x30,0x10,0x60,0x00,0x00,
0x00,0x00,0x20,0x20,0x70,0x20,0x20,0x20,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x50,0x50,0x50,0x50,0x30,0x00,0x00,
0x00,0x00,0x00,0x00,0x48,0x48,0x48,0x50,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x54,0x54,0x54,0x28,0x28,0x00,0x00,
0x00,0x00,0x00,0x00,0x48,0x48,0x30,0x48,0x48,0x00,0x00,
0x00,0x00,0x00,0x00,0x48,0x48,0x48,0x30,0x20,0x40,0x00,
0x00,0x00,0x00,0x00,0x70,0x10,0x20,0x40,0x70,0x00,0x00,
0x00,0x00,0x00,0x20,0x40,0x40,0xc0,0x40,0x40,0x20,0x00,
0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,
0x00,0x00,0x00,0x80,0x40,0x40,0x60,0x40,0x40,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x24,0x58,0x00,0x00,0x00,0x00
};
const font font_helv11 = {
32, 126, 11,
_gw, _go, _gd
};
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
/*
* Copyright (C) 2014 Julian Lewis
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Font glyphs defintion.
*/
#include "font.h"
static const uint8_t _gw[] = { 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4};
static const uint16_t _go[] = { 0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,255,260,265,270,275,280,285,290,295,300,305,310,315,320,325,330,335,340,345,350,355,360,365,370,375,380,385,390,395,400,405,410,415,420,425,430,435,440,445,450,455,460,465,470};
static const uint8_t _gd[] = { 0x00,0x00,0x00,0x00,0x00,
0xc0,0xc0,0xc0,0x00,0xc0,
0xa0,0xa0,0x00,0x00,0x00,
0xa0,0xe0,0xa0,0xe0,0xa0,
0x40,0xe0,0xc0,0x60,0xe0,
0xa0,0x60,0xc0,0xa0,0x00,
0x40,0x40,0xe0,0xc0,0x40,
0x20,0x60,0x00,0x00,0x00,
0x20,0x40,0x40,0x40,0x20,
0x80,0x40,0x40,0x40,0x80,
0xa0,0x40,0xe0,0x40,0xa0,
0x00,0x40,0xe0,0x40,0x00,
0x00,0x00,0x00,0x40,0xc0,
0x00,0x00,0xe0,0x00,0x00,
0x00,0x00,0x00,0xc0,0xc0,
0x20,0x20,0x40,0x40,0x80,
0x40,0xa0,0xa0,0xa0,0x40,
0x40,0xc0,0x40,0x40,0x40,
0xc0,0x20,0x40,0x80,0xe0,
0xc0,0x20,0x60,0x20,0xe0,
0xa0,0xa0,0xa0,0xe0,0x20,
0xe0,0x80,0xc0,0x20,0xc0,
0x60,0x80,0xe0,0xa0,0xe0,
0xe0,0x20,0x20,0x40,0x40,
0xe0,0xa0,0xe0,0xa0,0xe0,
0xe0,0xa0,0xe0,0x20,0xc0,
0xc0,0xc0,0x00,0xc0,0xc0,
0xc0,0xc0,0x00,0x40,0xc0,
0x20,0x40,0x80,0x40,0x20,
0x00,0xe0,0x00,0xe0,0x00,
0x80,0x40,0x20,0x40,0x80,
0xe0,0x20,0x60,0x00,0x40,
0x60,0xa0,0xc0,0x80,0x60,
0xe0,0xa0,0xe0,0xa0,0xa0,
0xe0,0xa0,0xc0,0xa0,0xe0,
0xe0,0x80,0x80,0x80,0xe0,
0xc0,0xa0,0xa0,0xa0,0xc0,
0xe0,0x80,0xe0,0x80,0xe0,
0xe0,0x80,0xe0,0x80,0x80,
0xe0,0x80,0xa0,0xa0,0xe0,
0xa0,0xa0,0xe0,0xa0,0xa0,
0xe0,0x40,0x40,0x40,0xe0,
0x20,0x20,0x20,0xa0,0xe0,
0xa0,0xa0,0xc0,0xa0,0xa0,
0x80,0x80,0x80,0x80,0xe0,
0xa0,0xe0,0xa0,0xa0,0xa0,
0xe0,0xa0,0xa0,0xa0,0xa0,
0xe0,0xa0,0xa0,0xa0,0xe0,
0xe0,0xa0,0xe0,0x80,0x80,
0xe0,0xa0,0xa0,0xc0,0x60,
0xe0,0xa0,0xc0,0xa0,0xa0,
0xe0,0x80,0xe0,0x20,0xe0,
0xe0,0x40,0x40,0x40,0x40,
0xa0,0xa0,0xa0,0xa0,0xe0,
0xa0,0xa0,0xa0,0xa0,0x40,
0xa0,0xa0,0xa0,0xe0,0xa0,
0xa0,0xe0,0x40,0xe0,0xa0,
0xa0,0xa0,0xe0,0x40,0x40,
0xe0,0x20,0x40,0x80,0xe0,
0x60,0x40,0x40,0x40,0x60,
0x80,0x80,0x40,0x40,0x20,
0xc0,0x40,0x40,0x40,0xc0,
0x40,0xa0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xe0,
0x40,0x60,0x00,0x00,0x00,
0x00,0xe0,0x60,0xa0,0xe0,
0x80,0xe0,0xa0,0xa0,0xe0,
0x00,0xe0,0x80,0x80,0xe0,
0x20,0xe0,0xa0,0xa0,0xe0,
0x00,0xe0,0xa0,0xc0,0xe0,
0x60,0x80,0xc0,0x80,0x80,
0x00,0xe0,0xa0,0x60,0xe0,
0x80,0xe0,0xa0,0xa0,0xa0,
0x00,0x40,0x40,0x40,0x40,
0x00,0x20,0x20,0xa0,0xe0,
0x80,0xa0,0xc0,0xc0,0xa0,
0xc0,0x40,0x40,0x40,0x40,
0x00,0xa0,0xe0,0xa0,0xa0,
0x00,0xe0,0xa0,0xa0,0xa0,
0x00,0xe0,0xa0,0xa0,0xe0,
0x00,0xe0,0xa0,0xe0,0x80,
0x00,0xe0,0xa0,0xe0,0x20,
0x00,0xe0,0xa0,0x80,0x80,
0x00,0xe0,0xc0,0x60,0xe0,
0x40,0xe0,0x40,0x40,0x60,
0x00,0xa0,0xa0,0xa0,0xe0,
0x00,0xa0,0xa0,0xa0,0x40,
0x00,0xa0,0xa0,0xe0,0xa0,
0x00,0xa0,0x40,0x40,0xa0,
0x00,0xa0,0xa0,0x60,0xc0,
0x00,0xe0,0x60,0xc0,0xe0,
0x60,0x40,0xc0,0x40,0x60,
0x40,0x40,0x40,0x40,0x40,
0xc0,0x40,0x60,0x40,0xc0,
0x00,0xc0,0x60,0x00,0x00
};
const font font_xm4x5 = {
32, 126, 5,
_gw, _go, _gd
};
/*
* Copyright (C) 2014 Julian Lewis
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Font glyphs defintion.
*/
#include "font.h"
static const uint8_t _gw[] = { 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4};
static const uint16_t _go[] = { 0,6,12,18,24,30,36,42,48,54,60,66,72,78,84,90,96,102,108,114,120,126,132,138,144,150,156,162,168,174,180,186,192,198,204,210,216,222,228,234,240,246,252,258,264,270,276,282,288,294,300,306,312,318,324,330,336,342,348,354,360,366,372,378,384,390,396,402,408,414,420,426,432,438,444,450,456,462,468,474,480,486,492,498,504,510,516,522,528,534,540,546,552,558,564};
static const uint8_t _gd[] = { 0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x40,0x40,0x00,0x40,0x00,
0xa0,0xa0,0x00,0x00,0x00,0x00,
0xa0,0xe0,0xa0,0xe0,0xa0,0x00,
0xe0,0xc0,0xe0,0x60,0xe0,0x00,
0xa0,0x20,0x40,0x80,0xa0,0x00,
0xe0,0x40,0xe0,0xa0,0xe0,0x00,
0x20,0x40,0x00,0x00,0x00,0x00,
0x20,0x40,0x40,0x40,0x20,0x00,
0x40,0x20,0x20,0x20,0x40,0x00,
0x40,0x40,0xe0,0x40,0xa0,0x00,
0x00,0x40,0xe0,0x40,0x00,0x00,
0x00,0x00,0x00,0x20,0x40,0x00,
0x00,0x00,0xe0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x40,0x00,
0x20,0x20,0x40,0x80,0x80,0x00,
0xe0,0xa0,0xa0,0xa0,0xe0,0x00,
0x40,0xc0,0x40,0x40,0x40,0x00,
0xe0,0x20,0xe0,0x80,0xe0,0x00,
0xe0,0x20,0xe0,0x20,0xe0,0x00,
0xa0,0xa0,0xe0,0x20,0x20,0x00,
0xe0,0x80,0xe0,0x20,0xe0,0x00,
0xe0,0x80,0xe0,0xa0,0xe0,0x00,
0xe0,0x20,0x20,0x20,0x20,0x00,
0xe0,0xa0,0xe0,0xa0,0xe0,0x00,
0xe0,0xa0,0xe0,0x20,0xe0,0x00,
0x00,0x40,0x00,0x40,0x00,0x00,
0x00,0x20,0x00,0x20,0x40,0x00,
0x20,0x40,0x80,0x40,0x20,0x00,
0x00,0xe0,0x00,0xe0,0x00,0x00,
0x80,0x40,0x20,0x40,0x80,0x00,
0xc0,0x20,0x40,0x00,0x40,0x00,
0xe0,0xa0,0xe0,0x80,0xe0,0x00,
0x40,0xa0,0xe0,0xa0,0xa0,0x00,
0xc0,0xa0,0xc0,0xa0,0xc0,0x00,
0x60,0x80,0x80,0x80,0x60,0x00,
0xc0,0xa0,0xa0,0xa0,0xc0,0x00,
0xe0,0x80,0xc0,0x80,0xe0,0x00,
0xe0,0x80,0xc0,0x80,0x80,0x00,
0x60,0x80,0xa0,0xa0,0x60,0x00,
0xa0,0xa0,0xe0,0xa0,0xa0,0x00,
0xe0,0x40,0x40,0x40,0xe0,0x00,
0x20,0x20,0x20,0xa0,0x40,0x00,
0xa0,0xa0,0xc0,0xa0,0xa0,0x00,
0x80,0x80,0x80,0x80,0xe0,0x00,
0xa0,0xe0,0xe0,0xa0,0xa0,0x00,
0xa0,0xe0,0xe0,0xe0,0xa0,0x00,
0x40,0xa0,0xa0,0xa0,0x40,0x00,
0xc0,0xa0,0xc0,0x80,0x80,0x00,
0x40,0xa0,0xa0,0xc0,0x60,0x00,
0xc0,0xa0,0xc0,0xa0,0xa0,0x00,
0x60,0x80,0x40,0x20,0xc0,0x00,
0xe0,0x40,0x40,0x40,0x40,0x00,
0xa0,0xa0,0xa0,0xa0,0xe0,0x00,
0xa0,0xa0,0xa0,0xa0,0x40,0x00,
0xa0,0xa0,0xe0,0xe0,0xa0,0x00,
0xa0,0xa0,0x40,0xa0,0xa0,0x00,
0xa0,0xa0,0x40,0x40,0x40,0x00,
0xe0,0x20,0x40,0x80,0xe0,0x00,
0x60,0x40,0x40,0x40,0x60,0x00,
0x80,0x80,0x40,0x20,0x20,0x00,
0x60,0x20,0x20,0x20,0x60,0x00,
0x40,0xa0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xe0,0x00,
0x40,0x20,0x00,0x00,0x00,0x00,
0x00,0x40,0xa0,0xa0,0x60,0x00,
0x80,0xc0,0xa0,0xa0,0xc0,0x00,
0x00,0x60,0x80,0x80,0x60,0x00,
0x20,0x60,0xa0,0xa0,0x60,0x00,
0x00,0x60,0xe0,0x80,0x60,0x00,
0x20,0x40,0xe0,0x40,0x40,0x00,
0x00,0x60,0xa0,0x60,0x20,0xc0,
0x80,0xc0,0xa0,0xa0,0xa0,0x00,
0x40,0x00,0x40,0x40,0x40,0x00,
0x20,0x00,0x20,0x20,0xa0,0x40,
0x80,0xa0,0xc0,0xc0,0xa0,0x00,
0x40,0x40,0x40,0x40,0x40,0x00,
0x00,0xe0,0xe0,0xe0,0xa0,0x00,
0x00,0xc0,0xa0,0xa0,0xa0,0x00,
0x00,0x40,0xa0,0xa0,0x40,0x00,
0x00,0xc0,0xa0,0xc0,0x80,0x80,
0x00,0x60,0xa0,0x60,0x20,0x20,
0x00,0xc0,0xa0,0x80,0x80,0x00,
0x00,0x60,0xc0,0x60,0xc0,0x00,
0x40,0xe0,0x40,0x40,0x40,0x00,
0x00,0xa0,0xa0,0xa0,0xe0,0x00,
0x00,0xa0,0xa0,0xa0,0x40,0x00,
0x00,0xa0,0xe0,0xe0,0xe0,0x00,
0x00,0xa0,0x40,0x40,0xa0,0x00,
0x00,0xa0,0xa0,0x60,0x20,0xc0,
0x00,0xe0,0x60,0xc0,0xe0,0x00,
0x60,0x40,0xc0,0x40,0x60,0x00,
0x40,0x40,0x00,0x40,0x40,0x00,
0xc0,0x40,0x60,0x40,0xc0,0x00,
0x20,0xe0,0x80,0x00,0x00,0x00
};
const struct font font_xm4x6 = {
32, 126, 6,
_gw, _go, _gd
};
#include "font.h"
static const uint8_t _gw[] = { 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5};
static const uint16_t _go[] = { 0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,256,264,272,280,288,296,304,312,320,328,336,344,352,360,368,376,384,392,400,408,416,424,432,440,448,456,464,472,480,488,496,504,512,520,528,536,544,552,560,568,576,584,592,600,608,616,624,632,640,648,656,664,672,680,688,696,704,712,720,728,736,744,752};
static const uint8_t _gd[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,0x20,0x20,0x20,0x20,0x00,0x20,0x00,
0x28,0x28,0x28,0x00,0x00,0x00,0x00,0x00,
0x50,0x50,0xf8,0x50,0xf8,0x50,0x50,0x00,
0x20,0x78,0xa0,0x70,0x28,0xf0,0x20,0x00,
0x60,0x68,0x10,0x20,0x58,0x18,0x00,0x00,
0x30,0x40,0x40,0x28,0x50,0x50,0x28,0x00,
0x10,0x10,0x20,0x00,0x00,0x00,0x00,0x00,
0x08,0x10,0x20,0x20,0x20,0x10,0x08,0x00,
0x40,0x20,0x10,0x10,0x10,0x20,0x40,0x00,
0x00,0x48,0x30,0x78,0x30,0x48,0x00,0x00,
0x00,0x20,0x20,0xf8,0x20,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x40,
0x00,0x00,0x00,0xf8,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x00,
0x08,0x08,0x10,0x10,0x20,0x20,0x40,0x40,
0x30,0x48,0x58,0x68,0x48,0x48,0x30,0x00,
0x20,0x60,0x20,0x20,0x20,0x20,0x20,0x00,
0x30,0x48,0x08,0x10,0x20,0x40,0x78,0x00,
0x30,0x48,0x08,0x30,0x08,0x48,0x30,0x00,
0x08,0x18,0x18,0x28,0x28,0x78,0x08,0x00,
0x78,0x40,0x40,0x70,0x08,0x08,0x70,0x00,
0x30,0x40,0x40,0x70,0x48,0x48,0x30,0x00,
0x78,0x08,0x08,0x10,0x10,0x20,0x20,0x00,
0x30,0x48,0x48,0x30,0x48,0x48,0x30,0x00,
0x30,0x48,0x48,0x38,0x08,0x08,0x30,0x00,
0x00,0x20,0x20,0x00,0x00,0x20,0x20,0x00,
0x00,0x20,0x20,0x00,0x00,0x20,0x20,0x40,
0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x00,
0x00,0x00,0xf8,0x00,0xf8,0x00,0x00,0x00,
0x40,0x20,0x10,0x08,0x10,0x20,0x40,0x00,
0x30,0x48,0x08,0x10,0x20,0x00,0x20,0x00,
0x00,0x30,0x48,0x58,0x58,0x40,0x30,0x00,
0x30,0x48,0x48,0x78,0x48,0x48,0x48,0x00,
0x70,0x48,0x48,0x70,0x48,0x48,0x70,0x00,
0x30,0x48,0x40,0x40,0x40,0x48,0x30,0x00,
0x70,0x48,0x48,0x48,0x48,0x48,0x70,0x00,
0x78,0x40,0x40,0x70,0x40,0x40,0x78,0x00,
0x78,0x40,0x40,0x70,0x40,0x40,0x40,0x00,
0x30,0x48,0x40,0x58,0x48,0x48,0x38,0x00,
0x48,0x48,0x48,0x78,0x48,0x48,0x48,0x00,
0x70,0x20,0x20,0x20,0x20,0x20,0x70,0x00,
0x18,0x08,0x08,0x08,0x48,0x48,0x30,0x00,
0x48,0x48,0x50,0x60,0x50,0x48,0x48,0x00,
0x40,0x40,0x40,0x40,0x40,0x40,0x78,0x00,
0x48,0x78,0x78,0x48,0x48,0x48,0x48,0x00,
0x48,0x68,0x68,0x58,0x58,0x48,0x48,0x00,
0x30,0x48,0x48,0x48,0x48,0x48,0x30,0x00,
0x70,0x48,0x48,0x70,0x40,0x40,0x40,0x00,
0x30,0x48,0x48,0x48,0x48,0x48,0x30,0x18,
0x70,0x48,0x48,0x70,0x50,0x48,0x48,0x00,
0x30,0x48,0x40,0x30,0x08,0x48,0x30,0x00,
0xf8,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
0x48,0x48,0x48,0x48,0x48,0x48,0x30,0x00,
0x48,0x48,0x48,0x48,0x30,0x30,0x30,0x00,
0x48,0x48,0x48,0x48,0x78,0x78,0x48,0x00,
0x48,0x48,0x30,0x30,0x48,0x48,0x48,0x00,
0x88,0x88,0x50,0x20,0x20,0x20,0x20,0x00,
0x78,0x08,0x10,0x20,0x40,0x40,0x78,0x00,
0x38,0x20,0x20,0x20,0x20,0x20,0x38,0x00,
0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x08,
0x70,0x10,0x10,0x10,0x10,0x10,0x70,0x00,
0x20,0x50,0x88,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,
0x20,0x20,0x10,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x48,0x48,0x58,0x28,0x00,
0x40,0x40,0x70,0x48,0x48,0x48,0x70,0x00,
0x00,0x00,0x38,0x40,0x40,0x40,0x38,0x00,
0x08,0x08,0x38,0x48,0x48,0x48,0x38,0x00,
0x00,0x00,0x30,0x48,0x78,0x40,0x30,0x00,
0x18,0x20,0x20,0x70,0x20,0x20,0x20,0x00,
0x00,0x00,0x38,0x48,0x48,0x38,0x08,0x30,
0x40,0x40,0x70,0x48,0x48,0x48,0x48,0x00,
0x20,0x00,0x60,0x20,0x20,0x20,0x70,0x00,
0x10,0x00,0x30,0x10,0x10,0x10,0x10,0x60,
0x40,0x40,0x48,0x50,0x60,0x50,0x48,0x00,
0x60,0x20,0x20,0x20,0x20,0x20,0x70,0x00,
0x00,0x00,0xd0,0xa8,0xa8,0xa8,0x88,0x00,
0x00,0x00,0x70,0x48,0x48,0x48,0x48,0x00,
0x00,0x00,0x30,0x48,0x48,0x48,0x30,0x00,
0x00,0x00,0x70,0x48,0x48,0x48,0x70,0x40,
0x00,0x00,0x38,0x48,0x48,0x48,0x38,0x08,
0x00,0x00,0x58,0x60,0x40,0x40,0x40,0x00,
0x00,0x00,0x38,0x40,0x30,0x08,0x70,0x00,
0x00,0x20,0x78,0x20,0x20,0x20,0x18,0x00,
0x00,0x00,0x48,0x48,0x48,0x48,0x38,0x00,
0x00,0x00,0x48,0x48,0x48,0x30,0x30,0x00,
0x00,0x00,0x88,0xa8,0xa8,0xa8,0x50,0x00,
0x00,0x00,0x48,0x48,0x30,0x48,0x48,0x00,
0x00,0x00,0x48,0x48,0x48,0x38,0x08,0x30,
0x00,0x00,0x78,0x10,0x20,0x40,0x78,0x00,
0x08,0x10,0x10,0x20,0x10,0x10,0x08,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
0x40,0x20,0x20,0x10,0x20,0x20,0x40,0x00,
0x28,0x50,0x00,0x00,0x00,0x00,0x00,0x00
};
const struct font font_xm5x8 = {
32, 126, 8, _gw, _go, _gd };
#include <string.h>
#include "gfx.h"
#define GFX_POOL_SIZE 4096
static uint32_t gfx_pool_mem[GFX_POOL_SIZE/4];
static int gfx_pool_pos = 0;
void *gfx_alloc(int count)
{
count += 3;
count *= 4;
count /= 4; // align to 32 bits
if(count + gfx_pool_pos >= GFX_POOL_SIZE)
return NULL;
void *p = gfx_pool_mem + gfx_pool_pos;
gfx_pool_pos += count;
return p;
}
static struct widget *widget_list;
void gfx_init_surface( struct surface *surf, struct surface *parent, int x0, int y0, int w, int h )
{
if(!parent)
{
surf->width = w;
surf->height = h;
surf->clip.x0 = 0;
surf->clip.y0 = 0;
surf->clip.x1 = w - 1;
surf->clip.y1 = h - 1;
surf->stride = (w + 7) / 8;
surf->data = gfx_alloc(surf->stride * h);
memset( surf->data, 0, surf->stride * h);
} else {
surf->width = parent->width;
surf->height= parent->height;
surf->stride = parent->stride;
surf->clip.x0 = 0;
surf->clip.y0 = 0;
surf->clip.x1 = w - 1;
surf->clip.y1 = h - 1;
surf->client_x = x0;
surf->client_y = y0;
surf->data = parent->data;
}
}
void gfx_set_clip (struct surface *surf, int x0, int y0, int x1, int y1 )
{
surf->clip.x0 = x0;
surf->clip.y0 = y0;
surf->clip.x1 = x1;
surf->clip.y1 = y1;
}
void gfx_reset_clip (struct surface *surf)
{
surf->clip.x0 = 0;
surf->clip.y0 = 0;
surf->clip.x1 = surf->width - 1;
surf->clip.y1 = surf->height - 1;
}
void gfx_box( struct surface *surf, int x0, int y0, int x1, int y1, int value)
{
uint8_t x, y;
x0 = MAX(x0, surf->clip.x0);
x1 = MIN(x1, surf->clip.x1);
y0 = MAX(y0, surf->clip.y0);
y1 = MIN(y1, surf->clip.y1);
for(x = x0; x <= x1; x++)
{
for(y = y0; y <= y1; y++)
{
gfx_set_pixel(surf, x, y, value);
}
}
}
void gfx_clear(struct surface *surf, int value)
{
gfx_box( surf, 0, 0, surf->width-1, surf->height-1, value);
}
void gfx_line( struct surface *surf, int x0, int y0, int x1, int y1, int value )
{
int dx = abs(x1 - x0);
int sx = x0 < x1 ? 1 : -1;
int dy = abs(y1 - y0);
int sy = y0 < y1 ? 1 : -1;
int err = (dx > dy ? dx : -dy) / 2;
int e2;
for(;;)
{
gfx_set_pixel(surf, x0, y0, value);
if(x0 == x1 && y0 == y1)
break;
e2 = err;
if(e2 > -dx) { err -= dy; x0 += sx; }
if(e2 < dy) { err += dx; y0 += sy; }
}
}
static uint8_t draw_glyph(const struct font *font, struct surface *surf, uint8_t x0, uint8_t y0, char c)
{
if(c < font->min_char || c > font->max_char)
return 0;
const uint8_t *buf = font->glyph_data + font->offset_table[c - font->min_char];
uint8_t w = font->width_table[c - font->min_char];
uint8_t x, y;
//printf("DrawGlyph: %d %d '%c'\n", x0, y0, c);
for(y = 0; y < font->height; y++)
{
for(x = 0; x < w; x++)
{
if(buf[((w + 7) >> 3) * y + (x >> 3)] & (1 << (7 - (x & 7))))
gfx_set_pixel(surf, x + x0, y + y0, c);
}
}
return w;
}
void gfx_text(struct surface *surf, const struct font *font, uint8_t x, uint8_t y, const char *str)
{
char c;
while((c = *str++))
x += draw_glyph(font, surf, x, y, c);
}
void gfx_centered_text(struct surface *surf, const struct font *font, uint8_t y, const char *str)
{
int w = gfx_text_width(font, str);
gfx_text(surf, font, surf->width / 2 - w / 2, y, str);
}
int gfx_text_width( const struct font *font, const char *str)
{
int c;
int w = 0;
while(c = *str++)
{
if(c < font->min_char || c > font->max_char)
continue;
const uint8_t *buf = font->glyph_data + font->offset_table[c - font->min_char];
w += font->width_table[c - font->min_char];
}
printf("Width %d\n", w);
return w;
}
#ifndef __GFX_H
#define __GFX_H
#include <stdint.h>
#include <stdio.h>
#include "font.h"
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define COLOR_WHITE 0
#define COLOR_BLACK 1
#define COLOR_TOGGLE 2
struct rect {
uint8_t x0, y0, x1, y1;
};
struct surface
{
uint8_t width, height, stride;
struct rect clip;
int client_x, client_y;
void *data;
};
static inline void gfx_set_pixel ( struct surface *surf, int x, int y, int value )
{
if(x < surf->clip.x0 || x > surf->clip.x1 || y < surf->clip.y0 || y > surf->clip.y1 )
return;
x += surf->client_x;
y += surf->client_y;
uint8_t mask = 1 << (x & 0x07);
uint8_t *p = surf->data + (y * surf->stride) + (x >> 3);
if(value == COLOR_BLACK)
*p |= mask;
else if (value == COLOR_WHITE)
*p &= ~mask;
else
*p ^= mask;
}
void gfx_init_surface( struct surface *surf, struct surface *parent, int x0, int y0, int w, int h );
void gfx_box( struct surface *surf, int x0, int y0, int x1, int y1, int value);
void gfx_line( struct surface *surf, int x0, int y0, int x1, int y1, int value );
void gfx_text(struct surface *surf, const struct font *font, uint8_t x, uint8_t y, const char *str);
void gfx_centered_text(struct surface *surf, const struct font *font, uint8_t y, const char *str);
int gfx_text_width( const struct font *font, const char *str );
void gfx_clear(struct surface *surf, int value);
void gfx_set_clip (struct surface *surf, int x0, int y0, int x1, int y1 );
void gfx_reset_clip (struct surface *surf );
#endif
\ No newline at end of file
#include "gfx.h"
#include "ui.h"
struct surface screen;
extern void lcd_update(struct surface *surf);
#define MAX_QUEUE_EVENTS 16
struct {
int head, tail, count;
struct ui_event q[MAX_QUEUE_EVENTS];
} event_queue;
static struct ui_widget *widget_list = NULL;
void ui_init()
{
gfx_init_surface( &screen, NULL, 0, 0, 128, 128 );
event_queue.head = 0;
event_queue.tail = 0;
event_queue.count = 0;
digtal_watch_create();
pls_viewer_create(); // move outsidem
}
void ui_post_event( int type, int data )
{
struct ui_event evt;
evt.type = type;
evt.data = data;
//DBG("Post %x/%x\n", type, data);
if(event_queue.count == MAX_QUEUE_EVENTS)
{
DBG("Dropping event %x/%x (queue full)\n", type, data);
return;
}
event_queue.q[event_queue.head] = evt;
event_queue.head = (event_queue.head + 1) % MAX_QUEUE_EVENTS;
event_queue.count++;
}
int ui_poll_events( struct ui_event *evt )
{
if(event_queue.count)
{
*evt = event_queue.q[event_queue.tail];
return 1;
}
return 0;
}
int ui_discard_event()
{
//DBG("discard\n");
event_queue.count--;
event_queue.tail = (event_queue.tail + 1) % MAX_QUEUE_EVENTS;
}
void ui_add_widget(struct ui_widget *w)
{
w->next = NULL;
if(!widget_list)
widget_list = w;
else {
struct ui_widget *wl;
for(wl = widget_list; wl->next; wl = wl->next);
wl->next = w;
}
if(! (w->flags & WF_DOUBLE_BUFFER))
gfx_init_surface(&w->dc, &screen, w->pos.x0, w->pos.y0, w->pos.x1 - w->pos.x0 + 1, w->pos.y1 - w->pos.y0 + 1);
else {
DBG ("NonImpl\n");
}
w->flags |= WF_DIRTY;
}
void ui_update()
{
struct ui_event evt;
int screen_dirty = 0;
if(ui_poll_events(&evt))
{
ui_discard_event();
struct ui_widget *w;
for(w = widget_list; w; w = w->next)
{
//DBG("w %p flags %x\n", w, w->flags);
if((w->flags & WF_ACTIVE) && (w->event))
{
w->event(w, evt);
}
if((w->flags & WF_VISIBLE) && (w->flags & WF_DIRTY))
{
w->redraw(w);
w->flags &= ~WF_DIRTY;
screen_dirty = 1;
}
}
}
if(screen_dirty)
lcd_update( &screen );
}
\ No newline at end of file
#ifndef __UI_H
#define __UI_H
#include <stdint.h>
#include "gfx.h"
#define DBG printf
#define WF_DIRTY (1<<0)
#define WF_VISIBLE (1<<1)
#define WF_TRANSPARENT (1<<2)
#define WF_ACTIVE (1<<3)
#define WF_DOUBLE_BUFFER (1<<4)
#define EVT_PRESS 1
#define EVT_RELEASE 2
#define EVT_TICK 3
#define EVT_FRAME 4
#define EVT_LONG_REEASE 5
#define EVT_TAP 5
#define EVT_ACTIVATE 6
#define EVT_NEXT_CYCLE 7
#define UI_TICK_RATE 30 /* UI refresh ticks = 30 milliseconds */
#define UI_CYCLE_RATE 1200 /* The Machine Cycle */
struct ui_event {
int type;
int data;
};
struct ui_widget {
void (*redraw)(struct ui_widget *w);
void (*event)(struct ui_widget *w, struct ui_event event);
struct rect pos;
uint8_t order;
int flags;
struct surface dc;
struct ui_widget *next;
};
extern struct surface screen;
#endif
#include <SDL/SDL.h>
#include <sys/time.h>
#include "gfx.h"
#include "ui.h"
static SDL_Surface *scr;
void sys_init()
{
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_EVENTTHREAD);
scr=SDL_SetVideoMode(128*3,128*3,32,0);
}
static int last_pressed_key=0;
static int key_hold_tics=0;
static int kb_activity_start;
static int64_t last_tics = -1;
int64_t sys_get_tics()
{
struct timezone tz = {0,0};
struct timeval tv;
gettimeofday(&tv, &tz);
return(tv.tv_sec*1000000LL+tv.tv_usec) / 1000LL;
}
int sys_update()
{
SDL_Event ev;
int cur_key=0;
/* UI Tick Timer */
int64_t tics;
static int64_t last_tics = -1, last_cycle = -1;
static int tick_count = 0, cycle_count = 0;
if(last_tics < 0)
last_tics = sys_get_tics();
if(last_cycle < 0)
last_cycle = sys_get_tics();
tics = sys_get_tics();
if(tics - last_tics >= UI_TICK_RATE)
{
ui_post_event ( EVT_TICK, tick_count );
tick_count ++;
last_tics = tics;
}
if(tics - last_cycle >= UI_CYCLE_RATE)
{
ui_post_event ( EVT_NEXT_CYCLE, cycle_count );
cycle_count ++;
last_cycle = tics;
}
while(SDL_PollEvent(&ev)!=0)
{
if(ev.type==SDL_KEYDOWN)
{
switch(ev.key.keysym.sym)
{
case SDLK_ESCAPE: exit(0); break;
#if 0
case SDLK_LEFT: cur_key=KEY_L; break;
case SDLK_RIGHT: cur_key=KEY_R; break;
case 'm': cur_key=KEY_M; break;
case 'v': cur_key=KEY_VOL; break;
case SDLK_SPACE: cur_key=KEY_PLAY; break;
#endif
}
}
#if 0
if(last_pressed_key!=cur_key)
{
last_pressed_key=cur_key;
key_hold_tics=sys_get_tics();
kb_activity_start =sys_get_tics();
return last_pressed_key|PRESS;
} else return last_pressed_key;
} else if (ev.type==SDL_KEYUP)
{
switch(ev.key.keysym.sym)
{
case SDLK_ESCAPE: exit(0); break;
case SDLK_LEFT: cur_key=KEY_L; break;
case SDLK_RIGHT: cur_key=KEY_R; break;
case 'm': cur_key=KEY_M; break;
case 'v': cur_key=KEY_VOL; break;
case SDLK_SPACE: cur_key=KEY_PLAY; break;
default:return 0;
}
last_pressed_key=0;
kb_activity_start =sys_get_tics();
return cur_key|RELEASE;
}
#endif
}
}
void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to set */
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
switch(bpp) {
case 1:
*p = pixel;
break;
case 2:
*(Uint16 *)p = pixel;
break;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
} else {
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;
case 4:
*(Uint32 *)p = pixel;
break;
}
}
void lcd_update(struct surface *surf)
{
int y, x;
for( y=0;y<3*surf->height;y++)
for( x=0;x<3*surf->width;x++)
{
uint8_t mask = 1 << ((x/3) & 0x07);
uint8_t *p = surf->data + ((y/3) * surf->stride) + ((x/3) >> 3);
putpixel(scr, x, y, (*p&mask) ? 0x202020 : 0xb0cdcb);
}
SDL_UpdateRect(scr, 0, 0, 0, 0);
}
main()
{
sys_init();
ui_init();
for(;;)
{
sys_update();
ui_update();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment