Esempio n. 1
0
//
// Handle Indicator paint events
//
// Really only needed for the Mac since SetBackgroundColour()
// doesn't seem to work with shaped frames.
//
void ToolManager::OnIndicatorPaint( wxPaintEvent & event )
{
   wxWindow *w = (wxWindow *)event.GetEventObject();
   wxPaintDC dc( w );
   dc.SetBackground( *wxBLUE_BRUSH );
   dc.Clear();
}
void wxdlg3dViewer::OnPaintPanelTexture( wxPaintEvent& event )
{
////@begin wxEVT_PAINT event handler for ID_PanelTexture in wxdlg3dViewer.
    // Before editing this code, remove the block markers.
    wxPaintDC dc(wxDynamicCast(event.GetEventObject(), wxWindow));
////@end wxEVT_PAINT event handler for ID_PanelTexture in wxdlg3dViewer. 
}
Esempio n. 3
0
void WeatherFaxWizard::OnPaintPhasing( wxPaintEvent& event )
{
    wxWindow *window = dynamic_cast<wxWindow*>(event.GetEventObject());
    if(!window)
        return;

    wxPaintDC dc( window );

    if(!m_thDecoder)
        return;

    dc.SetBrush(wxBrush(*wxBLACK));
    dc.SetPen(wxPen( *wxBLACK, 1 ));

    int blocksize = m_decoder.m_blocksize;
    int w, h;
    int s = 4;
    window->GetSize(&w, &h);
    for(int x = 0; x<w; x++) {
        int i = x * blocksize / w;
        int y = h*((m_decoder.m_imageline ? m_decoder.datadouble[i] : 0) +(s/2))/s;
        dc.DrawLine(x, h/2, x, y);
    }

    int p;
    dc.SetPen(wxPen( *wxRED, 1 ));
    p = h*(1+(s/2))/s;
    dc.DrawLine(0, p, w, p);
    p = h*(-1+(s/2))/s;
    dc.DrawLine(0, p, w, p);
    
    dc.SetPen(wxPen( wxColour(32,192,32), 1 ));
    p = h*(m_decoder.m_minus_saturation_threshold+(s/2))/s;
    dc.DrawLine(0, p, w, p);
}
Esempio n. 4
0
//
// This draws the background of a toolbar
//
void ToolBar::OnPaint( wxPaintEvent & event )
{
   wxPaintDC dc( (wxWindow *) event.GetEventObject() );

   // Start with a clean background
   //
   // Under GTK, we specifically set the toolbar background to the background
   // colour in the system theme.
#if defined( __WXGTK__ )
   dc.SetBackground( wxBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND ) ) );
#endif

   dc.Clear();

// EXPERIMENTAL_THEMING is set to not apply the gradient
// on wxMAC builds.  on wxMAC we have the AQUA_THEME.
#ifdef USE_AQUA_THEME
   Repaint( &dc );
#else

#ifdef EXPERIMENTAL_THEMING
   wxImage * mpBackGradient =   &theTheme.Image( bmpRecoloredUpLarge  );

   if( mpBackGradient != NULL )
   {
      wxSize imSz( mpBackGradient->GetWidth(), mpBackGradient->GetHeight() );
      wxSize sz = GetSize();
      int y;
      for(y=0;y<sz.y;y++)
      {
         int yPix = ((float)y * imSz.y - 1.0f)/(sz.y-1);
         wxColour col(
            mpBackGradient->GetRed( 0, yPix),
            mpBackGradient->GetGreen( 0, yPix),
            mpBackGradient->GetBlue( 0, yPix));

         // Set background colour so that controls placed on this
         // toolbar such as radio buttons will draw reasonably.
         // It's a little tacky setting the background colour
         // here, but we can't do it in the constructor as the gradient
         // may not be available yet.
         // Better than this would be to set the colour when the image
         // is loaded.
         // We use the colour at the half way point as a suitable 'average'.
         if( y==(sz.y/2) )
         {
            SetBackgroundColour( col );
         }
         wxPen Pen( col );
         dc.SetPen(Pen );
         AColor::Line(dc, 0, y, sz.x, y );
      }
   }
#endif
#endif
}
void PlotDialog::OnPaintPlot(wxPaintEvent& event)
{
    wxWindow *window = dynamic_cast<wxWindow*>(event.GetEventObject());
    if(!window)
        return;

    double position = m_sPosition->GetValue() / 100.0;
    double scale = 100.0 / m_sScale->GetValue();

    wxPaintDC dc(window);
    dc.SetBackgroundMode(wxTRANSPARENT);

    int w, h;
    m_PlotWindow->GetSize( &w, &h);

    dc.SetBrush(*wxTRANSPARENT_BRUSH);

    wxChoice *cVariable[3] = {m_cVariable1, m_cVariable2, m_cVariable3};
    wxColour colors[3] = {wxColour(255, 0, 0), wxColour(0, 255, 0), wxColour(0, 0, 255)};
    for(int i=0; i<3; i++) {
        dc.SetPen(wxPen(colors[i], 3));

        int lx, ly;
        bool first = true;
        for(std::list<PlotData>::iterator it = m_PlotData.begin(); it != m_PlotData.end(); it++) {
            double time = ((*it).time - m_StartTime).GetSeconds().ToDouble();
            double value = GetValue(*it, cVariable[i]->GetSelection());

            int x = w * (scale * ((time - m_mintime) / (m_maxtime - m_mintime) - position) + position);
            int y = h * (1 - (value - m_minvalue) / (m_maxvalue - m_minvalue));
            if(first)
                first = false;
            else
                dc.DrawLine(lx, ly, x, y);
            lx = x, ly = y;
        }
    }

    dc.SetTextForeground(wxColour(0, 0, 0));
    const double steps = 10;
    for(double x=1/steps; x<1-1/steps; x+=1/steps) {
        wxString time = wxString::Format
            (_T("%.0f"), ((x - position)/scale + position) * (m_maxtime - m_mintime) + m_mintime);
        wxSize s = dc.GetTextExtent(time);
        dc.DrawText(time, x*w-s.x/2, 0);

        wxString value = wxString::Format(_T("%.1f"), (1-x)*(m_maxvalue - m_minvalue) + m_minvalue);
        s = dc.GetTextExtent(value);
        dc.DrawText(value, 0, x*h - s.y/2);
    }
}
Esempio n. 6
0
void ClimatologyConfigDialog::OnPaintKey( wxPaintEvent& event )
{
    wxWindow *window = dynamic_cast<wxWindow*>(event.GetEventObject());

    wxPaintDC dc( window );

    double knots;
    wxString name = window->GetName();

    window->GetName().ToDouble(&knots);

    wxColour c = ClimatologyOverlayFactory::GetGraphicColor(CYCLONE_SETTING, knots);

    dc.SetBackground(c);
    dc.Clear();
}
Esempio n. 7
0
//
// This draws the background of a toolbar
//
void ToolBarResizer::OnPaint( wxPaintEvent & event )
{
   wxPaintDC dc( (wxWindow *) event.GetEventObject() );

   // Start with a clean background
   //
   // Under GTK, we specifically set the toolbar background to the background
   // colour in the system theme.
#if defined( __WXGTK__ )
   dc.SetBackground( wxBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND ) ) );
#endif

   dc.Clear();

   wxSize sz = GetSize();

   AColor::Dark( &dc, false );
   AColor::Line(dc, sz.x - 4,  0, sz.x - 4, sz.y );
   AColor::Line(dc, sz.x - 1,  0, sz.x - 1, sz.y );
}
Esempio n. 8
0
void CMainWindow::OnPaint( wxPaintEvent& event )
{
    wxWindow* window = wxDynamicCast(event.GetEventObject(), wxWindow);
    wxPaintDC dc(window);
    wxRect rect = window->GetClientRect();
    if (m_pBackGroundImage->Ok() && m_pBackGroundImage->GetWidth() > 0 && m_pBackGroundImage->GetHeight() > 0)
    {
        int w = m_pBackGroundImage->GetWidth();
        int h = m_pBackGroundImage->GetHeight();

        wxMemoryDC dcMem;

        dcMem.SelectObjectAsSource(*m_pBackGroundImage);
        int i, j;
        for (i = rect.x; i < rect.x + rect.width; i += w)
        {
            for (j = rect.y; j < rect.y + rect.height; j+= h)
                dc.Blit(i, j, w, h, & dcMem, 0, 0);
        }
        dcMem.SelectObject(wxNullBitmap);
    }
}
Esempio n. 9
0
//
// This draws the background of a toolbar
//
void ToolBar::OnPaint( wxPaintEvent & event )
{
   wxPaintDC dc( (wxWindow *) event.GetEventObject() );

   // Start with a clean background
   //
   // Under GTK, clearing will cause the background to be white and
   // rather than setting a background color, just bypass the clear.
#if !defined(__WXGTK__)
   dc.Clear();
#endif

   // Go repaint the rest
   Repaint( &dc );

   if( IsResizable() && IsDocked() )
   {
      wxSize sz = GetSize();

      AColor::Dark( &dc, false );
      dc.DrawLine( sz.x - 4,  0, sz.x - 4, sz.y );
      dc.DrawLine( sz.x - 1,  0, sz.x - 1, sz.y );
   }
}
Esempio n. 10
0
	virtual void OnPaintPanelTexture( wxPaintEvent& event )
	{
		wxPaintDC dc(wxDynamicCast(event.GetEventObject(), wxWindow));
		dc.SetBackground(*wxBLACK_BRUSH); dc.Clear();

		int selection = GetSelectedListviewItem(listPolys);
		if(selection < 0) return;
		if(selection>=viewer3d_state->polylist.count) return;

		POLY& poly = viewer3d_state->polylist.list[selection];

		TexCacheItem* texkey = TexCache_SetTexture(TexFormat_32bpp,poly.texParam,poly.texPalette);
		const u32 w = texkey->sizeX;
		const u32 h = texkey->sizeY;
		u8* const bmpdata = new u8[w*h*4];
		for(u32 i=0;i<w*h;i++) {
				bmpdata[i*3] = texkey->decoded[i*4];
				bmpdata[i*3+1] = texkey->decoded[i*4+1];
				bmpdata[i*3+2] = texkey->decoded[i*4+2];
			}
		for(u32 i=0;i<w*h;i++)
			bmpdata[w*h*3+i] = texkey->decoded[i*4+3];

		
		wxImage image(w,h,false);
		image.InitAlpha();
		image.SetData(bmpdata,true);
		image.SetAlpha(bmpdata+w*h*3,true);
		wxBitmap bitmap(image);
		double xscale = (double)panelTexture->GetSize().x / w;
		double yscale = (double)panelTexture->GetSize().y / h;

		dc.SetUserScale(xscale,yscale);
		dc.DrawBitmap(bitmap,0,0);
		delete[] bmpdata;
	}
Esempio n. 11
0
void FreqWindow::PlotPaint(wxPaintEvent & evt)
{
   wxPaintDC dc( (wxWindow *) evt.GetEventObject() );

   dc.DrawBitmap( *mBitmap, 0, 0, true );
   if( mProcessed == NULL )
      return;

   int alg = mAlgChoice->GetSelection();

   dc.SetFont(mFreqFont);

   wxRect r = mPlotRect;

   int width = r.width - 2;

   float xMin, xMax, xPos, xRatio, xLast, xStep;

   if (alg == 0) {
      xMin = mRate / mWindowSize;
      xMax = mRate / 2;
      xRatio = xMax / xMin;
      xPos = xMin;
      xLast = xPos / 2.0;
      if (mLogAxis)
         xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
      else
         xStep = (xMax - xMin) / width;
   } else {
      xMin = 0;
      xMax = mProcessedSize / mRate;
      xPos = xMin;
      xLast = xPos / 2.0;
      xStep = (xMax - xMin) / width;
   }

   // Find the peak nearest the cursor and plot it

   float bestpeak = float(0.0);
   if ( r.Contains(mMouseX, mMouseY) & (mMouseX!=0) & (mMouseX!=r.width-1) ) {
      if (mLogAxis)
         xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
      else
         xPos = xMin + xStep * (mMouseX - (r.x + 1));

      bool up = (mProcessed[1] > mProcessed[0]);
      float bestdist = 1000000;
      float bestValue = 0.0;
      for (int bin = 2; bin < mProcessedSize; bin++) {
         bool nowUp = mProcessed[bin] > mProcessed[bin - 1];
         if (!nowUp && up) {
            // Local maximum.  Find actual value by cubic interpolation
            int leftbin = bin - 2;
            if (leftbin < 1)
               leftbin = 1;
            float valueAtMax = 0.0;
            float max = leftbin + CubicMaximize(mProcessed[leftbin],
                                                mProcessed[leftbin + 1],
                                                mProcessed[leftbin + 2],
                                                mProcessed[leftbin + 3], &valueAtMax);

            float thispeak;
            if (alg == 0)
               thispeak = max * mRate / mWindowSize;
            else
               thispeak = max / mRate;

            if (fabs(thispeak - xPos) < bestdist) {
               bestpeak = thispeak;
               bestdist = fabs(thispeak - xPos);
               bestValue = valueAtMax;
               if (thispeak > xPos)
                  break;
            }
         }
         up = nowUp;
      }

      int px;
      if (mLogAxis)
         px = int (log(bestpeak / xMin) / log(xStep));
      else
         px = int ((bestpeak - xMin) * width / (xMax - xMin));

      dc.SetPen(wxPen(wxColour(160,160,160), 1, wxSOLID));
      AColor::Line(dc, r.x + 1 + px, r.y, r.x + 1 + px, r.y + r.height);

       // print out info about the cursor location

      float value;

      if (mLogAxis) {
         xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
         value = GetProcessedValue(xPos, xPos * xStep);
      } else {
         xPos = xMin + xStep * (mMouseX - (r.x + 1));
         value = GetProcessedValue(xPos, xPos + xStep);
      }

      wxString info;
      wxString xpitch;
      wxString peakpitch;
      const wxChar *xp;
      const wxChar *pp;

      if (alg == 0) {
         xpitch = PitchName_Absolute(FreqToMIDInoteNumber(xPos));
         peakpitch = PitchName_Absolute(FreqToMIDInoteNumber(bestpeak));
         xp = xpitch.c_str();
         pp = peakpitch.c_str();

         info.Printf(_("Cursor: %d Hz (%s) = %d dB    Peak: %d Hz (%s) = %.1f dB"),
               int (xPos + 0.5), xp,
               int (value + 0.5), int (bestpeak + 0.5),
               pp, bestValue);
      } else if (xPos > 0.0 && bestpeak > 0.0) {
         xpitch = PitchName_Absolute(FreqToMIDInoteNumber(1.0 / xPos));
         peakpitch = PitchName_Absolute(FreqToMIDInoteNumber(1.0 / bestpeak));
         xp = xpitch.c_str();
         pp = peakpitch.c_str();
         info.Printf(_("Cursor: %.4f sec (%d Hz) (%s) = %f,    Peak: %.4f sec (%d Hz) (%s) = %.3f"),
                     xPos,
                     int (1.0 / xPos + 0.5),
                     xp, value, bestpeak, int (1.0 / bestpeak + 0.5), pp, bestValue);
      }
      mInfoText->SetLabel(info);
   }
   else
      mInfoText->SetLabel(wxT(""));


   // Outline the graph
   dc.SetPen(*wxBLACK_PEN);
   dc.SetBrush(*wxTRANSPARENT_BRUSH);
   dc.DrawRectangle(r);
}
Esempio n. 12
0
void FreqWindow::PlotPaint(wxPaintEvent & event)
{
   wxPaintDC dc( (wxWindow *) event.GetEventObject() );

   dc.DrawBitmap( *mBitmap, 0, 0, true );
   // Fix for Bug 1226 "Plot Spectrum freezes... if insufficient samples selected"
   if (!mData || mDataLen < mWindowSize)
      return;

   dc.SetFont(mFreqFont);

   wxRect r = mPlotRect;

   int width = r.width - 2;

   float xMin, xMax, xRatio, xStep;

   if (mAlg == SpectrumAnalyst::Spectrum) {
      xMin = mRate / mWindowSize;
      xMax = mRate / 2;
      xRatio = xMax / xMin;
      if (mLogAxis)
         xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
      else
         xStep = (xMax - xMin) / width;
   } else {
      xMin = 0;
      xMax = mAnalyst->GetProcessedSize() / mRate;
      xStep = (xMax - xMin) / width;
   }

   float xPos = xMin;

   // Find the peak nearest the cursor and plot it
   if ( r.Contains(mMouseX, mMouseY) & (mMouseX!=0) & (mMouseX!=r.width-1) ) {
      if (mLogAxis)
         xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
      else
         xPos = xMin + xStep * (mMouseX - (r.x + 1));

      float bestValue = 0;
      float bestpeak = mAnalyst->FindPeak(xPos, &bestValue);

      int px;
      if (mLogAxis)
         px = (int)(log(bestpeak / xMin) / log(xStep));
      else
         px = (int)((bestpeak - xMin) * width / (xMax - xMin));

      dc.SetPen(wxPen(wxColour(160,160,160), 1, wxSOLID));
      AColor::Line(dc, r.x + 1 + px, r.y, r.x + 1 + px, r.y + r.height);

       // print out info about the cursor location

      float value;

      if (mLogAxis) {
         xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
         value = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
      } else {
         xPos = xMin + xStep * (mMouseX - (r.x + 1));
         value = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
      }

      wxString cursor;
      wxString peak;
      wxString xpitch;
      wxString peakpitch;
      const wxChar *xp;
      const wxChar *pp;

      if (mAlg == SpectrumAnalyst::Spectrum) {
         xpitch = PitchName_Absolute(FreqToMIDInote(xPos));
         peakpitch = PitchName_Absolute(FreqToMIDInote(bestpeak));
         xp = xpitch;
         pp = peakpitch;
         /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#*/
         cursor.Printf(_("%d Hz (%s) = %d dB"), (int)(xPos + 0.5), xp, (int)(value + 0.5));
         peak.Printf(_("%d Hz (%s) = %.1f dB"), (int)(bestpeak + 0.5), pp, bestValue);
      } else if (xPos > 0.0 && bestpeak > 0.0) {
         xpitch = PitchName_Absolute(FreqToMIDInote(1.0 / xPos));
         peakpitch = PitchName_Absolute(FreqToMIDInote(1.0 / bestpeak));
         xp = xpitch;
         pp = peakpitch;
         /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#
          * the %.4f are numbers, and 'sec' should be an abbreviation for seconds */
         cursor.Printf(_("%.4f sec (%d Hz) (%s) = %f"),
                     xPos, (int)(1.0 / xPos + 0.5), xp, value);
         peak.Printf(_("%.4f sec (%d Hz) (%s) = %.3f"),
                     bestpeak, (int)(1.0 / bestpeak + 0.5), pp, bestValue);
      }
      mCursorText->SetValue(cursor);
      mPeakText->SetValue(peak);
   }
   else {
      mCursorText->SetValue(wxT(""));
      mPeakText->SetValue(wxT(""));
   }


   // Outline the graph
   dc.SetPen(*wxBLACK_PEN);
   dc.SetBrush(*wxTRANSPARENT_BRUSH);
   dc.DrawRectangle(r);
}
Esempio n. 13
0
void ggscfg_ColorEditSheet::on_paint_sprite(wxPaintEvent& event) {
  draw_image(&wxPaintDC((wxWindow*)event.GetEventObject()), false);
}
Esempio n. 14
0
//
// This draws the background of a toolbar
//
void ToolBar::OnPaint( wxPaintEvent & event )
{
   wxPaintDC dc( (wxWindow *) event.GetEventObject() );

   // Start with a clean background
   //
   // Under GTK, clearing will cause the background to be white and
   // rather than setting a background color, just bypass the clear.
#if !defined(__WXGTK__)
   dc.Clear();
#endif

// EXPERIMENTAL_THEMING is set to not apply the gradient
// on wxMAC builds.  on wxMAC we have the AQUA_THEME.
#ifdef USE_AQUA_THEME
   Repaint( &dc );
#else

#ifdef EXPERIMENTAL_THEMING
   wxImage * mpBackGradient =   &theTheme.Image( bmpRecoloredUpLarge  );

   if( mpBackGradient != NULL )
   {
      wxSize imSz( mpBackGradient->GetWidth(), mpBackGradient->GetHeight() );
      wxSize sz = GetSize();
      int y;
      for(y=0;y<sz.y;y++)
      {
         int yPix = ((float)y * imSz.y - 0.0001f)/(sz.y-1);
         wxColour col( 
            mpBackGradient->GetRed( 0, yPix),
            mpBackGradient->GetGreen( 0, yPix),
            mpBackGradient->GetBlue( 0, yPix));

         // Set background colour so that controls placed on this
         // toolbar such as radio buttons will draw reasonably.
         // It's a little tacky setting the background colour 
         // here, but we can't do it in the constructor as the gradient
         // may not be available yet.
         // Better than this would be to set the colour when the image 
         // is loaded.
         // We use the colour at the half way point as a suitable 'average'.
         if( y==(sz.y/2) )
         {
            SetBackgroundColour( col );
         }
         wxPen Pen( col );
         dc.SetPen(Pen );
         dc.DrawLine( 0, y, sz.x, y );
      }
   }
#endif
#endif

   if( IsResizable() && IsDocked() )
   {
      wxSize sz = GetSize();

      AColor::Dark( &dc, false );
      dc.DrawLine( sz.x - 4,  0, sz.x - 4, sz.y );
      dc.DrawLine( sz.x - 1,  0, sz.x - 1, sz.y );
   }
}
Esempio n. 15
0
	virtual void _OnPaintPanel( wxPaintEvent& event )
	{
		wxClientDC dc(wxDynamicCast(event.GetEventObject(), wxWindow));
		RedrawPanel(&dc);
	}
Esempio n. 16
0
void ggscfg_ColorEditSheet::on_paint_palette(wxPaintEvent& event) {
  draw_palette(&wxPaintDC((wxWindow*)event.GetEventObject()));
}
void MainWindow::OnPaint( wxPaintEvent& event )
{
	wxPaintDC dc(wxDynamicCast(event.GetEventObject(), wxWindow)); 

	int id = wxDynamicCast(event.GetEventObject(), wxWindow)->GetId();
	BlendingModeRef blendingmode = _blendingModes->GetBlendingModeByBitmapId(id);
	std::string s = blendingmode.GetRenderModeLabel();
	
	WXHDC wxHDC = wxPaintDC::FindDCInCache((wxWindow*) event.GetEventObject());
	HDC hDC = (HDC) wxHDC;

	bool isCacheAvailable = _cachedOutputBitmaps.find(id) != _cachedOutputBitmaps.end();
	if (isCacheAvailable) {
		// Cache available
		BITMAP *cachedBmp = _cachedOutputBitmaps.find(id)->second;
		draw_to_hdc(hDC, cachedBmp, 0, 0); 
		return;
	}

	BITMAP *imageBitmap = create_bitmap(250, 188);
	clear_to_color(imageBitmap, makecol(0, 0, 0));

	BITMAP *baseBitmap = load_bitmap("images/Base_250x188.bmp", NULL);
	BITMAP *blendBitmap = load_bitmap("images/Blend_250x188.bmp", NULL);

	blit(baseBitmap, baseBitmap, 0, 0, 0, 0, baseBitmap->w, baseBitmap->h);
	
	wxString type(blendingmode.GetRenderModeLabel().c_str(), wxConvUTF8);
	for (int w=0; w<baseBitmap->w; w++) {
		for (int h=0; h<baseBitmap->h; h++) {
			if (type.IsSameAs(_T("Lighten"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_lighten);
			} else if (type.IsSameAs(_T("Darken"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_darken);
			} else if (type.IsSameAs(_T("Multiply"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_multiply);
			} else if (type.IsSameAs(_T("Average"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_average);
			} else if (type.IsSameAs(_T("Add"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_add);
			} else if (type.IsSameAs(_T("Subtract"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_subtract);
			} else if (type.IsSameAs(_T("Difference"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_difference);
			} else if (type.IsSameAs(_T("Negation"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_negation);
			} else if (type.IsSameAs(_T("Screen"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_screen);
			} else if (type.IsSameAs(_T("Exclusion"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_exclusion);
			} else if (type.IsSameAs(_T("Overlay"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_overlay);
			} else if (type.IsSameAs(_T("SoftLight"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_softlight);
			} else if (type.IsSameAs(_T("HardLight"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_hardlight);
			} else if (type.IsSameAs(_T("ColorDodge"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_colordodge);
			} else if (type.IsSameAs(_T("ColorBurn"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_colorburn);
			} else if (type.IsSameAs(_T("LinearDodge"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_lineardodge);
			} else if (type.IsSameAs(_T("LinearBurn"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_linearburn);
			} else if (type.IsSameAs(_T("LinearLight"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_linearlight);
			} else if (type.IsSameAs(_T("VividLight"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_vividlight);
			} else if (type.IsSameAs(_T("PinLight"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_pinlight);
			} else if (type.IsSameAs(_T("HardMix"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_hardmix);
			} else if (type.IsSameAs(_T("Reflect"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_reflect);
			} else if (type.IsSameAs(_T("Glow"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_glow);
			} else if (type.IsSameAs(_T("Phoenix"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_phoenix);
			} else if (type.IsSameAs(_T("Hue"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_hue);
			} else if (type.IsSameAs(_T("Saturation"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_saturation);
			} else if (type.IsSameAs(_T("Color"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_color);
			} else if (type.IsSameAs(_T("Luminosity"))) {
				put_blended_pixel(baseBitmap, w, h, getpixel(blendBitmap, w, h), blender_luminosity);
			}
		}
	}

	draw_to_hdc(hDC, baseBitmap, 0, 0); 
	
	// Store in cache
	_cachedOutputBitmaps[id] = baseBitmap;

	destroy_bitmap(imageBitmap);
	destroy_bitmap(blendBitmap);
}
Esempio n. 18
0
void BoatDialog::OnPaintCrossOverChart(wxPaintEvent& event)
{
    wxWindow *window = dynamic_cast<wxWindow*>(event.GetEventObject());
    if(!window)
        return;

    wxGCDC dc(window);
    dc.SetBackgroundMode(wxTRANSPARENT);

    long index = SelectedPolar();
    bool polar = !m_cPlotType->GetSelection();

    int w, h;
    m_CrossOverChart->GetSize( &w, &h);

    dc.SetPen(wxPen(wxColor(0, 0, 0)));
    dc.SetBrush(*wxTRANSPARENT_BRUSH);
    dc.SetTextForeground(wxColour(0, 55, 75));

    bool full = m_cbFullPlot->GetValue();
    double scale;
    int xc = full ? w / 2 : 0;
    if(polar) {
        scale = wxMin(full ? w/2 : w, h/2) / 40.0;
    }
    
    for(double VW = 0; VW < 40; VW += 10) {
        if(polar) {
            dc.DrawCircle(xc, h/2, VW * scale);
            dc.DrawText(wxString::Format(_T("%.0f"), VW), xc, h/2+(int)VW*scale);
        } else {
            int y = h - VW * h / 40;
            dc.DrawLine(0, y, w, y);
            dc.DrawText(wxString::Format(_T("%.0f"), VW), 0, y);
        }
    }

    for(double H = 0; H < 180; H += 10) {
        if(polar) {
            double x = scale*sin(deg2rad(H));
            double y = scale*cos(deg2rad(H));
            if(H < 180)
                dc.DrawLine(xc - x, h/2 + y, xc + x, h/2 - y);

            wxString str = wxString::Format(_T("%.0f"), H);
            int sw, sh;
            dc.GetTextExtent(str, &sw, &sh);
            dc.DrawText(str, xc + .9*x - sw/2, h/2 - .9*y - sh/2);
        } else {
            int x = H * w / 180;
            dc.DrawLine(x, 0, x, h);
            dc.DrawText(wxString::Format(_T("%.0f"), H), x, 0);
        }
    }
    
    wxColour colors[] = {*wxRED, *wxGREEN, *wxBLUE, *wxCYAN, *wxYELLOW,
                         wxColour(255, 0, 255)};
    int c = 0;
    for(unsigned int i=0; i<m_Boat.Polars.size(); i++) {
        bool bold = i == index;

//        dc.SetPen(wxPen(colors[c], bold ? 1 : 3));
        dc.SetPen(*wxTRANSPARENT_PEN);
        dc.SetBrush(wxColour(colors[c].Red(),
                             colors[c].Green(),
                             colors[c].Blue(),
                             bold ? 230 : 60));
        if(++c == (sizeof colors) / (sizeof *colors))
            c = 0;

        bool tri = true;
        TESStesselator *tess = m_Boat.Polars[i].CrossOverRegion.Tesselate(tri);

        if(!tess)
            continue;
          
        const float* verts = tessGetVertices(tess);
//        const int* vinds = tessGetVertexIndices(tess);
        const int* elems = tessGetElements(tess);
//        const int nverts = tessGetVertexCount(tess);
        const int nelems = tessGetElementCount(tess);
	
        // Draw polygons.
        for (int i = 0; i < nelems; ++i)
        {
            if(tri) {
                const int* p = &elems[i*3];
                wxPoint points[3];
                for (unsigned j = 0; j < 3 && p[j] != TESS_UNDEF; ++j) {
                    double H = verts[p[j]*2+0];
                    double VW = verts[p[j]*2+1];
                    points[j] = wxPoint(H * w / 180, h - VW * h / 40);
                }
                if(polar) {
                    int count[3] = {CalcPolarPoints(points[0], points[1]),
                                    CalcPolarPoints(points[1], points[2]),
                                    CalcPolarPoints(points[2], points[0])};
                    wxPoint *pts = new wxPoint[count[0] + count[1] + count[2]];
                    int c = 0;
                    for(int j = 0; j<3; j++) {
                        int jp1 = j+1 == 3 ? 0 : j+1;
                        for(int k=0; k<count[j]; k++) {
                            double d = (double)k / count[j];
                            double px = points[j].x * (1-d) + points[jp1].x * d;
                            double py = points[j].y * (1-d) + points[jp1].y * d;
                            double H = px / w * 180;
                            double VW = (h - py) / h * 40;
                            pts[c++] = wxPoint(xc + scale*VW*sin(deg2rad(H)),
                                               h/2 - scale*VW*cos(deg2rad(H)));
                        }
                    }
                    dc.DrawPolygon(c, pts);
                    if(full) {
                        for(int j = 0; j<c; j++)
                            pts[j].x = 2*xc - pts[j].x;
                        dc.DrawPolygon(c, pts);
                    }
                    delete [] pts;
                } else {
                    dc.DrawPolygon(3, points);
                }
            } else {
                int b = elems[i*2];
                int n = elems[i*2+1];

                wxPoint pl;
                for(int j = 0; j<=n; j++) {
                    int k = j < n ? j : 0;
                    float H = verts[2*(b + k)+0], VW = verts[2*(b + k)+1];
                    wxPoint p0;
                    if(polar)
                        p0 = wxPoint(xc + scale*VW*sin(deg2rad(H)),
                                            h/2 - scale*VW*cos(deg2rad(H)));
                    else
                        p0 = wxPoint(H * w / 180, h - VW * h / 40);

                    if(j > 0)
                        dc.DrawLine(pl, p0);
                    pl = p0;
                }
            }
        }

        tessDeleteTess(tess);
    }
}
Esempio n. 19
0
void BoatDialog::OnPaintPlot(wxPaintEvent& event)
{
    wxWindow *window = dynamic_cast<wxWindow*>(event.GetEventObject());
    if(!window)
        return;

    wxPaintDC dc(window);
    dc.SetBackgroundMode(wxTRANSPARENT);

    long index = SelectedPolar();
    if(index < 0) {
        dc.SetTextForeground(*wxBLACK);
        wxString str = _("Select a polar to view plot");
        int sw, sh;
        dc.GetTextExtent(str, &sw, &sh);
        dc.DrawText(str, 0, 0);
        return;
    }
    
    int plottype = m_cPlotType->GetSelection();
    int w, h;
    m_PlotWindow->GetSize( &w, &h);
    double maxVB = 0;

    Polar &polar = m_Boat.Polars[index];

    /* plot scale */
    int selection = m_cPlotVariable->GetSelection();

    for(unsigned int VWi = 0; VWi<polar.wind_speeds.size(); VWi++) {
        double windspeed = polar.wind_speeds[VWi].VW;
        for(unsigned int Wi = 0; Wi<polar.degree_steps.size(); Wi++) {
            double W = polar.degree_steps[Wi];
            double VB;
            if(selection < 2)
                VB = polar.Speed(W, windspeed);
            else
                VB = polar.SpeedAtApparentWindSpeed(W, windspeed);
            
            if(VB > maxVB)
                maxVB = VB;
        }
    }

    dc.SetPen(wxPen(wxColor(0, 0, 0)));
    dc.SetBrush(*wxTRANSPARENT_BRUSH);
    dc.SetTextForeground(wxColour(0, 55, 75));

    if(maxVB <= 0) maxVB = 1; /* avoid lock */
    double Vstep = ceil(maxVB / 5);
    maxVB += Vstep;

    m_PlotScale = (w < h ? w : h)/1.8 / (maxVB+1);
//    m_PlotScale = h/1.8 / (maxVB+1);

    bool full = m_cbFullPlot->GetValue();
    int xc = full ? w / 2 : 0;

    if(plottype == 0) {
        /* polar circles */
        for(double V = Vstep; V <= maxVB; V+=Vstep) {
            dc.DrawCircle(xc, h/2, V*m_PlotScale);
            dc.DrawText(wxString::Format(_T("%.0f"), V), xc, h/2+(int)V*m_PlotScale);
        }
    } else {
        for(double V = Vstep; V <= maxVB; V+=Vstep) {
            int y = h - 2*V*m_PlotScale;
            dc.DrawLine(0, y, w, y);
            dc.DrawText(wxString::Format(_T("%.0f"), V), 0, y);
        }
    }

    dc.SetTextForeground(wxColour(0, 0, 155));

    if(plottype == 0) {
        /* polar meridians */
        for(double B = 0; B < DEGREES; B+=15) {
            double x = maxVB*m_PlotScale*sin(deg2rad(B));
            double y = maxVB*m_PlotScale*cos(deg2rad(B));
            if(B < 180)
                dc.DrawLine(xc - x, h/2 + y, xc + x, h/2 - y);

            wxString str = wxString::Format(_T("%.0f"), B);
            int sw, sh;
            dc.GetTextExtent(str, &sw, &sh);
            dc.DrawText(str, xc + .9*x - sw/2, h/2 - .9*y - sh/2);
        }
    } else {
        for(int s = 0; s<num_wind_speeds; s++) {
            double windspeed = wind_speeds[s];

            double x = s * w / num_wind_speeds;
            dc.DrawLine(x, 0, x, h);

            wxString str = wxString::Format(_T("%.0f"), windspeed);
            int sw, sh;
            dc.GetTextExtent(str, &sw, &sh);
            dc.DrawText(str, x, 0);
        }
    }

    int cx = (full ? w/2 : 0), cy = h/2;

    dc.SetPen(wxPen(wxColor(255, 0, 0), 2));

    /* boat speeds */
    if(plottype == 0) {
        for(unsigned int VWi = 0; VWi<polar.wind_speeds.size(); VWi++) {
            double VW, VA;
            switch(selection) {
            case 0: case 1: VW = polar.wind_speeds[VWi].VW; break;
                // use grid vw for va steps
            case 2: case 3: VA = polar.wind_speeds[VWi].VW; break;
            }

            bool lastvalid = false;
            int lx, ly;
//            for(unsigned int Wi = 0; Wi<polar.degree_steps.size()+full; Wi++) {
            //              double W = polar.degree_steps[Wi%polar.degree_steps.size()];
            double W0 = polar.degree_steps[0];
            double Wn = polar.degree_steps[polar.degree_steps.size()-1];
            double Wd = Wn - W0, Ws = Wd / floor(Wd);
            for(double W = W0; W <= Wn; W+= Ws) {
                double VB;
                switch(selection) {
                case 0: case 1:
                    VB = polar.Speed(W, VW);
                    break;
                case 2: case 3:
                    VB = polar.SpeedAtApparentWindSpeed(W, VA);
                    VW = Polar::VelocityTrueWind(VA, VB, W);
                    break;
                }
                
                double a;
                
                switch(selection) {
                case 0: case 2: a = W; break;
                case 1: case 3: a = Polar::DirectionApparentWind(VB, W, VW); break;
                }
                
                int px, py;
                px =  m_PlotScale*VB*sin(deg2rad(a)) + cx;
                py = -m_PlotScale*VB*cos(deg2rad(a)) + cy;
                
                if(lastvalid) {
                    dc.DrawLine(lx, ly, px, py);
                    if(full)
                        dc.DrawLine(2*cx-lx, ly, 2*cx-px, py);
                    
//            dc.DrawArc(lx, ly, px, py, cx, cy);
                }

                lx = px, ly = py;
                lastvalid = true;
            }
        }
    } else {
        for(unsigned int Wi = 0; Wi<polar.degree_steps.size(); Wi++) {
            double W = polar.degree_steps[Wi], VB;

            bool lastvalid = false;
            int lx, ly;
            for(unsigned int VWi = 0; VWi<polar.wind_speeds.size(); VWi++) {
                double windspeed = polar.wind_speeds[VWi].VW;
                double VW, VA;
                switch(selection) {
                case 0: case 1: VW = windspeed; break;
                    // use grid vw for va steps
                case 2: case 3: VA = windspeed; break;
                }
                
                switch(selection) {
                case 0: case 1:
                    VB = polar.Speed(W, VW);
                    break;
                case 2: case 3:
                    VB = polar.SpeedAtApparentWindSpeed(W, VA);
                    VW = Polar::VelocityTrueWind(VA, VB, W);
                    break;
                }

                #if 0
                double a;
                
                switch(selection) {
                case 0: case 2: a = W; break;
                case 1: case 3: a = Polar::DirectionApparentWind(VB, W, VW); break;
                }
                #endif
                
                int px, py;
                int s;
                for(s = 0; s<num_wind_speeds-1; s++) {
                    if(wind_speeds[s] > polar.wind_speeds[VWi].VW)
                        break;
                }
                { // interpolate into non-linear windspeed space
                    double x = windspeed, x1 = wind_speeds[s], x2 = wind_speeds[s+1];
                    double y1 = s * w / num_wind_speeds;
                    double y2 = (s+1) * w / num_wind_speeds;

                    px = x2 - x1 ? (y2 - y1)*(x - x1)/(x2 - x1) + y1 : y1;
                }
                py = h - 2*VB*m_PlotScale;
                
                if(lastvalid) {
                    dc.DrawLine(lx, ly, px, py);
                    if(full)
                        dc.DrawLine(2*cx-lx, ly, 2*cx-px, py);
                }

                lx = px, ly = py;
                lastvalid = true;
            }
        }
    }

    /* vmg */

    wxPoint lastp[4];
    bool lastpvalid[4] = {false, false, false, false};
    for(unsigned int VWi = 0; VWi<polar.wind_speeds.size(); VWi++) {
        double VW = polar.wind_speeds[VWi].VW;
        SailingVMG vmg = polar.GetVMGTrueWind(VW);

        for(int i=0; i<4; i++) {
            if(i%2 == 0 && !full)
                continue;

            if(i < 2)
                dc.SetPen(wxPen(wxColor(255, 0, 255), 2));
            else
                dc.SetPen(wxPen(wxColor(255, 255, 0), 2));

            double W = vmg.values[i];
            if(isnan(W))
                continue;

            double VB = polar.Speed(W, VW);

            double a;
            switch(selection) {
            case 0: case 2: a = W; break;
            case 1: case 3: a = Polar::DirectionApparentWind(VB, W, VW); break;
            }

            wxPoint p;
            if(plottype == 0) {
                p.x =  m_PlotScale*VB*sin(deg2rad(a)) + cx;
                p.y = -m_PlotScale*VB*cos(deg2rad(a)) + cy;
            } else {
                p.x = a * w / (full ? 360 : 180) + cx;
                p.y = h - 2*VB*m_PlotScale;
            }

            if(lastpvalid[i])
                dc.DrawLine(lastp[i], p);
            lastp[i] = p;
            lastpvalid[i] = true;
        }
    }
}