Improve Cairo demo program
- remove unused variables - add comments - center drawn buttons - make text slightly smaller to fit into button - reorder button colors (r, g, b)
This commit is contained in:
parent
ee9ada9678
commit
61a86d1941
@ -30,9 +30,7 @@
|
|||||||
// uncomment the following line to enable Cairo context autolink feature:
|
// uncomment the following line to enable Cairo context autolink feature:
|
||||||
// #define AUTOLINK
|
// #define AUTOLINK
|
||||||
|
|
||||||
// put your drawing stuff here
|
// draw centered text
|
||||||
float drawargs[7] = {90, 90, 100, 100, 0, 360, 0};
|
|
||||||
const char *name[7] = {"X", "Y", "W", "H", "start", "end", "rotate"};
|
|
||||||
|
|
||||||
static void centered_text(cairo_t *cr, double x0, double y0, double w0, double h0, const char *my_text) {
|
static void centered_text(cairo_t *cr, double x0, double y0, double w0, double h0, const char *my_text) {
|
||||||
cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_OBLIQUE, CAIRO_FONT_WEIGHT_BOLD);
|
cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_OBLIQUE, CAIRO_FONT_WEIGHT_BOLD);
|
||||||
@ -50,12 +48,12 @@ static void centered_text(cairo_t *cr, double x0, double y0, double w0, double h
|
|||||||
cairo_set_line_width(cr, DEF_WIDTH);
|
cairo_set_line_width(cr, DEF_WIDTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw a button object with rounded corners and a label
|
||||||
|
|
||||||
static void round_button(cairo_t *cr, double x0, double y0,
|
static void round_button(cairo_t *cr, double x0, double y0,
|
||||||
double rect_width, double rect_height, double radius,
|
double rect_width, double rect_height, double radius,
|
||||||
double r, double g, double b) {
|
double r, double g, double b) {
|
||||||
|
|
||||||
double x1, y1;
|
double x1, y1;
|
||||||
|
|
||||||
x1 = x0 + rect_width;
|
x1 = x0 + rect_width;
|
||||||
y1 = y0 + rect_height;
|
y1 = y0 + rect_height;
|
||||||
if (!rect_width || !rect_height)
|
if (!rect_width || !rect_height)
|
||||||
@ -112,21 +110,27 @@ static void round_button(cairo_t *cr, double x0, double y0,
|
|||||||
cairo_set_source_rgba(cr, 0, 0, 0.5, 0.3);
|
cairo_set_source_rgba(cr, 0, 0, 0.5, 0.3);
|
||||||
cairo_stroke(cr);
|
cairo_stroke(cr);
|
||||||
|
|
||||||
cairo_set_font_size(cr, 0.08);
|
cairo_set_font_size(cr, 0.075);
|
||||||
centered_text(cr, x0, y0, rect_width, rect_height, "FLTK loves Cairo!");
|
centered_text(cr, x0, y0, rect_width, rect_height, "FLTK loves Cairo!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Cairo rendering cb called during Fl_Cairo_Window::draw() :
|
// draw the entire image (3 buttons), scaled to the given width and height
|
||||||
static void my_cairo_draw_cb(Fl_Cairo_Window *window, cairo_t *cr) {
|
|
||||||
|
|
||||||
int w = window->w(), h = window->h();
|
void draw_image(cairo_t *cr, int w, int h) {
|
||||||
|
|
||||||
cairo_set_line_width(cr, DEF_WIDTH);
|
cairo_set_line_width(cr, DEF_WIDTH);
|
||||||
cairo_scale(cr, w, h);
|
cairo_scale(cr, w, h);
|
||||||
|
|
||||||
round_button(cr, 0.1, 0.05, 0.8, 0.2, 0.4, 0, 0, 1);
|
round_button(cr, 0.1, 0.1, 0.8, 0.2, 0.4, 1, 0, 0);
|
||||||
round_button(cr, 0.1, 0.35, 0.8, 0.2, 0.4, 1, 0, 0);
|
round_button(cr, 0.1, 0.4, 0.8, 0.2, 0.4, 0, 1, 0);
|
||||||
round_button(cr, 0.1, 0.65, 0.8, 0.2, 0.4, 0, 1, 0);
|
round_button(cr, 0.1, 0.7, 0.8, 0.2, 0.4, 0, 0, 1);
|
||||||
|
|
||||||
|
} // draw_image()
|
||||||
|
|
||||||
|
// Cairo rendering cb called during Fl_Cairo_Window::draw()
|
||||||
|
|
||||||
|
static void my_cairo_draw_cb(Fl_Cairo_Window *window, cairo_t *cr) {
|
||||||
|
draw_image(cr, window->w(), window->h());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user