void pictmeter_paint(t_pictmeter *x, t_object *patcherview) { t_rect src, dst, rect; t_jgraphics *g = (t_jgraphics *) patcherview_get_jgraphics(patcherview); // obtain graphics context jbox_get_rect_for_view((t_object *)x, patcherview, &rect); if (!x->p_surface) return; // draw if the value is non zero if (x->p_value) { src.width = jgraphics_image_surface_get_width(x->p_surface); src.height = jgraphics_image_surface_get_height(x->p_surface); src.x = 0; src.y = 0; dst.width = rect.width * x->p_value; dst.height = rect.height * x->p_value; if (dst.width < 1 || dst.height < 1) return; dst.x = 0 + ((rect.width * 0.5) - (dst.width * 0.5)); dst.y = 0 + ((rect.height * 0.5) - (dst.height * 0.5)); jgraphics_image_surface_draw(g, x->p_surface, src, dst); } }
void uisimp_paint(t_uisimp *x, t_object *view) { t_jgraphics *g; t_rect rect; t_jrgba rgba, textcolor; t_jfont *jf; t_jtextlayout *jtl; char text[16]; g = (t_jgraphics*) patcherview_get_jgraphics(view); jbox_get_rect_for_view(&x->j_box.b_ob, view, &rect); if (x->j_mouse_is_down) { jbox_get_color((t_object *)x, &rgba); jgraphics_set_source_jrgba(g, &rgba); } else jgraphics_set_source_rgba(g, 0, 0, 0, 1.0); //jgraphics_fill(g); // draw counter jf = jfont_create(jbox_get_fontname((t_object *)x)->s_name, jbox_get_font_slant((t_object *)x), jbox_get_font_weight((t_object *)x), jbox_get_fontsize((t_object *)x)); jtl = jtextlayout_create(); sprintf(text,"%d",x->j_mouse_counter); jtextlayout_set(jtl, text, jf, 5, 5, rect.width - 10, rect.height- 10, JGRAPHICS_TEXT_JUSTIFICATION_CENTERED, JGRAPHICS_TEXTLAYOUT_NOWRAP); textcolor.red = textcolor.green = textcolor.blue = 1; textcolor.alpha = 1; jtextlayout_settextcolor(jtl, &textcolor); jtextlayout_draw(jtl, g); jtextlayout_destroy(jtl); jfont_destroy(jf); }
void tralala_paintCurrentText(t_tll *x, t_object *pv, char *string) { t_rect r; t_jgraphics *g = NULL; t_jfont *font = NULL; t_jgraphics_textlayout_flags flags = (t_jgraphics_textlayout_flags) (0); t_jgraphics_text_justification justification = JGRAPHICS_TEXT_JUSTIFICATION_RIGHT; jbox_get_rect_for_view((t_object *)x, pv, &r); g = (t_jgraphics *)patcherview_get_jgraphics(pv); font = jfont_create((jbox_get_fontname(((t_object *)x)))->s_name, (t_jgraphics_font_slant)(jbox_get_font_slant((t_object *)x)), (t_jgraphics_font_weight)(jbox_get_font_weight((t_object *)x)), (jbox_get_fontsize((t_object *)x))); jtextlayout_set(x->layer, string, font, 5., 5., r.width - 10., r.height - 5., justification, flags); if (TLL_FLAG_TRUE(TLL_FLAG_FOCUS)) { jtextlayout_settextcolor(x->layer, &x->text); } else { jtextlayout_settextcolor(x->layer, &x->uText); } jtextlayout_draw(x->layer, g); jfont_destroy(font); }
void meter_dopaint_vertical(t_meter *x, t_object *view) { t_rect rect; t_jgraphics* g; double level = TTClip(x->envelope, 0.0f, 1.0f); double position; double peakPosition; t_jrgba c; if (level > 0.0) level = pow(level, kTTGainMidiPowerInv); // this is taken from the midi conversion in the Gain Dataspace g = (t_jgraphics*) patcherview_get_jgraphics(view); // obtain graphics context jbox_get_rect_for_view((t_object *)x, view, &rect); // this is the box rectangle -- but we draw relative to 0 0, and thus only care about width & height rect.x = 0; rect.y = 0; position = rect.height * level * 0.96; peakPosition = rect.height * x->peak * 0.96; if (level > x->peak) x->peak = level; // TODO: Can we export this from the kernel??? // jgraphics_image_surface_draw_fast(g, x->gradientSurface); jgraphics_image_surface_draw(g, x->gradientSurface, x->gradientRect, rect); jgraphics_set_source_jrgba(g, &x->attrBgColor); jgraphics_rectangle_fill_fast(g, 0, 0, rect.width, rect.height-position); if (x->envelope > 1.0 || x->peak > 1.0) { c.red = 1.0; c.green = c.blue = 0.0; c.alpha = 1.0; jgraphics_set_source_jrgba(g, &c); jgraphics_rectangle_fill_fast(g, 0, 0, rect.width, rect.height * .04); } else { c.red = peakPosition / x->gradientRect.height; c.green = 1.0; c.blue = 0.0; c.alpha = 1.0; jgraphics_set_source_jrgba(g, &c); // TODO: Can we export this from the kernel??? // jgraphics_line_draw_fast(g, rect.width * level * 0.96, 0, rect.width * level * 0.96, rect.height, 1.0); jgraphics_move_to(g, 0.0, rect.height - peakPosition); jgraphics_line_to(g, rect.width, rect.height - peakPosition); jgraphics_set_line_width(g, 1.0); jgraphics_stroke(g); } }
void uisimp_paint(t_uisimp *x, t_object *view) { t_jgraphics *g; t_rect rect; t_jrgba rgba, textcolor; t_jfont *jf; t_jtextlayout *jtl; char text[16]; long inset = x->j_inset; g = (t_jgraphics*) patcherview_get_jgraphics(view); jbox_get_rect_for_view(&x->j_box.b_ob, view, &rect); if (x->j_shape == EXAMP_SQUARE) jgraphics_rectangle(g, inset, inset, rect.width - (inset * 2), rect.height - (inset * 2)); else if (x->j_shape == EXAMP_CIRCLE) { jgraphics_arc(g, rect.width * .5, rect.height * .5, (rect.width * .5) - (inset * 2), 0, JGRAPHICS_2PI); jgraphics_close_path(g); } else if (x->j_shape == EXAMP_ANGLE) { jgraphics_move_to(g, inset * 2, inset); jgraphics_line_to(g, rect.width - (inset * 2), inset); jgraphics_line_to(g, rect.width - (inset * 2), inset * 2); jgraphics_line_to(g, rect.width - (inset * 2), rect.height - (inset * 2)); jgraphics_line_to(g, rect.width - (inset * 2), rect.height - inset); jgraphics_line_to(g, inset * 2, rect.height - (inset * 2)); jgraphics_line_to(g, inset, rect.height - (inset * 3)); jgraphics_line_to(g, inset, inset * 2); jgraphics_line_to(g, inset * 2, inset); jgraphics_close_path(g); } if (x->j_mouse_is_down) { jbox_get_color((t_object *)x, &rgba); jgraphics_set_source_jrgba(g, &rgba); } else jgraphics_set_source_rgba(g, 0, 0, 0, 1.0); jgraphics_fill(g); // draw counter jf = jfont_create(jbox_get_fontname((t_object *)x)->s_name, jbox_get_font_slant((t_object *)x), jbox_get_font_weight((t_object *)x), jbox_get_fontsize((t_object *)x)); jtl = jtextlayout_create(); sprintf(text,"%d",x->j_mouse_counter); jtextlayout_set(jtl, text, jf, 5, 5, rect.width - 10, rect.height- 10, JGRAPHICS_TEXT_JUSTIFICATION_CENTERED, JGRAPHICS_TEXTLAYOUT_NOWRAP); textcolor.red = textcolor.green = textcolor.blue = 1; textcolor.alpha = 1; jtextlayout_settextcolor(jtl, &textcolor); jtextlayout_draw(jtl, g); jtextlayout_destroy(jtl); jfont_destroy(jf); }
void scripto_ui_paint(t_scripto_ui *x, t_object *patcherview) { t_jgraphics *g; t_rect r; long i, j; g = (t_jgraphics *) patcherview_get_jgraphics(patcherview); for (i = 0; i < SCRIPTO_UI_ROWS; i++) { for (j = 0; j < SCRIPTO_UI_COLS; j++) { scripto_ui_makerect(x, i, j, &r); jgraphics_set_source_jrgba(g, x->u_state[(i * SCRIPTO_UI_COLS) + j]? &x->u_oncolor : &x->u_offcolor); jgraphics_rectangle_fill_fast(g, r.x, r.y, r.width, r.height); } } }
void odisplay_paint(t_odisplay *x, t_object *patcherview) { int have_new_data = 0; int draw_new_data_indicator = 0; critical_enter(x->lock); have_new_data = x->have_new_data; draw_new_data_indicator = x->draw_new_data_indicator; critical_exit(x->lock); if(have_new_data){ odisplay_bundle2text(x); } t_rect rect; t_jgraphics *g = (t_jgraphics *)patcherview_get_jgraphics(patcherview); jbox_get_rect_for_view((t_object *)x, patcherview, &rect); jgraphics_set_source_jrgba(g, &(x->background_color)); jgraphics_rectangle_rounded(g, 0, 0, rect.width, rect.height - 10, 8, 8); jgraphics_rectangle(g, 0, rect.height - 14, 4, 4); jgraphics_rectangle(g, rect.width - 4, rect.height - 14, 4, 4); jgraphics_fill(g); jgraphics_set_source_jrgba(g, &(x->frame_color)); jgraphics_rectangle_rounded(g, 0, rect.height - 10, rect.width, 10, 8, 8); jgraphics_rectangle(g, 0, rect.height - 10, 4, 4); jgraphics_rectangle(g, rect.width - 4, rect.height - 10, 4, 4); jgraphics_fill(g); jgraphics_set_source_jrgba(g, &(x->frame_color)); jgraphics_rectangle_rounded(g, 1, 1, rect.width - 2, rect.height - 2, 8, 8); jgraphics_set_line_width(g, 2.); jgraphics_stroke(g); if (draw_new_data_indicator) { jgraphics_set_source_jrgba(g, &(x->flash_color)); jgraphics_ellipse(g, rect.width - 12, 6, 6, 6); jgraphics_fill(g); critical_enter(x->lock); x->draw_new_data_indicator = 0; critical_exit(x->lock); clock_delay(x->new_data_indicator_clock, 100); } }
void jucebox_paint(t_jucebox* x, t_object *patcherview) { t_rect rect, srcRect, destRect; int width, height, imgStride; unsigned char* data; if(x->j_component->isOnDesktop()) { x->j_component->setActive(); if(x->j_component->isContextOk()) { jbox_get_rect_for_view((t_object *)x, patcherview, &rect); t_jgraphics *g = (t_jgraphics *)patcherview_get_jgraphics(patcherview); if(g) { juce::Image openGLSnap = x->j_component->makeScreenshot((t_object *)x, rect.width, rect.height); juce::Image::BitmapData* snapBitmap = new juce::Image::BitmapData(openGLSnap, juce::Image::BitmapData::readOnly); data = snapBitmap->data; width = openGLSnap.getWidth(); height = openGLSnap.getHeight(); imgStride = snapBitmap->lineStride; srcRect.x = 0; destRect.x = 0; srcRect.y = 0; destRect.y = 0; srcRect.width = openGLSnap.getWidth(); srcRect.height = openGLSnap.getHeight(); destRect.width = rect.width; destRect.height = rect.height; t_jsurface* surface = jgraphics_image_surface_create_for_data(data, JGRAPHICS_FORMAT_ARGB32, width, height, imgStride, NULL, NULL); jgraphics_image_surface_draw(g, surface, srcRect, destRect); jgraphics_surface_destroy(surface); } } } }
void uisimp_paint(t_uisimp *x, t_object *patcherview) { t_rect rect; t_jgraphics *g = (t_jgraphics *) patcherview_get_jgraphics(patcherview); // obtain graphics context jbox_get_rect_for_view((t_object *)x, patcherview, &rect); // paint outline jgraphics_set_source_jrgba(g, &x->u_outline); jgraphics_set_line_width(g, 1.); jgraphics_rectangle(g, 0., 0., rect.width, rect.height); jgraphics_stroke(g); // paint "inner highlight" to indicate mouseover if (x->u_mouseover && !x->u_mousedowninside) { jgraphics_set_source_jrgba(g, &x->u_hilite); jgraphics_set_line_width(g, 1.); jgraphics_rectangle(g, 1., 1., rect.width - 2, rect.height - 2); jgraphics_stroke(g); } if (x->u_mousedowninside && !x->u_state) { // paint hilite color jgraphics_set_source_jrgba(g, &x->u_hilite); jgraphics_rectangle(g, 1., 1., rect.width - 2, rect.height - 2); jgraphics_fill(g); } // paint "check" (actually a filled rectangle) if state is on if (x->u_state) { t_jrgba col; jbox_get_color((t_object *)x, &col); jgraphics_set_source_jrgba(g, &col); if (x->u_mousedowninside) // make rect bigger if mouse is down and we are unchecking jgraphics_rectangle(g, 3., 3., rect.width - 6, rect.height - 6); else jgraphics_rectangle(g, 4., 4., rect.width - 8, rect.height - 8); jgraphics_fill(g); } }
void paramui_paint(t_paramui *x, t_object *view) { t_rect rect; t_jgraphics *g; double middle; double border_thickness = 1.5; double cornersize = 13.0; g = (t_jgraphics*) patcherview_get_jgraphics(view); jbox_get_rect_for_view((t_object*) &x->box, view, &rect); // clear the background jgraphics_rectangle_rounded(g, border_thickness, border_thickness, rect.width - (border_thickness * 2.0), rect.height - (border_thickness * 2.0), cornersize, cornersize); jgraphics_set_source_rgba(g, 0.1, 0.1, 0.1, 1.0); jgraphics_fill(g); // draw the inspector icon jgraphics_set_source_rgb(g, 0.2, 0.2, 0.2); jgraphics_set_line_width(g, 1.5); jgraphics_oval(g, border_thickness, border_thickness, rect.height - (border_thickness * 2.0), rect.height - (border_thickness * 2.0)); jgraphics_fill(g); jgraphics_rectangle_fill_fast(g, border_thickness + rect.height / 2 - (border_thickness), border_thickness, border_thickness + rect.height / 2, rect.height - (border_thickness * 2.0)); jgraphics_set_source_rgb(g, 0.4, 0.4, 0.4); middle = 6.0; jgraphics_move_to(g, 9.5, middle + 4.0); jgraphics_line_to(g, 13.0, middle); jgraphics_line_to(g, 6.0, middle); jgraphics_close_path(g); jgraphics_fill(g); if(x->attr_dataspace != jps_none) { char data[64]; strncpy(data, x->attr_unitActive->s_name, 64); // draw the unit display jgraphics_set_source_rgb(g, 0.2, 0.2, 0.2); jgraphics_set_line_width(g, 1.5); jgraphics_oval(g, rect.width - (rect.height - (border_thickness * 2.0)) - 2.0, border_thickness, rect.height - (border_thickness * 2.0), rect.height - (border_thickness * 2.0)); jgraphics_fill(g); jgraphics_rectangle_fill_fast(g, rect.width - ((border_thickness + rect.height / 2 - (border_thickness)) * 3.0) - 2.0, border_thickness, border_thickness + rect.height / 1, rect.height - (border_thickness * 2.0)); jtextlayout_settextcolor(x->layout_unit, &s_light_gray); jtextlayout_set(x->layout_unit, data, jfont_create(JAMOMA_DEFAULT_FONT, JGRAPHICS_FONT_SLANT_NORMAL, JGRAPHICS_FONT_WEIGHT_NORMAL, JAMOMA_DEFAULT_FONTSIZE), rect.width - 28.0, 0.0, 28.0, rect.height - 1.0, JGRAPHICS_TEXT_JUSTIFICATION_CENTERED, JGRAPHICS_TEXTLAYOUT_USEELLIPSIS); jtextlayout_draw(x->layout_unit, g); } { char data[256]; t_atom *av = NULL; long ac = 0; if(x->obj_parameter){ object_attr_getvalueof(x->obj_parameter, gensym("value"), &ac, &av); if(ac){ if(x->attr_type == jps_decimal) snprintf(data, 256, "%.4f", atom_getfloat(av)); else if(x->attr_type == jps_integer || x->attr_type == jps_boolean) snprintf(data, 256, "%ld", atom_getlong(av)); else if(x->attr_type == jps_string) strcpy(data, atom_getsym(av)->s_name); jtextlayout_settextcolor(x->layout_value, &s_light_gray); jtextlayout_set(x->layout_value, data, jfont_create(JAMOMA_DEFAULT_FONT, JGRAPHICS_FONT_SLANT_NORMAL, JGRAPHICS_FONT_WEIGHT_NORMAL, JAMOMA_DEFAULT_FONTSIZE), 84.0, 2.0, rect.width - 84.0 - 20.0, rect.height - 1.0, JGRAPHICS_TEXT_JUSTIFICATION_LEFT, JGRAPHICS_TEXTLAYOUT_USEELLIPSIS); jtextlayout_draw(x->layout_value, g); sysmem_freeptr(av); } } } // draw borders jgraphics_rectangle_rounded(g, border_thickness, border_thickness, rect.width - (border_thickness * 2.0), rect.height - (border_thickness * 2.0), cornersize, cornersize); jgraphics_set_source_rgb(g, 0.3, 0.3, 0.3); jgraphics_set_line_width(g, 1.5); jgraphics_stroke(g); jgraphics_set_line_width(g, 1.0); jgraphics_move_to(g, border_thickness, 19.5); jgraphics_line_to(g, rect.width - (border_thickness * 1.0), 19.5); jgraphics_stroke(g); }
void rd_paint(t_rd *x, t_object *patcherview){ t_rect rect; t_jgraphics *g = (t_jgraphics *)patcherview_get_jgraphics(patcherview); jbox_get_rect_for_view((t_object *)x, patcherview, &rect); jgraphics_set_source_jrgba(g, &(x->bordercolor)); jgraphics_set_line_width(g, 1); jgraphics_rectangle(g, 0., 0., rect.width, rect.height); jgraphics_stroke(g); jgraphics_set_source_jrgba(g, &(x->bgcolor)); jgraphics_rectangle(g, 0., 0., rect.width, rect.height); jgraphics_fill(g); // data { jgraphics_set_source_jrgba(g, &(x->datacolor)); int i; if(x->sinusoids){ t_sin *s = (t_sin *)(x->buffer); for(i = 0; i < x->n; i++){ double xx, yy; xx = rd_scale(s[i].f, x->freqmin, x->freqmax, 0, rect.width); if(x->log){ yy = rd_scale((20. * log(s[i].a)) / log(10), x->ampmin_log, x->ampmax_log, rect.height, 0.); }else{ yy = rd_scale(s[i].a, x->ampmin, x->ampmax, rect.height, 0); } jgraphics_move_to(g, xx, yy); jgraphics_line_to(g, xx, rect.height); jgraphics_stroke(g); } }else if(x->mode){ t_jsurface *s = jgraphics_image_surface_create(JGRAPHICS_FORMAT_ARGB32, rect.width, rect.height); //t_jgraphics *gg = jgraphics_create(s); t_res *r = (t_res *)(x->buffer); int j; t_jrgba c; for(j = 0; j < rect.width; j++){ for(i = 0; i < x->n; i++){ double amp = exp((-j / (rect.width * .1)) * r[i].d); c = (t_jrgba){x->datacolor.red * amp, x->datacolor.green * amp, x->datacolor.blue * amp, 1.}; jgraphics_image_surface_set_pixel(s, j, rd_scale(r[i].f, x->freqmin, x->freqmax, rect.height, 0), c); //jgraphics_set_source_jrgba(g, &c); //jgraphics_ellipse(g, j, rd_scale(r[i].f, 0., 22050., rect.height, 0), 1, 1); //jgraphics_fill(g); //jgraphics_move_to(g, 0, yy1); //jgraphics_line_to(g, xx, yy2); } } jgraphics_image_surface_draw(g, s, (t_rect){0., 0., rect.width, rect.height}, (t_rect){0., 0., rect.width, rect.height}); }else{ t_res *r = (t_res *)(x->buffer); for(i = 0; i < x->n; i++){ double xx, yy1, yy2; xx = rd_scale(r[i].f, x->freqmin, x->freqmax, 0, rect.width); if(x->log){ //yy1 = rd_scale((100+20.0*log(r[i].a))/100./log(10), -1., 1., rect.height, 0.); yy1 = rd_scale((20.0*log(r[i].a))/log(10), x->ampmin_log, x->ampmax_log, rect.height, 0.); }else{ yy1 = rd_scale(r[i].a, x->ampmin, x->ampmax, rect.height, 0); } yy2 = fabs((rect.height - yy1) * (.4 / sqrt(r[i].d))) + yy1; jgraphics_move_to(g, xx, yy1); jgraphics_line_to(g, xx, yy2); jgraphics_stroke(g); } } } // selection lines { jgraphics_set_source_jrgba(g, &(x->selectioncolor)); if(x->mode){ jgraphics_move_to(g, 0, rd_scale(x->selection.min, x->freqmin, x->freqmax, rect.height, 0)); jgraphics_line_to(g, rect.width, rd_scale(x->selection.min, x->freqmin, x->freqmax, rect.height, 0)); jgraphics_move_to(g, 0, rd_scale(x->selection.max, x->freqmin, x->freqmax, rect.height, 0)); jgraphics_line_to(g, rect.width, rd_scale(x->selection.max, x->freqmin, x->freqmax, rect.height, 0)); }else{ jgraphics_move_to(g, rd_scale(x->selection.min, x->freqmin, x->freqmax, 0, rect.width), 0); jgraphics_line_to(g, rd_scale(x->selection.min, x->freqmin, x->freqmax, 0, rect.width), rect.height); jgraphics_move_to(g, rd_scale(x->selection.max, x->freqmin, x->freqmax, 0, rect.width), 0); jgraphics_line_to(g, rd_scale(x->selection.max, x->freqmin, x->freqmax, 0, rect.width), rect.height); } jgraphics_stroke(g); } // info { char buf[128]; double w, h; jgraphics_set_source_jrgba(g, &x->datacolor); sprintf(buf, "%0.2f", x->selection.min); jgraphics_text_measure(g, buf, &w, &h); jgraphics_move_to(g, 0, h); jgraphics_show_text(g, buf); sprintf(buf, "%0.2f", x->selection.max); jgraphics_text_measure(g, buf, &w, &h); jgraphics_move_to(g, rect.width - w, h); jgraphics_show_text(g, buf); sprintf(buf, "%0.2fHz (%0.2fMc) %d/%ld", x->selection.max - x->selection.min, rd_ftom(x->selection.max) - rd_ftom(x->selection.min), x->num_partials_selected, x->n); jgraphics_text_measure(g, buf, &w, &h); jgraphics_move_to(g, (rect.width / 2) - (w / 2), h); jgraphics_show_text(g, buf); } }