コード例 #1
0
ファイル: IsoBarMap.cpp プロジェクト: CarCode/Cocoa-OCPN
/* draw a line segment in opengl from lat/lon and viewport */
void DrawLineSeg(wxDC *dc, PlugIn_ViewPort &VP, double lat1, double lon1, double lat2, double lon2)
{
    /* avoid lines which cross over the view port the long way */
    if(lon1+180 < VP.clon && lon2+180 > VP.clon)
        return;
    if(lon1+180 > VP.clon && lon2+180 < VP.clon)
        return;
    if(lon1-180 < VP.clon && lon2-180 > VP.clon)
        return;
    if(lon1-180 > VP.clon && lon2-180 < VP.clon)
        return;

    wxPoint r1, r2;
    GetCanvasPixLL(&VP, &r1, lat1, lon1);
    GetCanvasPixLL(&VP, &r2, lat2, lon2);

    if(dc)
        dc->DrawLine(r1.x, r1.y, r2.x, r2.y);
    else {
        glBegin(GL_LINES);
        glVertex2i(r1.x, r1.y);
        glVertex2i(r2.x, r2.y);
        glEnd();
    }
}
コード例 #2
0
ファイル: iacfile.cpp プロジェクト: rgleason/iacfleet_pi
// draw the fleet code data
// returns true if anything was drawn
bool IACFile::Draw(wxDC *dc, PlugIn_ViewPort *vp) {
    bool retval = false;
    // draw only if file was successfully read and decoded
    if (IsOk()) {
        wxColor colour;
        GetGlobalColor(_T ( "SNDG1" ), &colour);
        wxPoint p1, p2, p3, p4;
        double minlon, maxlon;
        if (m_minlone < 999)
            minlon = m_minlone;
        else
            minlon = m_minlonw;
        if (m_maxlonw > -999)
            maxlon = m_maxlonw;
        else
            maxlon = m_maxlone;
        if (-179.0 < m_minlonw && m_minlonw < 0 && 179.0 > m_maxlone && m_maxlone > 0) {
            minlon = m_minlonw;
            maxlon = m_maxlone;
        }

        GetCanvasPixLL(vp, &p1, m_minlat, minlon);
        GetCanvasPixLL(vp, &p2, m_maxlat, minlon);
        GetCanvasPixLL(vp, &p3, m_maxlat, maxlon);
        GetCanvasPixLL(vp, &p4, m_minlat, maxlon);
        if (dc) {
            if (p3.x > 0 && p1.x < vp->pix_width) {
                dc->SetPen(wxPen(colour, ISOBAR_WIDTH));
                wxPoint points[] = {p1, p2, p3, p4, p1};
                dc->DrawLines(5, points);
            }
        } else {
            wxFont font_numbers(NUMBERS_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
            m_TexFontNumbers.Build(font_numbers);
            wxFont font_systems(SYSTEMS_FONT_SIZE, wxFONTFAMILY_ROMAN, wxFONTSTYLE_ITALIC, wxFONTWEIGHT_BOLD);
            m_TexFontSystems.Build(font_systems);

            if (p3.x > 0 && p1.x < vp->pix_width) {
                glColor3ub(colour.Red(), colour.Green(), colour.Blue());
                glBegin(GL_LINE_LOOP);
                glVertex2i(p1.x, p1.y);
                glVertex2i(p2.x, p2.y);
                glVertex2i(p3.x, p3.y);
                glVertex2i(p4.x, p4.y);
                glEnd();
            }
        }
        // This magic initialisation to the random numer generator
        // ensures that the (random) positions where some text
        // is written does not change between several calls to "Draw"
        // I love this kind of crazy code - it is like in the good
        // old days of programming where everything was allowed.
        srand(77);
        retval |= DrawSystems(dc, vp, (IACSystems &)m_pressure);
        retval |= DrawSystems(dc, vp, (IACSystems &)m_frontal);
        retval |= DrawSystems(dc, vp, (IACSystems &)m_isobars);
        retval |= DrawSystems(dc, vp, (IACSystems &)m_tropical);
    }
    return retval;
}
コード例 #3
0
void RouteMapOverlay::DrawLine(Position *p1, wxColour &color1, Position *p2, wxColour &color2,
                               wrDC &dc, PlugIn_ViewPort &vp)
{
#if 0
    double p1plon, p2plon;
    if(fabs(vp.clon) > 90)
        p1plon = positive_degrees(p1->lon), p2plon = positive_degrees(p2->lon);
    else
        p1plon = heading_resolve(p1->lon), p2plon = heading_resolve(p2->lon);

    if((p1plon+180 < vp.clon && p2plon+180 > vp.clon) ||
       (p1plon+180 > vp.clon && p2plon+180 < vp.clon) ||
       (p1plon-180 < vp.clon && p2plon-180 > vp.clon) ||
       (p1plon-180 > vp.clon && p2plon-180 < vp.clon))
        return;
#endif

    wxPoint p1p, p2p;
    GetCanvasPixLL(&vp, &p1p, p1->lat, p1->lon);
    GetCanvasPixLL(&vp, &p2p, p2->lat, p2->lon);

    SetColor(dc, color1);
    if(dc.GetDC())
        dc.DrawLine(p1p.x, p1p.y, p2p.x, p2p.y);
    else {
        glVertex2d(p1p.x, p1p.y);
        SetColor(dc, color2);
        glVertex2d(p2p.x, p2p.y);
    }
}
コード例 #4
0
ファイル: iacfile.cpp プロジェクト: rgleason/iacfleet_pi
bool IACIsobarSystem::Draw(wxDC *dc, PlugIn_ViewPort *vp, TexFont &numfont, TexFont &sysfont) {
    bool hasDrawn = false;
    // draw isobar text at a random position of the isoline to prevent
    // text clutter. Getting the random positiuon must be before
    // "if" because otherwise the positions depend on the viewport
    int randomPositionIndex = rand() % m_positions.Count();

    if (dc) {
        wxColour colour;
        GetGlobalColor(_T ( "CHBLK" ), &colour);
        wxPen pen(colour, ISOBAR_WIDTH);
        dc->SetPen(pen);
        dc->SetBrush(*wxTRANSPARENT_BRUSH);

        hasDrawn = DrawPositions(dc, vp);
        if (hasDrawn) {
            GeoPoint &Pos = m_positions[randomPositionIndex];
            if (PointInLLBox(vp, Pos.x, Pos.y)) {
                wxPoint p;
                GetCanvasPixLL(vp, &p, Pos.y, Pos.x);
                dc->SetTextForeground(colour);
                wxFont *font = wxTheFontList->FindOrCreateFont(NUMBERS_FONT_SIZE, wxFONTFAMILY_SWISS, wxNORMAL, wxFONTWEIGHT_NORMAL,
                                                               FALSE, wxString(_T ( "Arial" )));
                dc->SetFont(*font);
                wxString msg;
                msg.Printf(wxT("%u"), m_val);
                wxSize s1 = dc->GetTextExtent(msg);
                dc->DrawText(msg, p.x - (s1.GetWidth() / 2), p.y - (s1.GetHeight()));
            }
        }
    } else {
        GetGlobalColor(_T ( "CHBLK" ), &m_isoLineColor);
        m_isoLineWidth = wxMax(ISOBAR_WIDTH, GL_MIN_LINE_WIDTH);
        hasDrawn = DrawPositions(dc, vp);
        if (hasDrawn) {
            wxColour colour;
            GetGlobalColor(_T ( "CHBLK" ), &colour);
            GeoPoint &Pos = m_positions[randomPositionIndex];
            wxPoint p;
            GetCanvasPixLL(vp, &p, Pos.y, Pos.x);
            wxString msg;
            msg.Printf(wxT("%u"), m_val);
            int w, h;
            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            glEnable(GL_TEXTURE_2D);
            glColor3ub(colour.Red(), colour.Green(), colour.Blue());
            numfont.GetTextExtent(msg, &w, &h);
            numfont.RenderString(msg, p.x - (w / 2), p.y - (h / 2));
            glDisable(GL_TEXTURE_2D);
            glDisable(GL_BLEND);
        }
    }
    return hasDrawn;
}
コード例 #5
0
ファイル: IsoLine.cpp プロジェクト: fzschornack/OpenCPN
void IsoLine::drawIsoLineLabels(GRIBOverlayFactory *pof, wxDC &dc, wxColour text_color, wxColour back_color,
                                PlugIn_ViewPort *vp, int density, int first, double coef)
{
///
//#if 0
    std::list<Segment *>::iterator it;
    int nb = first;
    wxString label;

    label.Printf(_T("%d"), (int)(value*coef+0.5));

    wxPen penText(text_color);

    int w, h;
    dc.GetTextExtent(label, &w, &h);

    dc.SetPen(penText);
    dc.SetBrush(wxBrush(back_color));
    dc.SetTextForeground(text_color);
    dc.SetTextBackground(back_color);

    //---------------------------------------------------------
    // Ecrit les labels
    //---------------------------------------------------------
    for (it=trace.begin(); it!=trace.end(); it++,nb++)
    {
        if (nb % density == 0)
		{
            Segment *seg = *it;

//            if(vp->vpBBox.PointInBox((seg->px1 + seg->px2)/2., (seg->py1 + seg->py2)/2., 0.))
            {
 //                 wxPoint ab = vp->GetMercatorPixFromLL(seg->py1, seg->px1);
 //                 wxPoint cd = vp->GetMercatorPixFromLL(seg->py2, seg->px2);
			wxPoint ab;
			GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
			wxPoint cd;
			GetCanvasPixLL(vp, &cd, seg->py1, seg->px1);
                  
			int label_offset = 6;
                  int xd = (ab.x + cd.x-(w+label_offset * 2))/2;
                  int yd = (ab.y + cd.y - h)/2;

                 
                  dc.DrawRoundedRectangle(xd, yd, w+(label_offset * 2), h, -.25);
                  dc.DrawText(label, label_offset/2 + xd, yd-1);
            }

        }
    }
//#endif
///
}
コード例 #6
0
void RouteMapOverlay::DrawLine(Position *p1, Position *p2,
                               wrDC &dc, PlugIn_ViewPort &vp)
{
    wxPoint p1p, p2p;
    GetCanvasPixLL(&vp, &p1p, p1->lat, p1->lon);
    GetCanvasPixLL(&vp, &p2p, p2->lat, p2->lon);

    if(dc.GetDC())
        dc.StrokeLine(p1p.x, p1p.y, p2p.x, p2p.y);
    else {
        glVertex2d(p1p.x, p1p.y);
        glVertex2d(p2p.x, p2p.y);
    }
}
コード例 #7
0
ファイル: IsoLine.cpp プロジェクト: OpenCPN/OpenCPN
void IsoLine::drawIsoLineLabels(GRIBOverlayFactory *pof, wxDC *dc,
                                PlugIn_ViewPort *vp, int density, int first,
                                wxImage &imageLabel)

{
    std::list<Segment *>::iterator it;
    int nb = first;
    wxString label;

    //---------------------------------------------------------
    // Ecrit les labels
    //---------------------------------------------------------
    wxRect prev;
    for (it=trace.begin(); it!=trace.end(); it++,nb++)
    {
        if (nb % density == 0)
        {
            Segment *seg = *it;

//            if(vp->vpBBox.PointInBox((seg->px1 + seg->px2)/2., (seg->py1 + seg->py2)/2., 0.))
            {
                wxPoint ab;
                GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
                wxPoint cd;
                GetCanvasPixLL(vp, &cd, seg->py1, seg->px1);

                int w = imageLabel.GetWidth();
                int h = imageLabel.GetHeight();

                int label_offset = 6;
                int xd = (ab.x + cd.x-(w+label_offset * 2))/2;
                int yd = (ab.y + cd.y - h)/2;

                int x = xd - label_offset;
                wxRect r(x ,yd ,w ,h);
                r.Inflate(w);
                if (!prev.Intersects(r))  {
                      prev = r;

                      /* don't use alpha for isobars, for some reason draw bitmap ignores
                         the 4th argument (true or false has same result) */
                      wxImage img(w, h, imageLabel.GetData(), true);
                      dc->DrawBitmap(img, xd, yd, false);
                }
            }
        }
    }
}
コード例 #8
0
ファイル: iacfile.cpp プロジェクト: rgleason/iacfleet_pi
bool IACSystem::DrawPositions(wxDC *dc, PlugIn_ViewPort *vp) {
    bool hasDrawn = false;
    if (dc) {
        for (size_t pointIndex = 0; pointIndex < m_positions.GetCount() - 1; pointIndex++) {
            GeoPoint &startP = m_positions[pointIndex];
            GeoPoint &endP = m_positions[pointIndex + 1];
            if (PointInLLBox(vp, startP.x, startP.y) || PointInLLBox(vp, endP.x, endP.y)) {
                wxPoint startpl;
                wxPoint endpl;
                GetCanvasPixLL(vp, &startpl, startP.y, startP.x);
                GetCanvasPixLL(vp, &endpl, endP.y, endP.x);
                dc->DrawLine(startpl, endpl);
                hasDrawn = true;
            }
        }
    } else {
        //      Enable anti-aliased lines, at best quality
        glEnable(GL_LINE_SMOOTH);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
        glLineWidth(m_isoLineWidth);

        glColor4ub(m_isoLineColor.Red(), m_isoLineColor.Green(), m_isoLineColor.Blue(), 255);
        glBegin(GL_LINES);
        wxPoint startpl;
        wxPoint endpl;
        for (size_t pointIndex = 0; pointIndex < m_positions.GetCount() - 1; pointIndex++) {
            GeoPoint &startP = m_positions[pointIndex];
            GeoPoint &endP = m_positions[pointIndex + 1];
            if (PointInLLBox(vp, startP.x, startP.y) || PointInLLBox(vp, endP.x, endP.y)) {
                GetCanvasPixLL(vp, &startpl, startP.y, startP.x);
                GetCanvasPixLL(vp, &endpl, endP.y, endP.x);
                glVertex2d(startpl.x, startpl.y);
                glVertex2d(endpl.x, endpl.y);
                hasDrawn = true;
            }
        }
        glEnd();
    }
    return hasDrawn;
}
void ConfigurationBatchDialog::Render(ocpnDC &dc, PlugIn_ViewPort &vp)
{
    if(!IsShown() ||
       m_notebookConfigurations->GetCurrentPage() != m_pRoutes)
        return;

    wxFont mfont( 12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL );
    dc.SetFont( mfont );

    dc.SetTextForeground(*wxRED);
//    dc.SetTextBackground(*wxTRANSPARENT);
//    dc.SetTextBackground(wxColour(0, 0, 0,  wxALPHA_TRANSPARENT));

    dc.SetPen(wxPen(*wxRED, 3));

    for(std::vector<BatchSource*>::iterator it = sources.begin();
        it != sources.end(); it++) {
        wxPoint p1, p2;
        double lat, lon;
        RouteMap::PositionLatLon((*it)->Name, lat, lon);
        GetCanvasPixLL(&vp, &p1, lat, lon);

        dc.DrawText((*it)->Name, p1.x, p1.y);
        dc.DrawCircle(p1.x, p1.y, 5);

        for(std::list<BatchSource*>::iterator it2 = (*it)->destinations.begin();
            it2 != (*it)->destinations.end(); it2++) {

            RouteMap::PositionLatLon((*it2)->Name, lat, lon);
            GetCanvasPixLL(&vp, &p2, lat, lon);

            dc.DrawLine(p1.x, p1.y, p2.x, p2.y);

            wxPoint p3((2*p1.x+3*p2.x)/5, (2*p1.y+3*p2.y)/5);
            wxPoint p4((p1.x+p2.x)/2, (p1.y+p2.y)/2);
            wxPoint p5((p2.y-p1.y)/8, (p1.x-p2.x)/8);
            dc.DrawLine(p3.x, p3.y, p4.x+p5.x, p4.y+p5.y);
            dc.DrawLine(p3.x, p3.y, p4.x-p5.x, p4.y-p5.y);
        }
    }
}
コード例 #10
0
ファイル: IsoLine.cpp プロジェクト: fzschornack/OpenCPN
void IsoLine::drawGLIsoLine(GRIBOverlayFactory *pof, PlugIn_ViewPort *vp, bool bShowLabels, bool bHiDef)
{
      int nsegs = trace.size();
      if(nsegs < 1)
            return;

     int width = 2;
     GetGlobalColor ( _T ( "UITX1" ), &isoLineColor );

     glColor4ub(isoLineColor.Red(), isoLineColor.Green(), isoLineColor.Blue(), 255/*isoLineColor.Alpha()*/);
     glLineWidth(width);

     std::list<Segment *>::iterator it;

    //---------------------------------------------------------
    // Dessine les segments
    //---------------------------------------------------------
    for (it=trace.begin(); it!=trace.end(); it++)
    {
        Segment *seg = *it;

        {
            wxPoint ab;
            GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
            wxPoint cd;
            GetCanvasPixLL(vp, &cd, seg->py2, seg->px2);


///            ClipResult res = cohen_sutherland_line_clip_i ( &ab.x, &ab.y, &cd.x, &cd.y,
///                         0, vp->pix_width, 0, vp->pix_height );
///            if ( res != Invisible )
             {
                  pof->DrawGLLine(ab.x, ab.y, cd.x, cd.y, width);
             }

        }
    }

}
コード例 #11
0
ファイル: IsoBarMap.cpp プロジェクト: CarCode/Cocoa-OCPN
/* draw text of the value of a conptour at a given location */
void IsoBarMap::DrawContour(wxDC *dc, PlugIn_ViewPort &VP, double contour, double lat, double lon)
{
    int index = (contour - m_MinContour) / m_Spacing;
    if(index < 0 || index >= m_contourcachesize)
        return;

    wxPoint r;

    GetCanvasPixLL(&VP, &r, lat, lon);

    double dist_squared1 = square(r.x-m_contourcache[index].lastx)
                           + square(r.y-m_contourcache[index].lasty);
    double dist_squared2 = square(r.x-lastx) + square(r.y-lasty);
    /* avoid printing numbers on top of each other */
    if(dist_squared1 < 100000 || dist_squared2 < 40000)
        return;

    m_contourcache[index].lastx = lastx = r.x;
    m_contourcache[index].lasty = lasty = r.y;

    int w = m_contourcache[index].image.GetWidth();
    int h = m_contourcache[index].image.GetHeight();

    if(dc) {
        wxBitmap bmp(m_contourcache[index].image);
        dc->DrawBitmap(bmp, r.x - w/2, r.y - h/2, true);
    } else {
        glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT);
        glColor4f( 1, 1, 1, 1 );

        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

        /* center */
        glRasterPos2i( r.x - w/2, r.y - h/2);
        glPixelZoom( 1, -1 ); /* draw data from top to bottom */
        glDrawPixels( w, h, GL_RGBA, GL_UNSIGNED_BYTE, m_contourcache[index].data);
        glPixelZoom( 1, 1 );

        glPopAttrib();
    }
}
コード例 #12
0
ファイル: osm_pi.cpp プロジェクト: ktec/osm_pi
bool osm_pi::RenderOverlay(wxDC &dc, PlugIn_ViewPort *vp)
{
    m_pdc = &dc;
    if(m_bShowOsm)
    {
        double x1 = m_pastVp.lon_min;
        double y1 = m_pastVp.lat_min;
        double x2 = m_pastVp.lon_max;
        double y2 = m_pastVp.lat_max;
        // TODO: Query local database for seamarks
        std::vector<Poi> seamarks;
        m_pOsmDb->SelectNodes(x1,y1,x2,y2,seamarks);

        for(std::vector<Poi>::iterator it = seamarks.begin(); it != seamarks.end(); ++it) {
            wxPoint pl;
            double lat = (*it).latitude;
            double lon = (*it).longitude;
            GetCanvasPixLL(vp, &pl, lon, lat);
            //wxLogMessage (_T("OSM_PI: Vector %i @ latlon[%f,%f] xy[%i,%i]"),(*it).id,lat,lon,pl.x,pl.y);
            DoDrawBitmap( *_img_osm, pl.x, pl.y, false );
            /*
            if(m_pdc && m_pdc->IsOk())
            {     
                m_pdc->SetPen(*wxBLACK_PEN);
                m_pdc->SetBrush(*wxTRANSPARENT_BRUSH);
            }

            if(m_pdc && m_pdc->IsOk())
            {
                m_pdc->DrawCircle(pl.x, pl.y,10);
                wxLogMessage (_T("OSM_PI: DrawCircle"));
            }*/
        }
        return true;
    }
    else
        return false;
    
//    if (!b_dbUsable || !m_bRenderOverlay)
//       return false;

}
コード例 #13
0
ファイル: IsoLine.cpp プロジェクト: OpenCPN/OpenCPN
//---------------------------------------------------------------
void IsoLine::drawIsoLine(GRIBOverlayFactory *pof, wxDC *dc, PlugIn_ViewPort *vp, bool bHiDef)
{
      int nsegs = trace.size();
      if(nsegs < 1)
            return;

      GetGlobalColor ( _T ( "UITX1" ), &isoLineColor );

#if wxUSE_GRAPHICS_CONTEXT
      wxGraphicsContext *pgc = NULL;
#endif

      if(dc) {
          wxPen ppISO ( isoLineColor, 2 );

#if wxUSE_GRAPHICS_CONTEXT
          wxMemoryDC *pmdc;
          pmdc= wxDynamicCast(dc, wxMemoryDC);
          pgc = wxGraphicsContext::Create(*pmdc);
          pgc->SetPen(ppISO);
#endif
          dc->SetPen(ppISO);
      } else { /* opengl */
#ifdef ocpnUSE_GL
          if(m_pixelMM > 0.2){        // pixel size large enough to render well
          //      Enable anti-aliased lines, at best quality
            glEnable( GL_LINE_SMOOTH );
            glEnable( GL_BLEND );
            glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
            glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
            glLineWidth( 2 );
          }
          else{
            glLineWidth( 0.4/m_pixelMM);        //  set a target line width by MM
          }
          
          glColor4ub(isoLineColor.Red(), isoLineColor.Green(), isoLineColor.Blue(),
                     255/*isoLineColor.Alpha()*/);
          glBegin( GL_LINES );
#endif          
      }

      std::list<Segment *>::iterator it;

    //---------------------------------------------------------
    // Dessine les segments
    //---------------------------------------------------------
    for (it=trace.begin(); it!=trace.end(); it++)
    {
        Segment *seg = *it;

        if(vp->m_projection_type == PI_PROJECTION_MERCATOR ||
           vp->m_projection_type == PI_PROJECTION_EQUIRECTANGULAR) {
            /* skip segments that go the wrong way around the world */
            double sx1 = seg->px1, sx2 = seg->px2;
            if(sx2 - sx1 > 180)
                sx2 -= 360;
            else if(sx1 - sx2 > 180)
                sx1 -= 360;

            if((sx1+180 < vp->clon && sx2+180 > vp->clon) ||
               (sx1+180 > vp->clon && sx2+180 < vp->clon) ||
               (sx1-180 < vp->clon && sx2-180 > vp->clon) ||
               (sx1-180 > vp->clon && sx2-180 < vp->clon))
                continue;
        }

        wxPoint ab;
        GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
        wxPoint cd;
        GetCanvasPixLL(vp, &cd, seg->py2, seg->px2);

        if(dc) {
#if wxUSE_GRAPHICS_CONTEXT
            if(bHiDef && pgc)
                pgc->StrokeLine(ab.x, ab.y, cd.x, cd.y);
            else
#endif
                dc->DrawLine(ab.x, ab.y, cd.x, cd.y);
        } else { /* opengl */
#ifdef ocpnUSE_GL
            glVertex2d(ab.x, ab.y);
            glVertex2d(cd.x, cd.y);
#endif                
        }
    }

#if 0
      int text_sx, text_sy;
      dc.GetTextExtent(_T("10000"), &text_sx, &text_sy);
//      double m = text_sy / 2;
      int label_size = text_sx;
      int label_space = 400;
//      double coef = .01;
      int len = label_space/4;

      //    Allocate an array big enough
      wxPoint *pPoints = new wxPoint[nsegs+1];

      MySegListList::Node *listnode;
      listnode = m_SegListList.GetFirst();
      while(listnode)
      {
            MySegList *listsort = listnode->GetData();

            //    Fill in the array
            MySegList::Node *node;
            Segment *seg;

            node = listsort->GetFirst();
            if(node)
            {
                  seg = node->GetData();
//                  wxPoint ab = vp->GetMercatorPixFromLL(seg->py1, seg->px1);
//                  wxPoint ab(0,0);
				  wxPoint ab;
				  GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
                  pPoints[0] = ab;
            }
            int ip=1;

            while (node)
            {
                  seg = node->GetData();
//                  wxPoint cd = vp->GetMercatorPixFromLL(seg->py2, seg->px2);
//                  wxPoint cd(0,0);
				  wxPoint cd;
				  GetCanvasPixLL(vp, &cd, seg->py2, seg->px2);
                  pPoints[ip++] = cd;

                  node=node->GetNext();
            }

            int np = listsort->GetCount() + 1;


            if(np > 1)
            {

      // Test code
      //          dc.DrawLines(np, pPoints);

                  GenerateSpline(np, pPoints);

      //    Test Code
      //            dc.DrawLines(&ocpn_wx_spline_point_list, 0, 0 );

                  bool bDrawing = true;
                  wxPoint lstart;

                  wxList::compatibility_iterator snode = ocpn_wx_spline_point_list.GetFirst();
                  wxPoint *point0 = (wxPoint *)snode->GetData();
                  snode=snode->GetNext();

                  while (snode)
                  {
                        wxPoint *point = (wxPoint *)snode->GetData();

                        ClipResult res = cohen_sutherland_line_clip_i ( &point0->x, &point0->y, &point->x, &point->y,
                                    0, vp->pix_width, 0, vp->pix_height );
                        if ( res != Invisible )
                        {
                              int dl = (int)sqrt(
                                            (double)((point0->x - point->x) * (point0->x - point->x))
                                          +(double)((point0->y - point->y) * (point0->y - point->y)));
                              if(bDrawing)
                              {
                                    len += dl;
                                    if(len > label_space)
                                    {
                                          bDrawing = false;
                                          len = 0;
                                          lstart = *point;
                                    }
                              }
                              else
                              {
                                    len += dl;
                                    if(len > label_size)
                                    {
                                          bDrawing = true;
                                          len = 0;
                                    }
                              }
                        }

                        *point0 = *point;
                        snode=snode->GetNext();
                  }

                  ClearSplineList();
            }

            listnode = listnode->GetNext();             // Next continuous chain

      }

      delete[] pPoints;

#endif

#if wxUSE_GRAPHICS_CONTEXT
      delete pgc;
#endif

      if(!dc) /* opengl */
          glEnd();
}
コード例 #14
0
ファイル: iacfile.cpp プロジェクト: rgleason/iacfleet_pi
bool IACSystem::Draw(wxDC *dc, PlugIn_ViewPort *vp, TexFont &numfont, TexFont &sysfont) {
    bool hasDrawn = false;
    if (dc) {
        if (m_positions.GetCount() == 1) {
            GeoPoint &Pos = m_positions[0];
            if (PointInLLBox(vp, Pos.x, Pos.y)) {
                wxPoint p;
                GetCanvasPixLL(vp, &p, Pos.y, Pos.x);
                wxColour colour;
                wxString msg1 = GetShortType(m_type);
                if (!msg1.IsEmpty()) {
                    hasDrawn = true;
                    GetGlobalColor(_T ( "UBLCK" ), &colour);
                    dc->SetTextForeground(colour);
                    wxFont sfont = dc->GetFont();

                    wxFont *font1 = wxTheFontList->FindOrCreateFont(SYSTEMS_FONT_SIZE, wxFONTFAMILY_ROMAN, wxNORMAL,
                                                                    wxFONTWEIGHT_BOLD, FALSE, wxString(_T ( "Arial" )));
                    dc->SetFont(*font1);
                    wxSize s1 = dc->GetTextExtent(msg1);
                    dc->DrawText(msg1, p.x - (s1.GetWidth() / 2), p.y - (s1.GetHeight() / 2));
                    wxFont *font2 = wxTheFontList->FindOrCreateFont(NUMBERS_FONT_SIZE, wxFONTFAMILY_SWISS, wxITALIC,
                                                                    wxFONTWEIGHT_NORMAL, FALSE, wxString(_T ( "Arial" )));
                    dc->SetFont(*font2);
                    wxString msg2 = GetValue();
                    if (!msg2.IsEmpty()) {
                        wxSize s2 = dc->GetTextExtent(msg2);
                        dc->DrawText(msg2, p.x - (s2.GetWidth() / 2), p.y + (s1.GetHeight() / 2) + (s2.GetHeight() / 2));

                        dc->SetFont(sfont);
                    }
                }
            }
        } else {
            wxColour colour;
            wxPen pen;
            pen = dc->GetPen();
            GetGlobalColor(_T ( "GREEN2" ), &colour);
            dc->SetPen(wxPen(colour, m_isoLineWidth));
            DrawPositions(dc, vp);
            dc->SetPen(pen);
        }
    } else {
        if (m_positions.GetCount() == 1) {
            GeoPoint &Pos = m_positions[0];
            if (PointInLLBox(vp, Pos.x, Pos.y)) {
                wxPoint p;
                GetCanvasPixLL(vp, &p, Pos.y, Pos.x);
                wxColour colour;
                wxString msg1 = GetShortType(m_type);
                if (!msg1.IsEmpty()) {
                    hasDrawn = true;
                    glEnable(GL_BLEND);
                    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

                    wxPoint p;
                    GetCanvasPixLL(vp, &p, Pos.y, Pos.x);
                    int w, h;
                    sysfont.GetTextExtent(msg1, &w, &h);

                    int xd = p.x - (w / 2);
                    int yd = p.y - (h / 2);

                    GetGlobalColor(_T ( "UBLCK" ), &colour);
                    glColor3ub(colour.Red(), colour.Green(), colour.Blue());

                    glEnable(GL_TEXTURE_2D);
                    sysfont.RenderString(msg1, xd, yd);
                    wxString msg2 = GetValue();
                    if (!msg2.IsEmpty()) {
                        int w1, h1;
                        numfont.GetTextExtent(msg2, &w1, &h1);
                        numfont.RenderString(msg2, p.x - (w1 / 2), p.y + (h / 2) + (h1 / 2));
                    }
                    glDisable(GL_TEXTURE_2D);
                    glDisable(GL_BLEND);
                }
            }
        } else {
            wxColour colour = m_isoLineColor;
            GetGlobalColor(_T ( "GREEN2" ), &m_isoLineColor);
            DrawPositions(dc, vp);
            m_isoLineColor = colour;
        }
    }
    return hasDrawn;
}
コード例 #15
0
void RouteMapOverlay::Render(wxDateTime time, SettingsDialog &settingsdialog,
                             wrDC &dc, PlugIn_ViewPort &vp, bool justendroute)
{
    if(!justendroute) {
        RouteMapConfiguration configuration = GetConfiguration();

        if(!isnan(configuration.StartLat)) {
            wxPoint r;
            GetCanvasPixLL(&vp, &r, configuration.StartLat, configuration.StartLon);
            SetColor(dc, *wxBLUE, true);
            SetWidth(dc, 3, true);
            dc.DrawLine(r.x, r.y-10, r.x+10, r.y+7);
            dc.DrawLine(r.x, r.y-10, r.x-10, r.y+7);
            dc.DrawLine(r.x-10, r.y+7, r.x+10, r.y+7);
        }

        if(!isnan(configuration.StartLon)) {
            wxPoint r;
            GetCanvasPixLL(&vp, &r, configuration.EndLat, configuration.EndLon);
            SetColor(dc, *wxRED, true);
            SetWidth(dc, 3, true);
            dc.DrawLine(r.x-10, r.y-10, r.x+10, r.y+10);
            dc.DrawLine(r.x-10, r.y+10, r.x+10, r.y-10);
        }

        static const double NORM_FACTOR = 16;
        bool use_dl = vp.m_projection_type == PI_PROJECTION_MERCATOR;
        if(!dc.GetDC() && use_dl) {
            glPushMatrix();

            /* center display list on start lat/lon */

            wxPoint point;
            GetCanvasPixLL(&vp, &point, configuration.StartLat, configuration.StartLon);

            glTranslated(point.x, point.y, 0);
            glScalef(vp.view_scale_ppm / NORM_FACTOR, vp.view_scale_ppm / NORM_FACTOR, 1);
            glRotated(vp.rotation*180/M_PI, 0, 0, 1);
        }

        if(!dc.GetDC() && !m_UpdateOverlay && use_dl && vp.m_projection_type == m_overlaylist_projection) {
            glCallList(m_overlaylist);
            glPopMatrix();

        } else {
            PlugIn_ViewPort nvp = vp;

            if(!dc.GetDC() && use_dl) {
                m_UpdateOverlay = false;

                if(!m_overlaylist)
                    m_overlaylist = glGenLists(1);
            
                glNewList(m_overlaylist, GL_COMPILE);

                nvp.clat = configuration.StartLat, nvp.clon = configuration.StartLon;
                nvp.pix_width = nvp.pix_height = 0;
                nvp.view_scale_ppm = NORM_FACTOR;
                nvp.rotation = nvp.skew = 0;

                m_overlaylist_projection = vp.m_projection_type;
            }

            /* draw alternate routes first */
            int AlternateRouteThickness = settingsdialog.m_sAlternateRouteThickness->GetValue();
            if(AlternateRouteThickness) {
                Lock();
                IsoChronList::iterator it;

                /* reset drawn flag for all positions
                   this is used to avoid duplicating alternate route segments */
                for(it = origin.begin(); it != origin.end(); ++it)
                    (*it)->ResetDrawnFlag();

                bool AlternatesForAll = settingsdialog.m_cbAlternatesForAll->GetValue();
                if(AlternatesForAll)
                    it = origin.begin();
                else {
                    it = origin.end();
                    it--;
                }

                SetWidth(dc, AlternateRouteThickness);
                if(!dc.GetDC())
                    glBegin(GL_LINES);
                for(; it != origin.end(); ++it)
                    for(IsoRouteList::iterator rit = (*it)->routes.begin();
                        rit != (*it)->routes.end(); ++rit) {
                        RenderAlternateRoute(*rit, !AlternatesForAll, dc, nvp);
                    }

                if(!dc.GetDC())
                    glEnd();
                Unlock();
            }

            unsigned char routecolors[][3] = {
                {  0,   0, 128}, {  0, 192,   0}, {  0, 128, 192}, {  0, 255,   0},
                {  0,   0, 255}, {  0, 128, 128}, {  0, 255,   0}, {  0, 192, 192},
                {  0, 128, 255}, {  0, 255, 128}, {  0,   0, 255}, {  0, 192,   0},
                {  0,   0, 128}, {  0, 255,   0}, {  0, 192, 128}, {  0, 128, 255}, 
                {  0, 192,   0}, {  0, 128,   0}, {  0,   0, 255}, {  0, 192, 192}};
#if 0
                {255, 127,   0}, {255, 127, 127},
                {  0, 255,   0}, {  0, 255, 127},
                {127, 255,   0}, {127, 255, 127},
                {127, 127,   0},                  {127, 127, 255},
                {255,   0,   0}, {255,   0, 127}, {255,   0, 255},
                {127,   0,   0}, {127,   0, 127}, {127,   0, 255},
                {  0, 127,   0}, {  0, 127, 127}, {  0, 127, 255},
                {255, 255,   0},                  };
コード例 #16
0
ファイル: IsoLine.cpp プロジェクト: fzschornack/OpenCPN
//---------------------------------------------------------------
void IsoLine::drawIsoLine(GRIBOverlayFactory *pof, wxDC &dc, PlugIn_ViewPort *vp, bool bShowLabels, bool bHiDef)
{
      int nsegs = trace.size();
      if(nsegs < 1)
            return;

      GetGlobalColor ( _T ( "UITX1" ), &isoLineColor );
      wxPen ppISO ( isoLineColor, 2 );

#if wxUSE_GRAPHICS_CONTEXT
      wxMemoryDC *pmdc;
//      pmdc = dynamic_cast<wxMemoryDC*>(&dc);
      pmdc= wxDynamicCast(&dc, wxMemoryDC);
      wxGraphicsContext *pgc = wxGraphicsContext::Create(*pmdc);
      pgc->SetPen(ppISO);
#endif

      dc.SetPen(ppISO);



      std::list<Segment *>::iterator it;

    //---------------------------------------------------------
    // Dessine les segments
    //---------------------------------------------------------
    for (it=trace.begin(); it!=trace.end(); it++)
    {
        Segment *seg = *it;

        {
 //             wxPoint ab = vp->GetMercatorPixFromLL(seg->py1, seg->px1);
 //             wxPoint cd = vp->GetMercatorPixFromLL(seg->py2, seg->px2);
            wxPoint ab;
            GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
            wxPoint cd;
            GetCanvasPixLL(vp, &cd, seg->py2, seg->px2);


///            ClipResult res = cohen_sutherland_line_clip_i ( &ab.x, &ab.y, &cd.x, &cd.y,
///                         0, vp->pix_width, 0, vp->pix_height );
///            if ( res != Invisible )
             {
#if wxUSE_GRAPHICS_CONTEXT
                  if(bHiDef && pgc)
                        pgc->StrokeLine(ab.x, ab.y, cd.x, cd.y);
                  else 
                        dc.DrawLine(ab.x, ab.y, cd.x, cd.y);
#else
                  dc.DrawLine(ab.x, ab.y, cd.x, cd.y);
#endif
             }

        }
    }
//#endif

      int text_sx, text_sy;
      dc.GetTextExtent(_T("10000"), &text_sx, &text_sy);
//      double m = text_sy / 2;
      int label_size = text_sx;
      int label_space = 400;
//      double coef = .01;
      int len = label_space/4;

      //    Allocate an array big enough
      wxPoint *pPoints = new wxPoint[nsegs+1];

      MySegListList::Node *listnode;
      listnode = m_SegListList.GetFirst();
      while(listnode)
      {
            MySegList *listsort = listnode->GetData();

            //    Fill in the array
            MySegList::Node *node;
            Segment *seg;

            node = listsort->GetFirst();
            if(node)
            {
                  seg = node->GetData();
//                  wxPoint ab = vp->GetMercatorPixFromLL(seg->py1, seg->px1);
//                  wxPoint ab(0,0);
				  wxPoint ab;
				  GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
                  pPoints[0] = ab;
            }
            int ip=1;

            while (node)
            {
                  seg = node->GetData();
//                  wxPoint cd = vp->GetMercatorPixFromLL(seg->py2, seg->px2);
//                  wxPoint cd(0,0);
				  wxPoint cd;
				  GetCanvasPixLL(vp, &cd, seg->py2, seg->px2);
                  pPoints[ip++] = cd;

                  node=node->GetNext();
            }

            int np = listsort->GetCount() + 1;


            if(np > 1)
            {

      // Test code
      //          dc.DrawLines(np, pPoints);

                  GenerateSpline(np, pPoints);

      //    Test Code
      //            dc.DrawLines(&ocpn_wx_spline_point_list, 0, 0 );

                  bool bDrawing = true;
                  wxPoint lstart;

                  wxList::compatibility_iterator snode = ocpn_wx_spline_point_list.GetFirst();
                  wxPoint *point0 = (wxPoint *)snode->GetData();
                  snode=snode->GetNext();

                  while (snode)
                  {
                        wxPoint *point = (wxPoint *)snode->GetData();

                        ClipResult res = cohen_sutherland_line_clip_i ( &point0->x, &point0->y, &point->x, &point->y,
                                    0, vp->pix_width, 0, vp->pix_height );
                        if ( res != Invisible )
                        {
                              int dl = (int)sqrt(
                                            (double)((point0->x - point->x) * (point0->x - point->x))
                                          +(double)((point0->y - point->y) * (point0->y - point->y)));
                              if(bDrawing)
                              {
                                    len += dl;
                                    if(len > label_space)
                                    {
                                          bDrawing = false;
                                          len = 0;
                                          lstart = *point;
                                    }
                              }
                              else
                              {
                                    len += dl;
                                    if(len > label_size)
                                    {
                                          bDrawing = true;
                                          len = 0;
#if 0
                                          if(bShowLabels)
                                          {
                                                double label_angle = atan2((double)(lstart.y - point->y),
                                                    (double)(point->x - lstart.x)) * 180. / PI;
                                                wxString label;
                                                label.Printf(_T("%d"), (int)(value*coef+0.5));

                                                double xs = lstart.x - (m * sin(label_angle * PI / 180.));
                                                double ys = lstart.y - (m * cos(label_angle * PI / 180.));
                                                dc.DrawRotatedText(label, (int)xs, (int)ys, label_angle);
                                          }
#endif
                                    }
                              }

#if 0
//                              if(bDrawing || !bShowLabels)
                              {
                                    if(bHiDef)
                                          dc.StrokeLine(point0->x, point0->y, point->x, point->y);
                                    else
                                          dc.DrawLine(point0->x, point0->y, point->x, point->y);
                              }
#endif
                        }

                        *point0 = *point;
                        snode=snode->GetNext();
                  }

                  ClearSplineList();
            }

            listnode = listnode->GetNext();             // Next continuous chain

      }

      delete[] pPoints;

#if wxUSE_GRAPHICS_CONTEXT
      delete pgc;
#endif

}
コード例 #17
0
ファイル: iacfile.cpp プロジェクト: rgleason/iacfleet_pi
bool IACTropicalSystem::Draw(wxDC *dc, PlugIn_ViewPort *vp, TexFont &numfont, TexFont &sysfont) {
    bool hasDrawn = false;
    if (dc) {
        wxColour colour;
        GetGlobalColor(_T ( "YELO1" ), &colour);
        wxPen pen(colour, FRONT_WIDTH);
        dc->SetPen(pen);
        dc->SetBrush(*wxTRANSPARENT_BRUSH);
    } else {
        GetGlobalColor(_T ( "YELO1" ), &m_isoLineColor);
        m_isoLineWidth = wxMax(FRONT_WIDTH, GL_MIN_LINE_WIDTH);
    }
    hasDrawn = DrawPositions(dc, vp);
    if (dc) {
        if (m_positions.Count() > 0) {
            GeoPoint &Pos = m_positions[0];
            if (PointInLLBox(vp, Pos.x, Pos.y)) {
                wxPoint p;
                GetCanvasPixLL(vp, &p, Pos.y, Pos.x);
                wxColour colour;
                wxString msg1 = GetShortType(m_type);
                if (!msg1.IsEmpty()) {
                    hasDrawn = true;
                    GetGlobalColor(_T ( "SNDG1" ), &colour);
                    dc->SetTextForeground(colour);
                    wxFont sfont = dc->GetFont();

                    wxFont *font1 = wxTheFontList->FindOrCreateFont(SYSTEMS_FONT_SIZE, wxFONTFAMILY_ROMAN, wxNORMAL,
                                                                    wxFONTWEIGHT_BOLD, FALSE, wxString(_T ( "Arial" )));
                    dc->SetFont(*font1);
                    wxSize s1 = dc->GetTextExtent(msg1);
                    dc->DrawText(msg1, p.x - (s1.GetWidth() / 2), p.y - (s1.GetHeight() / 2));
                    dc->SetFont(sfont);
                }
            }
        }
    } else {
        if (m_positions.GetCount() > 0) {
            GeoPoint &Pos = m_positions[0];
            if (PointInLLBox(vp, Pos.x, Pos.y)) {
                wxPoint p;
                GetCanvasPixLL(vp, &p, Pos.y, Pos.x);
                wxColour colour;
                wxString msg1 = GetShortType(m_type);
                if (!msg1.IsEmpty()) {
                    hasDrawn = true;
                    glEnable(GL_BLEND);
                    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

                    wxPoint p;
                    GetCanvasPixLL(vp, &p, Pos.y, Pos.x);
                    int w, h;
                    sysfont.GetTextExtent(msg1, &w, &h);

                    int xd = p.x - (w / 2);
                    int yd = p.y - (h / 2);

                    GetGlobalColor(_T ( "SNDG1" ), &colour);
                    glColor3ub(colour.Red(), colour.Green(), colour.Blue());

                    glEnable(GL_TEXTURE_2D);
                    sysfont.RenderString(msg1, xd, yd);
                    glDisable(GL_TEXTURE_2D);
                    glDisable(GL_BLEND);
                }
            }
        }
    }

    return hasDrawn;
}
コード例 #18
0
ファイル: TextPoint.cpp プロジェクト: Hakansv/ocpn_draw_pi
void TextPoint::DrawGL( PlugIn_ViewPort &pivp )
{
    if( !m_bIsVisible )
        return;
    
    if( m_iDisplayTextWhen == ID_TEXTPOINT_DISPLAY_TEXT_SHOW_ALWAYS || m_iDisplayTextWhen == ID_TEXTPOINT_DISPLAY_TEXT_SHOW_ON_ROLLOVER ) {
        if( m_TextPointText.Len() > 0 ) {
            CalculateTextExtents();
            int teX, teY;
            int scalefactor = round(g_ocpn_draw_pi->m_chart_scale / m_natural_scale);
            
            if(m_natural_scale > (g_ocpn_draw_pi->m_chart_scale / 2) ) {
                teX = m_TextExtents.x;
                teY = m_TextExtents.y;
            } else {
                teX = m_TextExtents.x / scalefactor;
                teY = m_TextExtents.y / scalefactor;
            }
            
            if(teX > 0 && teY > 0 && scalefactor <= 8 ) {
                switch ( m_iTextPosition )
                {
                    case ID_TEXT_TOP:
                        m_TextLocationOffsetX = g_iTextTopOffsetX;
                        m_TextLocationOffsetY = g_iTextTopOffsetY - teY;
                        break;
                    case ID_TEXT_CENTRE_TOP:
                        m_TextLocationOffsetX = g_iTextTopOffsetX - (teX / 2);
                        m_TextLocationOffsetY = g_iTextTopOffsetY - teY;
                        break;
                    case ID_TEXT_BOTTOM:
                        m_TextLocationOffsetX = g_iTextBottomOffsetX;
                        m_TextLocationOffsetY = g_iTextBottomOffsetY;
                        if(m_bShowName) m_TextLocationOffsetY += g_iTextBottomNameExtraOffsetY;
                        break;
                    case ID_TEXT_CENTRE_BOTTOM:
                        m_TextLocationOffsetX = g_iTextBottomOffsetX - (teX / 2);
                        m_TextLocationOffsetY = g_iTextBottomOffsetY;
                        break;
                    case ID_TEXT_CENTRE:
                        m_TextLocationOffsetX = g_iTextCentreOffsetX - (teX / 2);
                        m_TextLocationOffsetY = g_iTextCentreOffsetY - (teY / 2);
                        break;
                    case ID_TEXT_RIGHT:
                        m_TextLocationOffsetX = g_iTextRightOffsetX;
                        m_TextLocationOffsetY = g_iTextRightOffsetY;
                        break;
                    case ID_TEXT_LEFT:
                        m_TextLocationOffsetX = g_iTextLeftOffsetX - teX;
                        m_TextLocationOffsetY = g_iTextLeftOffsetY;
                        break;
                }
                int sx2 = m_pbmIcon->GetWidth() / 2;
                int sy2 = m_pbmIcon->GetHeight() / 2;
                
                //    Calculate the mark drawing extents
                wxPoint r;
                GetCanvasPixLL( g_pivp, &r,  m_lat, m_lon);    
                wxRect r1( r.x - sx2, r.y - sy2, sx2 * 2, sy2 * 2 );           // the bitmap extents
                if( m_DisplayTextFont.IsOk() ) {
                    // Added to help with display of text (stops end clipping)
                    teX += 20;
                    wxRect r2( r.x + m_TextLocationOffsetX, r.y + m_TextLocationOffsetY, teX,
                            teY );
                    r1.Union( r2 );
                    
                    r.x = r.x + m_TextLocationOffsetX;
                    r.y = r.y + m_TextLocationOffsetY;
                    if( scalefactor != m_scale_factor || m_bTextChanged || ( !m_iDisplayTextTexture && teX != 0 && teY != 0 ) ) {
                        m_scale_factor = scalefactor;
                        m_bTextChanged = false;
                        wxBitmap tbm(teX, teY); /* render text on dc */
                        wxMemoryDC dc;
                        dc.SelectObject( tbm );               
                        dc.SetBackground( wxBrush( *wxBLACK ) );
                        dc.Clear();
                        dc.SetFont( m_DisplayTextFont );
                        dc.SetTextForeground(* wxWHITE );
                        if(m_natural_scale > (g_ocpn_draw_pi->m_chart_scale / 2))
                            dc.DrawText( m_TextPointText, 10, 0);
                        //else
                        //    dc.DrawText( wxT(""), 10, 0 );
                        dc.SelectObject( wxNullBitmap );
                        
                        /* make alpha texture for text */
                        wxImage image = tbm.ConvertToImage();
                        unsigned char *d = image.GetData();
                        unsigned char *e = new unsigned char[teX * teY];
                        if(d && e){
                            for( int p = 0; p < teX*teY; p++)
                                e[p] = d[3*p + 0];
                        }
                        /* create texture for rendered text */
                        glGenTextures(1, &m_iDisplayTextTexture);
                        glBindTexture(GL_TEXTURE_2D, m_iDisplayTextTexture);
                        
                        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
                        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
                        
                        m_iDisplayTextTextureWidth = NextPow2(teX);
                        m_iDisplayTextTextureHeight = NextPow2(teY);
                        glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, m_iDisplayTextTextureWidth, m_iDisplayTextTextureHeight,
                                    0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL);
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, teX, teY,
                                        GL_ALPHA, GL_UNSIGNED_BYTE, e);
                        delete [] e;
                    }
                    
                    if(m_iDisplayTextTexture) {
                        // Draw backing box
                        ODDC ocpndc;
                        g_ocpn_draw_pi->AlphaBlending( ocpndc, r.x, r.y, r2.width, r2.height, 6.0, m_colourTextBackgroundColour, m_iBackgroundTransparency );
                                
                        /* draw texture with text */
                        glBindTexture(GL_TEXTURE_2D, m_iDisplayTextTexture);
                        
                        glEnable(GL_TEXTURE_2D);
                        glEnable(GL_BLEND);
                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                        
                        glColor3ub(m_colourTextColour.Red(), m_colourTextColour.Green(), m_colourTextColour.Blue());
                        
                        int x = r.x, y = r.y;
                        float u = (float)teX/m_iDisplayTextTextureWidth, v = (float)teY/m_iDisplayTextTextureHeight;
                        glBegin(GL_QUADS);
                        glTexCoord2f(0, 0); glVertex2f(x, y);
                        glTexCoord2f(u, 0); glVertex2f(x+teX, y);
                        glTexCoord2f(u, v); glVertex2f(x+teX, y+teY);
                        glTexCoord2f(0, v); glVertex2f(x, y+teY);
                        glEnd();
                        glDisable(GL_BLEND);
                        glDisable(GL_TEXTURE_2D);
                    }

                }
            }
        }
    }
    ODPoint::DrawGL( pivp );
}
コード例 #19
0
ファイル: TextPoint.cpp プロジェクト: Hakansv/ocpn_draw_pi
void TextPoint::Draw( ODDC& dc, wxPoint *rpn )
{
    if( !m_bIsVisible )
        return;
    
    if( m_iDisplayTextWhen == ID_TEXTPOINT_DISPLAY_TEXT_SHOW_ALWAYS || 
        ( m_iDisplayTextWhen == ID_TEXTPOINT_DISPLAY_TEXT_SHOW_ON_ROLLOVER && m_bShowDisplayTextOnRollover)  ) {
        if( m_TextPointText.Len() > 0 ) {
            CalculateTextExtents();
            int teX, teY;
            int scalefactor = round(g_ocpn_draw_pi->m_chart_scale / m_natural_scale);
            
            if(m_natural_scale > (g_ocpn_draw_pi->m_chart_scale / 2) ) {
                teX = m_TextExtents.x;
                teY = m_TextExtents.y;
            } else {
                teX = m_TextExtents.x / scalefactor;
                teY = m_TextExtents.y / scalefactor;
            }
            
            if(teX > 0 && teY > 0 && scalefactor <= 8) {
                switch ( m_iTextPosition )
                {
                    case ID_TEXT_TOP:
                        m_TextLocationOffsetX = g_iTextTopOffsetX;
                        m_TextLocationOffsetY = g_iTextTopOffsetY - teY;
                        break;
                    case ID_TEXT_CENTRE_TOP:
                        m_TextLocationOffsetX = g_iTextTopOffsetX - (teX / 2);
                        m_TextLocationOffsetY = g_iTextTopOffsetY - teY;
                        break;
                    case ID_TEXT_BOTTOM:
                        m_TextLocationOffsetX = g_iTextBottomOffsetX;
                        m_TextLocationOffsetY = g_iTextBottomOffsetY;
                        if(m_bShowName) m_TextLocationOffsetY += g_iTextBottomNameExtraOffsetY;
                        break;
                    case ID_TEXT_CENTRE_BOTTOM:
                        m_TextLocationOffsetX = g_iTextBottomOffsetX - (teX / 2);
                        m_TextLocationOffsetY = g_iTextBottomOffsetY;
                        break;
                    case ID_TEXT_CENTRE:
                        m_TextLocationOffsetX = g_iTextCentreOffsetX - (teX / 2);
                        m_TextLocationOffsetY = g_iTextCentreOffsetY - (teY / 2);
                        break;
                    case ID_TEXT_RIGHT:
                        m_TextLocationOffsetX = g_iTextRightOffsetX;
                        m_TextLocationOffsetY = g_iTextRightOffsetY;
                        break;
                    case ID_TEXT_LEFT:
                        m_TextLocationOffsetX = g_iTextLeftOffsetX - teX;
                        m_TextLocationOffsetY = g_iTextLeftOffsetY;
                        break;
                }
                int sx2 = m_pbmIcon->GetWidth() / 2;
                int sy2 = m_pbmIcon->GetHeight() / 2;
                
                //    Calculate the mark drawing extents
                wxPoint r;
                GetCanvasPixLL( g_pivp, &r,  m_lat, m_lon);    
                wxRect r1( r.x - sx2, r.y - sy2, sx2 * 2, sy2 * 2 );           // the bitmap extents
                if( m_DisplayTextFont.IsOk() ) {
                    // Added to help with display of text (stops end clipping)
                    teX += 20;
                    wxRect r2( r.x + m_TextLocationOffsetX, r.y + m_TextLocationOffsetY, teX,
                            teY );
                    r1.Union( r2 );
            
                    r.x = r.x + m_TextLocationOffsetX;
                    r.y = r.y + m_TextLocationOffsetY;
                
                    dc.SetFont( m_DisplayTextFont );
                    dc.SetTextForeground( m_colourTextColour );
                    g_ocpn_draw_pi->AlphaBlending( dc, r.x, r.y, r2.width, r2.height, 6.0, m_colourTextBackgroundColour, m_iBackgroundTransparency );
                    if(m_natural_scale > (g_ocpn_draw_pi->m_chart_scale / 2) )
                        dc.DrawText( m_TextPointText, r.x + 10, r.y );
                    else 
                        dc.DrawText( wxT(" "), r.x + 10, r.y );
                }
            }
        }
    }
    ODPoint::Draw( dc, rpn );
}
コード例 #20
0
ファイル: IsoLine.cpp プロジェクト: OpenCPN/OpenCPN
void IsoLine::drawIsoLineLabelsGL(GRIBOverlayFactory *pof,
                                  PlugIn_ViewPort *vp, int density, int first,
                                  wxString label, wxColour &color, TexFont &texfont)

{
    std::list<Segment *>::iterator it;
    int nb = first;

#ifdef ocpnUSE_GL
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );


    //---------------------------------------------------------
    // Ecrit les labels
    //---------------------------------------------------------
    wxRect prev;
    for (it=trace.begin(); it!=trace.end(); it++,nb++)
    {
        if (nb % density == 0)
        {
            Segment *seg = *it;

//            if(vp->vpBBox.PointInBox((seg->px1 + seg->px2)/2., (seg->py1 + seg->py2)/2., 0.))
            {
                wxPoint ab;
                GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
                wxPoint cd;
                GetCanvasPixLL(vp, &cd, seg->py1, seg->px1);

                int w, h;
                texfont.GetTextExtent(label, &w, &h);

                int label_offsetx = 6, label_offsety = 1;
                int xd = (ab.x + cd.x-(w+label_offsetx * 2))/2;
                int yd = (ab.y + cd.y - h)/2;
                int x = xd - label_offsetx, y = yd - label_offsety;
                w += 2*label_offsetx, h += 2*label_offsety;

                wxRect r(x,y, w,h);
                r.Inflate(w);
                if (!prev.Intersects(r)) 
                {
                      prev = r;
                      glColor4ub(color.Red(), color.Green(), color.Blue(), color.Alpha());

                      /* draw bounding rectangle */
                      glBegin(GL_QUADS);
                      glVertex2i(x,   y);
                      glVertex2i(x+w, y);
                      glVertex2i(x+w, y+h);
                      glVertex2i(x,   y+h);
                      glEnd();

                      glColor3ub(0, 0, 0);

                      glBegin(GL_LINE_LOOP);
                      glVertex2i(x,   y);
                      glVertex2i(x+w, y);
                      glVertex2i(x+w, y+h);
                      glVertex2i(x,   y+h);
                      glEnd();

                      glEnable(GL_TEXTURE_2D);
                      texfont.RenderString(label, xd, yd);
                      glDisable(GL_TEXTURE_2D);
                }
            }
        }
    }
    glDisable( GL_BLEND );
#endif
}
コード例 #21
0
ファイル: IsoLine.cpp プロジェクト: fzschornack/OpenCPN
void IsoLine::drawGLIsoLineLabels(GRIBOverlayFactory *pof, wxColour text_color, wxColour back_color,
                                PlugIn_ViewPort *vp, int density, int first, double coef)
{
    std::list<Segment *>::iterator it;
    int nb = first;
    wxString label;

    label.Printf(_T("%d"), (int)(value*coef+0.5));

    int w, h;

    wxPen penText(text_color);
    wxBrush backBrush(back_color);

    int label_offset = 10;

      if(!m_imageLabel.IsOk())
      {
            wxBitmap bm(100,100);          // big enough
            wxMemoryDC mdc(bm);
            mdc.Clear();

            mdc.GetTextExtent(label, &w, &h);

            mdc.SetPen(penText);
            mdc.SetBrush(backBrush);
            mdc.SetTextForeground(text_color);
            mdc.SetTextBackground(back_color);

            int xd = 0;
            int yd = 0;
//            mdc.DrawRoundedRectangle(xd, yd, w+(label_offset * 2), h, -.25);
            mdc.DrawRectangle(xd, yd, w+(label_offset * 2), h+2);
            mdc.DrawText(label, label_offset/2 + xd, yd-1);
            
            mdc.SelectObject(wxNullBitmap);

            wxBitmap sub_BMLabel = bm.GetSubBitmap(wxRect(0,0,w+(label_offset * 2), h+2));
            m_imageLabel = sub_BMLabel.ConvertToImage();
      }

    //---------------------------------------------------------
    // Ecrit les labels
    //---------------------------------------------------------
    for (it=trace.begin(); it!=trace.end(); it++,nb++)
    {
        if (nb % density == 0)
		{
            Segment *seg = *it;

//            if(vp->vpBBox.PointInBox((seg->px1 + seg->px2)/2., (seg->py1 + seg->py2)/2., 0.))
            {
                  int w = m_imageLabel.GetWidth();
                  int h = m_imageLabel.GetHeight();
                  wxPoint ab;
                  GetCanvasPixLL(vp, &ab, seg->py1, seg->px1);
                  wxPoint cd;
                  GetCanvasPixLL(vp, &cd, seg->py1, seg->px1);

                  int xd = (ab.x + cd.x-(w+label_offset * 2))/2;
                  int yd = (ab.y + cd.y - h)/2;

                  glRasterPos2i(xd, yd);
                  glPixelZoom(1, -1); /* draw data from top to bottom */
                  glDrawPixels(w, h, GL_RGB, GL_UNSIGNED_BYTE, m_imageLabel.GetData());
                  glPixelZoom(1, 1);
            }
        }
    }
}
コード例 #22
0
bool GribRequestSetting::DoRenderZoneOverlay()
{
    wxPoint p;
    GetCanvasPixLL( m_Vp, &p, m_Lat, m_Lon);

    int x = (m_StartPoint.x < p.x) ? m_StartPoint.x : p.x;
    int y = (m_StartPoint.y < p.y) ? m_StartPoint.y : p.y;

    int zw = fabs( (double ) p.x - m_StartPoint.x );
    int zh = fabs( (double ) p.y - m_StartPoint.y );

    wxPoint center;
    center.x = x + (zw / 2);
    center.y = y + (zh / 2);

    wxFont *font = OCPNGetFont(_("Dialog"), 10);
    wxColour pen_color, back_color;
    GetGlobalColor( _T ( "DASHR" ), &pen_color );
    GetGlobalColor( _T ( "YELO1" ), &back_color );

    int label_offsetx = 5, label_offsety = 1;

    double size;
    EstimateFileSize( &size );

    wxString label( _("Coord. ") );
    label.Append( toMailFormat(1, m_spMaxLat->GetValue()) + _T(" "));
    label.Append( toMailFormat(0, m_spMinLon->GetValue()) + _T(" "));
    label.Append( toMailFormat(1, m_spMinLat->GetValue()) + _T(" "));
    label.Append( toMailFormat(0, m_spMaxLon->GetValue()) + _T("\n"));
    label.Append( _T("Estim. Size ") ).Append((wxString::Format( _T("%1.2f " ) , size ) + _("MB") ) );

    if( m_pdc ) {
        wxPen pen(pen_color);
        pen.SetWidth(3);
        m_pdc->SetPen( pen );
        m_pdc->SetBrush( *wxTRANSPARENT_BRUSH);
        m_pdc->DrawRectangle(x, y, zw, zh);



        int w, h, sl;
#ifdef __WXMAC__
        wxScreenDC sdc;
        sdc.GetMultiLineTextExtent(label, &w, &h, &sl, font);
#else
        m_pdc->GetMultiLineTextExtent(label, &w, &h, &sl, font);
#endif
        w += 2*label_offsetx, h += 2*label_offsety;
        x = center.x - (w / 2);
        y = center.y - (h / 2);

        wxBitmap bm(w, h);
        wxMemoryDC mdc(bm);
        mdc.Clear();

        mdc.SetFont( *font );
        mdc.SetBrush(back_color);
        mdc.SetPen(*wxTRANSPARENT_PEN);
        mdc.SetTextForeground(wxColor( 0, 0, 0 ));
        mdc.DrawRectangle(0, 0, w, h);
        mdc.DrawLabel( label, wxRect( label_offsetx, label_offsety, w, h ) );

        wxImage im = bm.ConvertToImage();
        im.InitAlpha();
        w = im.GetWidth(), h = im.GetHeight();
        for( int j = 0; j < h; j++ )
			for( int i = 0; i < w; i++ )
				im.SetAlpha( i, j, 155 );

        m_pdc->DrawBitmap(im, x, y, true);

    } else {

#ifdef ocpnUSE_GL
    TexFont m_TexFontlabel;
    m_TexFontlabel.Build(*font);

    glColor3ub(pen_color.Red(), pen_color.Green(), pen_color.Blue() );

    glPushAttrib(GL_COLOR_BUFFER_BIT | GL_LINE_BIT | GL_ENABLE_BIT |
                     GL_POLYGON_BIT | GL_HINT_BIT );

   glEnable( GL_LINE_SMOOTH );
   glEnable( GL_BLEND );
   glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
   glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
   glLineWidth( 3.f );

   glBegin( GL_LINES );
   glVertex2d( x, y );
   glVertex2d( x+zw, y );
   glVertex2d( x+zw, y );
   glVertex2d( x+zw, y+zh );
   glVertex2d( x+zw, y+zh );
   glVertex2d( x, y+zh );
   glVertex2d( x, y+zh );
   glVertex2d( x, y );
   glEnd();

   int w, h;
   glColor4ub(back_color.Red(), back_color.Green(), back_color.Blue(), 155 );
   m_TexFontlabel.GetTextExtent(label, &w, &h );

    w += 2*label_offsetx, h += 2*label_offsety;
    x = center.x - (w / 2);
    y = center.y - (h / 2);

   /* draw text background */
   glBegin(GL_QUADS);
   glVertex2i(x,   y);
   glVertex2i(x+w, y);
   glVertex2i(x+w, y+h);
   glVertex2i(x,   y+h);
   glEnd();

   /* draw text */
   glColor3ub( 0, 0, 0 );

   glEnable(GL_TEXTURE_2D);
   m_TexFontlabel.RenderString(label, x + label_offsetx, y + label_offsety);
   glDisable(GL_TEXTURE_2D);

   glDisable( GL_BLEND );

#endif
    }
    return true;
}
コード例 #23
0
ファイル: ODPoint.cpp プロジェクト: nohal/ocpn_draw_pi
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
}
コード例 #24
0
ファイル: ODPoint.cpp プロジェクト: nohal/ocpn_draw_pi
void ODPoint::Draw( ODDC& dc, wxPoint *rpn )
{
    wxPoint r;
    wxRect hilitebox;

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

    //  return the home point in this dc to allow "connect the dots"
    if( NULL != rpn ) *rpn = r;

    if( !m_bIsVisible /*&& !m_bIsInTrack*/)     // pjotrc 2010.02.13, 2011.02.24
        return;

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

    wxPen *pen;
    if( m_bPointPropertiesBlink || m_bPathManagerBlink ) pen = g_pPathMan->GetActiveODPointPen();
    else pen = g_pPathMan->GetODPointPen();

//    Substitue icon?
    wxBitmap *pbm;
    if( ( m_bIsActive ) && ( m_IconName != _T("mob") ) ) pbm = g_pODPointMan->GetIconBitmap( _T ( "activepoint" ) );
    else
        pbm = m_pbmIcon;
    
    float l_ChartScaleFactorExp = GetOCPNChartScaleFactor_Plugin();
    if(m_fIconScaleFactor != l_ChartScaleFactorExp) {
        m_fIconScaleFactor = l_ChartScaleFactorExp;
        if(m_fIconScaleFactor != 0) {
            wxImage scaled_image = pbm->ConvertToImage();
            int new_width = pbm->GetWidth() * m_fIconScaleFactor;
            int new_height = pbm->GetHeight() * m_fIconScaleFactor;
            m_ScaledBMP = wxBitmap(scaled_image.Scale(new_width, new_height, wxIMAGE_QUALITY_HIGH));
        }
    }
    if( m_fIconScaleFactor != 0 && m_ScaledBMP.IsOk() )
        pbm = &m_ScaledBMP;
    
    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

    if( m_bShowName ) {
        if( 0 == m_pMarkFont ) {
            m_pMarkFont = GetOCPNScaledFont_PlugIn( wxS("Marks") );
            m_FontColor = GetFontColour_PlugIn( wxS( "Marks" ) );
            CalculateNameExtents();
        }

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

    hilitebox = r1;
    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;
    }

    wxColour hi_colour;
    hi_colour = pen->GetColour();
    unsigned char transparency = 100;
    if( m_bIsBeingEdited ){
        GetGlobalColor( wxS( "YELO1" ), &hi_colour );
        transparency = 150;
    }
    
        
    //  Highlite any selected point
    if( m_bPtIsSelected || m_bIsBeingEdited ) {
        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 ) ) {
        dc.DrawBitmap( *pbm, r.x - sx2, r.y - sy2, true );
        // on MSW, the dc Bounding box is not updated on DrawBitmap() method.
        // Do it explicitely here for all platforms.
        dc.CalcBoundingBox( r.x - sx2, r.y - sy2 );
        dc.CalcBoundingBox( r.x + sx2, r.y + sy2 );
    }

    if( m_bShowName ) {
        if( m_pMarkFont ) {
            dc.SetFont( *m_pMarkFont );
            dc.SetTextForeground( m_FontColor );

            dc.DrawText( m_ODPointName, r.x + (m_NameLocationOffsetX * m_fIconScaleFactor), r.y + (m_NameLocationOffsetY * m_fIconScaleFactor) );
        }
    }

    // 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;

        wxBrush saveBrush = dc.GetBrush();
        wxPen savePen = dc.GetPen();
        dc.SetPen( wxPen( m_wxcODPointRangeRingsSchemeColour, m_iRangeRingWidth, m_iRangeRingStyle ) );
        dc.SetBrush( wxBrush( m_wxcODPointRangeRingsSchemeColour, wxBRUSHSTYLE_TRANSPARENT ) );

        for( int i = 1; i <= m_iODPointRangeRingsNumber; i++ )
            dc.StrokeCircle( r.x, r.y, i * pix_radius );
        dc.SetPen( savePen );
        dc.SetBrush( saveBrush );
    }
    
    //  Save the current draw rectangle in the current DC
    //    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

}