Ejemplo n.º 1
0
bool Format7DrawingArea::on_button_release_event( GdkEventButton* event )
{
    gdouble endX = event->x;
    gdouble endY = event->y;

    ClipPoint( &endX, &endY );

    const unsigned int endXOrig = ToOriginal( (float)endX );
    const unsigned int endYOrig = ToOriginal( (float)endY );

    switch ( event->button )
    {
    case 1:
        m_left = std::min<unsigned int>(m_startX, endXOrig);
        m_top = std::min<unsigned int>(m_startY, endYOrig);
        m_width = std::max<unsigned int>(m_startX, endXOrig) - m_left;
        m_height = std::max<unsigned int>(m_startY, endYOrig) - m_top;

        ClampAllValues();

        m_imageSizeChanged = true;

        m_leftMBHeld = false;
        break;

    case 3:
        get_window()->set_cursor();

        m_rightMBHeld = false;
        break;
    }

    queue_draw();
    m_signal_image_size_changed( m_left, m_top, m_width, m_height, true);
    return true;
}
Ejemplo n.º 2
0
    bool Format7DrawingArea::on_expose_event( GdkEventExpose* event )
    {
        Glib::RefPtr<Gdk::Window> window = get_window();
        if( window == NULL)
        {
            return true;
        }

        Cairo::RefPtr<Cairo::Context> refCairo = window->create_cairo_context();

        // clip to the area indicated by the expose event so that we only redraw
        // the portion of the window that needs to be redrawn
        refCairo->rectangle(
            event->area.x, 
            event->area.y,
            event->area.width, 
            event->area.height);
        refCairo->clip();               

        // Get width / height of widget
        int width;
        int height;
        window->get_size( width, height );        

        // Figure out which scale to use (horizontal or vertical)
        const float horzScale = m_maxWidth / (float)width;
        const float vertScale = m_maxHeight / (float)height;
                
        m_previewScale = (horzScale < vertScale) ? vertScale : horzScale;

        Gtk::AspectFrame* pFrame = (Gtk::AspectFrame*)get_parent();
        float fRatio = m_maxWidth / (float)m_maxHeight;       
        if ( fRatio != pFrame->property_ratio())
        {
            pFrame->set( 0.0, 0.0, fRatio, false );
        } 

        unsigned int scaledLeft = static_cast<unsigned int>(ToScaled( m_left ));
        unsigned int scaledTop = static_cast<unsigned int>(ToScaled( m_top ));
        unsigned int scaledWidth = static_cast<unsigned int>(ToScaled( m_width ));
        unsigned int scaledHeight = static_cast<unsigned int>(ToScaled( m_height ));        

        // Fill the background with the PGR color
        FillBackground( 
            refCairo, 
            event->area.x, 
            event->area.y,
            event->area.width, 
            event->area.height);

        // Draw the data on top of the filled background
        DrawRectangle( refCairo, scaledLeft, scaledTop, scaledWidth, scaledHeight );
        DrawDashedLines( refCairo, scaledLeft, scaledTop, scaledWidth, scaledHeight );        
        DrawImageDimensionsText( refCairo, m_left, m_top, m_width, m_height );
        DrawCurrentCursorPositionText( refCairo, m_currX, m_currY );       

        if ( m_imageSizeChanged == true )
        {
            if ( m_left != m_lastFiredLeft ||
                m_top != m_lastFiredTop ||
                m_width != m_lastFiredWidth ||
                m_height != m_lastFiredHeight )
            {
                m_signal_image_size_changed( m_left, m_top, m_width, m_height );     

                m_lastFiredLeft = m_left;
                m_lastFiredTop = m_top;
                m_lastFiredWidth = m_width;
                m_lastFiredHeight = m_height;
            }
            
            m_imageSizeChanged = false;
        }

        return true;
    }