void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated fill, int alphaFill, ColourAllocated outline, int alphaOutline, int /*flags*/) { #if wxUSE_GRAPHICS_CONTEXT wxGCDC dc(*(wxMemoryDC*)hdc); wxColour penColour(wxColourFromCAandAlpha(outline, alphaOutline)); wxColour brushColour(wxColourFromCAandAlpha(fill, alphaFill)); dc.SetPen(wxPen(penColour)); dc.SetBrush(wxBrush(brushColour)); dc.DrawRoundedRectangle(wxRectFromPRectangle(rc), cornerSize); return; #else #ifdef wxHAVE_RAW_BITMAP // TODO: do something with cornerSize wxUnusedVar(cornerSize); int x, y; wxRect r = wxRectFromPRectangle(rc); wxBitmap bmp(r.width, r.height, 32); wxAlphaPixelData pixData(bmp); pixData.UseAlpha(); // Set the fill pixels ColourDesired cdf(fill.AsLong()); int red = cdf.GetRed(); int green = cdf.GetGreen(); int blue = cdf.GetBlue(); wxAlphaPixelData::Iterator p(pixData); for (y=0; y<r.height; y++) { p.MoveTo(pixData, 0, y); for (x=0; x<r.width; x++) { p.Red() = wxPy_premultiply(red, alphaFill); p.Green() = wxPy_premultiply(green, alphaFill); p.Blue() = wxPy_premultiply(blue, alphaFill); p.Alpha() = alphaFill; ++p; } } // Set the outline pixels ColourDesired cdo(outline.AsLong()); red = cdo.GetRed(); green = cdo.GetGreen(); blue = cdo.GetBlue(); for (x=0; x<r.width; x++) { p.MoveTo(pixData, x, 0); p.Red() = wxPy_premultiply(red, alphaOutline); p.Green() = wxPy_premultiply(green, alphaOutline); p.Blue() = wxPy_premultiply(blue, alphaOutline); p.Alpha() = alphaOutline; p.MoveTo(pixData, x, r.height-1); p.Red() = wxPy_premultiply(red, alphaOutline); p.Green() = wxPy_premultiply(green, alphaOutline); p.Blue() = wxPy_premultiply(blue, alphaOutline); p.Alpha() = alphaOutline; } for (y=0; y<r.height; y++) { p.MoveTo(pixData, 0, y); p.Red() = wxPy_premultiply(red, alphaOutline); p.Green() = wxPy_premultiply(green, alphaOutline); p.Blue() = wxPy_premultiply(blue, alphaOutline); p.Alpha() = alphaOutline; p.MoveTo(pixData, r.width-1, y); p.Red() = wxPy_premultiply(red, alphaOutline); p.Green() = wxPy_premultiply(green, alphaOutline); p.Blue() = wxPy_premultiply(blue, alphaOutline); p.Alpha() = alphaOutline; } // Draw the bitmap hdc->DrawBitmap(bmp, r.x, r.y, true); #else wxUnusedVar(cornerSize); wxUnusedVar(alphaFill); wxUnusedVar(alphaOutline); RectangleDraw(rc, outline, fill); #endif #endif }
void TimeInstantLayer::paint(View *v, QPainter &paint, QRect rect) const { if (!m_model || !m_model->isOK()) return; // Profiler profiler("TimeInstantLayer::paint", true); int x0 = rect.left(), x1 = rect.right(); long frame0 = v->getFrameForX(x0); long frame1 = v->getFrameForX(x1); SparseOneDimensionalModel::PointList points(m_model->getPoints (frame0, frame1)); bool odd = false; if (m_plotStyle == PlotSegmentation && !points.empty()) { int index = m_model->getIndexOf(*points.begin()); odd = ((index % 2) == 1); } paint.setPen(getBaseQColor()); QColor brushColour(getBaseQColor()); brushColour.setAlpha(100); paint.setBrush(brushColour); QColor oddBrushColour(brushColour); if (m_plotStyle == PlotSegmentation) { if (getBaseQColor() == Qt::black) { oddBrushColour = Qt::gray; } else if (getBaseQColor() == Qt::darkRed) { oddBrushColour = Qt::red; } else if (getBaseQColor() == Qt::darkBlue) { oddBrushColour = Qt::blue; } else if (getBaseQColor() == Qt::darkGreen) { oddBrushColour = Qt::green; } else { oddBrushColour = oddBrushColour.light(150); } oddBrushColour.setAlpha(100); } // std::cerr << "TimeInstantLayer::paint: resolution is " // << m_model->getResolution() << " frames" << std::endl; QPoint localPos; long illuminateFrame = -1; if (v->shouldIlluminateLocalFeatures(this, localPos)) { SparseOneDimensionalModel::PointList localPoints = getLocalPoints(v, localPos.x()); if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; } int prevX = -1; int textY = v->getTextLabelHeight(this, paint); for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin(); i != points.end(); ++i) { const SparseOneDimensionalModel::Point &p(*i); SparseOneDimensionalModel::PointList::const_iterator j = i; ++j; int x = v->getXForFrame(p.frame); if (x == prevX && p.frame != illuminateFrame) continue; int iw = v->getXForFrame(p.frame + m_model->getResolution()) - x; if (iw < 2) { if (iw < 1) { iw = 2; if (j != points.end()) { int nx = v->getXForFrame(j->frame); if (nx < x + 3) iw = 1; } } else { iw = 2; } } if (p.frame == illuminateFrame) { paint.setPen(getForegroundQColor(v)); } else { paint.setPen(brushColour); } if (m_plotStyle == PlotInstants) { if (iw > 1) { paint.drawRect(x, 0, iw - 1, v->height() - 1); } else { paint.drawLine(x, 0, x, v->height() - 1); } } else { if (odd) paint.setBrush(oddBrushColour); else paint.setBrush(brushColour); int nx; if (j != points.end()) { const SparseOneDimensionalModel::Point &q(*j); nx = v->getXForFrame(q.frame); } else { nx = v->getXForFrame(m_model->getEndFrame()); } if (nx >= x) { if (illuminateFrame != p.frame && (nx < x + 5 || x >= v->width() - 1)) { paint.setPen(Qt::NoPen); } paint.drawRect(x, -1, nx - x, v->height() + 1); } odd = !odd; } paint.setPen(getBaseQColor()); if (p.label != "") { // only draw if there's enough room from here to the next point int lw = paint.fontMetrics().width(p.label); bool good = true; if (j != points.end()) { int nx = v->getXForFrame(j->frame); if (nx >= x && nx - x - iw - 3 <= lw) good = false; } if (good) { paint.drawText(x + iw + 2, textY, p.label); } } prevX = x; } }