/* ---------------------------------------------------------------------------- * Draws the textbox. It's basically a rectangle with a border. * The border is drawn line by line. Finally, it draws the * text within. */ void textbox::draw_self() { al_draw_filled_rectangle(x1, y1, x2, y2, get_bg_color()); draw_line(this, DRAW_LINE_TOP, 0, 1, 0, get_darker_bg_color()); // Top line. draw_line(this, DRAW_LINE_LEFT, 0, 1, 0, get_darker_bg_color()); // Left line. draw_line(this, DRAW_LINE_BOTTOM, 1, 0, 0, get_lighter_bg_color()); // Bottom line. draw_line(this, DRAW_LINE_RIGHT, 1, 0, 0, get_lighter_bg_color()); // Right line. if(style->text_font) { int text_start = x1 + 2 - scroll_x; if(parent->focused_widget == this) { al_draw_filled_rectangle( text_start + al_get_text_width(style->text_font, text.substr(0, min(sel_start, sel_end)).c_str()), y1 + 2, text_start + al_get_text_width(style->text_font, text.substr(0, max(sel_start, sel_end)).c_str()), y2 - 2, get_alt_color() ); } al_draw_text(style->text_font, get_fg_color(), text_start, (y2 + y1) / 2 - al_get_font_line_height(style->text_font) / 2, 0, text.c_str()); unsigned int cursor_x = al_get_text_width(style->text_font, text.substr(0, cursor).c_str()); if(parent->focused_widget == this) { al_draw_line( x1 + cursor_x + 1.5 - scroll_x, y1 + 2, x1 + cursor_x + 1.5 - scroll_x, y2 - 2, get_alt_color(), 1); } } }
static void draw_img_a(int x, int y, const Image_t* img) { int i; for (i = 0; i < (img->width * img->height); i++) { uint8_t alpha = img->alpha[i]; if (alpha == 255) { lcd_write_data(ctx->fcolor); } else { uint16_t by = y + (i / img->width); uint16_t bx = x + (i % img->width); color_t bcolor = get_bg_color(bx, by); if (alpha == 0) { lcd_write_data(bcolor); } else { lcd_write_data(BLENDED_COLOR(ctx->fcolor, bcolor, alpha)); } } } }
void gfx_draw_glyph(const glyph_t* g, int x, int y) { uint16_t j; gfx_set_cursor(x, y, x + g->width - 1, y + g->height - 1); for (j = 0; j < (g->width * g->height); j++) { uint8_t alpha = g->data[j]; if (alpha == 255) { lcd_write_data(ctx->fcolor); } else { uint16_t by = y + (j / g->width); uint16_t bx = x + (j % g->width); color_t bcolor = get_bg_color(bx, by); if (alpha == 0) { lcd_write_data(bcolor); } else { lcd_write_data(BLENDED_COLOR(ctx->fcolor, ctx->bcolor, alpha)); } } } lcd_clr_cursor(); }
COLORREF get_mixed_color(StyleItem *pSI) { COLORREF b = get_bg_color(pSI); COLORREF t = pSI->TextColor; if (greyvalue(b) > greyvalue(t)) return mixcolors(t, b, 96); else return mixcolors(t, b, 144); }
void DjVuANT::decode(class GLParser & parser) { bg_color=get_bg_color(parser); zoom=get_zoom(parser); mode=get_mode(parser); hor_align=get_hor_align(parser); ver_align=get_ver_align(parser); map_areas=get_map_areas(parser); #ifndef NO_METADATA_IN_ANT_CHUNK metadata=get_metadata(parser); #endif }
/* ---------------------------------------------------------------------------- * Draws the circle and the pointer. */ void angle_picker::draw_self() { float circle_r = (y2 - y1) / 2; float circle_cx = x1 + circle_r; float circle_cy = y1 + circle_r; al_draw_filled_circle(circle_cx, circle_cy, circle_r, get_bg_color()); al_draw_arc(circle_cx, circle_cy, circle_r, M_PI_2 + M_PI_4, M_PI, get_darker_bg_color(), 1); al_draw_arc(circle_cx, circle_cy, circle_r, M_PI_2 + M_PI_4 + M_PI, M_PI, get_lighter_bg_color(), 1); al_draw_line( circle_cx, circle_cy, circle_cx + cos(angle) * circle_r, circle_cy + sin(angle) * circle_r, get_fg_color(), 2 ); }
int BC_Title::draw(int flush) { int i, j, x, y; // Fix background for block fonts. // This should eventually be included in a BC_WindowBase::is_blocked_font() if(font == MEDIUM_7SEGMENT) { //leave it up to the theme to decide if we need a background or not. if (top_level->get_resources()->draw_clock_background) { BC_WindowBase::set_color(get_bg_color()); draw_box(0, 0, w, h); } } else draw_top_background(parent_window, 0, 0, w, h); set_font(font); BC_WindowBase::set_color(color); int text_len = strlen(text); j = 0; x = 0; y = get_text_ascent(font); for(i = 0; i <= text_len; i++) { if(text[i] == '\n' || text[i] == 0) { if(centered) { draw_center_text(get_w() / 2, y, &text[j], i - j); j = i + 1; } else { draw_text(x, y, &text[j], i - j); j = i + 1; } y += get_text_height(font); } } set_font(MEDIUMFONT); // reset flash(flush); return 0; }
/* ---------------------------------------------------------------------------- * Draws the checkbox box. It's just a square with a fancy border. * The latter is drawn line by line. It also draws the checkmark, * if the box is ticked. */ void checkbox_box::draw_self() { al_draw_filled_rectangle(x1, y1, x2, y2, get_bg_color()); //Top line. draw_line(this, DRAW_LINE_TOP, 0, 1, 0, get_darker_bg_color()); //Left line. draw_line(this, DRAW_LINE_LEFT, 0, 1, 0, get_darker_bg_color()); //Bottom line. draw_line(this, DRAW_LINE_BOTTOM, 1, 0, 0, get_lighter_bg_color()); //Right line. draw_line(this, DRAW_LINE_RIGHT, 1, 0, 0, get_lighter_bg_color()); if(checked) { //Southeast-going line. al_draw_line(x1 + 2.5, y1 + 6.5, x1 + 5.5, y1 + 9.5, get_fg_color(), 3); //Northeast-going line. al_draw_line(x1 + 3.5, y1 + 9.5, x1 + 10, y1 + 3, get_fg_color(), 3); } }
/* ---------------------------------------------------------------------------- * Draws the actual frame. Like the frame of a painting, this * is basically a rectangle and a border. */ void frame::draw_self() { al_draw_filled_rectangle(x1, y1, x2, y2, get_bg_color()); //Top line, outermost. draw_line(this, DRAW_LINE_TOP, 0, 1, 0, get_lighter_bg_color()); //Top line, innermost. draw_line(this, DRAW_LINE_TOP, 1, 2, 1, get_darker_bg_color()); //Left line, outermost. draw_line(this, DRAW_LINE_LEFT, 0, 1, 0, get_lighter_bg_color()); //Left line, innermost. draw_line(this, DRAW_LINE_LEFT, 1, 2, 1, get_darker_bg_color()); //Bottom line, outermost. draw_line(this, DRAW_LINE_BOTTOM, 1, 0, 0, get_darker_bg_color()); //Bottom line, innermost. draw_line(this, DRAW_LINE_BOTTOM, 2, 1, 1, get_lighter_bg_color()); //Right line, outermost. draw_line(this, DRAW_LINE_RIGHT, 1, 0, 0, get_darker_bg_color()); //Right line, innermost. draw_line(this, DRAW_LINE_RIGHT, 2, 1, 1, get_lighter_bg_color()); }
void ScopeGUI::draw_overlays(int overlays, int borders, int flush) { if(overlays && borders) { clear_box(0, 0, get_w(), get_h()); } if(overlays) { set_line_dashes(1); set_color(GREEN); set_font(SMALLFONT); if(histogram && (use_hist || use_hist_parade)) { histogram->draw_line(hist_w * -FLOAT_MIN / (FLOAT_MAX - FLOAT_MIN), 0, hist_w * -FLOAT_MIN / (FLOAT_MAX - FLOAT_MIN), hist_h); histogram->draw_line(hist_w * (1.0 - FLOAT_MIN) / (FLOAT_MAX - FLOAT_MIN), 0, hist_w * (1.0 - FLOAT_MIN) / (FLOAT_MAX - FLOAT_MIN), hist_h); set_line_dashes(0); histogram->draw_point(); set_line_dashes(1); histogram->flash(0); } // Waveform overlay if(waveform && (use_wave || use_wave_parade)) { set_color(GREEN); for(int i = 0; i <= WAVEFORM_DIVISIONS; i++) { int y = wave_h * i / WAVEFORM_DIVISIONS; int text_y = y + wave_y + get_text_ascent(SMALLFONT) / 2; CLAMP(text_y, waveform->get_y() + get_text_ascent(SMALLFONT), waveform->get_y() + waveform->get_h() - 1); int x = wave_x - 20; char string[BCTEXTLEN]; sprintf(string, "%d", (int)((FLOAT_MAX - i * (FLOAT_MAX - FLOAT_MIN) / WAVEFORM_DIVISIONS) * 100)); draw_text(x, text_y, string); int y1 = CLAMP(y, 0, waveform->get_h() - 1); waveform->draw_line(0, y1, wave_w, y1); //waveform->draw_rectangle(0, 0, wave_w, wave_h); } set_line_dashes(0); waveform->draw_point(); set_line_dashes(1); waveform->flash(0); } // Vectorscope overlay if(vectorscope && use_vector) { set_color(GREEN); int radius = MIN(vector_w / 2, vector_h / 2); for(int i = 1; i <= VECTORSCOPE_DIVISIONS; i += 2) { int x = vector_w / 2 - radius * i / VECTORSCOPE_DIVISIONS; int y = vector_h / 2 - radius * i / VECTORSCOPE_DIVISIONS; int text_x = vector_x - 20; int text_y = y + vector_y + get_text_ascent(SMALLFONT) / 2; int w = radius * i / VECTORSCOPE_DIVISIONS * 2; int h = radius * i / VECTORSCOPE_DIVISIONS * 2; char string[BCTEXTLEN]; sprintf(string, "%d", (int)((FLOAT_MAX / VECTORSCOPE_DIVISIONS * i) * 100)); draw_text(text_x, text_y, string); //printf("ScopeGUI::draw_overlays %d %d %d %s\n", __LINE__, text_x, text_y, string); vectorscope->draw_circle(x, y, w, h); //vectorscope->draw_rectangle(0, 0, vector_w, vector_h); } // vectorscope->draw_circle(vector_w / 2 - radius, // vector_h / 2 - radius, // radius * 2, // radius * 2); set_line_dashes(0); vectorscope->draw_point(); set_line_dashes(1); vectorscope->flash(0); } set_font(MEDIUMFONT); set_line_dashes(0); } if(borders) { if(use_hist || use_hist_parade) { draw_3d_border(hist_x - 2, hist_y - 2, hist_w + 4, hist_h + 4, get_bg_color(), BLACK, MDGREY, get_bg_color()); } if(use_wave || use_wave_parade) { draw_3d_border(wave_x - 2, wave_y - 2, wave_w + 4, wave_h + 4, get_bg_color(), BLACK, MDGREY, get_bg_color()); } if(use_vector) { draw_3d_border(vector_x - 2, vector_y - 2, vector_w + 4, vector_h + 4, get_bg_color(), BLACK, MDGREY, get_bg_color()); } } flash(0); if(flush) this->flush(); }
static gboolean calf_vumeter_expose (GtkWidget *widget, GdkEventExpose *event) { g_assert(CALF_IS_VUMETER(widget)); CalfVUMeter *vu = CALF_VUMETER(widget); cairo_t *c = gdk_cairo_create(GDK_DRAWABLE(widget->window)); float r, g, b; int x = widget->allocation.x; int y = widget->allocation.y; int width = widget->allocation.width; int height = widget->allocation.height; int border_x = widget->style->xthickness; int border_y = widget->style->ythickness; int space_x = 1; int space_y = 1; // inner border around led bar int led = 2; // single LED size int led_m = 1; // margin between LED int led_s = led + led_m; // size of LED with margin int led_x = widget->style->xthickness; int led_y = widget->style->ythickness; // position of first LED int led_w = width - 2 * led_x + led_m; // width of LED bar w/o text calc (additional led margin, is removed later; used for filling the led bar completely w/o margin gap) int led_h = height - 2 * led_y; // height of LED bar w/o text calc int text_x = 0; int text_y = 0; int text_w = 0; int text_h = 0; // only valid if vumeter is enabled cairo_text_extents_t extents; if(vu->vumeter_position) { cairo_select_font_face(c, "cairo:sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(c, 8); cairo_text_extents(c, "-88.88", &extents); text_w = extents.width; text_h = extents.height; switch(vu->vumeter_position) { case 1: text_x = width / 2 - text_w / 2; text_y = border_y + led_y - extents.y_bearing; led_y += text_h + led_y; led_h -= text_h + led_y; break; case 2: text_x = width - border_x - led_x - text_w; text_y = height / 2 - text_h / 2 - extents.y_bearing; led_w -= led_x + text_w; break; case 3: text_x = width / 2 - text_w / 2; text_y = height - border_y - led_y - text_h - extents.y_bearing; led_h -= led_y + text_h; break; case 4: text_x = border_x + led_x; text_y = height / 2 - text_h / 2 - extents.y_bearing; led_x += led_x + text_w; led_w -= led_x + text_w; break; } } led_w -= led_w % led_s + led_m; //round LED width to LED size and remove margin gap, width is filled with LED without margin gap now if( vu->cache_surface == NULL ) { // looks like its either first call or the widget has been resized. // create the cache_surface. vu->cache_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height ); cairo_t *cache_cr = cairo_create( vu->cache_surface ); float radius, bevel; get_bg_color(widget, NULL, &r, &g, &b); gtk_widget_style_get(widget, "border-radius", &radius, "bevel", &bevel, NULL); create_rectangle(cache_cr, 0, 0, width, height, radius); cairo_set_source_rgb(cache_cr, r, g, b); cairo_fill(cache_cr); draw_bevel(cache_cr, 0, 0, width, height, radius, bevel); // border around LED cairo_rectangle(cache_cr, led_x, led_y, led_w, led_h); cairo_set_source_rgb (cache_cr, 0, 0, 0); cairo_fill(cache_cr); led_x += space_x; led_y += space_y; led_w -= 2 * space_x; led_h -= 2 * space_y; // LED bases cairo_set_line_width(cache_cr, 1); for (int x = led_x; x + led <= led_x + led_w; x += led_s) { float ts = (x - led_x) * 1.0 / led_w; float r = 0.f, g = 0.f, b = 0.f; switch(vu->mode) { case VU_STANDARD: default: if (ts < 0.75) r = ts / 0.75, g = 0.5 + ts * 0.66, b = 1 - ts / 0.75; else r = 1, g = 1 - (ts - 0.75) / 0.25, b = 0; // if (vu->value < ts || vu->value <= 0) // r *= 0.5, g *= 0.5, b *= 0.5; break; case VU_STANDARD_CENTER: if (ts < 0.25) // 0.0 -> 0.25 // green: 0.f -> 1.f r = 1, g = (ts) / 0.25, b = 0; else if (ts > 0.75) // 0.75 -> 1.0 // green: 1.f -> 0.f r = 1, g = 1 - (ts - 0.75) / 0.25, b = 0; else if (ts > 0.5) // 0.5 -> 0.75 // red: 0.f -> 1.f // green: 0.5 -> 1.f // blue: 1.f -> 0.f r = (ts - 0.5) / 0.25, g = 0.5 + (ts - 0.5) * 2.f, b = 1 - (ts - 0.5) / 0.25; else // 0.25 -> 0.5 // red: 1.f -> 0.f // green: 1.f -> 0.5 // blue: 0.f -> 1.f r = 1 - (ts - 0.25) / 0.25, g = 1.f - (ts * 2.f - .5f), b = (ts - 0.25) / 0.25; // if (vu->value < ts || vu->value <= 0) // r *= 0.5, g *= 0.5, b *= 0.5; break; case VU_MONOCHROME_REVERSE: r = 0, g = 170.0 / 255.0, b = 1; // if (!(vu->value < ts) || vu->value >= 1.0) // r *= 0.5, g *= 0.5, b *= 0.5; break; case VU_MONOCHROME: r = 0, g = 170.0 / 255.0, b = 1; // if (vu->value < ts || vu->value <= 0) // r *= 0.5, g *= 0.5, b *= 0.5; break; case VU_MONOCHROME_CENTER: r = 0, g = 170.0 / 255.0, b = 1; // if (vu->value < ts || vu->value <= 0) // r *= 0.5, g *= 0.5, b *= 0.5; break; } GdkColor sc2 = { 0, (guint16)(65535 * r + 0.2), (guint16)(65535 * g), (guint16)(65535 * b) }; GdkColor sc3 = { 0, (guint16)(65535 * r * 0.7), (guint16)(65535 * g * 0.7), (guint16)(65535 * b * 0.7) }; gdk_cairo_set_source_color(cache_cr, &sc2); cairo_move_to(cache_cr, x + 0.5, led_y); cairo_line_to(cache_cr, x + 0.5, led_y + led_h); cairo_stroke(cache_cr); gdk_cairo_set_source_color(cache_cr, &sc3); cairo_move_to(cache_cr, x + 1.5, led_y + led_h); cairo_line_to(cache_cr, x + 1.5, led_y); cairo_stroke(cache_cr); } // create blinder pattern cairo_pattern_t *pat = cairo_pattern_create_linear (led_x, led_y, led_x, led_y + led_h); cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 0.25); cairo_pattern_add_color_stop_rgba (pat, 0.5, 0.5, 0.5, 0.5, 0.0); cairo_pattern_add_color_stop_rgba (pat, 1, 0.0, 0.0, 0.0, 0.25); cairo_rectangle(cache_cr, led_x, led_y, led_w, led_h); cairo_set_source(cache_cr, pat); cairo_fill(cache_cr); // create overlay vu->cache_overlay = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t *over_cr = cairo_create(vu->cache_overlay); // copy surface to overlay cairo_set_source_surface(over_cr, vu->cache_surface, 0, 0); cairo_rectangle(over_cr, 0, 0, width, height); cairo_fill(over_cr); // create blinder pattern pat = cairo_pattern_create_linear (led_x, led_y, led_x, led_y + led_h); cairo_pattern_add_color_stop_rgba (pat, 0, 0.2, 0.2, 0.2, 0.7); cairo_pattern_add_color_stop_rgba (pat, 0.4, 0.05, 0.05, 0.05, 0.7); cairo_pattern_add_color_stop_rgba (pat, 0.401, 0.05, 0.05, 0.05, 0.9); cairo_pattern_add_color_stop_rgba (pat, 1, 0.05, 0.05, 0.05, 0.75); // draw on top of overlay cairo_set_source(over_cr, pat); cairo_rectangle(over_cr, 0, 0, width, height); cairo_paint(over_cr); // clean up cairo_destroy(cache_cr); cairo_destroy(over_cr); } else { led_x += space_x; led_y += space_y; led_w -= 2 * space_x; led_h -= 2 * space_y; } led_x += x; led_y += y; text_x += x; text_y += y; // draw LED blinder cairo_set_source_surface( c, vu->cache_surface, x, y ); cairo_paint( c ); cairo_set_source_surface( c, vu->cache_overlay, x, y ); // get microseconds timeval tv; gettimeofday(&tv, 0); long time = tv.tv_sec * 1000 * 1000 + tv.tv_usec; // limit to 1.f float value_orig = std::max(std::min(vu->value, 1.f), 0.f); float value = 0.f; // falloff? if(vu->vumeter_falloff > 0.f and vu->mode != VU_MONOCHROME_REVERSE) { // fall off a bit float s = ((float)(time - vu->last_falltime) / 1000000.0); float m = vu->last_falloff * s * vu->vumeter_falloff; vu->last_falloff -= m; // new max value? if(value_orig > vu->last_falloff) { vu->last_falloff = value_orig; } value = vu->last_falloff; vu->last_falltime = time; vu->falling = vu->last_falloff > 0.00000001; } else { // falloff disabled vu->last_falloff = 0.f; vu->last_falltime = 0.f; value = value_orig; vu->falling = false; } float draw = 0.f; float draw_last = 0.f; if(vu->vumeter_hold > 0.0) { // peak hold timer if(time - (long)(vu->vumeter_hold * 1000 * 1000) > vu->last_hold) { // time's up, reset vu->last_value = value; vu->last_hold = time; vu->holding = false; vu->disp_value = value_orig; } if( vu->mode == VU_MONOCHROME_REVERSE ) { if(value < vu->last_value) { // value is above peak hold vu->last_value = value; vu->last_hold = time; vu->holding = true; } draw = log10(1 + value * 9); draw_last = log10(1 + vu->last_value * 9); // blinder left -> hold LED int hold_x = round((draw_last) * (led_w + led_m)); // add last led_m removed earlier hold_x -= hold_x % led_s + led_m; hold_x = std::max(0, hold_x); cairo_rectangle( c, led_x, led_y, hold_x, led_h); // blinder hold LED -> value int val_x = round((1 - draw) * (led_w + led_m)); // add last led_m removed earlier val_x -= val_x % led_s; int blind_x = std::min(hold_x + led_s, led_w); int blind_w = std::min(std::max(led_w - val_x - hold_x - led_s, 0), led_w); cairo_rectangle(c, led_x + blind_x, led_y, blind_w, led_h); } else if( vu->mode == VU_STANDARD_CENTER ) { if(value > vu->last_value) { // value is above peak hold vu->last_value = value; vu->last_hold = time; vu->holding = true; } draw = log10(1 + value * 9); int val_x = round((1 - draw) / 2.f * (led_w + led_m)); // add last led_m removed earlier cairo_rectangle(c, led_x, led_y, val_x, led_h); cairo_rectangle(c, led_x + led_w - val_x, led_y, val_x, led_h); } else { if(value > vu->last_value) { // value is above peak hold vu->last_value = value; vu->last_hold = time; vu->holding = true; } draw = log10(1 + value * 9); draw_last = log10(1 + vu->last_value * 9); int hold_x = round((1 - draw_last) * (led_w + led_m)); // add last led_m removed earlier hold_x -= hold_x % led_s; int val_x = round(draw * (led_w + led_m)); // add last led_m removed earlier val_x -= val_x % led_s; int blind_w = led_w - hold_x - led_s - val_x; blind_w = std::min(std::max(blind_w, 0), led_w); cairo_rectangle(c, led_x + val_x, led_y, blind_w, led_h); cairo_rectangle( c, led_x + led_w - hold_x, led_y, hold_x, led_h); } } else { // darken normally float draw = log10(1 + value * 9); if( vu->mode == VU_MONOCHROME_REVERSE ) cairo_rectangle( c, led_x, led_y, draw * led_w, led_h); else if( vu->mode == VU_STANDARD_CENTER ) { int val_x = round((1 - draw) / 2.f * (led_w + led_m)); // add last led_m removed earlier cairo_rectangle(c, led_x, led_y, val_x, led_h); cairo_rectangle(c, led_x + led_w - val_x, led_y, val_x, led_h); } else cairo_rectangle( c, led_x + draw * led_w, led_y, led_w * (1 - draw), led_h); } cairo_fill( c ); if (vu->vumeter_position) { char str[32]; if((vu->value > vu->disp_value and vu->mode != VU_MONOCHROME_REVERSE) or (vu->value < vu->disp_value and vu->mode == VU_MONOCHROME_REVERSE)) vu->disp_value = vu->value; if (vu->disp_value < 1.0 / 32768.0) snprintf(str, sizeof(str), "-inf"); else snprintf(str, sizeof(str), "%0.2f", dsp::amp2dB(vu->disp_value)); // draw value as number cairo_text_extents(c, str, &extents); cairo_move_to(c, text_x + (text_w - extents.width) / 2.0, text_y); GtkStateType state; if(vu->disp_value > 1.f and vu->mode != VU_MONOCHROME_REVERSE) state = GTK_STATE_ACTIVE; else state = GTK_STATE_NORMAL; get_fg_color(widget, &state, &r, &g, &b); cairo_set_source_rgba (c, r, g, b, 1); cairo_show_text(c, str); cairo_fill(c); } cairo_destroy(c); //gtk_paint_shadow(widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, widget, NULL, ox - 2, oy - 2, sx + 4, sy + 4); //printf("exposed %p %d+%d\n", widget->window, widget->allocation.x, widget->allocation.y); return TRUE; }
/* ---------------------------------------------------------------------------- * Draws the scrollbar. The button can draw itself, but this widget * draws the harness. */ void scrollbar::draw_self() { int w = x2 - x1; int h = y2 - y1; if(vertical) { al_draw_filled_rectangle( x1 + w / 2 - 2, y1 + 0.5, x1 + w / 2 + 2, y2 - 0.5, get_bg_color() ); al_draw_line( x1 + w / 2 - 0.5, y1 + 0.5, x1 + w / 2 - 0.5, y2 - 0.5, get_lighter_bg_color(), 1 ); al_draw_line( x1 + w / 2 + 0.5, y1 + 0.5, x1 + w / 2 + 0.5, y2 - 0.5, get_darker_bg_color(), 1 ); al_draw_line(x1 + w / 2 - 4, y1 + 0.5, x1 + w / 2 + 4, y1 + 0.5, get_lighter_bg_color(), 1); al_draw_line(x1 + w / 2 - 4, y1 + 1.5, x1 + w / 2 + 4, y1 + 1.5, get_darker_bg_color(), 1); al_draw_line(x1 + w / 2 - 4, y2 - 0.5, x1 + w / 2 + 4, y2 - 0.5, get_darker_bg_color(), 1); al_draw_line(x1 + w / 2 - 4, y2 - 1.5, x1 + w / 2 + 4, y2 - 1.5, get_lighter_bg_color(), 1); } else { //Horizontal bar. al_draw_filled_rectangle( x1 + 0.5, y1 + h / 2 - 2, x2 - 0.5, y1 + h / 2 + 2, get_bg_color() ); al_draw_line( x1 + 0.5, y1 + h / 2 - 0.5, x2 - 0.5, y1 + h / 2 - 0.5, get_lighter_bg_color(), 1 ); al_draw_line( x1 + 0.5, y1 + h / 2 + 0.5, x2 - 0.5, y1 + h / 2 + 0.5, get_darker_bg_color(), 1 ); al_draw_line(x1 + 0.5, y1 + h / 2 - 4, x1 + 0.5, y1 + h / 2 + 4, get_lighter_bg_color(), 1); al_draw_line(x1 + 1.5, y1 + h / 2 - 4, x1 + 1.5, y1 + h / 2 + 4, get_darker_bg_color(), 1); al_draw_line(x2 - 0.5, y1 + h / 2 - 4, x2 - 0.5, y1 + h / 2 + 4, get_darker_bg_color(), 1); al_draw_line(x2 - 1.5, y1 + h / 2 - 4, x2 - 1.5, y1 + h / 2 + 4, get_lighter_bg_color(), 1); } }
void CompressorWindow::draw_scales() { draw_3d_border(canvas->get_x() - 2, canvas->get_y() - 2, canvas->get_w() + 4, canvas->get_h() + 4, get_bg_color(), BLACK, MDGREY, get_bg_color()); set_font(SMALLFONT); set_color(get_resources()->default_text_color); #define DIVISIONS 8 for(int i = 0; i <= DIVISIONS; i++) { int y = canvas->get_y() + 10 + canvas->get_h() / DIVISIONS * i; int x = canvas->get_x() - 30; char string[BCTEXTLEN]; sprintf(string, "%.0f", (float)i / DIVISIONS * plugin->config.min_db); draw_text(x, y, string); int y1 = canvas->get_y() + canvas->get_h() / DIVISIONS * i; int y2 = canvas->get_y() + canvas->get_h() / DIVISIONS * (i + 1); for(int j = 0; j < 10; j++) { y = y1 + (y2 - y1) * j / 10; if(j == 0) { draw_line(canvas->get_x() - 10, y, canvas->get_x(), y); } else if(i < DIVISIONS) { draw_line(canvas->get_x() - 5, y, canvas->get_x(), y); } } } for(int i = 0; i <= DIVISIONS; i++) { int y = canvas->get_h() + 30; int x = canvas->get_x() + (canvas->get_w() - 10) / DIVISIONS * i; char string[BCTEXTLEN]; sprintf(string, "%.0f", (1.0 - (float)i / DIVISIONS) * plugin->config.min_db); draw_text(x, y, string); int x1 = canvas->get_x() + canvas->get_w() / DIVISIONS * i; int x2 = canvas->get_x() + canvas->get_w() / DIVISIONS * (i + 1); for(int j = 0; j < 10; j++) { x = x1 + (x2 - x1) * j / 10; if(j == 0) { draw_line(x, canvas->get_y() + canvas->get_h(), x, canvas->get_y() + canvas->get_h() + 10); } else if(i < DIVISIONS) { draw_line(x, canvas->get_y() + canvas->get_h(), x, canvas->get_y() + canvas->get_h() + 5); } } } flash(); }
/* ---------------------------------------------------------------------------- * Draws the button. It' just a rectangle with a fancy border; * the latter is drawn one line at a time. */ void button::draw_self() { unsigned int w = x2 - x1; unsigned int h = y2 - y1; ALLEGRO_COLOR top_color, bottom_color; if(mouse_clicking && mouse_in) { top_color = get_darker_bg_color(); bottom_color = get_lighter_bg_color(); } else { top_color = get_lighter_bg_color(); bottom_color = get_darker_bg_color(); } al_draw_filled_rectangle(x1, y1, x2, y2, get_bg_color()); //Top line, outermost. draw_line(this, DRAW_LINE_TOP, 0, 1, 0, top_color); //Top line, innermost. draw_line(this, DRAW_LINE_TOP, 0, 2, 1, top_color); //Left line, outermost. draw_line(this, DRAW_LINE_LEFT, 0, 1, 0, top_color); //Left line, innermost. draw_line(this, DRAW_LINE_LEFT, 0, 2, 1, top_color); //Bottom line, outermost. draw_line(this, DRAW_LINE_BOTTOM, 1, 0, 0, bottom_color); //Bottom line, innermost. draw_line(this, DRAW_LINE_BOTTOM, 2, 0, 1, bottom_color); //Right line, outermost. draw_line(this, DRAW_LINE_RIGHT, 1, 0, 0, bottom_color); //Right line, innermost. draw_line(this, DRAW_LINE_RIGHT, 2, 0, 1, bottom_color); //This is the center of the text, not top left. Also, relative coordinates. signed short final_text_y = 0; //Top left of the icon. signed short final_icon_y = 0; if(icon && text.size()) { //If there's an icon and text. unsigned short total_height = al_get_bitmap_height(icon) + al_get_font_line_height(style->text_font) + 2; //The icon goes to the top of the 2. final_icon_y = h / 2 - total_height / 2; //The text uses the same base y as the icon, except lowered, obviously. final_text_y = final_icon_y + al_get_bitmap_height(icon) + al_get_font_line_height(style->text_font) / 2 + 2; } else if(icon) { //Icon, but no text. final_icon_y = h / 2 - al_get_bitmap_height(icon) / 2; } else if(!icon && text.size()) { //Text, but no icon. final_text_y = h / 2; } if(icon) { al_draw_bitmap( icon, x1 + (w / 2 - al_get_bitmap_width(icon) / 2), y1 + final_icon_y, 0); } if(text.size()) { draw_text_lines( style->text_font, get_fg_color(), x1 + (w / 2), y1 + final_text_y, ALLEGRO_ALIGN_CENTRE, true, text); } }
int GP_ReadGIFEx(GP_IO *io, GP_Context **img, GP_DataStorage *storage, GP_ProgressCallback *callback) { GifFileType *gf; GifRecordType rec_type; GP_Context *res = NULL; GP_Pixel bg; int32_t x, y; int err; errno = 0; #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5 gf = DGifOpen(io, gif_input_func, NULL); #else gf = DGifOpen(io, gif_input_func); #endif if (gf == NULL) { /* * The giflib uses open() so when we got a failure and errno * is set => open() has failed. * * When errno is not set the file content was not valid so we * set errno to EIO. */ if (errno == 0) errno = EIO; return 1; } GP_DEBUG(1, "Have GIF image %ix%i, %i colors, %i bpp", gf->SWidth, gf->SHeight, gf->SColorResolution, gf->SColorMap ? gf->SColorMap->BitsPerPixel : -1); do { if (DGifGetRecordType(gf, &rec_type) != GIF_OK) { //TODO: error handling GP_DEBUG(1, "DGifGetRecordType() error %s (%i)", gif_err_name(gif_err(gf)), gif_err(gf)); err = EIO; goto err1; } GP_DEBUG(2, "Have GIF record type %s", rec_type_name(rec_type)); switch (rec_type) { case EXTENSION_RECORD_TYPE: if ((err = read_extensions(gf))) goto err1; continue; case IMAGE_DESC_RECORD_TYPE: break; default: continue; } if (DGifGetImageDesc(gf) != GIF_OK) { //TODO: error handling GP_DEBUG(1, "DGifGetImageDesc() error %s (%i)", gif_err_name(gif_err(gf)), gif_err(gf)); err = EIO; goto err1; } if (storage) fill_metadata(gf, storage); GP_DEBUG(1, "Have GIF Image left-top %ix%i, width-height %ix%i," " interlace %i, bpp %i", gf->Image.Left, gf->Image.Top, gf->Image.Width, gf->Image.Height, gf->Image.Interlace, gf->Image.ColorMap ? gf->Image.ColorMap->BitsPerPixel : -1); if (!img) break; res = GP_ContextAlloc(gf->SWidth, gf->SHeight, GP_PIXEL_RGB888); if (res == NULL) { err = ENOMEM; goto err1; } /* If background color is defined, use it */ if (get_bg_color(gf, &bg)) { GP_DEBUG(1, "Filling bg color %x", bg); GP_Fill(res, bg); } /* Now finally read gif image data */ for (y = gf->Image.Top; y < gf->Image.Height; y++) { uint8_t line[gf->Image.Width]; DGifGetLine(gf, line, gf->Image.Width); unsigned int real_y = y; if (gf->Image.Interlace == 64) { real_y = interlace_real_y(gf, y); GP_DEBUG(3, "Interlace y -> real_y %u %u", y, real_y); } //TODO: just now we have only 8BPP for (x = 0; x < gf->Image.Width; x++) GP_PutPixel_Raw_24BPP(res, x + gf->Image.Left, real_y, get_color(gf, line[x])); if (GP_ProgressCallbackReport(callback, y - gf->Image.Top, gf->Image.Height, gf->Image.Width)) { GP_DEBUG(1, "Operation aborted"); err = ECANCELED; goto err2; } } //TODO: now we exit after reading first image break; } while (rec_type != TERMINATE_RECORD_TYPE); DGifCloseFile(gf); /* No Image record found :( */ if (img && !res) { errno = EINVAL; return 1; } if (img) *img = res; return 0; err2: GP_ContextFree(res); err1: DGifCloseFile(gf); errno = err; return 1; }