void draw_test (int id, ps_context* gc) { ps_rect r = {0.3f, 2.7f, 320.45f, 240.19f}; ps_ellipse(gc, &r); ps_set_source_image(gc, pi); ps_fill(gc); }
void draw_test (int id, ps_context* gc) { ps_rect cr = {2.2f , 4.4f, 322.6f, 261.1f}; ps_reset_clip(gc); switch (ct) { case 1: { ps_rect er = {10, 10, 120, 100}; ps_ellipse(gc, &er); ps_clip(gc); } break; case 2: { ps_rect r1 = {10, 10, 80, 80}; ps_rect r2 = {70, 10, 80, 80}; ps_rect r3 = {40, 70, 80, 80}; ps_clip_rect(gc, &r1); ps_clip_rect(gc, &r2); ps_clip_rect(gc, &r3); } break; case 3: { ps_rect ra[] = {{10, 10, 50, 50},{70, 10, 50, 50},{40, 70, 50, 50}}; ps_clip_rects(gc, ra, 3); } break; case 4: { ps_rect ar = {30, 30, 80,100}; ps_rect br = {10, 10, 120, 140}; ps_path * ph = ps_path_create(); ps_path_add_rect(ph, &ar); ps_path_add_rounded_rect(ph, &br, 10, 10, 10, 10, 15, 15, 15, 15); ps_path_sub_close(ph); ps_clip_path(gc, ph, FILL_RULE_EVEN_ODD); ps_path_unref(ph); } break; } ps_rectangle(gc, &cr); //ps_set_source_image(gc, pi); ps_set_source_pattern(gc, pt); ps_fill(gc); }
static void ps_draw_rect(void *handle, int x, int y, int w, int h, int colour) { psdata *ps = (psdata *)handle; y = ps->ytop - y; /* * Offset by half a pixel for the exactness requirement. */ ps_printf(ps, "newpath %g %g moveto %d 0 rlineto 0 %d rlineto" " %d 0 rlineto closepath\n", x - 0.5, y + 0.5, w, -h, -w); ps_fill(ps, colour); }
void draw_test (int id, ps_context* gc) { ps_rect r1 = {10.1f, 10, 200.3f, 200.6f}; ps_rect r2 = {230.2f, 10, 200.3f, 200.6f}; ps_rect r3 = {10.1f, 230, 200.3f, 200.6f}; ps_rect r4 = {230.2f, 230, 200.3f, 200.6f}; ps_rectangle(gc, &r1); ps_set_source_pattern(gc, pt1); ps_fill(gc); ps_rectangle(gc, &r2); ps_set_source_pattern(gc, pt2); ps_fill(gc); ps_rectangle(gc, &r3); ps_set_source_pattern(gc, pt3); ps_fill(gc); ps_rectangle(gc, &r4); ps_set_source_pattern(gc, pt4); ps_fill(gc); }
static void ps_draw_circle(void *handle, int cx, int cy, int radius, int fillcolour, int outlinecolour) { psdata *ps = (psdata *)handle; cy = ps->ytop - cy; ps_printf(ps, "newpath %d %d %d 0 360 arc closepath\n", cx, cy, radius); if (fillcolour >= 0) { ps_printf(ps, "gsave\n"); ps_fill(ps, fillcolour); ps_printf(ps, "grestore\n"); } ps_stroke(ps, outlinecolour); }
void draw_test (int id, ps_context* gc) { ps_color col = {0, 0, 1, 0.8f}; ps_color sol = {1, 0, 0, 0.8f}; ps_rect cr = {2.7f , 3.4f, 272.4f, 261.3f}; ps_rect gr = {50.2f, 48.8f, 250.1f, 224.5f}; ps_set_composite_operator(gc, (ps_composite)3); ps_set_line_width(gc, 3); ps_rectangle(gc, &cr); ps_set_source_color(gc, &col); ps_paint(gc); ps_set_composite_operator(gc, (ps_composite)op); ps_set_source_color(gc, &sol); ps_ellipse(gc, &gr); ps_fill(gc); }
static void ps_draw_polygon(void *handle, int *coords, int npoints, int fillcolour, int outlinecolour) { psdata *ps = (psdata *)handle; int i; ps_printf(ps, "newpath %d %d moveto\n", coords[0], ps->ytop - coords[1]); for (i = 1; i < npoints; i++) ps_printf(ps, "%d %d lineto\n", coords[i*2], ps->ytop - coords[i*2+1]); ps_printf(ps, "closepath\n"); if (fillcolour >= 0) { ps_printf(ps, "gsave\n"); ps_fill(ps, fillcolour); ps_printf(ps, "grestore\n"); } ps_stroke(ps, outlinecolour); }
void draw_test (int id, ps_context* gc) { // int i; // double w; ps_font* old; // ps_size ts; // ps_font_info info; // ps_glyph g[5]; ps_glyph tg; // ps_point s1; // ps_point e1; ps_color c1= {1, 0, 0, 0.8f}; ps_color c2= {0, 0, 1, 0.8f}; //ps_color x = {0, 0, 0, 1}; ps_rect r = {150, 150, 400, 250}; /* ps_rect er = {150, 50, 100, 100}; ps_reset_clip(gc); ps_ellipse(gc, &er); ps_clip(gc); */ ps_point s = {100, 100}; ps_point e = {250, 100}; // ps_set_shadow(gc, 1, 1, 0.15f); // ps_set_shadow_color(gc, &x); ps_translate(gc, -200, -200); ps_rotate(gc, 0.02f); ps_translate(gc, 200, 200); // ps_set_text_antialias(gc, False); // double ds[] = {5, 3.1, 1.2, 5.5}; // ps_set_line_dash(gc, 0, ds, 4); ps_move_to(gc, &s); ps_line_to(gc, &e); ps_stroke(gc); // ps_set_text_render_type(gc, TEXT_TYPE_MONO); ps_set_text_matrix(gc, pn); ps_text_out_length(gc, 100, 100, text, strlen(text)); /* if (a) { // ps_font_set_size(pf, 16); ps_set_text_color(gc, &c1); a = 0; } else { // ps_font_set_size(pf, 26); ps_set_text_color(gc, &c2); a = 1; } */ //ps_matrix_rotate(pm, 0.13); ps_set_text_matrix(gc, pm); //ps_font_set_weight(pf, w); ps_set_text_color(gc, &c1); ps_set_text_stroke_color(gc, &c2); ps_rectangle(gc, &r); ps_stroke(gc); // ps_wide_text_out_length(gc, 200, 100, wtext, 5); old = ps_set_font(gc, pf); //ts = ps_text_extent(gc, wtext, 5); //fprintf(stderr, "w: %.2f - h: %.2f \n", ts.w, ts.h); /// s1.x = s1.y = 150; // e1.y = 150; // e1.x = 150 + ts.w; // ps_move_to(gc, &s1); // ps_line_to(gc, &e1); // ps_stroke(gc); ps_draw_text(gc, &r, wtext, 5, DRAW_TEXT_STROKE, TEXT_ALIGN_LEFT | TEXT_ALIGN_TOP); //ps_set_source_gradient(gc, gr); //ps_set_source_image(gc, pi); ps_set_source_pattern(gc, pt); ps_get_glyph(gc, 0x56fe, &tg); // ts = ps_glyph_extent(&tg); //fprintf(stderr, "w: %.2f - h: %.2f \n", ts.w, ts.h); ps_get_path_from_glyph(gc, &tg, pa); ps_set_path(gc, pa); ps_fill(gc); // ps_get_font_info(gc, &info); //fprintf(stderr, "h: %.2f - a: %.2f - d: %.2f - l: %.2f \n", info.size, info.ascent, info.descent, info.leading); ps_set_font(gc, old); ps_set_text_render_type(gc, TEXT_TYPE_STROKE); /* for (i=0; i<5; i++) ps_get_glyph(gc, gtext[i], &g[i]); ps_show_glyphs(gc, 200, 200, g, 5); */ }
void on_draw(ps_context* gc) { int i; ps_color color = {1, 1, 1, 1}; ps_set_source_color(gc, &color); ps_clear(gc); ps_set_line_cap(gc, LINE_CAP_BUTT); ps_set_composite_operator(gc, COMPOSITE_SRC_OVER); ps_identity(gc); ps_set_matrix(gc, adjust); ps_scale(gc, (float)scale, (float)scale); // draw background ps_set_source_gradient(gc, shadowGradient); ps_set_path(gc, shadowPath); ps_fill(gc); // draw quadrant ps_set_source_gradient(gc, quadrantGradient); ps_set_path(gc, quadrantPath); ps_fill(gc); ps_identity(gc); ps_scale(gc, (float)scale, (float)scale); // draw inner bevel ps_set_source_gradient(gc, bevelsGradient); ps_set_fill_rule(gc, FILL_RULE_EVEN_ODD); ps_set_path(gc, innerBevelPath); ps_fill(gc); ps_identity(gc); ps_translate(gc, -256, -256); ps_rotate(gc, (float)PI); ps_translate(gc, 256, 256); ps_scale(gc, (float)scale, (float)scale); ps_set_source_gradient(gc, bevelsGradient); ps_set_fill_rule(gc, FILL_RULE_EVEN_ODD); ps_set_path(gc, outerBevelPath); ps_fill(gc); // draw seconds tags { ps_color sc = {0.11f, 0.12f, 0.13f, 0.65f}; ps_set_line_width(gc, 2.0f); ps_set_line_cap(gc, LINE_CAP_ROUND); ps_set_stroke_color(gc, &sc); for (i = 0; i < 60; i++) { if ((i % 5) != 0) { ps_identity(gc); ps_translate(gc, -256, -256); ps_rotate(gc, 2 * PI - ((float)i/60.0f) * PI * 2); ps_translate(gc, 256, 256); ps_scale(gc, (float)scale, (float)scale); ps_set_path(gc, secondTagPath); ps_stroke(gc); } } // draw hours and milliseconds tags for (i = 0; i < 12; i++) { float rot = 2 * PI - (((float)i / 12.0f) * PI * 2); ps_set_line_width(gc, 7.0); ps_identity(gc); ps_translate(gc, -256, -256); ps_rotate(gc, (float)rot); ps_translate(gc, 256, 256); ps_scale(gc, (float)scale, (float)scale); ps_set_path(gc, hourTagPath); ps_stroke(gc); ps_set_line_width(gc, 2.0); ps_identity(gc); ps_translate(gc, -356, -256); ps_rotate(gc, (float)rot); ps_translate(gc, 356, 256); ps_scale(gc, (float)scale, (float)scale); ps_set_path(gc, msTagPath); ps_stroke(gc); } } //draw cursors { time_t ctime; struct tm *ltime; ctime = time(NULL); ltime = localtime(&ctime); drawCursors(gc, ltime->tm_hour, ltime->tm_min, ltime->tm_sec, millsecons); } //draw glass { ps_color gcol = {0.04f, 0.045f, 0.05f, 0.8f}; ps_identity(gc); ps_set_matrix(gc, adjust); ps_scale(gc, (float)scale, (float)scale); ps_set_composite_operator(gc, COMPOSITE_PLUS); ps_set_source_color(gc, &gcol); ps_set_path(gc, glassPath); ps_fill(gc); } }
static void drawCursors(ps_context*gc, unsigned hours, unsigned minutes, unsigned seconds, unsigned milliseconds) { float hh, mm, ss, ks; ps_color col; if (hours < 13) hh = (((float)hours / 12.0f + (float)minutes / 720.0f) * PI * 2) - PI; else hh = (((float)(hours - 12.0f) / 12.0f + (float)minutes / 720.0f) * PI * 2) - PI; mm = (((float)minutes / 60.0f + (float)seconds / 3600.0f) * 2 * PI) - PI; ss = (((float)seconds / 60.0f) * 2 * PI) - PI; ks = (((float)milliseconds / 1000.0f) * 2 * PI) - PI; // milliseconds col.r = 0.0f; col.g = 0.2f; col.b = 0.6f; col.a = 1.0f; ps_identity(gc); ps_set_source_color(gc, &col); ps_translate(gc, -356, -256); ps_rotate(gc, (float)ks); ps_translate(gc, 356, 256); ps_scale(gc, (float)scale, (float)scale); ps_set_path(gc, msCursorPath); ps_fill(gc); // seconds shadow col.r = 0.3f; col.g = 0.3f; col.b = 0.3f; col.a = 0.25f; ps_identity(gc); ps_set_source_color(gc, &col); ps_translate(gc, -255, -257); ps_rotate(gc, (float)ss); ps_translate(gc, 255, 257); ps_scale(gc, (float)scale, (float)scale); ps_set_path(gc, secondCursorPath); ps_fill(gc); // minutes shadow ps_identity(gc); ps_translate(gc, -255.5f, -256.5f); ps_scale(gc, 1.25f, 1.01f); ps_rotate(gc, (float)mm); ps_translate(gc, 255.5f, 256.5f); ps_scale(gc, (float)scale, (float)scale); ps_set_path(gc, minuteCursorPath); ps_fill(gc); // hours shadow ps_identity(gc); ps_translate(gc, -255.5f, -256.5f); ps_scale(gc, 1.25f, 1.01f); ps_rotate(gc, (float)hh); ps_translate(gc, 255.5f, 256.5f); ps_scale(gc, (float)scale, (float)scale); ps_set_path(gc, hourCursorPath); ps_fill(gc); // hours col.r = 0.2f; col.g = 0.2f; col.b = 0.22f; col.a = 1.0f; ps_identity(gc); ps_set_source_color(gc, &col); ps_translate(gc, -256, -256); ps_rotate(gc, (float)hh); ps_translate(gc, 256, 256); ps_scale(gc, (float)scale, (float)scale); ps_set_path(gc, hourCursorPath); ps_fill(gc); // draw screw ps_identity(gc); ps_scale(gc, (float)scale, (float)scale); ps_set_path(gc, cursorScrewPath); ps_fill(gc); // minutes ps_identity(gc); ps_translate(gc, -256, -256); ps_rotate(gc, (float)mm); ps_translate(gc, 256, 256); ps_scale(gc, (float)scale, (float)scale); ps_set_path(gc, minuteCursorPath); ps_fill(gc); // seconds col.r = 0.65f; col.g = 0.1f; col.b = 0.075f; col.a = 1.0f; ps_identity(gc); ps_set_source_color(gc, &col); ps_translate(gc, -256, -256); ps_rotate(gc, (float)ss); ps_translate(gc, 256, 256); ps_scale(gc, (float)scale, (float)scale); ps_set_path(gc, secondCursorPath); ps_fill(gc); }