Commit 886a3e93 authored by tomasz.wlostowski@cern.ch's avatar tomasz.wlostowski@cern.ch
Browse files

Merged Orson's branch

parents 299f4243 9adbdd80
Loading
Loading
Loading
Loading
+12 −11
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ set(GAL_SRCS
    # Common part
    # Common part
    drawpanel_gal.cpp
    drawpanel_gal.cpp
    painter.cpp
    painter.cpp
    worksheet_item.cpp
    gal/graphics_abstraction_layer.cpp
    gal/graphics_abstraction_layer.cpp
    gal/stroke_font.cpp
    gal/stroke_font.cpp
    gal/color4d.cpp
    gal/color4d.cpp
+5 −7
Original line number Original line Diff line number Diff line
@@ -981,18 +981,16 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
        // Switch to GAL rendering
        // Switch to GAL rendering
        if( !m_galCanvasActive )
        if( !m_galCanvasActive )
        {
        {
            // Set up grid settings
            gal->SetGridVisibility( IsGridVisible() );
            gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) );
            gal->SetGridOrigin( VECTOR2D( screen->GetGridOrigin() ) );
            gal->SetGridOriginMarkerSize( 15 );
            gal->SetGridDrawThreshold( 10 );

            // Set up viewport
            // Set up viewport
            double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() );
            double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() );
            view->SetScale( zoom );
            view->SetScale( zoom );
            view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) );
            view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) );
        }
        }

        // Set up grid settings
        gal->SetGridVisibility( IsGridVisible() );
        gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) );
        gal->SetGridOrigin( VECTOR2D( screen->GetGridOrigin() ) );
    }
    }
    else
    else
    {
    {
+16 −11
Original line number Original line Diff line number Diff line
@@ -91,7 +91,8 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
	Connect( wxEVT_KEY_UP,      wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
	Connect( wxEVT_KEY_UP,      wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
	Connect( wxEVT_KEY_DOWN,    wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
	Connect( wxEVT_KEY_DOWN,    wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
    Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this );
    Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this );
    
    Connect( TOOL_DISPATCHER::EVT_REFRESH_MOUSE, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ),
             NULL, this );
    
    
    m_refreshTimer.SetOwner( this );
    m_refreshTimer.SetOwner( this );
    Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this );
    Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this );
@@ -130,7 +131,7 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
    m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) );
    m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) );
    m_gal->ClearScreen();
    m_gal->ClearScreen();


    m_view->PrepareTargets();
    m_view->ClearTargets();
    // Grid has to be redrawn only when the NONCACHED target is redrawn
    // Grid has to be redrawn only when the NONCACHED target is redrawn
    if( m_view->IsTargetDirty( KiGfx::TARGET_NONCACHED ) )
    if( m_view->IsTargetDirty( KiGfx::TARGET_NONCACHED ) )
        m_gal->DrawGrid();
        m_gal->DrawGrid();
@@ -170,13 +171,16 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect )
    wxLongLong t = wxGetLocalTimeMillis();
    wxLongLong t = wxGetLocalTimeMillis();
    wxLongLong delta = t - m_lastRefresh;
    wxLongLong delta = t - m_lastRefresh;


    if(t >= MinRefreshPeriod)
    if( delta >= MinRefreshPeriod )
    {
    {
        wxPaintEvent redrawEvent;
        wxPaintEvent redrawEvent;
        wxPostEvent( this, redrawEvent );
        wxPostEvent( this, redrawEvent );
        m_pendingRefresh = true;
        m_pendingRefresh = true;
    } else {
    }
        m_refreshTimer.Start ( (MinRefreshPeriod - t).ToLong(), true );
    else
    {
        // One shot timer
        m_refreshTimer.Start( ( MinRefreshPeriod - delta ).ToLong(), true );
        m_pendingRefresh = true;
        m_pendingRefresh = true;
    }
    }
} 
} 
@@ -236,16 +240,17 @@ void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent )
        m_eventDispatcher->DispatchWxEvent( aEvent );
        m_eventDispatcher->DispatchWxEvent( aEvent );
    }
    }


	if(m_view->IsDirty())
    Refresh();
    Refresh();
}
}




void EDA_DRAW_PANEL_GAL::onEnter( wxEvent& aEvent )
void EDA_DRAW_PANEL_GAL::onEnter( wxEvent& aEvent )
{
{
    // Getting focus is necessary in order to receive key events properly
    SetFocus();
    SetFocus();
}
}



void EDA_DRAW_PANEL_GAL::skipEvent( wxEvent& aEvent )
void EDA_DRAW_PANEL_GAL::skipEvent( wxEvent& aEvent )
{
{
    // This is necessary for CHAR_HOOK event to generate KEY_UP and KEY_DOWN events
    // This is necessary for CHAR_HOOK event to generate KEY_UP and KEY_DOWN events
+58 −46
Original line number Original line Diff line number Diff line
@@ -30,9 +30,9 @@ using namespace KiGfx;


COLOR4D::COLOR4D( EDA_COLOR_T aColor )
COLOR4D::COLOR4D( EDA_COLOR_T aColor )
{
{
    r = g_ColorRefs[aColor].m_Red;
    r = g_ColorRefs[aColor].m_Red / 255.0;
    g = g_ColorRefs[aColor].m_Green;
    g = g_ColorRefs[aColor].m_Green / 255.0;
    b = g_ColorRefs[aColor].m_Blue;
    b = g_ColorRefs[aColor].m_Blue / 255.0;
    a = 1.0;
    a = 1.0;
}
}


@@ -59,7 +59,8 @@ const bool COLOR4D::operator!=( const COLOR4D& aColor )
    return a != aColor.a || r != aColor.r || g != aColor.g || b != aColor.b;
    return a != aColor.a || r != aColor.r || g != aColor.g || b != aColor.b;
}
}


void COLOR4D::ToHSV(double& out_h, double& out_s, double& out_v) const

void COLOR4D::ToHSV( double& aOutH, double& aOutS, double& aOutV ) const
{
{
    double min, max, delta;
    double min, max, delta;


@@ -69,81 +70,91 @@ void COLOR4D::ToHSV(double& out_h, double& out_s, double& out_v) const
    max = r > g ? r : g;
    max = r > g ? r : g;
    max = max > b ? max : b;
    max = max > b ? max : b;


    out_v = max;                                // v
    aOutV = max;                                // v
    delta = max - min;
    delta = max - min;


    if( max > 0.0 ) {
    if( max > 0.0 )
        out_s = (delta / max);                  // s
    {
    } else {
        aOutS = ( delta / max );                  // s
    }
    else
    {
        // r = g = b = 0                        // s = 0, v is undefined
        // r = g = b = 0                        // s = 0, v is undefined
        out_s = 0.0;
        aOutS = 0.0;
        out_h = NAN;                            // its now undefined
        aOutH = NAN;                            // its now undefined
        return;
        return;
    }
    }
    if( r >= max )                           // > is bogus, just keeps compilor happy

        out_h = ( g - b ) / delta;        // between yellow & magenta
    if( r >= max )                           // > is bogus, just keeps compiler happy
    else
        aOutH = ( g - b ) / delta;           // between yellow & magenta
    if( g >= max )
    else if( g >= max )
        out_h = 2.0 + ( b - r ) / delta;  // between cyan & yellow
        aOutH = 2.0 + ( b - r ) / delta;     // between cyan & yellow
    else
    else
        out_h = 4.0 + ( r - g ) / delta;  // between magenta & cyan
        aOutH = 4.0 + ( r - g ) / delta;     // between magenta & cyan


    out_h *= 60.0;                              // degrees
    aOutH *= 60.0;                              // degrees


    if( out_h < 0.0 )
    if( aOutH < 0.0 )
        out_h += 360.0;
        aOutH += 360.0;
}
}


void COLOR4D::FromHSV(double in_h, double in_s, double in_v)

void COLOR4D::FromHSV( double aInH, double aInS, double aInV )
{
{
    double hh, p, q, t, ff;
    double hh, p, q, t, ff;
    long i;
    long i;


    if(in_s <= 0.0) {       // < is bogus, just shuts up warnings
    if( aInS <= 0.0 )   // < is bogus, just shuts up warnings
        r = in_v;
    {
        g = in_v;
        r = aInV;
        b = in_v;
        g = aInV;
        b = aInV;
        return;
        return;
    }
    }
    hh = in_h;

    if(hh >= 360.0) hh = 0.0;
    hh = aInH;
    if( hh >= 360.0 )
        hh = 0.0;
    hh /= 60.0;
    hh /= 60.0;

    i = (long) hh;
    i = (long) hh;
    ff = hh - i;
    ff = hh - i;
    p = in_v * (1.0 - in_s);
    q = in_v * (1.0 - (in_s * ff));
    t = in_v * (1.0 - (in_s * (1.0 - ff)));


    switch(i) {
    p = aInV * ( 1.0 - aInS );
    q = aInV * ( 1.0 - ( aInS * ff ) );
    t = aInV * ( 1.0 - ( aInS * ( 1.0 - ff ) ) );

    switch (i)
    {
    case 0:
    case 0:
        r = in_v;
        r = aInV;
        g = t;
        g = t;
        b = p;
        b = p;
        break;
        break;
    case 1:
    case 1:
        r = q;
        r = q;
        g = in_v;
        g = aInV;
        b = p;
        b = p;
        break;
        break;
    case 2:
    case 2:
        r = p;
        r = p;
        g = in_v;
        g = aInV;
        b = t;
        b = t;
        break;
        break;


    case 3:
    case 3:
        r = p;
        r = p;
        g = q;
        g = q;
        b = in_v;
        b = aInV;
        break;
        break;
    case 4:
    case 4:
        r = t;
        r = t;
        g = p;
        g = p;
        b = in_v;
        b = aInV;
        break;
        break;
    case 5:
    case 5:
    default:
    default:
        r = in_v;
        r = aInV;
        g = p;
        g = p;
        b = q;
        b = q;
        break;
        break;
@@ -151,6 +162,7 @@ void COLOR4D::FromHSV(double in_h, double in_s, double in_v)
    
    
}
}



COLOR4D& COLOR4D::Saturate( double aFactor )
COLOR4D& COLOR4D::Saturate( double aFactor )
{
{
    double h, s, v;
    double h, s, v;
+5 −4
Original line number Original line Diff line number Diff line
@@ -29,7 +29,6 @@
#include <gal/graphics_abstraction_layer.h>
#include <gal/graphics_abstraction_layer.h>
#include <gal/definitions.h>
#include <gal/definitions.h>



using namespace KiGfx;
using namespace KiGfx;


GAL::GAL() :
GAL::GAL() :
@@ -41,19 +40,21 @@ GAL::GAL() :
    SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
    SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
    SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    SetZoomFactor( 1.0 );
    SetZoomFactor( 1.0 );
    SetDepthRange( VECTOR2D( -2048, 2047 ) );
    SetDepthRange( VECTOR2D( GAL::MIN_DEPTH, GAL::MAX_DEPTH ) );
    SetFlip( false, false );
    SetFlip( false, false );
    SetLineWidth( 1.0 );
    SetLineWidth( 1.0 );


    // Set grid defaults
    // Set grid defaults
    SetGridVisibility( true );
    SetGridVisibility( true );
    SetGridStyle( GRID_STYLE_LINES );
    SetGridStyle( GRID_STYLE_LINES );
    SetGridOriginMarkerSize( 15 );
    SetGridDrawThreshold( 10 );
    SetCoarseGrid( 10 );
    SetCoarseGrid( 10 );
    SetGridLineWidth( 0.5 );
    SetGridLineWidth( 0.5 );


    // Initialize the cursor shape
    // Initialize the cursor shape
    SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    SetCursorSize( 20 );
    SetCursorSize( 15 );
    SetCursorEnabled( true );
    SetCursorEnabled( true );


    strokeFont.LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize );
    strokeFont.LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize );
@@ -112,7 +113,7 @@ void GAL::DrawGrid()


    // Draw the origin marker
    // Draw the origin marker
    double origSize = static_cast<double>( gridOriginMarkerSize ) / worldScale;
    double origSize = static_cast<double>( gridOriginMarkerSize ) / worldScale;
    SetLayerDepth( 0.0 );
    SetLayerDepth( GAL::GRID_DEPTH );
    SetIsFill( false );
    SetIsFill( false );
    SetIsStroke( true );
    SetIsStroke( true );
    SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
Loading