Exemplo n.º 1
0
void GribRequestSetting::OnMouseEventTimer( wxTimerEvent & event)
{
    //compute zone starting point lon/lat for zone drawing
    double lat,lon;
    GetCanvasLLPix( m_Vp, m_StartPoint, &lat, &lon);

    //compute rounded coordinates
    if( lat > m_Lat) {
        m_spMaxLat->SetValue( (int) ceil(lat) );
        m_spMinLat->SetValue( (int) floor(m_Lat) );
    }
    else {
        m_spMaxLat->SetValue( (int) ceil(m_Lat) );
        m_spMinLat->SetValue( (int) floor(lat) );
    }
	if(m_IsMaxLong) {
        m_spMaxLon->SetValue( (int) ceil(lon) );
        m_spMinLon->SetValue( (int) floor(m_Lon) );
    }
    else {
        m_spMaxLon->SetValue( (int) ceil(m_Lon) );
        m_spMinLon->SetValue( (int) floor(lon) );
    }

    RequestRefresh( m_parent.pParent );
}
Exemplo n.º 2
0
bool GribRequestSetting::MouseEventHook( wxMouseEvent &event )
{
    if( m_ZoneSelMode == AUTO_SELECTION || m_ZoneSelMode == SAVED_SELECTION || m_ZoneSelMode == START_SELECTION ) return false;

    if( event.Moving()) return false;                           //maintain status bar and tracking dialog updated

    if( event.LeftDown() ) {
        m_parent.pParent->SetFocus();
        m_ZoneSelMode = DRAW_SELECTION;                         //restart a new drawing
        m_parent.SetRequestBitmap( m_ZoneSelMode );
        if( this->IsShown() ) this->Hide();                     //eventually hide diaog in case of mode change
        m_RenderZoneOverlay = 0;                                //eventually hide previous drawing
    }

    if( event.LeftUp () && m_RenderZoneOverlay == 2 ) {
        m_ZoneSelMode = COMPLETE_SELECTION;                     //ask to complete selection
        m_parent.SetRequestBitmap( m_ZoneSelMode );
        SetCoordinatesText();
        m_MailImage->SetValue( WriteMail() );
        m_RenderZoneOverlay = 1;
    }

    if( event.Dragging() ) {
        if( m_RenderZoneOverlay < 2 ) {
            m_StartPoint = event.GetPosition();                                    //starting selection point
            m_RenderZoneOverlay = 2;
        }
		m_IsMaxLong = m_StartPoint.x > event.GetPosition().x? true: false;         //find if startpoint is max longitude 
        GetCanvasLLPix( m_Vp, event.GetPosition(), &m_Lat, &m_Lon);                //extend selection
        if( !m_tMouseEventTimer.IsRunning() ) m_tMouseEventTimer.Start( 20, wxTIMER_ONE_SHOT );
    }
    return true;
}
Exemplo n.º 3
0
void ODPoint::DrawGL( PlugIn_ViewPort &pivp )
{
    if( !m_bIsVisible )
    return;

    //    Optimization, especially apparent on tracks in normal cases
    if( m_IconName == _T("empty") && !m_bShowName && !m_bPtIsSelected ) return;

    if(m_wpBBox.GetValid() &&
        pivp.chart_scale == m_wpBBox_chart_scale &&
        pivp.rotation == m_wpBBox_rotation) {
    }

    wxPoint r;
    wxRect hilitebox;
    unsigned char transparency = 150;

    GetCanvasPixLL( &g_VP, &r, m_lat, m_lon );

//    Substitue icon?
    wxBitmap *pbm;
    if( ( m_bIsActive ) && ( m_IconName != _T("mob") ) )
        pbm = g_pODPointMan->GetIconBitmap(  _T ( "activepoint" ) );
    else
        pbm = m_pbmIcon;

    int sx2 = pbm->GetWidth() / 2;
    int sy2 = pbm->GetHeight() / 2;

//    Calculate the mark drawing extents
    wxRect r1( r.x - sx2, r.y - sy2, sx2 * 2, sy2 * 2 );          // the bitmap extents
    
    float  l_fIconScaleFactor = GetOCPNChartScaleFactor_Plugin();
    wxRect r3 = r1;
    if( m_bShowName ) {
        if( !m_pMarkFont ) {
            m_pMarkFont = GetOCPNScaledFont_PlugIn( wxT( "Marks" ) );
            m_FontColor = GetFontColour_PlugIn( wxS( "Marks" ) );
            CalculateNameExtents();
        }

        if( m_pMarkFont ) {
            wxRect r2( r.x + (m_NameLocationOffsetX * l_fIconScaleFactor), r.y + (m_NameLocationOffsetY * l_fIconScaleFactor),
                       m_NameExtents.x, m_NameExtents.y );
            r3.Union( r2 );
        }
    }

    hilitebox = r3;
    hilitebox.x -= r.x;
    hilitebox.y -= r.y;
    float radius;
    if( IsTouchInterface_PlugIn() ){
        hilitebox.Inflate( 20 );
        radius = 20.0f;
    }
    else{
        hilitebox.Inflate( 4 );
        radius = 4.0f;
    }
    
    /* update bounding box */
    if(!m_wpBBox.GetValid() || pivp.chart_scale != m_wpBBox_chart_scale || pivp.rotation != m_wpBBox_rotation) {
        double lat1, lon1, lat2, lon2;
        wxPoint wxpoint;
        wxpoint.x = r.x+hilitebox.x;
        wxpoint.y = r.y + hilitebox.height;
        GetCanvasLLPix( &pivp, wxpoint, &lat1, &lon1 );
        wxpoint.x = r.x + hilitebox.x + hilitebox.width;
        wxpoint.y = r.y + hilitebox.y;
        GetCanvasLLPix( &pivp, wxpoint, &lat2, &lon2 );

        if(lon1 > lon2)
            m_wpBBox.Set(lat1, lon1, lat2, lon2+360);
        else
            m_wpBBox.Set(lat1, lon1, lat2, lon2);
        m_wpBBox_chart_scale = pivp.chart_scale;
        m_wpBBox_rotation = pivp.rotation;
    }

    ODDC dc;

    //  Highlite any selected point
    if( m_bPtIsSelected || m_bIsBeingEdited ) {
        wxColour hi_colour;
        if( m_bPointPropertiesBlink || m_bPathManagerBlink ){
            wxPen *pen = g_pPathMan->GetActiveODPointPen();
            hi_colour = pen->GetColour();
        }
        else{
            GetGlobalColor( wxS( "YELO1" ), &hi_colour );
        }
        
        g_ocpn_draw_pi->AlphaBlending( dc, r.x + hilitebox.x, r.y + hilitebox.y, hilitebox.width, hilitebox.height, radius,
                       hi_colour, transparency );
    }
    
    bool bDrawHL = false;

    if( (m_bPointPropertiesBlink || m_bPathManagerBlink) && ( g_ocpn_draw_pi->nBlinkerTick & 1 ) ) bDrawHL = true;

    if( ( !bDrawHL ) && ( NULL != m_pbmIcon ) ) {
        int glw, glh;
        unsigned int IconTexture = g_pODPointMan->GetIconTexture( pbm, glw, glh );
        
        glBindTexture(GL_TEXTURE_2D, IconTexture);
        
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
        
        glColor3f(1, 1, 1);
        
        float l_ChartScaleFactorExp = GetOCPNChartScaleFactor_Plugin();
        float w = r1.width * l_ChartScaleFactorExp;
        float h = r1.height * l_ChartScaleFactorExp;
        float x = r.x - w/2; 
        float y = r.y - h/2;
        float u = (float)r1.width/glw, v = (float)r1.height/glh;
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex2f(x, y);
        glTexCoord2f(u, 0); glVertex2f(x+w, y);
        glTexCoord2f(u, v); glVertex2f(x+w, y+h);
        glTexCoord2f(0, v); glVertex2f(x, y+h);
        glEnd();
        glDisable(GL_BLEND);
        glDisable(GL_TEXTURE_2D);
    }

    if( m_bShowName && m_pMarkFont ) {
        int w = m_NameExtents.x, h = m_NameExtents.y;
        if(!m_iTextTexture && w && h) {
            wxBitmap tbm(w, h); /* render text on dc */
            wxMemoryDC dc;
            dc.SelectObject( tbm );               
            dc.SetBackground( wxBrush( *wxBLACK ) );
            dc.Clear();
            dc.SetFont( *m_pMarkFont );
            dc.SetTextForeground( *wxWHITE );
            dc.DrawText( m_ODPointName, 0, 0);
            dc.SelectObject( wxNullBitmap );
            
            /* make alpha texture for text */
            wxImage image = tbm.ConvertToImage();
            unsigned char *d = image.GetData();
            unsigned char *e = new unsigned char[w * h];
            if(d && e){
                for( int p = 0; p < w*h; p++)
                    e[p] = d[3*p + 0];
            }
            
            /* create texture for rendered text */
            glGenTextures(1, &m_iTextTexture);
            glBindTexture(GL_TEXTURE_2D, m_iTextTexture);
            
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );

            m_iTextTextureWidth = NextPow2(w);
            m_iTextTextureHeight = NextPow2(h);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, m_iTextTextureWidth, m_iTextTextureHeight,
                         0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL);
            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h,
                            GL_ALPHA, GL_UNSIGNED_BYTE, e);
            delete [] e;
        }

        if(m_iTextTexture) {
            /* draw texture with text */
            glBindTexture(GL_TEXTURE_2D, m_iTextTexture);
            
            glEnable(GL_TEXTURE_2D);
            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        
            glColor3ub(m_FontColor.Red(), m_FontColor.Green(), m_FontColor.Blue());
            
            int x = r.x + (m_NameLocationOffsetX * l_fIconScaleFactor), y = r.y + (m_NameLocationOffsetY * l_fIconScaleFactor);
            float u = (float)w/m_iTextTextureWidth, v = (float)h/m_iTextTextureHeight;
            glBegin(GL_QUADS);
            glTexCoord2f(0, 0); glVertex2f(x, y);
            glTexCoord2f(u, 0); glVertex2f(x+w, y);
            glTexCoord2f(u, v); glVertex2f(x+w, y+h);
            glTexCoord2f(0, v); glVertex2f(x, y+h);
            glEnd();
            glDisable(GL_BLEND);
            glDisable(GL_TEXTURE_2D);
        }
    }
    
    // Draw ODPoint range rings if activated
    if( m_iODPointRangeRingsNumber && m_bShowODPointRangeRings ) {
        double factor = 1.00;
        if( m_iODPointRangeRingsStepUnits == 1 )          // nautical miles
            factor = 1 / 1.852;
        
        factor *= m_fODPointRangeRingsStep;
        
        double tlat, tlon;
        wxPoint r1;
        ll_gc_ll( m_lat, m_lon, 0, factor, &tlat, &tlon );
        GetCanvasPixLL( &g_VP, &r1,  tlat, tlon);
        
        double lpp = sqrt( pow( (double) (r.x - r1.x), 2) +
        pow( (double) (r.y - r1.y), 2 ) );
        int pix_radius = (int) lpp;
        
        wxPen ppPen1( m_wxcODPointRangeRingsSchemeColour, m_iRangeRingWidth, m_iRangeRingStyle );
        wxBrush saveBrush = dc.GetBrush();
        wxPen savePen = dc.GetPen();
        dc.SetPen( ppPen1 );
        dc.SetBrush( wxBrush( m_wxcODPointRangeRingsSchemeColour, wxBRUSHSTYLE_TRANSPARENT ) );
        dc.SetGLStipple();
        
        for( int i = 1; i <= m_iODPointRangeRingsNumber; i++ )
            dc.StrokeCircle( r.x, r.y, i * pix_radius );
        
        glDisable( GL_LINE_STIPPLE );
        
        dc.SetPen( savePen );
        dc.SetBrush( saveBrush );
    }
    
    if( m_bPointPropertiesBlink || m_bPathManagerBlink ) g_blink_rect = CurrentRect_in_DC;               // also save for global blinker
    
    //    This will be useful for fast icon redraws
    CurrentRect_in_DC.x = r.x + hilitebox.x;
    CurrentRect_in_DC.y = r.y + hilitebox.y;
    CurrentRect_in_DC.width = hilitebox.width;
    CurrentRect_in_DC.height = hilitebox.height;

    if( m_bPointPropertiesBlink || m_bPathManagerBlink ) g_blink_rect = CurrentRect_in_DC;               // also save for global blinker
}