Add gpanel library.

This commit is contained in:
Serge Vakulenko
2015-10-06 13:15:39 -07:00
parent 8f220cdf97
commit 9831ddd3a8
13 changed files with 566 additions and 0 deletions

18
src/libgpanel/Makefile Normal file
View File

@@ -0,0 +1,18 @@
TOPSRC = $(shell cd ../..; pwd)
include $(TOPSRC)/target.mk
CFLAGS += -O -Wall -Werror
OBJS = open.o clear.o pixel.o line.o rect.o fill.o circle.o \
image.o char.o text.o text_width.o
all: ../libgpanel.a
../libgpanel.a: ${OBJS}
@$(AR) cru $@ ${OBJS}
$(RANLIB) $@
install: all
clean:
rm -f *.o a.out core test errs ../libgpanel*.a

39
src/libgpanel/char.c Normal file
View File

@@ -0,0 +1,39 @@
/*
* Draw a single character glyph.
*
* Copyright (C) 2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/
#include <sys/ioctl.h>
#include <sys/gpanel.h>
void gpanel_char(const struct gpanel_font_t *font, int color, int background,
int x, int y, int sym)
{
struct gpanel_char_t param;
param.font = font;
param.color = color;
param.background = background;
param.x = x;
param.y = y;
param.sym = sym;
ioctl(_gpanel_fd, GPANEL_CHAR, &param);
}

36
src/libgpanel/circle.c Normal file
View File

@@ -0,0 +1,36 @@
/*
* Draw a circle (no fill).
*
* Copyright (C) 2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/
#include <sys/ioctl.h>
#include <sys/gpanel.h>
void gpanel_circle(int color, int x, int y, int radius)
{
struct gpanel_circle_t param;
param.color = color;
param.x = x;
param.y = x;
param.radius = radius;
ioctl(_gpanel_fd, GPANEL_CIRCLE, &param);
}

30
src/libgpanel/clear.c Normal file
View File

@@ -0,0 +1,30 @@
/*
* Clear the screen.
*
* Copyright (C) 2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/
#include <sys/ioctl.h>
#include <sys/gpanel.h>
void gpanel_clear(int color)
{
ioctl(_gpanel_fd, GPANEL_CLEAR, color);
}

37
src/libgpanel/fill.c Normal file
View File

@@ -0,0 +1,37 @@
/*
* Fill a rectangle.
*
* Copyright (C) 2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/
#include <sys/ioctl.h>
#include <sys/gpanel.h>
void gpanel_fill(int color, int x0, int y0, int x1, int y1)
{
struct gpanel_rect_t param;
param.color = color;
param.x0 = x0;
param.y0 = y0;
param.x1 = x1;
param.y1 = y1;
ioctl(_gpanel_fd, GPANEL_FILL, &param);
}

37
src/libgpanel/image.c Normal file
View File

@@ -0,0 +1,37 @@
/*
* Draw a rectangular image.
*
* Copyright (C) 2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/
#include <sys/ioctl.h>
#include <sys/gpanel.h>
void gpanel_image(int x, int y, int width, int height, const unsigned short *data)
{
struct gpanel_image_t param;
param.x = x;
param.y = x;
param.width = width;
param.height = height;
param.image = data;
ioctl(_gpanel_fd, GPANEL_IMAGE, &param);
}

37
src/libgpanel/line.c Normal file
View File

@@ -0,0 +1,37 @@
/*
* Draw a line.
*
* Copyright (C) 2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/
#include <sys/ioctl.h>
#include <sys/gpanel.h>
void gpanel_line(int color, int x0, int y0, int x1, int y1)
{
struct gpanel_line_t param;
param.color = color;
param.x0 = x0;
param.y0 = y0;
param.x1 = x1;
param.y1 = y1;
ioctl(_gpanel_fd, GPANEL_LINE, &param);
}

50
src/libgpanel/open.c Normal file
View File

@@ -0,0 +1,50 @@
/*
* Device open and close routines.
*
* Copyright (C) 2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/
#include <unistd.h>
#include <fcntl.h>
#include <sys/gpanel.h>
int _gpanel_fd = -1;
/*
* Open a graphics panel device.
*/
int gpanel_open(const char *devname)
{
_gpanel_fd = open(devname, O_RDWR);
if (_gpanel_fd < 0)
return -1;
return 0;
}
/*
* Close gpanel device.
*/
void gpanel_close(void)
{
if (_gpanel_fd >= 0) {
close(_gpanel_fd);
_gpanel_fd = -1;
}
}

35
src/libgpanel/pixel.c Normal file
View File

@@ -0,0 +1,35 @@
/*
* Draw a single pixel.
*
* Copyright (C) 2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/
#include <sys/ioctl.h>
#include <sys/gpanel.h>
void gpanel_pixel(int color, int x, int y)
{
struct gpanel_pixel_t param;
param.color = color;
param.x = x;
param.y = x;
ioctl(_gpanel_fd, GPANEL_PIXEL, &param);
}

37
src/libgpanel/rect.c Normal file
View File

@@ -0,0 +1,37 @@
/*
* Draw a rectangle frame (no fill).
*
* Copyright (C) 2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/
#include <sys/ioctl.h>
#include <sys/gpanel.h>
void gpanel_rect(int color, int x0, int y0, int x1, int y1)
{
struct gpanel_rect_t param;
param.color = color;
param.x0 = x0;
param.y0 = y0;
param.x1 = x1;
param.y1 = y1;
ioctl(_gpanel_fd, GPANEL_RECT, &param);
}

39
src/libgpanel/text.c Normal file
View File

@@ -0,0 +1,39 @@
/*
* Draw a string.
*
* Copyright (C) 2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/
#include <sys/ioctl.h>
#include <sys/gpanel.h>
void gpanel_text(const struct gpanel_font_t *font, int color, int background,
int x, int y, const char *text)
{
struct gpanel_text_t param;
param.font = font;
param.color = color;
param.background = background;
param.x = x;
param.y = y;
param.text = text;
ioctl(_gpanel_fd, GPANEL_TEXT, &param);
}

View File

@@ -0,0 +1,52 @@
/*
* Compute a string width in pixels.
*
* Copyright (C) 2015 Serge Vakulenko, <serge@vak.ru>
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaim all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
*/
#include <string.h>
#include <sys/ioctl.h>
#include <sys/gpanel.h>
/*
* Calculate a width of text output.
* Handle both fixed and proportional fonts.
* TODO: UTF8 decoding.
*/
int gpanel_text_width(const struct gpanel_font_t *font, const char *text, int nchars)
{
int width, c;
if (! nchars)
nchars = strlen (text);
if (! font->width) {
/* Fixed-width font. */
return nchars * font->maxwidth;
}
width = 0;
while (--nchars >= 0) {
c = (unsigned char) *text++;
if (c < font->firstchar || c >= font->firstchar + font->size)
c = font->defaultchar;
width += font->width[c - font->firstchar];
}
return width;
}