git.y1.nz

fbui

Framebuffer-based graphical environment
download: https://git.y1.nz/archives/fbui.tar.gz
README | Files | Log | Refs

libfbui/MultiTest/main.c

      1 
      2 /*=========================================================================
      3  *
      4  * fbmtest, a multiple-window-per-application test program for FBUI
      5  * Copyright (C) 2004 Zachary T Smith, fbui@comcast.net
      6  *
      7  * This module is free software; you can redistribute it and/or modify
      8  * it under the terms of the GNU General Public License as published by
      9  * the Free Software Foundation; either version 2 of the License, or
     10  * (at your option) any later version.
     11  *
     12  * This module is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  * GNU General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU General Public License
     18  * along with this module; if not, write to the Free Software
     19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
     20  *
     21  * (See the file COPYING in the main directory of this archive for
     22  * more details.)
     23  *
     24  *=======================================================================*/
     25 
     26 
     27 typedef unsigned long u32;
     28 #include <stdio.h>
     29 #include <sys/types.h>
     30 #include <sys/stat.h>
     31 #include <fcntl.h>
     32 #include <sys/ioctl.h>
     33 #include <linux/fb.h>
     34 #include <sys/mman.h>
     35 #include <unistd.h>
     36 #include <string.h>
     37 
     38 #include <linux/vt.h>
     39 #include <linux/input.h>
     40 
     41 #include "libfbui.h"
     42 
     43 
     44 #define NUMWINS 5
     45 int
     46 main(int argc, char** argv)
     47 {
     48 	Display *dpy;
     49 	Window *windows[NUMWINS];
     50 	int inside[NUMWINS];
     51 	Font *pcf = font_new ();
     52 	u32 fg,bg;
     53 	int i;
     54 	int vc=-1;
     55 
     56 	i=1;
     57 	while(i<argc) {
     58 		if (!strncmp("-c",argv[i],2)) {
     59 			if (argv[i][2])
     60 				vc = atoi (2 + argv[i]);
     61 		}
     62 		i++;
     63 	}
     64 
     65 	if (!pcf_read (pcf, "timR12.pcf")) {
     66 		font_free (pcf);
     67 		pcf = NULL;
     68 		FATAL ("cannot load font");
     69 	}
     70 
     71 	short line_height = pcf->ascent + pcf->descent;
     72 
     73 	fg = RGB_YELLOW;
     74 	bg = RGB_BROWN;
     75 
     76 	short win_w, win_h;
     77 	dpy = fbui_display_open ();
     78 	if (!dpy) 
     79 		FATAL ("cannot open display");
     80 
     81 	srand (time(NULL));
     82 
     83 	for (i=0; i< NUMWINS; i++) {
     84 		Window *win;
     85 		char subtitle[10];
     86 
     87 		inside[i] = 0;
     88 
     89 		sprintf (subtitle, "%d", i);
     90 
     91 		do {
     92 			short win_w = 150;
     93 			short win_h = 150;
     94 			int x = rand () % (dpy->width - win_w);
     95 			int y = rand () & (dpy->height - win_h);
     96 			win = fbui_window_open (dpy, win_w, win_h, 
     97 				&win_w, &win_h, 999,999,
     98 				x, y,
     99 				&fg, &bg, 
    100 				"fbmtest", subtitle, 
    101 				FBUI_PROGTYPE_APP, 
    102 				false,false, vc,
    103 				false, 
    104 				false, 
    105 				i == 3 ? true : false, // hide the 4th window
    106 				0,NULL);
    107 		} while (!win);
    108 
    109 		windows[i] = win;
    110 	}
    111 
    112 	printf ("MultiTest: All windows created.\n");
    113 
    114 	while (1) {
    115 		int total;
    116 		int need=0;
    117 		Event ev;
    118 		Window *win;
    119 		int x=0, y=0;
    120 		int type;
    121 		int err;
    122 
    123 		/* Get any event for ANY of our windows */
    124 
    125 		if (err = fbui_wait_event (dpy, &ev, FBUI_EVENTMASK_ALL))
    126 		{
    127 			fbui_print_error (err);
    128 			continue;
    129 		}
    130 
    131 		win = ev.win;
    132 		if (!win)
    133 			FATAL("null window");
    134 
    135 		type = ev.type;
    136 
    137 printf ("%s (subwindow %d) got event %s\n", argv[0], win->id, 
    138 	fbui_get_event_name (type));
    139 
    140 		if (type == FBUI_EVENT_ENTER)
    141 			inside [win->id] = 1;
    142 		else if (type == FBUI_EVENT_LEAVE)
    143 			inside [win->id] = 0;
    144 
    145 		fbui_clear (dpy, win);
    146 
    147 		char expr[100];
    148 		sprintf (expr, "This is window %d", win->id);
    149 
    150 		i=0;
    151 		int in = 0;
    152 		while(i < NUMWINS) {
    153 			if (win->id == windows[i]->id) {
    154 				in = inside[i];
    155 				break;
    156 			}
    157 			i++;
    158 		}
    159 
    160 		if (in)
    161 			fbui_draw_rect (dpy, win, 0, 0, 149,149, RGB_YELLOW);
    162 
    163 		fbui_draw_string (dpy, win, pcf, 6,6, expr, fg);
    164 
    165 		if (type == FBUI_EVENT_MOTION) {
    166 			fbui_draw_line (dpy, win, 0,0, ev.x, ev.y, RGB_WHITE);
    167 			fbui_flush (dpy, win);
    168 		}
    169 	}
    170 
    171 	fbui_display_close (dpy);
    172 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.