void wxImageBox::Paint() { // image width & height m_imageWidth = (int) (GetImage().GetWidth()*m_scale); m_imageHeight = (int) (GetImage().GetHeight()*m_scale); if (m_imageWidth == 0 || m_imageHeight == 0) { delete m_buffer; m_buffer = new wxBitmap(0,0); return; } // get paintRect wxRect paintRect = getPaintRect(); // make buffer 2 times as big as visible area (paintRect) paintRect.x -= paintRect.width/2; if (paintRect.x < 0) paintRect.x = 0; paintRect.y -= paintRect.height/2; if (paintRect.y < 0) paintRect.y = 0; paintRect.width *= 2; paintRect.height *= 2; if (paintRect.GetRight() > m_imageWidth) paintRect.width = m_imageWidth - paintRect.x; if (paintRect.GetBottom() > m_imageHeight) paintRect.height = m_imageHeight - paintRect.y; m_bufferX = paintRect.x; m_bufferY = paintRect.y; // scale //wxImage img = GetImage().Scale(m_imageWidth, m_imageHeight); wxRect subRect = ScaleRect(paintRect, 1/m_scale); wxImage img; int imgw = GetImage().GetWidth(); int imgh = GetImage().GetHeight(); // if subRect equal image (+-1%) if (subRect.x*100/imgw!=0 || subRect.y*100/imgh!=0 || (subRect.width-imgw)*100/imgw!=0 || (subRect.height-imgh)*100/imgh!=0) img = GetImage().GetSubImage(subRect); else img = GetImage(); img = img.Scale(paintRect.width, paintRect.height); PaintImg(img); delete m_buffer; m_buffer = new wxBitmap(img); }
void LuminanceRangeWidget::showValuePointer( float value ) { QRect fRect = getPaintRect(); int oldx = showVP ? getWindowX( valuePointer ) : -1; valuePointer = value; showVP = true; int newx = getWindowX( valuePointer ); if( oldx == -1 ) oldx = newx; QRect updateRect( min( oldx, newx ), fRect.top(), max( oldx, newx ) - min(oldx, newx )+1, fRect.height() ); update( updateRect ); }
void wxImageBox::OnPaint(wxPaintEvent &event) { wxRect paintRect = getPaintRect(); if (paintRect.GetRight() >= m_imageWidth) paintRect.width = m_imageWidth - paintRect.x; if (paintRect.GetBottom() >= m_imageHeight) paintRect.height = m_imageHeight - paintRect.y; wxRect bufferRect(m_bufferX, m_bufferY, m_buffer->GetWidth(), m_buffer->GetHeight()); if (m_repaint || paintRect.x < bufferRect.x || paintRect.y < bufferRect.y || paintRect.GetRight() > bufferRect.GetRight() || paintRect.GetBottom() > bufferRect.GetBottom()) { Paint(); // update buffer m_repaint = false; //wxLogMessage("Repaint: %d,%d - %d,%d -> %d,%d - %d,%d", // paintRect.x, paintRect.y, paintRect.width, paintRect.height, // bufferRect.x, bufferRect.y, bufferRect.width, bufferRect.height); } wxPaintBox::OnPaint(event); }
void LuminanceRangeWidget::mouseMoveEvent( QMouseEvent *me ) { // printf( "MouseButton: %d\n", me->button() ); if( (me->buttons() & Qt::LeftButton) != 0 && dragMode != DRAG_NO ) { if( mouseDragStart != DRAGNOTSTARTED ) { QRect fRect = getPaintRect(); int windowCordShift = me->x() - mouseDragStart; dragShift = (float)windowCordShift / (float)fRect.width() * (maxValue - minValue); update(); } } else { QRect fRect = rect(); int winBegPos = getWindowX( windowMin ); int winEndPos = getWindowX( windowMax ); if( abs( me->x() - winBegPos ) < dragZoneMargin ) { setCursor( QCursor( Qt::SplitHCursor ) ); dragMode = DRAG_MIN; } else if( abs( me->x() - winEndPos ) < dragZoneMargin ) { setCursor( QCursor( Qt::SplitHCursor ) ); dragMode = DRAG_MAX; } else if( me->x() > winBegPos && me->x() < winEndPos ) { setCursor( QCursor( Qt::SizeHorCursor ) ); dragMode = DRAG_MINMAX; } else { unsetCursor(); dragMode = DRAG_NO; } } }
void LuminanceRangeWidget::paintEvent( QPaintEvent *pe ) { { QPainter p( this ); QRect fRect = getPaintRect(); if( fRect.width() < 50 ) // Does not make sense to paint anything return; // Paint range window { int x1, x2; x1 = getWindowX( draggedMin() ); x2 = getWindowX( draggedMax() ); QColor selectionColor = mouseDragStart == DRAGNOTSTARTED ? QColor( 0, 100, 255 ) : QColor( 0, 150, 255 ); p.fillRect( x1, fRect.top(), x2-x1, fRect.height(), QBrush( selectionColor ) ); } // Paint histogram if( histogramImage != NULL ) { if( histogram == NULL || histogram->getBins() != fRect.width() ) { delete histogram; // Build histogram from at least 5000 pixels int accuracy = histogramImage->getRows()*histogramImage->getCols()/5000; if( accuracy < 1 ) accuracy = 1; histogram = new Histogram( fRect.width(), accuracy ); histogram->computeLog( histogramImage, minValue, maxValue ); } float maxP = histogram->getMaxP(); int i = 0; p.setPen( Qt::green ); for( int x = fRect.left(); i < histogram->getBins(); x++, i++ ) { if( histogram->getP(i) > 0 ) { int barSize = (int)((float)fRect.height() * histogram->getP(i)/maxP); p.drawLine( x, fRect.bottom(), x, fRect.bottom() - barSize ); } } } // Paint scale QFont labelFont( "SansSerif", 8 ); p.setFont( labelFont ); p.setPen( Qt::black ); QRect textBounding = p.boundingRect( fRect, Qt::AlignHCenter|Qt::AlignBottom, "-8" ); for( float x = ceil( minValue ); x <= floor( maxValue ); x++ ) { int rx = getWindowX(x); p.drawLine( rx, fRect.top(), rx, textBounding.top() ); char str[10]; sprintf( str, "%g", x ); p.drawText( rx-20, textBounding.top(), 40, textBounding.height(), Qt::AlignHCenter|Qt::AlignBottom, str ); } // Paint value pointer if( showVP ) { int x = getWindowX( valuePointer ); if( fRect.contains( x, fRect.y() ) ) { p.setPen( Qt::yellow ); p.drawLine( x, fRect.top(), x, fRect.bottom() ); } } } QFrame::paintEvent(pe); }