26#include <libnsfb_plot.h>
27#include <libnsfb_plot_util.h>
28#include <libnsfb_event.h>
47#define brighten_colour(c1) \
48 (((((7 * ((c1 >> 16) & 0xff)) >> 3) + 32) << 16) | \
49 ((((7 * ((c1 >> 8) & 0xff)) >> 3) + 32) << 8) | \
50 ((((7 * (c1 & 0xff)) >> 3) + 32) << 0))
53#define px_to_pt(x) (((x) * 72) / FBTK_DPI)
60 if (widget->
u.
text.outline)
66 *padding += widget->
height / 6;
67 *font_height = widget->
height - *padding - *padding;
70 *padding = (widget->
height - *padding - *font_height) / 2;
96 int caret_x, caret_y, caret_h;
103 .background_images =
true,
119 nsfb_claim(
root->u.root.fb, &bbox);
122 if ((widget->
bg & 0xFF000000) != 0) {
124 nsfb_plot_rectangle_fill(
root->u.root.fb, &bbox, widget->
bg);
128 if (widget->
u.
text.outline) {
131 nsfb_plot_rectangle(
root->u.root.fb, &
rect, 1,
132 0x00000000,
false,
false);
135 if (widget->
u.
text.text != NULL) {
136 int x = bbox.x0 + padding;
137 int y = bbox.y0 + ((fh * 3 + 2) / 4) + padding;
139#ifdef FB_USE_FREETYPE
144 if (caret && widget->
width - padding - padding < caret_x) {
145 scroll = (widget->
width - padding - padding) - caret_x;
163 line.x0 = bbox.x0 + caret_x + scroll;
164 line.y0 = bbox.y0 + caret_y;
165 line.x1 = bbox.x0 + caret_x + scroll;
166 line.y1 = bbox.y0 + caret_y + caret_h;
168 pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
169 pen.stroke_width = 1;
170 pen.stroke_colour = 0xFF0000FF;
175 nsfb_update(
root->u.root.fb, &bbox);
194 if (widget->
u.
text.text != NULL) {
195 free(widget->
u.
text.text);
222 .background_images =
true,
228 pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
229 pen.stroke_width = 1;
238 nsfb_claim(
root->u.root.fb, &bbox);
241 if ((widget->
bg & 0xFF000000) != 0) {
243 nsfb_plot_rectangle_fill(
root->u.root.fb, &
rect, widget->
bg);
246 if (widget->
u.
text.outline) {
251 nsfb_plot_line(
root->u.root.fb, &
line, &pen);
256 nsfb_plot_line(
root->u.root.fb, &
line, &pen);
262 nsfb_plot_line(
root->u.root.fb, &
line, &pen);
267 nsfb_plot_line(
root->u.root.fb, &
line, &pen);
270 if (widget->
u.
text.text != NULL) {
275 bbox.y0 + ((fh * 3) / 4) +
border,
280 nsfb_update(
root->u.root.fb, &bbox);
310 bool caret_moved =
false;
314 if (cbi->
event == NULL) {
316 if (widget->
u.
text.text == NULL)
317 widget->
u.
text.text = calloc(1,1);
322 value = cbi->
event->value.keycode;
324 if (cbi->
event->type != NSFB_EVENT_KEY_DOWN) {
326 case NSFB_KEY_RSHIFT:
327 modifier &= ~FBTK_MOD_RSHIFT;
330 case NSFB_KEY_LSHIFT:
331 modifier &= ~FBTK_MOD_LSHIFT;
335 modifier &= ~FBTK_MOD_RCTRL;
339 modifier &= ~FBTK_MOD_LCTRL;
349 case NSFB_KEY_BACKSPACE:
350 if (widget->
u.
text.idx <= 0)
352 memmove(widget->
u.
text.text + widget->
u.
text.idx - 1,
355 widget->
u.
text.idx--;
356 widget->
u.
text.len--;
365 case NSFB_KEY_RETURN:
370 if (widget->
u.
text.idx < widget->
u.
text.len) {
372 widget->
u.
text.idx++;
381 if (widget->
u.
text.idx > 0) {
383 widget->
u.
text.idx--;
385 widget->
u.
text.idx = 0;
392 if (widget->
u.
text.idx > 0) {
393 widget->
u.
text.idx = 0;
400 if (widget->
u.
text.idx < widget->
u.
text.len) {
407 case NSFB_KEY_PAGEUP:
408 case NSFB_KEY_PAGEDOWN:
415 case NSFB_KEY_RSHIFT:
419 case NSFB_KEY_LSHIFT:
434 if (value == NSFB_KEY_u) {
436 widget->
u.
text.idx = 0;
437 widget->
u.
text.len = 0;
438 widget->
u.
text.text[widget->
u.
text.len] =
'\0';
439 widget->
u.
text.width = 0;
446 temp = realloc(widget->
u.
text.text, widget->
u.
text.len + 2);
451 widget->
u.
text.text = temp;
452 memmove(widget->
u.
text.text + widget->
u.
text.idx + 1,
457 widget->
u.
text.idx++;
458 widget->
u.
text.len++;
459 widget->
u.
text.text[widget->
u.
text.len] =
'\0';
469 widget->
u.
text.idx, &widget->
u.
text.idx_offset);
503 &widget->
u.
text.idx_offset);
504 widget->
u.
text.idx = idx;
534 widget->
u.
text.enter = enter;
535 widget->
u.
text.pw = pw;
551 if (widget->
u.
text.text != NULL) {
552 if (strcmp(widget->
u.
text.text,
text) == 0)
554 free(widget->
u.
text.text);
565 widget->
u.
text.idx, &widget->
u.
text.idx_offset);
596 neww->
u.
text.outline = outline;
624 neww->
u.
text.outline = outline;
625 neww->
u.
text.enter = enter;
626 neww->
u.
text.pw = pw;
656 neww->
u.
text.outline =
true;
Browser window creation and manipulation interface.
int fbtk_set_ptr(fbtk_widget_t *widget, fbtk_callback_info *cbi)
set pointer to bitmap in context.
fbtk_widget_t * fbtk_widget_new(fbtk_widget_t *parent, enum fbtk_widgettype_e type, int x, int y, int width, int height)
creates a new widget and insert it into to hierachy.
fbtk_widget_t * fbtk_get_root_widget(fbtk_widget_t *widget)
find the root widget from any widget in the toolkit hierarchy.
fbtk_callback fbtk_set_handler(fbtk_widget_t *widget, fbtk_callback_type cbt, fbtk_callback cb, void *pw)
Set a callback handler.
void fbtk_request_redraw(fbtk_widget_t *widget)
Indicate a widget should be redrawn.
fbtk_modifier_type
Key modifier status.
bool fbtk_get_bbox(fbtk_widget_t *widget, struct nsfb_bbox_s *bbox)
Get a widget's bounding box in absolute screen co-ordinates.
int fbtk_keycode_to_ucs4(int code, fbtk_modifier_type mods)
Convert a framebuffer keycode to ucs4.
int(* fbtk_enter_t)(void *pw, char *text)
void fbtk_set_caret(fbtk_widget_t *widget, bool set, int x, int y, int height, void(*remove_caret)(fbtk_widget_t *widget))
Set caret owner and position.
nsfb_t * fbtk_get_nsfb(fbtk_widget_t *widget)
Retrieve the framebuffer library handle from toolkit widget.
bool fbtk_get_caret(fbtk_widget_t *widget, int *x, int *y, int *height)
Get a widget caret pos, if it owns caret.
int(* fbtk_callback)(fbtk_widget_t *widget, fbtk_callback_info *cbi)
static struct directory * root
const struct plotter_table fb_plotters
framebuffer plot operation table
nserror fb_font_position(const struct plot_font_style *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x)
Find the position in a string where an x coordinate falls.
nserror fb_font_width(const struct plot_font_style *fstyle, const char *string, size_t length, int *width)
Measure the width of a string.
struct fbtk_bitmap hand_image
Target independent plotting interface.
#define darken_colour(c1)
@ PLOT_FONT_FAMILY_SANS_SERIF
#define PLOT_STYLE_SCALE
Scaling factor for plot styles.
Interface to utility string handling.
Container for border values during table border calculations.
widget callback information
plot_font_generic_family_t family
Generic family to plot with.
colour foreground
Colour of text.
plot_font_flags_t flags
Font flags.
plot_style_fixed size
Font size, in pt.
colour background
Background colour to blend to, if appropriate.
int weight
Font weight: value in range [100,900] as per CSS.
nserror(* text)(const struct redraw_context *ctx, const plot_font_style_t *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
const struct plotter_table * plot
Current plot operation table.
bool interactive
Redraw to show interactive features.
static int text_input_strip_focus(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Routine called when "stripped of focus" event occours for writeable widget.
static int text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Routine called when text events occour in writeable widget.
static int text_input_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Routine called when click events occour in writeable widget.
fbtk_widget_t * fbtk_create_text(fbtk_widget_t *parent, int x, int y, int width, int height, colour bg, colour fg, bool outline)
Create a text widget.
void fbtk_writable_text(fbtk_widget_t *widget, fbtk_enter_t enter, void *pw)
Alter a text widget to be writable.
static void fb_text_font_style(fbtk_widget_t *widget, int *font_height, int *padding, plot_font_style_t *font_style)
#define brighten_colour(c1)
void fbtk_set_text(fbtk_widget_t *widget, const char *text)
Change the text of a text widget.
fbtk_widget_t * fbtk_create_writable_text(fbtk_widget_t *parent, int x, int y, int width, int height, colour bg, colour fg, bool outline, fbtk_enter_t enter, void *pw)
Create a writable text widget.
fbtk_widget_t * fbtk_create_text_button(fbtk_widget_t *parent, int x, int y, int width, int height, colour bg, colour fg, fbtk_callback click, void *pw)
Create a button with text.
static void fb_text_input_remove_caret_cb(fbtk_widget_t *widget)
static int fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Text redraw callback.
static int fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Text button redraw callback.
static int fb_destroy_text(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Text destroy callback.
uint32_t colour
Colour type: XBGR.
struct rect rect
Rectangle coordinates.
static nserror line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.