Ejemplo n.º 1
0
BOOL Chips::startAnimate(CDC* pDC, const CChips& chips, const CPoint& pos, DWORD dwFlags)
{
  if (!drawChips_) return FALSE;

  BOOL rc = createAnimationBuffers(chips);

  if (!rc)
    return FALSE;

  // Create buffer for animation
  if (!bmpSave_.GetSafeHandle())
  {
    CWindowDC dcScreen(NULL);
    bmpSave_.CreateCompatibleBitmap(&dcScreen, Width_, Height_);
  }

  // Save area at 'pos'
  CDC memDC;
  rc = memDC.CreateCompatibleDC(pDC);
  if (rc)
  {
    CSize s = getAnimationBufferSize();
    CBitmap* pOldBmp = memDC.SelectObject(&bmpSave_);
    memDC.BitBlt(0, 0, s.cx, s.cy,
                 pDC, pos.x, pos.y, SRCCOPY);
    memDC.SelectObject(pOldBmp);
  }

  return rc;
}
Ejemplo n.º 2
0
BOOL CSplashDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CClientDC dcScreen( this );
	
	m_bmSplash.LoadBitmap( IDB_PRODUCTS );
	
	m_bmBuffer.CreateCompatibleBitmap( &dcScreen, SPLASH_WIDTH, SPLASH_HEIGHT );
	m_dcBuffer1.CreateCompatibleDC( &dcScreen );
	m_dcBuffer2.CreateCompatibleDC( &dcScreen );
	
	SetWindowPos( NULL, 0, 0, SPLASH_WIDTH, SPLASH_HEIGHT, SWP_NOMOVE );
	CenterWindow();
	
	if ( m_hUser32 = LoadLibrary( _T("User32.dll") ) )
	{
		(FARPROC&)m_pfnAnimateWindow = GetProcAddress( m_hUser32, "AnimateWindow" );
		
		if ( m_pfnAnimateWindow != NULL )
		{
			(*m_pfnAnimateWindow)( GetSafeHwnd(), 250, AW_BLEND );
		}
	}
	
	SetWindowPos( &wndTop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW );
	UpdateWindow();
	
	return TRUE;
}
Ejemplo n.º 3
0
//////////////////
// Helper to get color table. Does all the mem DC voodoo.
//
UINT CDib::GetColorTable(RGBQUAD* colorTab, UINT nColors)
{
	CWindowDC dcScreen(NULL);
	CDC memdc;
	memdc.CreateCompatibleDC(&dcScreen);
	CBitmap* pOldBm = memdc.SelectObject(this);
	nColors = GetDIBColorTable(memdc, 0, nColors, colorTab);
	memdc.SelectObject(pOldBm);
	return nColors;
}
Ejemplo n.º 4
0
/////////////////////////////////////////////////////////////////////////////
//
// Helper to get color table.  Does all the mem DC voodoo.
//
/////////////////////////////////////////////////////////////////////////////
UINT
ZDib::GetColorTable( RGBQUAD *colorTab, UINT nColors )
{
   CWindowDC dcScreen( 0 );
   CDC memDC;

   memDC.CreateCompatibleDC( &dcScreen );
   CBitmap *pOldBmp = memDC.SelectObject( this );
   nColors = GetDIBColorTable( memDC, 0, nColors, colorTab );
   memDC.SelectObject( pOldBmp );
   return( nColors );
}
void CSaveModifiedItemsDialog::CreateDefaultStateImages(void)
{
	if(!m_stateImages.IsNull())
	{
		CWindowDC dcScreen(NULL);

		int cx = ::GetSystemMetrics(SM_CXSMICON);
		int cy = ::GetSystemMetrics(SM_CYSMICON);

		m_imageUnchecked     = this->AddCheckStateImage(dcScreen, cx, cy, eCheckState_Unchecked);
		m_imageChecked       = this->AddCheckStateImage(dcScreen, cx, cy, eCheckState_Checked);
		m_imageIndeterminate = this->AddCheckStateImage(dcScreen, cx, cy, eCheckState_Indeterminate);
	}
}
Ejemplo n.º 6
0
LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	CNCaptureApplication::Instance()->m_pMainFrame = this;

	// create command bar window
	HWND hWndCmdBar = m_CmdBar.Create(m_hWnd, rcDefault, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE);
	// attach menu
	m_CmdBar.AttachMenu(GetMenu());
	// load command bar images
	m_CmdBar.LoadImages(IDR_MAINFRAME);
	// remove old menu
	SetMenu(NULL);

	HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_MAINFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);

	CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
	AddSimpleReBarBand(hWndCmdBar);
	AddSimpleReBarBand(hWndToolBar, NULL, TRUE);

	CreateSimpleStatusBar();

	m_hWndClient = m_view.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
	m_view.Initialize();
	
#ifdef FTL_DEBUG
	HRESULT hr = E_FAIL;
	CWindowDC dcScreen(NULL);
	m_bitmap.CreateCompatibleBitmap(dcScreen, 100, 100);
	CCapImageObj* pImageObj = new CCapImageObj(TEXT("G:\\TestImage.PNG"), NULL);
	COM_VERIFY(pImageObj->Load(TEXT("G:\\TestImage.PNG")));
	if (SUCCEEDED(hr))
	{
		CNCaptureApplication::Instance()->GetDocument()->SetCurCaptureImage(pImageObj);
	}
#endif

	UIAddToolBar(hWndToolBar);
	UISetCheck(ID_VIEW_TOOLBAR, 1);
	UISetCheck(ID_VIEW_STATUS_BAR, 1);

	// register object for message filtering and idle updates
	CMessageLoop* pLoop = _Module.GetMessageLoop();
	ATLASSERT(pLoop != NULL);
	pLoop->AddMessageFilter(this);
	pLoop->AddIdleHandler(this);

	
	return 0;
}
Ejemplo n.º 7
0
CSize CBCGPMSMCaptionBar::CalcFixedLayout (BOOL, BOOL)
{
	ASSERT_VALID(this);

	// recalculate based on font height + icon height + borders
	TEXTMETRIC tm;
	{
		CClientDC dcScreen(NULL);
		HFONT hFont = GetCaptionFont ();

		HGDIOBJ hOldFont = dcScreen.SelectObject(hFont);
		VERIFY(dcScreen.GetTextMetrics(&tm));
		dcScreen.SelectObject(hOldFont);
	}

	int nHeight = max ( max (tm.tmHeight, m_szIcon.cy), GetCaptionHeight ());

	return CSize (32767, nHeight);// + CY_BORDER * 4 - rectSize.Height());
}
Ejemplo n.º 8
0
/////////////////////////////////////////////////////////////////////////////
//
// Create the palette.  Use halftone palette for hi-color bitmaps.
//
/////////////////////////////////////////////////////////////////////////////
zBOOL
ZDib::CreatePalette( CPalette& pal )
{
   // Should not already have palette
   ASSERT( pal.m_hObject == 0 );

   zBOOL bRC = FALSE;
   RGBQUAD *colors = new RGBQUAD[ MAXPALCOLORS ];
   UINT nColors = GetColorTable( colors, MAXPALCOLORS );
   if ( nColors > 0 )
   {
      // Allocate memory for logical palette.
      int nLth = sizeof( LOGPALETTE ) + sizeof( PALETTEENTRY ) * nColors;
      LOGPALETTE *pLogPal = (LOGPALETTE *) new char[ nLth ];
      if ( pLogPal == 0 )
         return( 0 );

      // Set version and number of palette entries.
      pLogPal->palVersion = PALVERSION;
      pLogPal->palNumEntries = nColors;

      // Copy color entries.
      for ( UINT k = 0; k < nColors; k++ )
      {
         pLogPal->palPalEntry[ k ].peRed   = colors[ k ].rgbRed;
         pLogPal->palPalEntry[ k ].peGreen = colors[ k ].rgbGreen;
         pLogPal->palPalEntry[ k ].peBlue  = colors[ k ].rgbBlue;
         pLogPal->palPalEntry[ k ].peFlags = 0;
      }

      // Create the palette and destroy LOGPAL.
      bRC = pal.CreatePalette( pLogPal );
      delete [] (zPCHAR) pLogPal;
   }
   else
   {
      CWindowDC dcScreen( 0 );
      bRC = pal.CreateHalftonePalette( &dcScreen );
   }

   delete [] colors;
   return( bRC );
}
Ejemplo n.º 9
0
//////////////////
// Create the palette. Use halftone palette for hi-color bitmaps.
//
BOOL CDib::CreatePalette(CPalette& pal)
{ 
	// should not already have palette
	ASSERT(pal.m_hObject==NULL);

	BOOL bRet = FALSE;
	RGBQUAD* colors = new RGBQUAD[MAXPALCOLORS];
	UINT nColors = GetColorTable(colors, MAXPALCOLORS);
	if (nColors > 0) {
		// Allocate memory for logical palette 
		int len = sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * nColors;
		LOGPALETTE* pLogPal = (LOGPALETTE*)new char[len];
		if (!pLogPal)
			return NULL;

		// set version and number of palette entries
		pLogPal->palVersion = PALVERSION;
		pLogPal->palNumEntries = nColors;

		// copy color entries 
		for (UINT i = 0; i < nColors; i++) {
			pLogPal->palPalEntry[i].peRed   = colors[i].rgbRed;
			pLogPal->palPalEntry[i].peGreen = colors[i].rgbGreen;
			pLogPal->palPalEntry[i].peBlue  = colors[i].rgbBlue;
			pLogPal->palPalEntry[i].peFlags = 0;
		}

		// create the palette and destroy LOGPAL
		bRet = pal.CreatePalette(pLogPal);
		delete [] (char*)pLogPal;
	} else {
		CWindowDC dcScreen(NULL);
		bRet = pal.CreateHalftonePalette(&dcScreen);
	}
	delete colors;
	return bRet;
}
Ejemplo n.º 10
0
LRESULT CProgressBar::OnSetFont(WPARAM wParam, LPARAM)
// Copied verbatim from barcore.cpp
{
	m_hFont = (HFONT)wParam;

	ASSERT(m_hFont != NULL);

	// recalculate based on font height + borders
	TEXTMETRIC tm;
	// get text metrics of font
	{
		CClientDC dcScreen(NULL);

		CFont *OurFont = CHECKFONT(CFont::FromHandle(m_hFont));
		CFont *OldFont = CHECKFONT(dcScreen.SelectObject(OurFont));

		VERIFY(dcScreen.GetTextMetrics(&tm));
		CHECKFONT(dcScreen.SelectObject(OldFont));
	}
	CRect rectSize;
	rectSize.SetRectEmpty();
	CalcInsideRect(rectSize);       // will be negative size

#if _MFC_VER < 0x300
	m_sizeFixedLayout.cy = (tm.tmHeight - tm.tmInternalLeading) + 
			CY_BORDER*3 /* 1 extra on top, 2 on bottom */ - rectSize.Height();
	ASSERT(m_sizeFixedLayout.cx == 32767);  // max size
#else
	BarHeight = (tm.tmHeight - tm.tmInternalLeading) + 
			CY_BORDER*3 /* 1 extra on top, 2 on bottom */ - rectSize.Height();
#endif

	m_FontDescent = tm.tmDescent;	// Cache descent size

	return 0L;      // does not re-draw or invalidate - resize parent instead
}
Ejemplo n.º 11
0
BOOL Chips::createAnimationBuffers(const CChips& chips)
{
  if (chips == chips_)
  {  // The same amount of chips was animated last time,
     // reuse animation buffers
     return TRUE;
  }
  else
  {  // Must recreate animation buffers if
     // image will be bigger than previous animation
     chips_ = chips;
     CSize s = getChipsSize(chips, 0, 0);

     // SANITY CHECK
     if (s.cx > 300)
       s.cx = 300;
     if (s.cy > 300)
       s.cy = 300;

     bool recreate = false;
     BITMAP bm;
     memset(&bm, 0, sizeof(bm));

     if (!chipsImage_.GetSafeHandle())
     {
       bm.bmWidth = s.cx;
       bm.bmHeight = s.cy;
       recreate = true;
     }
     else
     {
       chipsImage_.GetBitmap(&bm);
       if (bm.bmWidth != s.cx || bm.bmHeight != s.cy)
         recreate = true;
       else
         recreate = false;
     }

     CWindowDC dcScreen(NULL);
     if (recreate)
     {
       chipsImage_.DeleteObject();
       chipsMask_.DeleteObject();
       bmpSave_.DeleteObject();

       if (!chipsImage_.CreateCompatibleBitmap(&dcScreen, s.cx, s.cy) ||
           !chipsMask_.CreateCompatibleBitmap(&dcScreen, s.cx, s.cy) ||
           !bmpSave_.CreateCompatibleBitmap(&dcScreen, s.cx, s.cy))
       {
         return FALSE;
       }

       chipsImage_.GetBitmap(&bm);
     }

     CDC dcTmp;
     dcTmp.CreateCompatibleDC(&dcScreen);

     // Create the image
     CBitmap* pOldBmp = dcTmp.SelectObject(&chipsImage_);
     dcTmp.PatBlt(0, 0, bm.bmWidth, bm.bmHeight, BLACKNESS);
     drawChips(&dcTmp, chips, 0, bm.bmHeight - Height_, 0);

// Debugging:
//     dcScreen.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcTmp,
//                     0, 0, SRCCOPY);

     // Create the mask
     dcTmp.SelectObject(&chipsMask_);
     dcTmp.PatBlt(0, 0, bm.bmWidth, bm.bmHeight, WHITENESS);
     drawChips(&dcTmp, chips, 0, bm.bmHeight - Height_, DF_CreateMask);

// Debugging:
//     dcScreen.BitBlt(bm.bmWidth + 2, 0, bm.bmWidth, bm.bmHeight, &dcTmp,
//                     0, 0, SRCCOPY);

     // Clean up
     dcTmp.SelectObject(pOldBmp);
   }

  return TRUE;
}
Ejemplo n.º 12
0
BOOL Chips::loadChipGraphics(LPCTSTR pszFileBase, CString* pErrMsg)
{
  BOOL rc = TRUE;

  rc = oneChip_.Attach((HBITMAP)LoadImage(NULL,
                                          "chip-1.bmp",
                                          IMAGE_BITMAP,
                                          0, 0, LR_LOADFROMFILE));

  if (!rc)
  {
    AfxMessageBox("Unable to load 1 chip image "
                  "- chip graphics will not be available.");
    return FALSE;
  }

  rc = fiveChip_.Attach((HBITMAP)LoadImage(NULL,
                                          "chip-5.bmp",
                                          IMAGE_BITMAP,
                                          0, 0, LR_LOADFROMFILE));

  if (!rc)
  {
    AfxMessageBox("Unable to load 5 chip image "
                  "- chip graphics will not be available.");
    return FALSE;
  }

  rc = tenChip_.Attach((HBITMAP)LoadImage(NULL,
                                          "chip-10.bmp",
                                          IMAGE_BITMAP,
                                          0, 0, LR_LOADFROMFILE));

  if (!rc)
  {
    AfxMessageBox("Unable to load 10 chip image "
                  "- chip graphics will not be available.");
    return FALSE;
  }

  rc = twenty5Chip_.Attach((HBITMAP)LoadImage(NULL,
                                          "chip-25.bmp",
                                          IMAGE_BITMAP,
                                          0, 0, LR_LOADFROMFILE));

  if (!rc)
  {
    AfxMessageBox("Unable to load 25 chip image "
                  "- chip graphics will not be available.");
    return FALSE;
  }

  rc = fiftyChip_.Attach((HBITMAP)LoadImage(NULL,
                                          "chip-50.bmp",
                                          IMAGE_BITMAP,
                                          0, 0, LR_LOADFROMFILE));

  if (!rc)
  {
    AfxMessageBox("Unable to load 50 chip image "
                  "- chip graphics will not be available.");
    return FALSE;
  }

  rc = hundredChip_.Attach((HBITMAP)LoadImage(NULL,
                                          "chip-100.bmp",
                                          IMAGE_BITMAP,
                                          0, 0, LR_LOADFROMFILE));

  if (!rc)
  {
    AfxMessageBox("Unable to load 100 chip image "
                  "- chip graphics will not be available.");
    return FALSE;
  }

  rc = fiveHundredChip_.Attach((HBITMAP)LoadImage(NULL,
                                                  "chip-500.bmp",
                                                  IMAGE_BITMAP,
                                                  0, 0, LR_LOADFROMFILE));

  if (!rc)
  {
    AfxMessageBox("Unable to load 500 chip image "
                  "- chip graphics will not be available.");
    return FALSE;
  }

  rc = thousandChip_.Attach((HBITMAP)LoadImage(NULL,
                                               "chip-1000.bmp",
                                               IMAGE_BITMAP,
                                               0, 0, LR_LOADFROMFILE));

  if (!rc)
  {
    AfxMessageBox("Unable to load 1000 chip image "
                  "- chip graphics will not be available.");
    return FALSE;
  }

  rc = fiveThousandChip_.Attach((HBITMAP)LoadImage(NULL,
                                               "chip-5000.bmp",
                                               IMAGE_BITMAP,
                                               0, 0, LR_LOADFROMFILE));

  if (!rc)
  {
    AfxMessageBox("Unable to load 5000 chip image "
                  "- chip graphics will not be available.");
    return FALSE;
  }


  rc = chipMask_.Attach((HBITMAP)LoadImage(NULL,
                                          "chip-mask.bmp",
                                          IMAGE_BITMAP,
                                          0, 0, LR_LOADFROMFILE));

  chipMask2_.Attach((HBITMAP)LoadImage(NULL,
                                       "chip-mask2.bmp",
                                       IMAGE_BITMAP,
                                       0, 0, LR_LOADFROMFILE));


  if (rc)
  {
    BITMAP bm;
    if (chipMask_.GetBitmap(&bm))
    {
      Width_ = bm.bmWidth;
      Height_ = bm.bmHeight;
      if (Width_ > 0 && Height_ > 0)
      {
        CWindowDC dcScreen(NULL);
        rc = bmpBuf_.CreateCompatibleBitmap(&dcScreen, Width_, Height_);
      }
    }
  }

  drawChips_ = true;

  return rc;
}
////////////////
// Draw overlay
void VideoDisplayVisual::DrawOverlay() {
	// Variables
	int x = mouseX;
	int y = mouseY;
	int w = parent->w;
	int h = parent->h;
	int frame_n = parent->frame_n;
	int sw,sh;
	parent->GetScriptSize(sw,sh);

	// Create backbuffer if needed
	bool needCreate = false;
	if (!backbuffer) needCreate = true;
	else if (backbuffer->GetWidth() != w || backbuffer->GetHeight() != h) {
		needCreate = true;
		delete backbuffer;
	}
	if (needCreate) backbuffer = new wxBitmap(w,h);

	// Prepare drawing
	wxMemoryDC dc;
	dc.SelectObject(*backbuffer);

	// Draw frame
	dc.DrawBitmap(parent->GetFrame(frame_n),0,0);

	// Draw the control points for FexTracker
	DrawTrackingOverlay(dc);

	// Draw lines
	if (mode != 0) {
		int numRows = parent->grid->GetRows();
		AssDialogue *diag;
		AssDialogue *diagHigh = NULL;

		// Find where the highlight is
		if (mode == 1) {
			int dx,dy;
			for (int i=0;i<numRows;i++) {
				diag = parent->grid->GetDialogue(i);
				if (diag) {
					if (VFR_Output.GetFrameAtTime(diag->Start.GetMS(),true) <= frame_n && VFR_Output.GetFrameAtTime(diag->End.GetMS(),false) >= frame_n) {
						GetLinePosition(diag,dx,dy);
						dx = dx * w / sw;
						dy = dy * h / sh;
						if (x >= dx-8 && x <= dx+8 && y >= dy-8 && y <= dy+8) {
							diagHigh = diag;
						}
					}
				}
			}
		}

		// For each line
		for (int i=0;i<numRows;i++) {
			diag = parent->grid->GetDialogue(i);
			if (diag) {
				// Draw?
				bool draw = false;
				bool high = false;
				bool isCur = diag == curSelection;
				bool timeVisible = VFR_Output.GetFrameAtTime(diag->Start.GetMS(),true) <= frame_n && VFR_Output.GetFrameAtTime(diag->End.GetMS(),false) >= frame_n;
				bool show = timeVisible;
				if (mode != 1) {
					show = diag == parent->grid->GetDialogue(parent->grid->editBox->linen) && timeVisible;
				}

				// Variables
				int dx = -1;
				int dy = -1;
				int orgx = -1;
				int orgy = -1;
				float rx = 0.0f;
				float ry = 0.0f;
				float rz = 0.0f;
				float scalX = 100.0f;
				float scalY = 100.0f;
				int deltax = 0;
				int deltay = 0;

				// Line visible?
				if (show) {
					// Get position
					if (isCur && mode == 1) {
						dx = curX;
						dy = curY;
						high = true;
					}
					else GetLinePosition(diag,dx,dy,orgx,orgy);

					// Mouse over?
					if (diag == diagHigh) {
						high = true;
					}

					// Highlight
					int brushCol = 1;
					if (high) brushCol = 2;
					dc.SetBrush(wxBrush(colour[brushCol]));
					dc.SetPen(wxPen(colour[0],1));

					// Set drawing coordinates
					int radius = (int) sqrt(double((dx-orgx)*(dx-orgx)+(dy-orgy)*(dy-orgy)));
					dx = dx * w / sw;
					dy = dy * h / sh;
					orgx = orgx * w / sw;
					orgy = orgy * h / sh;

					// Drag
					if (mode == 1) {
						dc.DrawRectangle(dx-8,dy-8,17,17);
						dc.DrawLine(dx,dy-16,dx,dy+16);
						dc.DrawLine(dx-16,dy,dx+16,dy);
					}

					// Rotation
					if (mode == 2 || mode == 3) {
						// Pivot coordinates
						int odx = dx;
						int ody = dy;
						dx = orgx;
						dy = orgy;

						// Draw pivot
						dc.DrawCircle(dx,dy,7);
						dc.DrawLine(dx,dy-16,dx,dy+16);
						dc.DrawLine(dx-16,dy,dx+16,dy);
							
						// Get angle
						if (isCur) {
							if (mode == 2) rz = curAngle;
							else {
								rx = curAngle;
								ry = curAngle2;
							}
						}
						else GetLineRotation(diag,rx,ry,rz);

						// Rotate Z
						if (mode == 2) {
							// Calculate radii
							int oRadiusX = radius * w / sw;
							int oRadiusY = radius * h / sh;
							if (radius < 50) radius = 50;
							int radiusX = radius * w / sw;
							int radiusY = radius * h / sh;

							// Draw the circle
							dc.SetBrush(*wxTRANSPARENT_BRUSH);
							dc.DrawEllipse(dx-radiusX-2,dy-radiusY-2,2*radiusX+4,2*radiusY+4);
							dc.DrawEllipse(dx-radiusX+2,dy-radiusY+2,2*radiusX-4,2*radiusY-4);

							// Draw line to mouse
							dc.DrawLine(dx,dy,mouseX,mouseY);

							// Get deltas
							deltax = int(cos(rz*3.1415926536/180.0)*radiusX);
							deltay = int(-sin(rz*3.1415926536/180.0)*radiusY);

							// Draw the baseline
							dc.SetPen(wxPen(colour[3],2));
							dc.DrawLine(dx+deltax,dy+deltay,dx-deltax,dy-deltay);

							// Draw the connection line
							if (orgx != odx && orgy != ody) {
								double angle = atan2(double(dy*sh/h-ody*sh/h),double(odx*sw/w-dx*sw/w)) + rz*3.1415926536/180.0;
								int fx = dx+int(cos(angle)*oRadiusX);
								int fy = dy-int(sin(angle)*oRadiusY);
								dc.DrawLine(dx,dy,fx,fy);
								int mdx = cos(rz*3.1415926536/180.0)*20;
								int mdy = -sin(rz*3.1415926536/180.0)*20;
								dc.DrawLine(fx-mdx,fy-mdy,fx+mdx,fy+mdy);
							}

							// Draw the rotation line
							dc.SetPen(wxPen(colour[0],1));
							dc.SetBrush(wxBrush(colour[brushCol]));
							dc.DrawCircle(dx+deltax,dy+deltay,4);
						}

						// Rotate XY
						if (mode == 3) {
							// Calculate radii
							if (radius < 80) radius = 80;
							int radius1X = radius * w / sw / 3;
							int radius1Y = radius * h / sh;
							int radius2X = radius * w / sw;
							int radius2Y = radius * h / sh / 3;

							// Draw the ellipses
							dc.SetBrush(*wxTRANSPARENT_BRUSH);
							dc.DrawEllipse(dx-radius1X-2,dy-radius1Y-2,2*radius1X+4,2*radius1Y+4);
							dc.DrawEllipse(dx-radius1X+2,dy-radius1Y+2,2*radius1X-4,2*radius1Y-4);
							dc.DrawEllipse(dx-radius2X-2,dy-radius2Y-2,2*radius2X+4,2*radius2Y+4);
							dc.DrawEllipse(dx-radius2X+2,dy-radius2Y+2,2*radius2X-4,2*radius2Y-4);

							// Draw line to mouse
							dc.DrawLine(dx,dy,mouseX,mouseY);
							dc.SetBrush(wxBrush(colour[brushCol]));

							// Draw Y baseline
							deltax = int(cos(ry*3.1415926536/180.0)*radius2X);
							deltay = int(-sin(ry*3.1415926536/180.0)*radius2Y);
							dc.SetPen(wxPen(colour[3],2));
							dc.DrawLine(dx+deltax,dy+deltay,dx-deltax,dy-deltay);
							dc.SetPen(wxPen(colour[0],1));
							dc.DrawCircle(dx+deltax,dy+deltay,4);

							// Draw X baseline
							deltax = int(cos(rx*3.1415926536/180.0)*radius1X);
							deltay = int(-sin(rx*3.1415926536/180.0)*radius1Y);
							dc.SetPen(wxPen(colour[3],2));
							dc.DrawLine(dx+deltax,dy+deltay,dx-deltax,dy-deltay);
							dc.SetPen(wxPen(colour[0],1));
							dc.DrawCircle(dx+deltax,dy+deltay,4);
						}
					}

					// Scale
					if (mode == 4) {
						// Get scale
						if (isCur) {
							scalX = curScaleX;
							scalY = curScaleY;
						}
						else GetLineScale(diag,scalX,scalY);

						// Scale parameters
						int len = 160;
						int lenx = int(1.6 * scalX);
						int leny = int(1.6 * scalY);
						int drawX = dx + len/2 + 10;
						int drawY = dy + len/2 + 10;

						// Draw length markers
						dc.SetPen(wxPen(colour[3],2));
						dc.DrawLine(dx-lenx/2,drawY+10,dx+lenx/2,drawY+10);
						dc.DrawLine(drawX+10,dy-leny/2,drawX+10,dy+leny/2);
						dc.SetPen(wxPen(colour[0],1));
						dc.SetBrush(wxBrush(colour[brushCol]));
						dc.DrawCircle(dx+lenx/2,drawY+10,4);
						dc.DrawCircle(drawX+10,dy-leny/2,4);

						// Draw horizontal scale
						dc.SetPen(wxPen(colour[0],1));
						dc.DrawRectangle(dx-len/2,drawY,len+1,5);
						dc.SetPen(wxPen(colour[0],2));
						dc.DrawLine(dx-len/2+1,drawY+5,dx-len/2+1,drawY+15);
						dc.DrawLine(dx+len/2,drawY+5,dx+len/2,drawY+15);

						// Draw vertical scale
						dc.SetPen(wxPen(colour[0],1));
						dc.DrawRectangle(drawX,dy-len/2,5,len+1);
						dc.SetPen(wxPen(colour[0],2));
						dc.DrawLine(drawX+5,dy-len/2+1,drawX+15,dy-len/2+1);
						dc.DrawLine(drawX+5,dy+len/2,drawX+15,dy+len/2);
					}

					// Clip
					if (mode == 5) {
						int dx1,dx2,dy1,dy2;

						// Get position
						if (isCur) {
							dx1 = startX;
							dy1 = startY;
							dx2 = x;
							dy2 = y;
						}
						else {
							GetLineClip(diag,dx1,dy1,dx2,dy2);
							dx1 = dx1 * w / sw;
							dx2 = dx2 * w / sw;
							dy1 = dy1 * h / sh;
							dy2 = dy2 * h / sh;
						}

						// Draw rectangle
						dc.SetPen(wxPen(colour[3],1));
						dc.SetBrush(*wxTRANSPARENT_BRUSH);
						dc.DrawRectangle(dx1,dy1,dx2-dx1+1,dy2-dy1+1);

						// Draw circles
						dc.SetPen(wxPen(colour[0],1));
						dc.SetBrush(wxBrush(colour[brushCol]));
						dc.DrawCircle(dx1,dy1,4);
						dc.DrawCircle(dx1,dy2,4);
						dc.DrawCircle(dx2,dy1,4);
						dc.DrawCircle(dx2,dy2,4);
					}
				}
			}
		}
	}

	// Current position info
	if (mode == 0 && x >= 0 && x < w && y >= 0 && y < h) {
		// Draw cross
		dc.SetPen(wxPen(colour[2],1));
		dc.SetLogicalFunction(wxINVERT);
		dc.DrawLine(0,y,w-1,y);
		dc.DrawLine(x,0,x,h-1);

		// Setup text
		wxFont font(10,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Verdana"));
		dc.SetFont(font);
		int tw,th;
		parent->GetTextExtent(mouseText,&tw,&th,NULL,NULL,&font);

		// Inversion
		bool left = x > w/2;
		bool bottom = y < h/2;

		// Text draw coords
		int dx = x,dy = y;
		if (left) dx -= tw + 4;
		else dx += 4;
		if (bottom) dy += 3;
		else dy -= th + 3;

		// Draw text
		dc.SetTextForeground(wxColour(64,64,64));
		dc.DrawText(mouseText,dx+1,dy-1);
		dc.DrawText(mouseText,dx+1,dy+1);
		dc.DrawText(mouseText,dx-1,dy-1);
		dc.DrawText(mouseText,dx-1,dy+1);
		dc.SetTextForeground(colour[2]);
		dc.DrawText(mouseText,dx,dy);
	}

	// Blit to screen
	wxClientDC dcScreen(parent);
	//dcScreen.DrawBitmap(backbuffer,0,0);
	dcScreen.Blit(0,0,w,h,&dc,0,0);
}
Ejemplo n.º 14
0
void ViewFilesDialog::DisplayText(const WCHAR* fileName)
{
    CWaitCursor wait;   // streaming of big files can take a little while
    bool errFlg;
    bool emptyFlg = false;
    bool editHadFocus = false;
    
    ASSERT(fpOutput != NULL);
    ASSERT(fileName != NULL);

    errFlg = fpOutput->GetOutputKind() == ReformatOutput::kOutputErrorMsg;

    ASSERT(fpOutput->GetOutputKind() != ReformatOutput::kOutputUnknown);

    CRichEditCtrl* pEdit = (CRichEditCtrl*) GetDlgItem(IDC_FVIEW_EDITBOX);
    ASSERT(pEdit != NULL);

    /* retain the selection even if we lose focus [can't do this in OnInit] */
    pEdit->SetOptions(ECOOP_OR, ECO_SAVESEL);

#if 0
    /*
     * Start by trashing anything that's there.  Not strictly necessary,
     * but it prevents the control from trying to maintain the old stuff
     * in an undo buffer.  (Not entirely sure if a stream-in operation is
     * undoable, but it costs very little to be certain.)
     *
     * UPDATE: I turned this off because it was dinging the speaker (?!).
     * Might be doing that because it's in read-only mode.
     */
    pEdit->SetSel(0, -1);
    pEdit->Clear();
    pEdit->EmptyUndoBuffer();
#endif

    /*
     * There's a redraw flash that goes away if you change the input
     * focus to something other than the edit ctrl.  (Move between large
     * files; it looks like you can see the text being selected and
     * hightlighted.  The control doesn't have an "always highlight" flag
     * set, so if the focus is on a different control it doesn't light up.)
     *
     * Since we're currently forcing the focus to be on the edit ctrl later
     * on, we just jam it to something else here.  If nothing has the focus,
     * as can happen if we click on "resource fork" and then Alt-N to a
     * file without a resource fork, we force the focus to return to the
     * edit window.
     *
     * NOTE: this would look a little better if we used the Prev/Next
     * buttons to hold the temporary focus, but we need to know which key
     * the user hit.  We could also create a bogus control, move it into
     * negative space where it will be invisible, and use that as a "focus
     * holder".
     */
    CWnd* pFocusWnd = GetFocus();
    if (pFocusWnd == NULL || pFocusWnd->m_hWnd == pEdit->m_hWnd) {
        editHadFocus = true;
        GetDlgItem(IDOK)->SetFocus();
    }

    /*
     * The text color isn't getting reset when we reload the control.  I
     * can't find a "set default text color" call, so I'm reformatting
     * part of the buffer.
     *
     * Here's the weird part: it doesn't seem to matter what color I
     * set it to under Win2K.  It reverts to black so long as I do anything
     * here.  Under Win98, it uses the new color.
     */
    //if (0)
    {
        CHARFORMAT cf;
        cf.cbSize = sizeof(CHARFORMAT);
        cf.dwMask = CFM_COLOR;
        cf.crTextColor = RGB(0, 0, 0);
        pEdit->SetSel(0, 1);    // must select at least one char
        pEdit->SetSelectionCharFormat(cf);
    }

    /*
     * Add the appropriate data.  If the "bitmap" flag is set, use the
     * MyDIBitmap pointer instead.
     */
    if (fpOutput->GetOutputKind() == ReformatOutput::kOutputBitmap) {
        CClientDC dcScreen(this);
        HBITMAP hBitmap;

        if (fpRichEditOle == NULL) {
            /* can't do this in OnInitDialog -- m_pWnd isn't initialized */
            fpRichEditOle = pEdit->GetIRichEditOle();
            ASSERT(fpRichEditOle != NULL);
        }

        //FILE* fp = fopen("C:/test/output.bmp", "wb");
        //if (fp != NULL) {
        //  pDib->WriteToFile(fp);
        //  fclose(fp);
        //}
        
        hBitmap = fpOutput->GetDIB()->ConvertToDDB(dcScreen.m_hDC);
        if (hBitmap == NULL) {
            LOGI("ConvertToDDB failed!");
            pEdit->SetWindowText(L"Internal error.");
            errFlg = true;
        } else {
            //DumpBitmapInfo(hBitmap);
            //DumpBitmapInfo(pDib->GetHandle());

            LOGI("Inserting bitmap");
            pEdit->SetWindowText(L"");
            CImageDataObject::InsertBitmap(fpRichEditOle, hBitmap);

            /* RichEditCtrl has it now */
            ::DeleteObject(hBitmap);
        }
    } else {
        /*
         * Stream the data in, using the appropriate format.  Since we don't
         * have the "replace selection" flag set, this replaces everything
         * that's currently in there.
         *
         * We can't use SetWindowText() unless we're willing to forgo viewing
         * of binary files in "raw" form.  There doesn't seem to be any other
         * difference between the two approaches.
         */
        const char* textBuf;
        long textLen;
        int streamFormat;

        textBuf = fpOutput->GetTextBuf();
        textLen = fpOutput->GetTextLen();
        streamFormat = SF_TEXT;
        if (fpOutput->GetOutputKind() == ReformatOutput::kOutputRTF)
            streamFormat = SF_RTF;
        if (fpOutput->GetTextLen() == 0) {
            textBuf = "(file is empty)";
            textLen = strlen(textBuf);
            emptyFlg = true;
            EnableFormatSelection(FALSE);
        }
        if (fpOutput->GetOutputKind() == ReformatOutput::kOutputErrorMsg)
            EnableFormatSelection(FALSE);

        /* make sure the control will hold everything we throw at it */
        pEdit->LimitText(textLen+1);
        LOGI("Streaming %ld bytes (kind=%d)",
            textLen, fpOutput->GetOutputKind());

        /* clear this early to avoid loading onto yellow */
        if (errFlg)
            pEdit->SetBackgroundColor(FALSE, RGB(255, 255, 0));
        else if (emptyFlg)
            pEdit->SetBackgroundColor(FALSE, RGB(192, 192, 192));
        else
            pEdit->SetBackgroundColor(TRUE, 0);

        RichEditXfer xfer(textBuf, textLen);
        EDITSTREAM es;
        es.dwCookie = (DWORD) &xfer;
        es.dwError = 0;
        es.pfnCallback = RichEditXfer::EditStreamCallback;
        long count;
        count = pEdit->StreamIn(streamFormat, es);
        LOGI("StreamIn returned count=%ld dwError=%d", count, es.dwError);

        if (es.dwError != 0) {
            /* a -16 error can happen if the type is RTF but contents are not */
            char errorText[256];

            sprintf(errorText,
                "ERROR: failed while loading data (err=0x%08lx)\n"
                "(File contents might be too big for Windows to display)\n",
                es.dwError);
            RichEditXfer errXfer(errorText, strlen(errorText));
            es.dwCookie = (DWORD) &errXfer;
            es.dwError = 0;

            count = pEdit->StreamIn(SF_TEXT, es);
            LOGI("Error StreamIn returned count=%ld dwError=%d", count, es.dwError);

            errFlg = true;
        }

        //pEdit->SetSel(0, 0);
    }

    /* move us back to the top */
    pEdit->LineScroll(-pEdit->GetFirstVisibleLine());

    /* just in case it's trying to hold on to something */
    pEdit->EmptyUndoBuffer();

    /* work around bug that creates unnecessary scroll bars */
    pEdit->SetScrollRange(SB_VERT, 0, 0, TRUE);
    pEdit->SetScrollRange(SB_HORZ, 0, 0, TRUE);

    /* display the entire message in the user's selected font */
    if (!fpOutput->GetMultipleFontsFlag()) {
        // adjust the font, stripping default boldness from SF_TEXT
        NewFontSelected(fpOutput->GetOutputKind() != ReformatOutput::kOutputRTF);
    }

    /* enable/disable the scroll bars */
    //pEdit->EnableScrollBar(SB_BOTH, ESB_DISABLE_BOTH);

    if (errFlg)
        pEdit->SetBackgroundColor(FALSE, RGB(255, 255, 0));
    else if (emptyFlg)
        pEdit->SetBackgroundColor(FALSE, RGB(192, 192, 192));
    else
        pEdit->SetBackgroundColor(TRUE, 0);

    /*
     * Work around a Windows bug that prevents the scroll bars from
     * being displayed immediately.  This makes them appear, but the
     * vertical scroll bar comes out funky on short files (fixed with
     * the SetScrollRange call above).
     *
     * Best guess: when the edit box is resized, it chooses the scroll bar
     * configuration based on the currently-loaded data.  If you resize it
     * and *then* add data, you're stuck with the previous scroll bar
     * values.  This doesn't quite make sense though...
     *
     * This works:
     *  - Set up dialog.
     *  - Load data.
     *  - Do minor twiddling.
     *  - Resize box significantly.
     *
     * This works:
     *  - (box already has data in it)
     *  - Load new data.
     *  - Do minor twiddling.
     *
     * This doesn't:
     *  - Set up dialog
     *  - Resize box significantly.
     *  - Load data.
     *  - Do minor twiddling.
     *
     * There might be some first-time setup issues in here.  Hard to say.
     * Anything related to RichEdit controls is extremely fragile, and must
     * be tested with a variety of inputs, preference settings, and under
     * at least Win98 and Win2K (which are *very* different).
     */
    if (fFirstResize) {
        /* adjust the size of the window to match the last size used */
        const Preferences* pPreferences = GET_PREFERENCES();
        long width = pPreferences->GetPrefLong(kPrFileViewerWidth);
        long height = pPreferences->GetPrefLong(kPrFileViewerHeight);
        CRect fullRect;
        GetWindowRect(&fullRect);
        //LOGI(" VFD pre-size %dx%d", fullRect.Width(), fullRect.Height());
        fullRect.right = fullRect.left + width;
        fullRect.bottom = fullRect.top + height;
        MoveWindow(fullRect, TRUE);

        editHadFocus = true;    // force focus on edit box

        fFirstResize = false;
    } else {
        /* this should be enough */
        ShiftControls(0, 0);
    }
        
    if (fpOutput->GetOutputKind() == ReformatOutput::kOutputBitmap) {
        /* get the cursor off of the image */
        pEdit->SetSel(-1, -1);
    }

    /*
     * We want the focus to be on the text window so keyboard selection
     * commands work.  However, it's also nice to be able to arrow through
     * the format selection box.
     */
    if (editHadFocus)
        pEdit->SetFocus();

    fTitle = fileName;
    //if (fpOutput->GetOutputKind() == ReformatOutput::kOutputText ||
    //  fpOutput->GetOutputKind() == ReformatOutput::kOutputRTF ||
    //  fpOutput->GetOutputKind() == ReformatOutput::kOutputCSV ||
    //  fpOutput->GetOutputKind() == ReformatOutput::kOutputBitmap ||
    //  fpOutput->GetOutputKind() == ReformatOutput::kOutputRaw)
    //{
        // not for error messages
        fTitle += _T(" [");
        fTitle += fpOutput->GetFormatDescr();
        fTitle += _T("]");
    //} else if (fpOutput->GetOutputKind() == ReformatOutput::kOutputRaw) {
    //  fTitle += _T(" [Raw]");
    //}

    CString winTitle = _T("File Viewer - ");
    winTitle += fTitle;
    SetWindowText(winTitle);

    /*
     * Enable or disable the next/prev buttons.
     */
    CButton* pButton;
    pButton = (CButton*) GetDlgItem(IDC_FVIEW_PREV);
    pButton->EnableWindow(fpSelSet->IterHasPrev());
    pButton = (CButton*) GetDlgItem(IDC_FVIEW_NEXT);
    pButton->EnableWindow(fpSelSet->IterHasNext());
}
Ejemplo n.º 15
0
/*nQualityLevel
1: low, 2: media, 3: High */
int SystemDownSample(const char *inputFile, int nWidth, int nHeight, int nQualityLevel, bool bOutPutFile,int nTimes)
{
    int nRet = -1;
    char *pData = NULL;
    CBitmap bmpSource;
    CWindowDC dcScreen(NULL);
    CDC hdcMemDest = CreateCompatibleDC(dcScreen);
    do {
        USES_CONVERSION;
        //load image from file
        std::string strInputPath = inputFile;
        if (strInputPath.find('\\') == std::string::npos) {
            char szPath[MAX_PATH] = { 0 };
            GetModuleFileNameA((HMODULE)NULL, szPath, MAX_PATH);
            std::string strNewInputPath = szPath;
            size_t found = strNewInputPath.rfind('\\');
            if (found != std::string::npos) {
                strNewInputPath.replace(found, std::string::npos, "\\");
            }
            strNewInputPath += strInputPath;
            strInputPath = strNewInputPath;
        }
        bmpSource = LoadBmpFromImageFile(A2W(strInputPath.c_str()));
        if (bmpSource.IsNull()) {
            break;
        }
        SIZE szBitmap  ;
        bmpSource.GetSize(szBitmap);

        //get raw data from HBITMAP to simulate the screen capture output
        CDC dcTemp = CreateCompatibleDC(dcScreen);
        dcTemp.SelectBitmap(bmpSource);

        BITMAPINFO  bmTmp = { 0 };
        bmTmp.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        bmTmp.bmiHeader.biPlanes = 1;
        bmTmp.bmiHeader.biBitCount = 32;
        bmTmp.bmiHeader.biCompression = BI_RGB;
        bmTmp.bmiHeader.biWidth = szBitmap.cx;
        bmTmp.bmiHeader.biHeight = szBitmap.cy;
        pData = new char[szBitmap.cx*szBitmap.cy*4];
        int nRetTmp = GetDIBits(dcTemp, bmpSource, 0,
                                (UINT)szBitmap.cy,
                                pData,
                                (BITMAPINFO *)&bmTmp, DIB_RGB_COLORS);
        if (nRetTmp <= 0) { break; }

        //prepare for dest for testing downsample .
        WBXSize szSource = { szBitmap.cx, szBitmap.cy };
        WBXSize szDest = { nWidth, nHeight };
        szDest = WbxGraphicUtil::WbxGetMaxCapSize(szSource, szDest);
        BITMAPINFO  bm = { 0 };
        bm.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        bm.bmiHeader.biPlanes = 1;
        bm.bmiHeader.biBitCount = 32;
        bm.bmiHeader.biCompression = BI_RGB;
        bm.bmiHeader.biWidth = szDest.cx;
        bm.bmiHeader.biHeight = szDest.cy;
        void *pDestData = NULL;
        CBitmap hbmDest = CreateDIBSection(hdcMemDest, &bm, DIB_RGB_COLORS, &pDestData, NULL, 0);
        if (hbmDest.IsNull()) { break; }

        //real downsample by GDI
        int nStart = ticker::now();
        for (int i=0; i<nTimes; i++) {
            if (nQualityLevel>1) {
                SetStretchBltMode(hdcMemDest, HALFTONE);
            }
            HGDIOBJ hbmOldDest = SelectObject(hdcMemDest, hbmDest);
            bm.bmiHeader.biWidth = szSource.cx;
            bm.bmiHeader.biHeight = szSource.cy;
            StretchDIBits(hdcMemDest, 0, 0, szDest.cx, szDest.cy, 0, 0, szSource.cx, szSource.cy, pData, &bm, DIB_RGB_COLORS, SRCCOPY);
            SelectObject(hdcMemDest, hbmOldDest);
        }
        nRet = ticker::now() - nStart;
        if (bOutPutFile) {
            CImage image;
            image.Attach(hbmDest);
            std::stringstream streamPngFilePath;
            streamPngFilePath << strInputPath << "_" << nWidth << "_" << nHeight << "_" << nQualityLevel << ".png";
            image.Save(A2W(streamPngFilePath.str().c_str())); // change extension to save to png
        }
    } while (0);

    //clean
    if (pData) { delete[] pData; }
    return nRet;
}
Ejemplo n.º 16
0
void ScreenshotButton::GetScreenshot(wxBitmap &screenshot) {

   //Create a DC for the main window
   wxClientDC dcScreen(GetParent());

   //Get the size of the screen/DC
   wxCoord screenWidth, screenHeight;

   //Size of the image
   int width, height;
   //The pixel array
   byte* graph;
   //Fill the pixel array
   graf->getPixels(graph, width, height);
   
   dcScreen.GetSize(&screenWidth, &screenHeight);

   //Create a Bitmap that will later on hold the screenshot image
   //Note that the Bitmap must have a size big enough to hold the screenshot
   //-1 means using the current default colour depth
   screenshot.Create(screenWidth, screenHeight,-1);
   //screenshot.Create(width, height,-1);

   //Create a memory DC that will be used for actually taking the screenshot
   wxMemoryDC memDC;
   //Tell the memory DC to use our Bitmap
   //all drawing action on the memory DC will go to the Bitmap now
   memDC.SelectObject(screenshot);
   //Blit (in this case copy) the actual screen on the memory DC
   //and thus the Bitmap
   memDC.Blit( 0, //Copy to this X coordinate
            0, //Copy to this Y coordinate
            screenWidth, //Copy this width
            screenHeight, //Copy this height
            &dcScreen, //From where do we copy?
            0, //What's the X offset in the original DC?
            0  //What's the Y offset in the original DC?
         );
   //Draw the graph on the screenshot


   //Temporary color
   wxColour color = wxColor(255,0,0);
   //Temporary position in pixel array
   int pos;

   //Loop through pixel array
   for(int y=0; y<height; y++) {
	   for(int x=0; x<width; x++) {
		   pos = (x+(height-y)*width)*3;
		   color.Set(graph[pos], graph[pos+1], graph[pos+2]);
		   memDC.SetBrush(color);
		   memDC.SetPen(color);
		   memDC.DrawPoint(x+79, y+59);
	   }
   }

   
   //Select the Bitmap out of the memory DC by selecting a new
   //uninitialized Bitmap
   memDC.SelectObject(wxNullBitmap);

   

   return;
}