// Make border pixels opaque void graphics__update_image_transparency(wxImage &image) { int width = image.GetWidth() ; int height = image.GetHeight() ; for( size_t x = 0 ; x < width ; x++ ) { for( size_t y = 0 ; y < height ; y++ ) { long int pos = 3 * (y * width + x) ; // Look for non-black pixel if( image.GetData()[pos] != 0 || image.GetData()[pos+1] != 0 || image.GetData()[pos+2] != 0 ) { image.SetAlpha(x, y, 255) ; // Set Opaque // If any of the four neighboring pixels are black, it's a border pixel, set the pixel opaque // otherwise it's an internal pixel, set the pixel transparent. if( x > 0 ) { pos = 3 * (y * width + (x - 1)) ; if( image.GetData()[pos] == 0 && image.GetData()[pos+1] == 0 && image.GetData()[pos+2] == 0 ) continue ; } if( x < width - 2 ) { pos = 3 * (y * width + (x + 1)) ; if( image.GetData()[pos] == 0 && image.GetData()[pos+1] == 0 && image.GetData()[pos+2] == 0 ) continue ; } if( y > 0 ) { pos = 3 * ((y - 1) * width + x) ; if( image.GetData()[pos] == 0 && image.GetData()[pos+1] == 0 && image.GetData()[pos+2] == 0 ) continue ; } if( y < height - 2 ) { pos = 3 * ((y + 1) * width + x) ; if( image.GetData()[pos] == 0 && image.GetData()[pos+1] == 0 && image.GetData()[pos+2] == 0 ) continue ; } image.SetAlpha(x, y, 0) ; // Set Transparent } } } } void graphics__arc__outline(window_attribute_p_t window_attribute_p, position_t center_position, coord radius, int starting_angle, // In 1/64 degrees int increment_angle, // In 1/64 degrees coord path_width, short endpoint_type, double alpha) { double starting_angle_double = starting_angle/11520.0 * M_PI ; double increment_angle_double = increment_angle/11520.0 * M_PI ; if( increment_angle < 0 ) { starting_angle_double = starting_angle_double + increment_angle_double ; increment_angle_double = ((-1) * increment_angle_double) ; } int fill_style = window_attribute_p->active_fill_style ; graphics__set_fill_style(window_attribute_p, display_$fill_transparent, (bool) color__is_white(import_export.window_p->edit_p->background_color_index) ) ; graphics__set_foreground_color(window_attribute_p,dc,window_attribute_p->active_color_index); graphics__set_line_width(window_attribute_p,dc,path_width) ; graphics__set_clip_region(window_attribute_p,iti_dc,window_attribute_p->clip_region); graphics__set_alpha(window_attribute_p, dc, alpha) ; graphics__set_cap_type(window_attribute_p, dc, endpoint_type) ; coord startX = center_position.x_coord + radius * graphics__round(cos(starting_angle_double)) ; coord startY = center_position.y_coord - radius * graphics__round(sin(starting_angle_double)) ; coord endX = center_position.x_coord + radius * graphics__round(cos(starting_angle_double + increment_angle_double)) ; coord endY = center_position.y_coord - radius * graphics__round(sin(starting_angle_double + increment_angle_double)) ; coord centerX = center_position.x_coord ; coord centerY = center_position.y_coord ; coord minX, minY, maxX, maxY ; graphics__determine_arc_extent(dc, center_position, radius, path_width, minX, minY, maxX, maxY) ; coord xDist = maxX - minX ; startX -= minX ; endX -= minX ; centerX -= minX ; coord yDist = maxY - minY ; startY -= minY ; endY -= minY ; centerY -= minY ; if( xDist <= 0 || yDist <= 0 ) return ; wxSize size(xDist, yDist) ; wxBitmap bitmap(size, 32) ; wxMemoryDC memDC(bitmap) ; wxPen pen = dc->GetPen() ; pen.SetStyle(wxPENSTYLE_SOLID) ; memDC.SetPen(pen) ; wxBrush brush = dc->GetBrush() ; brush.SetStyle(wxBRUSHSTYLE_TRANSPARENT) ; memDC.SetBrush(brush) ; memDC.Blit(0, 0, size.GetWidth(), size.GetHeight(), dc, minX, minY) ; memDC.DrawArc(startX, startY, endX, endY, centerX, centerY); wxImage image ; bitmap.UseAlpha() ; if( bitmap.HasAlpha() ) { image = bitmap.ConvertToImage() ; } if( image.IsOk() && image.HasAlpha() ) { graphics__update_image_transparency(image) ; wxBitmap newBitmap(image, 32) ; if( !newBitmap.IsOk() ) return ; dc->DrawBitmap(newBitmap, minX, minY) ; } else { dc->DrawBitmap(bitmap, minX, minY) ; } }