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; }
static bool framebuffer_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) { nsfb_bbox_t rect; bool dotted = false; bool dashed = false; rect.x0 = x0; rect.y0 = y0; rect.x1 = x1; rect.y1 = y1; if (style->fill_type != PLOT_OP_TYPE_NONE) { nsfb_plot_rectangle_fill(nsfb, &rect, style->fill_colour); } if (style->stroke_type != PLOT_OP_TYPE_NONE) { if (style->stroke_type == PLOT_OP_TYPE_DOT) dotted = true; if (style->stroke_type == PLOT_OP_TYPE_DASH) dashed = true; nsfb_plot_rectangle(nsfb, &rect, style->stroke_width, style->stroke_colour, dotted, dashed); } return true; }
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; }
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; }
static bool framebuffer_plot_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, bitmap_flags_t flags) { int xf,yf; nsfb_bbox_t loc; nsfb_bbox_t clipbox; bool repeat_x = (flags & BITMAPF_REPEAT_X); bool repeat_y = (flags & BITMAPF_REPEAT_Y); int bmwidth; int bmheight; unsigned char *bmptr; nsfb_t *bm = (nsfb_t *)bitmap; /* x and y define coordinate of top left of of the initial explicitly * placed tile. The width and height are the image scaling and the * bounding box defines the extent of the repeat (which may go in all * four directions from the initial tile). */ if (!(repeat_x || repeat_y)) { /* Not repeating at all, so just plot it */ loc.x0 = x; loc.y0 = y; loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; return nsfb_plot_copy(bm, NULL, nsfb, &loc); } nsfb_plot_get_clip(nsfb, &clipbox); nsfb_get_geometry(bm, &bmwidth, &bmheight, NULL); nsfb_get_buffer(bm, &bmptr, NULL); /* Optimise tiled plots of 1x1 bitmaps by replacing with a flat fill * of the area. Can only be done when image is fully opaque. */ if ((bmwidth == 1) && (bmheight == 1)) { if ((*(nsfb_colour_t *)bmptr & 0xff000000) != 0) { return nsfb_plot_rectangle_fill(nsfb, &clipbox, *(nsfb_colour_t *)bmptr); } } /* Optimise tiled plots of bitmaps scaled to 1x1 by replacing with * a flat fill of the area. Can only be done when image is fully * opaque. */ if ((width == 1) && (height == 1)) { if (bitmap_get_opaque(bm)) { /** TODO: Currently using top left pixel. Maybe centre * pixel or average value would be better. */ return nsfb_plot_rectangle_fill(nsfb, &clipbox, *(nsfb_colour_t *)bmptr); } } /* get left most tile position */ if (repeat_x) for (; x > clipbox.x0; x -= width); /* get top most tile position */ if (repeat_y) for (; y > clipbox.y0; y -= height); /* tile down and across to extents */ for (xf = x; xf < clipbox.x1; xf += width) { for (yf = y; yf < clipbox.y1; yf += height) { loc.x0 = xf; loc.y0 = yf; loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; nsfb_plot_copy(bm, NULL, nsfb, &loc); if (!repeat_y) break; } if (!repeat_x) break; } return true; }
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); }
static bool framebuffer_plot_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, bitmap_flags_t flags) { nsfb_bbox_t loc; nsfb_bbox_t clipbox; bool repeat_x = (flags & BITMAPF_REPEAT_X); bool repeat_y = (flags & BITMAPF_REPEAT_Y); int bmwidth; int bmheight; int bmstride; enum nsfb_format_e bmformat; unsigned char *bmptr; nsfb_t *bm = (nsfb_t *)bitmap; /* x and y define coordinate of top left of of the initial explicitly * placed tile. The width and height are the image scaling and the * bounding box defines the extent of the repeat (which may go in all * four directions from the initial tile). */ if (!(repeat_x || repeat_y)) { /* Not repeating at all, so just plot it */ loc.x0 = x; loc.y0 = y; loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; return nsfb_plot_copy(bm, NULL, nsfb, &loc); } nsfb_plot_get_clip(nsfb, &clipbox); nsfb_get_geometry(bm, &bmwidth, &bmheight, &bmformat); nsfb_get_buffer(bm, &bmptr, &bmstride); /* Optimise tiled plots of 1x1 bitmaps by replacing with a flat fill * of the area. Can only be done when image is fully opaque. */ if ((bmwidth == 1) && (bmheight == 1)) { if ((*(nsfb_colour_t *)bmptr & 0xff000000) != 0) { return nsfb_plot_rectangle_fill(nsfb, &clipbox, *(nsfb_colour_t *)bmptr); } } /* Optimise tiled plots of bitmaps scaled to 1x1 by replacing with * a flat fill of the area. Can only be done when image is fully * opaque. */ if ((width == 1) && (height == 1)) { if (framebuffer_bitmap_get_opaque(bm)) { /** TODO: Currently using top left pixel. Maybe centre * pixel or average value would be better. */ return nsfb_plot_rectangle_fill(nsfb, &clipbox, *(nsfb_colour_t *)bmptr); } } /* get left most tile position */ if (repeat_x) for (; x > clipbox.x0; x -= width); /* get top most tile position */ if (repeat_y) for (; y > clipbox.y0; y -= height); /* set up top left tile location */ loc.x0 = x; loc.y0 = y; loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; /* plot tiling across and down to extents */ nsfb_plot_bitmap_tiles(nsfb, &loc, repeat_x ? ((clipbox.x1 - x) + width - 1) / width : 1, repeat_y ? ((clipbox.y1 - y) + height - 1) / height : 1, (nsfb_colour_t *)bmptr, bmwidth, bmheight, bmstride * 8 / 32, bmformat == NSFB_FMT_ABGR8888); return true; }
/** 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; }
/** 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; }
static bool framebuffer_plot_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, bitmap_flags_t flags) { int xf,yf; nsfb_bbox_t loc; nsfb_bbox_t clipbox; bool repeat_x = (flags & BITMAPF_REPEAT_X); bool repeat_y = (flags & BITMAPF_REPEAT_Y); nsfb_plot_get_clip(nsfb, &clipbox); /* x and y define coordinate of top left of of the initial explicitly * placed tile. The width and height are the image scaling and the * bounding box defines the extent of the repeat (which may go in all * four directions from the initial tile). */ if (!(repeat_x || repeat_y)) { /* Not repeating at all, so just plot it */ loc.x0 = x; loc.y0 = y; loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; if ((bitmap->width == 1) && (bitmap->height == 1)) { if ((*(nsfb_colour_t *)bitmap->pixdata & 0xff000000) == 0) { return true; } return nsfb_plot_rectangle_fill(nsfb, &loc, *(nsfb_colour_t *)bitmap->pixdata); } else { return nsfb_plot_bitmap(nsfb, &loc, (nsfb_colour_t *)bitmap->pixdata, bitmap->width, bitmap->height, bitmap->width, !bitmap->opaque); } } /* get left most tile position */ if (repeat_x) for (; x > clipbox.x0; x -= width); /* get top most tile position */ if (repeat_y) for (; y > clipbox.y0; y -= height); /* tile down and across to extents */ for (xf = x; xf < clipbox.x1; xf += width) { for (yf = y; yf < clipbox.y1; yf += height) { loc.x0 = xf; loc.y0 = yf; loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; if ((bitmap->width == 1) && (bitmap->height == 1)) { if ((*(nsfb_colour_t *)bitmap->pixdata & 0xff000000) != 0) { nsfb_plot_rectangle_fill(nsfb, &loc, *(nsfb_colour_t *)bitmap->pixdata); } } else { nsfb_plot_bitmap(nsfb, &loc, (nsfb_colour_t *)bitmap->pixdata, bitmap->width, bitmap->height, bitmap->width, !bitmap->opaque); } if (!repeat_y) break; } if (!repeat_x) break; } return true; }
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; }
/** 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; }
/** 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; }
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; }