Example #1
0
/**
 * handler for toolkit window redraw event
 */
static int fb_cw_draw_event(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
	struct fb_corewindow *fb_cw;
	nsfb_bbox_t rbox;
	struct rect clip;

	fb_cw = (struct fb_corewindow *)cbi->context;

	rbox.x0 = fbtk_get_absx(widget);
	rbox.y0 = fbtk_get_absy(widget);

	rbox.x1 = rbox.x0 + fbtk_get_width(widget);
	rbox.y1 = rbox.y0 + fbtk_get_height(widget);

	nsfb_claim(fbtk_get_nsfb(widget), &rbox);

	clip.x0 = fb_cw->scrollx;
	clip.y0 = fb_cw->scrolly;
	clip.x1 = fbtk_get_width(widget) + fb_cw->scrollx;
	clip.y1 = fbtk_get_height(widget) + fb_cw->scrolly;

	fb_cw->draw(fb_cw, &clip);

	nsfb_update(fbtk_get_nsfb(widget), &rbox);

	return 0;
}
Example #2
0
static int
fb_redraw_bitmap(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
    nsfb_bbox_t bbox;
    nsfb_bbox_t rect;
    nsfb_t *nsfb;

    nsfb = fbtk_get_nsfb(widget);

    fbtk_get_bbox(widget, &bbox);

    rect = bbox;

    nsfb_claim(nsfb, &bbox);

    /* clear background */
    if ((widget->bg & 0xFF000000) != 0) {
        /* transparent polygon filling isnt working so fake it */
        nsfb_plot_rectangle_fill(nsfb, &bbox, widget->bg);
    }

    /* plot the image */
    nsfb_plot_bitmap(nsfb,
                     &rect,
                     (nsfb_colour_t *)widget->u.bitmap.bitmap->pixdata,
                     widget->u.bitmap.bitmap->width,
                     widget->u.bitmap.bitmap->height,
                     widget->u.bitmap.bitmap->width,
                     !widget->u.bitmap.bitmap->opaque);

    nsfb_update(nsfb, &bbox);

    return 0;
}
Example #3
0
static int
hscroll_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
	int hscroll;
	int hpos;
	nsfb_bbox_t bbox;
	nsfb_bbox_t rect;
	fbtk_widget_t *root = fbtk_get_root_widget(widget);

	fbtk_get_bbox(widget, &bbox);

	nsfb_claim(root->u.root.fb, &bbox);

	rect = bbox;

	/* background */
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);

	/* scroll well */
	rect.x0 = bbox.x0 + 1;
	rect.y0 = bbox.y0 + 2;
	rect.x1 = bbox.x1 - 2;
	rect.y1 = bbox.y1 - 3;
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->fg);

	/* scroll well outline */
	nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0xFF999999, false, false);

	if ((widget->u.scroll.maximum - widget->u.scroll.minimum) > 0) {
		hscroll = ((widget->width - 4) * widget->u.scroll.thumb) /
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
		hpos = ((widget->width - 4) * widget->u.scroll.position) /
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
	} else {
		hscroll = (widget->width - 4);
		hpos = 0;
	}

	LOG(("hscroll %d", hscroll));

	rect.x0 = bbox.x0 + 3 + hpos;
	rect.y0 = bbox.y0 + 5;
	rect.x1 = bbox.x0 + hscroll + hpos;
	rect.y1 = bbox.y0 + widget->height - 5;

	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);

	nsfb_update(root->u.root.fb, &bbox);

	return 0;
}
Example #4
0
static int
fb_redraw_fill(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
	nsfb_bbox_t bbox;
	nsfb_t *nsfb;

	nsfb = fbtk_get_nsfb(widget);

	fbtk_get_bbox(widget, &bbox);

	nsfb_claim(nsfb, &bbox);

	/* clear background */
	if ((widget->bg & 0xFF000000) != 0) {
		/* transparent polygon filling isnt working so fake it */
		nsfb_plot_rectangle_fill(nsfb, &bbox, widget->bg);
	}

	nsfb_update(nsfb, &bbox);

	return 0;
}
Example #5
0
static int
localhistory_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
	struct gui_localhistory *glh = cbi->context;
	nsfb_bbox_t rbox;

	struct redraw_context ctx = {
		.interactive = true,
		.background_images = true,
		.plot = &fb_plotters
	};

	rbox.x0 = fbtk_get_absx(widget);
	rbox.y0 = fbtk_get_absy(widget);

	rbox.x1 = rbox.x0 + fbtk_get_width(widget);
	rbox.y1 = rbox.y0 + fbtk_get_height(widget);

	nsfb_claim(fbtk_get_nsfb(widget), &rbox);

	nsfb_plot_rectangle_fill(fbtk_get_nsfb(widget), &rbox, 0xffffffff);

	history_redraw_rectangle(glh->bw->history,
				 glh->scrollx,
				 glh->scrolly,
				 fbtk_get_width(widget) + glh->scrollx,
				 fbtk_get_height(widget) + glh->scrolly,
				 0, 0, &ctx);

	nsfb_update(fbtk_get_nsfb(widget), &rbox);

	return 0;
}

static int
localhistory_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
	struct gui_localhistory *glh = cbi->context;

	if (cbi->event->type != NSFB_EVENT_KEY_UP)
		return 0;

	history_click(glh->bw, glh->bw->history, cbi->x, cbi->y, false);

	fbtk_set_mapping(glh->window, false);

	return 1;
}

struct gui_localhistory *
fb_create_localhistory(struct browser_window *bw,
		       fbtk_widget_t *parent,
		       int furniture_width)
{
	struct gui_localhistory *glh;
	glh = calloc(1, sizeof(struct gui_localhistory));

	if (glh == NULL)
		return NULL;

	glh->bw = bw;

	/* container window */
	glh->window = fbtk_create_window(parent, 0, 0, 0, 0, 0);

	glh->history = fbtk_create_user(glh->window, 0, 0, -furniture_width, -furniture_width, glh);

	fbtk_set_handler(glh->history, FBTK_CBT_REDRAW, localhistory_redraw, glh);
	fbtk_set_handler(glh->history, FBTK_CBT_CLICK, localhistory_click, glh);
	/*
	  fbtk_set_handler(gw->localhistory, FBTK_CBT_INPUT, fb_browser_window_input, gw);
	  fbtk_set_handler(gw->localhistory, FBTK_CBT_POINTERMOVE, fb_browser_window_move, bw);
	*/

	/* create horizontal scrollbar */
	glh->hscroll = fbtk_create_hscroll(glh->window,
					   0,
					   fbtk_get_height(glh->window) - furniture_width,
					   fbtk_get_width(glh->window) - furniture_width,
					   furniture_width,
					   FB_SCROLL_COLOUR,
					   FB_FRAME_COLOUR,
					   NULL,
					   NULL);

	glh->vscroll = fbtk_create_vscroll(glh->window,
					   fbtk_get_width(glh->window) - furniture_width,
					   0,
					   furniture_width,
					   fbtk_get_height(glh->window) - furniture_width,
					   FB_SCROLL_COLOUR,
					   FB_FRAME_COLOUR,
					   NULL,
					   NULL);

	fbtk_create_fill(glh->window,
			 fbtk_get_width(glh->window) - furniture_width,
			 fbtk_get_height(glh->window) - furniture_width,
			 furniture_width,
			 furniture_width,
			 FB_FRAME_COLOUR);

	return glh;
}

void
fb_localhistory_map(struct gui_localhistory * glh)
{
	fbtk_set_zorder(glh->window, INT_MIN);
	fbtk_set_mapping(glh->window, true);
}
Example #6
0
static void
fb_redraw(fbtk_widget_t *widget,
	  struct browser_widget_s *bwidget,
	  struct browser_window *bw)
{
	int x;
	int y;
	int caret_x, caret_y, caret_h;
	struct rect clip;
	struct redraw_context ctx = {
		.interactive = true,
		.background_images = true,
		.plot = &fb_plotters
	};
	nsfb_t *nsfb = fbtk_get_nsfb(widget);
	float scale = browser_window_get_scale(bw);

	LOG(("%d,%d to %d,%d",
	     bwidget->redraw_box.x0,
	     bwidget->redraw_box.y0,
	     bwidget->redraw_box.x1,
	     bwidget->redraw_box.y1));

	x = fbtk_get_absx(widget);
	y = fbtk_get_absy(widget);

	/* adjust clipping co-ordinates according to window location */
	bwidget->redraw_box.y0 += y;
	bwidget->redraw_box.y1 += y;
	bwidget->redraw_box.x0 += x;
	bwidget->redraw_box.x1 += x;

	nsfb_claim(nsfb, &bwidget->redraw_box);

	/* redraw bounding box is relative to window */
	clip.x0 = bwidget->redraw_box.x0;
	clip.y0 = bwidget->redraw_box.y0;
	clip.x1 = bwidget->redraw_box.x1;
	clip.y1 = bwidget->redraw_box.y1;

	browser_window_redraw(bw,
			(x - bwidget->scrollx) / scale,
			(y - bwidget->scrolly) / scale,
			&clip, &ctx);

	if (fbtk_get_caret(widget, &caret_x, &caret_y, &caret_h)) {
		/* This widget has caret, so render it */
		nsfb_bbox_t line;
		nsfb_plot_pen_t pen;

		line.x0 = x - bwidget->scrollx + caret_x;
		line.y0 = y - bwidget->scrolly + caret_y;
		line.x1 = x - bwidget->scrollx + caret_x;
		line.y1 = y - bwidget->scrolly + caret_y + caret_h;

		pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
		pen.stroke_width = 1;
		pen.stroke_colour = 0xFF0000FF;

		nsfb_plot_line(nsfb, &line, &pen);
	}

	nsfb_update(fbtk_get_nsfb(widget), &bwidget->redraw_box);

	bwidget->redraw_box.y0 = bwidget->redraw_box.x0 = INT_MAX;
	bwidget->redraw_box.y1 = bwidget->redraw_box.x1 = INT_MIN;
	bwidget->redraw_required = false;
}

static int
fb_browser_window_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
	struct gui_window *gw = cbi->context;
	struct browser_widget_s *bwidget;

	bwidget = fbtk_get_userpw(widget);
	if (bwidget == NULL) {
		LOG(("browser widget from widget %p was null", widget));
		return -1;
	}

	if (bwidget->pan_required) {
		fb_pan(widget, bwidget, gw->bw);
	}

	if (bwidget->redraw_required) {
		fb_redraw(widget, bwidget, gw->bw);
	} else {
		bwidget->redraw_box.x0 = 0;
		bwidget->redraw_box.y0 = 0;
		bwidget->redraw_box.x1 = fbtk_get_width(widget);
		bwidget->redraw_box.y1 = fbtk_get_height(widget);
		fb_redraw(widget, bwidget, gw->bw);
	}
	return 0;
}

static int fb_browser_window_destroy(fbtk_widget_t *widget,
		fbtk_callback_info *cbi)
{
	struct browser_widget_s *browser_widget;

	if (widget == NULL) {
		return 0;
	}

	/* Free private data */
	browser_widget = fbtk_get_userpw(widget);
	free(browser_widget);

	return 0;
}


static const char *fename;
static int febpp;
static int fewidth;
static int feheight;
static const char *feurl;

static bool
process_cmdline(int argc, char** argv)
{
	int opt;

	LOG(("argc %d, argv %p", argc, argv));

	fename = "mtl";
	febpp = 32;

	fewidth = nsoption_int(window_width);
	if (fewidth <= 0) {
		fewidth = 800;
	}
	feheight = nsoption_int(window_height);
	if (feheight <= 0) {
		feheight = 480;
	}

	if ((nsoption_charp(homepage_url) != NULL) && 
	    (nsoption_charp(homepage_url)[0] != '\0')) {
		feurl = nsoption_charp(homepage_url);
	} else {
		feurl = NETSURF_HOMEPAGE;
	}

	while((opt = getopt(argc, argv, "f:b:w:h:")) != -1) {
		switch (opt) {
		case 'f':
			fename = optarg;
			break;

		case 'b':
			febpp = atoi(optarg);
			break;

		case 'w':
			fewidth = atoi(optarg);
			break;

		case 'h':
			feheight = atoi(optarg);
			break;

		default:
			fprintf(stderr,
				"Usage: %s [-f frontend] [-b bpp] url\n",
				argv[0]);
			return false;
		}
	}

	if (optind < argc) {
		feurl = argv[optind];
	}

	return true;
}
Example #7
0
/** Text redraw callback.
 *
 * Called when a text widget requires redrawing.
 *
 * @param widget The widget to be redrawn.
 * @param cbi The callback parameters.
 * @return The callback result.
 */
static int
fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
{
	nsfb_bbox_t bbox;
	nsfb_bbox_t rect;
	fbtk_widget_t *root;
	plot_font_style_t font_style;
	int fh;
	int padding;

	padding = (widget->height * FBTK_WIDGET_PADDING) / 200;

	root = fbtk_get_root_widget(widget);

	fbtk_get_bbox(widget, &bbox);

	rect = bbox;

	nsfb_claim(root->u.root.fb, &bbox);

	/* clear background */
	if ((widget->bg & 0xFF000000) != 0) {
		/* transparent polygon filling isnt working so fake it */
		nsfb_plot_rectangle_fill(root->u.root.fb, &bbox, widget->bg);
	}

	/* widget can have a single pixel outline border */
	if (widget->u.text.outline) {
		rect.x1--;
		rect.y1--;
		nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0x00000000, false, false);
		padding++;
	}

	if (widget->u.text.text != NULL) {
		fh = widget->height - padding - padding;
		font_style.family = PLOT_FONT_FAMILY_SANS_SERIF;
		font_style.size = px_to_pt(fh) * FONT_SIZE_SCALE;
		font_style.weight = 400;
		font_style.flags = FONTF_NONE;
		font_style.background = widget->bg;
		font_style.foreground = widget->fg;

		FBTK_LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d padding %d",
		     widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
		     widget->width, widget->height, fh, padding));
		/* Call the fb text plotting, baseline is 3/4 down the
		 * font, somewhere along the way the co-ordinate
		 * system for the baseline is to the "higher value
		 * pixel co-ordinate" due to this the + 1 is neccessary.
		 */
		fb_plotters.text(bbox.x0 + padding,
			  bbox.y0 + (((fh * 3) + 3)/4) + padding + 1,
			  widget->u.text.text,
			  strlen(widget->u.text.text),
			  &font_style);
	}

	nsfb_update(root->u.root.fb, &bbox);

	return 0;
}
Example #8
0
/** Text button redraw callback.
 *
 * Called when a text widget requires redrawing.
 *
 * @param widget The widget to be redrawn.
 * @param cbi The callback parameters.
 * @return The callback result.
 */
static int
fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
{
	nsfb_bbox_t bbox;
	nsfb_bbox_t rect;
	nsfb_bbox_t line;
	nsfb_plot_pen_t pen;
	plot_font_style_t font_style;
	int fh;
	int border;
	fbtk_widget_t *root = fbtk_get_root_widget(widget);

	if (widget->height < 20) {
		border = 0;
	} else {
		border = (widget->height * 10) / 90;
	}

	pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
	pen.stroke_width = 1;
	pen.stroke_colour = brighten_colour(widget->bg);

	fbtk_get_bbox(widget, &bbox);

	rect = bbox;
	rect.x1--;
	rect.y1--;

	nsfb_claim(root->u.root.fb, &bbox);

	/* clear background */
	if ((widget->bg & 0xFF000000) != 0) {
		/* transparent polygon filling isnt working so fake it */
		nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
	}

	if (widget->u.text.outline) {
		line.x0 = rect.x0;
		line.y0 = rect.y0;
		line.x1 = rect.x0;
		line.y1 = rect.y1;
		nsfb_plot_line(root->u.root.fb, &line, &pen);
		line.x0 = rect.x0;
		line.y0 = rect.y0;
		line.x1 = rect.x1;
		line.y1 = rect.y0;
		nsfb_plot_line(root->u.root.fb, &line, &pen);
		pen.stroke_colour = darken_colour(widget->bg);
		line.x0 = rect.x0;
		line.y0 = rect.y1;
		line.x1 = rect.x1;
		line.y1 = rect.y1;
		nsfb_plot_line(root->u.root.fb, &line, &pen);
		line.x0 = rect.x1;
		line.y0 = rect.y0;
		line.x1 = rect.x1;
		line.y1 = rect.y1;
		nsfb_plot_line(root->u.root.fb, &line, &pen);
		border++;
	}

	if (widget->u.text.text != NULL) {
		fh = widget->height - border - border;
		font_style.family = PLOT_FONT_FAMILY_SANS_SERIF;
		font_style.size = px_to_pt(fh) * FONT_SIZE_SCALE;
		font_style.weight = 400;
		font_style.flags = FONTF_NONE;
		font_style.background = widget->bg;
		font_style.foreground = widget->fg;

		LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d border %d",
		     widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
		     widget->width, widget->height, fh, border));
		/* Call the fb text plotting, baseline is 3/4 down the
		 * font, somewhere along the way the co-ordinate
		 * system for the baseline is to the "higher value
		 * pixel co-ordinate" due to this the + 1 is neccessary.
		 */
		fb_plotters.text(bbox.x0 + border,
			  bbox.y0 + (((fh * 3) + 3)/4) + border + 1,
			  widget->u.text.text,
			  strlen(widget->u.text.text),
			  &font_style);
	}

	nsfb_update(root->u.root.fb, &bbox);

	return 0;
}
Example #9
0
int main(int argc, char **argv)
{
    const char *fename;
    enum nsfb_type_e fetype;
    nsfb_t *nsfb;

    nsfb_bbox_t box;
    nsfb_bbox_t box3;
    uint8_t *fbptr;
    int fbstride;
    int i;
    unsigned int x, y;

    if (argc < 2) {
        fename="sdl";
    } else {
        fename = argv[1];
    }

    fetype = nsfb_type_from_name(fename);
    if (fetype == NSFB_SURFACE_NONE) {
        printf("Unable to convert \"%s\" to nsfb surface type\n",
               fename);
        return EXIT_FAILURE;
    }

    nsfb = nsfb_new(fetype);
    if (nsfb == NULL) {
        printf("Unable to allocate \"%s\" nsfb surface\n", fename);
        return EXIT_FAILURE;
    }

    if (nsfb_init(nsfb) == -1) {
        printf("Unable to initialise nsfb surface\n");
        nsfb_free(nsfb);
        return EXIT_FAILURE;
    }

    /* get the geometry of the whole screen */
    box.x0 = box.y0 = 0;
    nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);

    nsfb_get_buffer(nsfb, &fbptr, &fbstride);
    nsfb_claim(nsfb, &box);

    /* Clear to white */
    nsfb_plot_clg(nsfb, 0xffffffff);
    nsfb_update(nsfb, &box);

    /* test glyph plotting */
    for (i = 0; i < 1000; i++) {
        for (y = 0; y < box.y1 - Mglyph1.h; y += Mglyph1.h) {
            for (x = 0; x < box.x1 - Mglyph1.w; x += Mglyph1.w) {
                box3.x0 = x;
                box3.y0 = y;
                box3.x1 = box3.x0 + Mglyph1.w;
                box3.y1 = box3.y0 + Mglyph1.h;

                nsfb_plot_glyph1(nsfb, &box3,  Mglyph1.data,
                                 Mglyph1.w, 0xff000000);
            }
        }
        nsfb_update(nsfb, &box);
    }

    nsfb_update(nsfb, &box);
    nsfb_free(nsfb);

    return 0;
}
Example #10
0
static int
fb_redraw_bitmap(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
	LOG(("REDRAW BITMAP"));
	//__menuet__debug_out("REDRAW BITMAP");
	nsfb_bbox_t bbox;
	nsfb_bbox_t rect;
	nsfb_t *nsfb;

	LOG(("REDRAW BITMAP 1 "));
	//__menuet__debug_out("REDRAW BITMAP 1");


	nsfb = fbtk_get_nsfb(widget);

	LOG(("REDRAW BITMAP 2"));
	//__menuet__debug_out("REDRAW BITMAP 2");


	fbtk_get_bbox(widget, &bbox);

	rect = bbox;

	LOG(("REDRAW BITMAP 3 "));
	//__menuet__debug_out("REDRAW BITMAP 3");


	nsfb_claim(nsfb, &bbox);

	LOG(("REDRAW BITMAP 4"));
	//__menuet__debug_out("REDRAW BITMAP 4");

	/* clear background */
	if ((widget->bg & 0xFF000000) != 0) {
		/* transparent polygon filling isnt working so fake it */
		
			LOG(("REDRAW BITMAP 5"));
	//__menuet__debug_out("REDRAW BITMAP 5");

		nsfb_plot_rectangle_fill(nsfb, &bbox, widget->bg);
	}

	LOG(("REDRAW BITMAP 6"));
	//__menuet__debug_out("REDRAW BITMAP 6\n");

	/* plot the image */
	
	LOG(("STUB: DON'T REAL DRAW"));
	//__menuet__debug_out("STUB: DON'T REAL DRAW\n");
	
	
	LOG(("pixdata is %x", (nsfb_colour_t *)widget->u.bitmap.bitmap->pixdata));
	LOG(("pixdata is w:%d h:%d",widget->u.bitmap.bitmap->width,
			 widget->u.bitmap.bitmap->height));
	
	//hmm
	
	//int zap;
	//if (widget->u.bitmap.bitmap->width % 4 != 0) {
	//	zap = widget->u.bitmap.bitmap->width + 2; }
	
	//nsfb_plot_rectangle_fill(nsfb, &rect, 0xFFFFFF);
	
	
	nsfb_plot_bitmap(nsfb,
			 &rect,
			 (nsfb_colour_t *)widget->u.bitmap.bitmap->pixdata,
			 //0, 0, 0, 
			 widget->u.bitmap.bitmap->width,
			 widget->u.bitmap.bitmap->height,
			 widget->u.bitmap.bitmap->width, 
			 !widget->u.bitmap.bitmap->opaque);
	
	
		
	
	
	LOG(("REDRAW BITMAP 7"));
	//__menuet__debug_out("REDRAW BITMAP 7\n");

	nsfb_update(nsfb, &bbox);

	LOG(("REDRAW BITMAP OK\n"));
	//__menuet__debug_out("REDRAW BITMAP OK\n");

	return 0;
}
Example #11
0
/** Text redraw callback.
 *
 * Called when a text widget requires redrawing.
 *
 * @param widget The widget to be redrawn.
 * @param cbi The callback parameters.
 * @return The callback result.
 */
static int
fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
{
	nsfb_bbox_t bbox;
	nsfb_bbox_t rect;
	fbtk_widget_t *root;
	plot_font_style_t font_style;
	int caret_x, caret_y, caret_h;
	int fh;
	int padding;
	int scroll = 0;
	bool caret = false;

	fb_text_font_style(widget, &fh, &padding, &font_style);

	if (fbtk_get_caret(widget, &caret_x, &caret_y, &caret_h)) {
		caret = true;
	}

	root = fbtk_get_root_widget(widget);

	fbtk_get_bbox(widget, &bbox);

	rect = bbox;

	nsfb_claim(root->u.root.fb, &bbox);

	/* clear background */
	if ((widget->bg & 0xFF000000) != 0) {
		/* transparent polygon filling isnt working so fake it */
		nsfb_plot_rectangle_fill(root->u.root.fb, &bbox, widget->bg);
	}

	/* widget can have a single pixel outline border */
	if (widget->u.text.outline) {
		rect.x1--;
		rect.y1--;
		nsfb_plot_rectangle(root->u.root.fb, &rect, 1,
				0x00000000, false, false);
	}

	if (widget->u.text.text != NULL) {
		int x = bbox.x0 + padding;
		int y = bbox.y0 + ((fh * 3 + 2) / 4) + padding;

#ifdef FB_USE_FREETYPE
		/* Freetype renders text higher */
		y += 1;
#endif

		if (caret && widget->width - padding - padding < caret_x) {
			scroll = (widget->width - padding - padding) - caret_x;
			x +=  scroll;
		}

		/* Call the fb text plotting, baseline is 3/4 down the font */
		fb_plotters.text(x, y, widget->u.text.text,
				widget->u.text.len, &font_style);
	}

	if (caret) {
		/* This widget has caret, so render it */
		nsfb_t *nsfb = fbtk_get_nsfb(widget);
		nsfb_bbox_t line;
		nsfb_plot_pen_t pen;

		line.x0 = bbox.x0 + caret_x + scroll;
		line.y0 = bbox.y0 + caret_y;
		line.x1 = bbox.x0 + caret_x + scroll;
		line.y1 = bbox.y0 + caret_y + caret_h;

		pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
		pen.stroke_width = 1;
		pen.stroke_colour = 0xFF0000FF;

		nsfb_plot_line(nsfb, &line, &pen);
	}

	nsfb_update(root->u.root.fb, &bbox);

	return 0;
}
Example #12
0
/** Text button redraw callback.
 *
 * Called when a text widget requires redrawing.
 *
 * @param widget The widget to be redrawn.
 * @param cbi The callback parameters.
 * @return The callback result.
 */
static int
fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
{
	nsfb_bbox_t bbox;
	nsfb_bbox_t rect;
	nsfb_bbox_t line;
	nsfb_plot_pen_t pen;
	plot_font_style_t font_style;
	int fh;
	int border;
	fbtk_widget_t *root = fbtk_get_root_widget(widget);

	fb_text_font_style(widget, &fh, &border, &font_style);

	pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
	pen.stroke_width = 1;
	pen.stroke_colour = brighten_colour(widget->bg);

	fbtk_get_bbox(widget, &bbox);

	rect = bbox;
	rect.x1--;
	rect.y1--;

	nsfb_claim(root->u.root.fb, &bbox);

	/* clear background */
	if ((widget->bg & 0xFF000000) != 0) {
		/* transparent polygon filling isnt working so fake it */
		nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
	}

	if (widget->u.text.outline) {
		line.x0 = rect.x0;
		line.y0 = rect.y0;
		line.x1 = rect.x0;
		line.y1 = rect.y1;
		nsfb_plot_line(root->u.root.fb, &line, &pen);
		line.x0 = rect.x0;
		line.y0 = rect.y0;
		line.x1 = rect.x1;
		line.y1 = rect.y0;
		nsfb_plot_line(root->u.root.fb, &line, &pen);
		pen.stroke_colour = darken_colour(widget->bg);
		line.x0 = rect.x0;
		line.y0 = rect.y1;
		line.x1 = rect.x1;
		line.y1 = rect.y1;
		nsfb_plot_line(root->u.root.fb, &line, &pen);
		line.x0 = rect.x1;
		line.y0 = rect.y0;
		line.x1 = rect.x1;
		line.y1 = rect.y1;
		nsfb_plot_line(root->u.root.fb, &line, &pen);
	}

	if (widget->u.text.text != NULL) {
		/* Call the fb text plotting, baseline is 3/4 down the font */
		fb_plotters.text(bbox.x0 + border,
				bbox.y0 + ((fh * 3) / 4) + border,
				widget->u.text.text,
				widget->u.text.len,
				&font_style);
	}

	nsfb_update(root->u.root.fb, &bbox);

	return 0;
}
Example #13
0
int main(int argc, char **argv)
{
    const char *fename;
    enum nsfb_type_e fetype;
    nsfb_t *nsfb;

    int waitloop = 3;

    nsfb_event_t event;
    nsfb_bbox_t box;
    uint8_t *fbptr;
    int fbstride;

    int sides;
    int radius;
    nsfb_point_t *points;
    int loop;
    nsfb_plot_pen_t pen;

    double rotate;

    if (argc < 2) {
        fename="sdl";
    } else {
        fename = argv[1];
    }

    fetype = nsfb_type_from_name(fename);
    if (fetype == NSFB_SURFACE_NONE) {
        fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename);
        return 1;
    }

    nsfb = nsfb_new(fetype);
    if (nsfb == NULL) {
        fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename);
        return 2;
    }

    if (nsfb_init(nsfb) == -1) {
        fprintf(stderr, "Unable to initialise nsfb surface\n");
        nsfb_free(nsfb);
        return 4;
    }

    /* get the geometry of the whole screen */
    box.x0 = box.y0 = 0;
    nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);

    nsfb_get_buffer(nsfb, &fbptr, &fbstride);


    pen.stroke_colour = 0xff000000;
    pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;


    for (rotate =0; rotate < (2 * M_PI); rotate += (M_PI / 8)) {
	    /* claim the whole screen for update */
	    nsfb_claim(nsfb, &box);

	    nsfb_plot_clg(nsfb, 0xffffffff);

	    radius = (box.y1 / 2);

	    for (sides = 18; sides >=9; sides-=2) {
		    points = malloc(sizeof(nsfb_point_t) * sides);

		    for (loop = 0; loop < sides;loop+=2) {
			    points[loop].x = (box.x1 / 2) + 
				    (radius * cos((loop * 2 * M_PI / sides) + rotate));
			    points[loop].y = (box.y1 / 2) + 
				    (radius * sin((loop * 2 * M_PI / sides) + rotate));

			    points[loop+1].x = (box.x1 / 2) + 
				     ((radius / 3) * cos(((loop+1) * 2 * M_PI / sides) + rotate));
			    points[loop+1].y = (box.y1 / 2) + 
				     ((radius / 3) * sin(((loop+1) * 2 * M_PI / sides) + rotate));
		    }

		    nsfb_plot_polygon(nsfb, (const int *)points, sides, 
				      0xff000000 | (0xffffff / (sides * 2)));

		    nsfb_plot_polylines(nsfb, sides, points, &pen);

		    free(points);
		    radius -= 40;
	    }

	    nsfb_update(nsfb, &box);
	    sleepMilli(100);
    }
    
    /* wait for quit event or timeout */
    while (waitloop > 0) {
	if (nsfb_event(nsfb, &event, 1000)  == false) {
	    break;
	}
	if (event.type == NSFB_EVENT_CONTROL) {
	    if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) {
		/* timeout */
		waitloop--;
	    } else if (event.value.controlcode == NSFB_CONTROL_QUIT) {
		break;
	    }
	}
    }

    nsfb_free(nsfb);

    return 0;
}
Example #14
0
int main(int argc, char **argv)
{
    const char *fename;
    enum nsfb_type_e fetype;
    nsfb_t *nsfb;
    nsfb_event_t event;
    int waitloop = 3;

    nsfb_bbox_t box;
    nsfb_bbox_t box2;
    nsfb_bbox_t box3;
    uint8_t *fbptr;
    int fbstride;
    int p[] = { 300,300,  350,350, 400,300, 450,250, 400,200};
    int loop;
    nsfb_plot_pen_t pen;
    const char *dumpfile = NULL;

    if (argc < 2) {
        fename="sdl";
    } else {
        fename = argv[1];
	if (argc >= 3) {
	    dumpfile = argv[2];
	}
    }

    fetype = nsfb_type_from_name(fename);
    if (fetype == NSFB_SURFACE_NONE) {
        fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename);
        return 1;
    }

    nsfb = nsfb_new(fetype);
    if (nsfb == NULL) {
        fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename);
        return 2;
    }

    if (nsfb_init(nsfb) == -1) {
        fprintf(stderr, "Unable to initialise nsfb surface\n");
        nsfb_free(nsfb);
        return 4;
    }

    /* get the geometry of the whole screen */
    box.x0 = box.y0 = 0;
    nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);

    nsfb_get_buffer(nsfb, &fbptr, &fbstride);

    /* claim the whole screen for update */
    nsfb_claim(nsfb, &box);

    /* first test, repeatedly clear the graphics area, should result in the
     * same operation as a single clear to the final colour 
     */
    for (loop = 0; loop < 256;loop++) {
        nsfb_plot_clg(nsfb, 0xffffff00 | loop);
    }

    /* draw black radial lines from the origin */
    pen.stroke_colour = 0xff000000;
    for (loop = 0; loop < box.x1; loop += 20) {
        box2 = box;
        box2.x1 = loop;
        nsfb_plot_line(nsfb, &box2, &pen);
    }
    
    /* draw blue radial lines from the bottom right */
    pen.stroke_colour = 0xffff0000;
    for (loop = 0; loop < box.x1; loop += 20) {
        box2 = box;
        box2.x0 = loop;
        nsfb_plot_line(nsfb, &box2, &pen);
    }
    
    /* draw green radial lines from the bottom left */
    pen.stroke_colour = 0xff00ff00;
    for (loop = 0; loop < box.x1; loop += 20) {
        box2.x0 = box.x0;
        box2.x1 = loop;
        box2.y0 = box.y1;
        box2.y1 = box.y0;
        nsfb_plot_line(nsfb, &box2, &pen);
    }

    /* draw red radial lines from the top right */
    pen.stroke_colour = 0xff0000ff;
    for (loop = 0; loop < box.x1; loop += 20) {
        box2.x0 = box.x1;
        box2.x1 = loop;
        box2.y0 = box.y0;
        box2.y1 = box.y1;
        nsfb_plot_line(nsfb, &box2, &pen);
    }

    /* draw an unclipped rectangle */
    box2.x0 = box2.y0 = 100;
    box2.x1 = box2.y1 = 300;

    nsfb_plot_rectangle_fill(nsfb, &box2, 0xff0000ff);

    nsfb_plot_rectangle(nsfb, &box2, 1, 0xff00ff00, false, false);

    nsfb_plot_polygon(nsfb, p, 5, 0xffff0000);

    nsfb_plot_set_clip(nsfb, &box2);

    box3.x0 = box3.y0 = 200;
    box3.x1 = box3.y1 = 400;

    nsfb_plot_rectangle_fill(nsfb, &box3, 0xff00ffff);

    nsfb_plot_rectangle(nsfb, &box3, 1, 0xffffff00, false, false);

    for (loop = 100; loop < 400;loop++) {
        nsfb_plot_point(nsfb, loop, 150, 0xffaa1111);
        nsfb_plot_point(nsfb, loop, 160, 0x99aa1111);
    }

    nsfb_plot_set_clip(nsfb, NULL);

    box3.x0 = box3.y0 = 400;
    box3.x1 = box3.y1 = 600;

    nsfb_plot_ellipse_fill(nsfb, &box3, 0xffff0000);

    nsfb_plot_ellipse(nsfb, &box3, 0xff0000ff);

    box3.x0 = 500;
    box3.x1 = 700;
    box3.y0 = 400;
    box3.y1 = 500;

    nsfb_plot_ellipse_fill(nsfb, &box3, 0xffff0000);

    nsfb_plot_ellipse(nsfb, &box3, 0xff0000ff);

    box3.x0 = 600;
    box3.x1 = 700;
    box3.y0 = 300;
    box3.y1 = 500;

    nsfb_plot_ellipse_fill(nsfb, &box3, 0xff0000ff);

    nsfb_plot_ellipse(nsfb, &box3, 0xffff0000);

    box2.x0 = 400;
    box2.y0 = 400;
    box2.x1 = 500;
    box2.y1 = 500;

    box3.x0 = 600;
    box3.y0 = 200;
    box3.x1 = 700;
    box3.y1 = 300;

    nsfb_plot_copy(nsfb, &box2, nsfb, &box3);

    /* test glyph plotting */
    for (loop = 100; loop < 200; loop+= Mglyph1.w) {
        box3.x0 = loop;
        box3.y0 = 20;
        box3.x1 = box3.x0 + Mglyph8.w;
        box3.y1 = box3.y0 + Mglyph8.h;

        nsfb_plot_glyph1(nsfb, &box3,  Mglyph1.data, Mglyph1.w, 0xff000000);
    }

    /* test glyph plotting */
    for (loop = 100; loop < 200; loop+= Mglyph8.w) {
        box3.x0 = loop;
        box3.y0 = 50;
        box3.x1 = box3.x0 + Mglyph8.w;
        box3.y1 = box3.y0 + Mglyph8.h;

        nsfb_plot_glyph8(nsfb, &box3,  Mglyph8.data, Mglyph8.w, 0xff000000);
    }

    nsfb_update(nsfb, &box);

    /* random rectangles in clipped area*/
    box2.x0 = 400;
    box2.y0 = 50;
    box2.x1 = 600;
    box2.y1 = 100;

    nsfb_plot_set_clip(nsfb, &box2);

    srand(1234);

    for (loop=0; loop < 10000; loop++) {
        nsfb_claim(nsfb, &box2);
        box3.x0 = rand() / (RAND_MAX / box.x1);
        box3.y0 = rand() / (RAND_MAX / box.y1);
        box3.x1 = rand() / (RAND_MAX / 400);
        box3.y1 = rand() / (RAND_MAX / 400);
        nsfb_plot_rectangle_fill(nsfb, &box3, 0xff000000 | rand());
        nsfb_update(nsfb, &box2);
    }

    /* wait for quit event or timeout */
    while (waitloop > 0) {
	if (nsfb_event(nsfb, &event, 1000)  == false) {
	    break;
	}
	if (event.type == NSFB_EVENT_CONTROL) {
	    if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) {
		/* timeout */
		waitloop--;
	    } else if (event.value.controlcode == NSFB_CONTROL_QUIT) {
		break;
	    }
	}
    }

    dump(nsfb, dumpfile);

    nsfb_free(nsfb);

    return 0;
}
Example #15
0
int main(int argc, char **argv)
{
extern nsfb_surface_rtns_t sdl_rtns;
	
	_nsfb_register_surface(NSFB_SURFACE_SDL, &sdl_rtns, "sdl");
	
	__menuet__debug_out("Starting bezier\n");
	freopen("stderr","w",stderr);
	
	freopen("stdout","w",stdout);

    const char *fename;
    enum nsfb_type_e fetype;
    nsfb_t *nsfb;
    nsfb_event_t event;
    int waitloop = 3;

    nsfb_bbox_t box;
    nsfb_bbox_t box2;
    uint8_t *fbptr;
    int fbstride;
    nsfb_point_t ctrla;
    nsfb_point_t ctrlb;
    int loop;
    nsfb_plot_pen_t pen;

    if (argc < 2) {
        fename="sdl";
    } else {
        fename = argv[1];
    }

    fetype = nsfb_type_from_name(fename);
    if (fetype == NSFB_SURFACE_NONE) {
    __menuet__debug_out("Can't convert\n");
        fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename);
        return 1;
    }

    nsfb = nsfb_new(fetype);
    if (nsfb == NULL) {
		__menuet__debug_out("Can't allocate\n");
        fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename);
        return 2;
    }

    if (nsfb_init(nsfb) == -1) {
		__menuet__debug_out("Init failed\n");
        fprintf(stderr, "Unable to initialise nsfb surface\n");
        nsfb_free(nsfb);
        return 4;
    }

    /* get the geometry of the whole screen */
    box.x0 = box.y0 = 0;
    nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);

    nsfb_get_buffer(nsfb, &fbptr, &fbstride);

    /* claim the whole screen for update */
    nsfb_claim(nsfb, &box);

    nsfb_plot_clg(nsfb, 0xffffffff);

    box2.x0=100;
    box2.y0=100;

    box2.x1=400;
    box2.y1=400;

    pen.stroke_colour = 0xff000000;
    pen.fill_colour = 0xffff0000;
    pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
    pen.fill_type = NFSB_PLOT_OPTYPE_NONE;

    for (loop=-300;loop < 600;loop+=100) {
        ctrla.x = 100;
        ctrla.y = loop;

        ctrlb.x = 400;
        ctrlb.y = 500 - loop;

        nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrlb, &pen);
    }


    box2.x0=400;
    box2.y0=100;

    box2.x1=600;
    box2.y1=400;

    nsfb_plot_line(nsfb, &box2, &pen);

    box2.x0=800;
    box2.y0=100;

    box2.x1=600;
    box2.y1=400;

    nsfb_plot_line(nsfb, &box2, &pen);

    box2.x0=400;
    box2.y0=100;

    box2.x1=800;
    box2.y1=100;

    ctrla.x = 600;
    ctrla.y = 400;

    pen.stroke_colour = 0xffff0000;

    nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrla, &pen);

    box2.x0=400;
    box2.y0=100;

    box2.x1=800;
    box2.y1=100;

    ctrla.x = 600;
    ctrla.y = 400;

    pen.stroke_colour = 0xff0000ff;

    nsfb_plot_quadratic_bezier(nsfb, &box2, &ctrla, &pen);

    nsfb_update(nsfb, &box);
    
    /* wait for quit event or timeout */
    while (waitloop > 0) {
	if (nsfb_event(nsfb, &event, 1000)  == false) {
	    break;
	}
	if (event.type == NSFB_EVENT_CONTROL) {
	    if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) {
		/* timeout */
		waitloop--;
	    } else if (event.value.controlcode == NSFB_CONTROL_QUIT) {
		break;
	    }
	}
    }

    nsfb_free(nsfb);

    return 0;
}