コード例 #1
0
/*****************************************************
**
**   BasicWidget   ---   OnPaint
**
******************************************************/
void BasicWidget::OnPaint( wxPaintEvent &event )
{
	int vx, vy;

	wxPaintDC context( this );
	PrepareDC( context );

	wxRegionIterator upd( GetUpdateRegion());
	if ( upd ) refreshRect = upd.GetRect();
	while ( ++upd )
	{
		refreshRect.Union( upd.GetRect() );
	}
	GetViewStart( &vx, &vy );
	if ( vx || vy )
	{
		refreshRect.x += vx;
		refreshRect.y += vy;
	}

	assert( painter == 0 );
	painter = new DcPainter( &context );
	doPaint();
	delete painter;
	painter = 0;
}
コード例 #2
0
void gcSpinningBar::onNeedRedraw()
{
	m_bNotifyRedraw = false;

	wxClientDC dc(this);
	doPaint(&dc);
}
コード例 #3
0
ファイル: cornerhandler.cpp プロジェクト: honsey/fztaxedit
void CornerHandler::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
	Q_UNUSED(option);
	Q_UNUSED(widget);
	if(m_isVisible && m_parent->isResizable()) {
		doPaint(painter);
	}
}
コード例 #4
0
bool SkOSWindow::onEvent(const SkEvent& evt)
{
    if (evt.isType("inval-imageview")) {
        update(NULL);
        doPaint();
        return true;
    }
    return INHERITED::onEvent(evt);
}
コード例 #5
0
LRESULT CALLBACK wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	LONG_PTR userdata;
	ID2D1HwndRenderTarget *rt = NULL;
	WINDOWPOS *wp = (WINDOWPOS *) lParam;
	RECT client;
	D2D1_SIZE_U size;

	userdata = GetWindowLongPtrW(hwnd, GWLP_USERDATA);
	if (userdata == 0) {
		if (uMsg == WM_CREATE)
			SetWindowLongPtrW(hwnd, GWLP_USERDATA, 1);
		return DefWindowProcW(hwnd, uMsg, wParam, lParam);
	}

	if (userdata == 1) {
		rt = mkRenderTarget(hwnd);
		if (rt == NULL) {
			PostQuitMessage(1);
			return DefWindowProcW(hwnd, uMsg, wParam, lParam);
		}
		SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) rt);
	} else
		rt = (ID2D1HwndRenderTarget *) userdata;

	switch (uMsg) {
	case WM_PAINT:
		switch (doPaint(rt)) {
		case S_OK:
			ValidateRect(hwnd, NULL);
			return 0;
		case D2DERR_RECREATE_TARGET:
			rt->Release();
			SetWindowLongPtrW(hwnd, GWLP_USERDATA, 1);
			return 0;
		}
		rt->Release();
		PostQuitMessage(1);
		break;
	case WM_WINDOWPOSCHANGED:
		if ((wp->flags & SWP_NOSIZE) != 0)
			break;
		GetClientRect(hwnd, &client);
		size.width = client.right - client.left;
		size.height = client.bottom - client.top;
		rt->Resize(&size);
		InvalidateRect(hwnd, NULL, TRUE);
		return 0;
	case WM_CLOSE:
		rt->Release();
		PostQuitMessage(0);
	}
	return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
コード例 #6
0
void gcSpinningBar::onPaint(wxPaintEvent& event)
{
	wxPaintDC dc(this);

	if (GetSize().GetWidth() == 0 || GetSize().GetHeight() == 0)
		return;

	dc.SetTextBackground(GetBackgroundColour());

	if (m_imgProg.getImg() && m_imgProg->IsOk())
		doPaint(&dc);
}
コード例 #7
0
ファイル: plotter.cpp プロジェクト: Andriks/SwDoor
void Plotter::paintEvent(QPaintEvent *event)
{
   int w = width();
   int h = height();
   int side = qMin(w, h);

   QPainter painter(this);
   painter.setRenderHint(QPainter::Antialiasing);
   painter.translate(0 , h / 2);
   painter.scale(side / 200.0, side / 200.0);
   doPaint(painter);
}
コード例 #8
0
QPixmap AvatarPainter::getOrCreateCacheItem()
{
	QString key = cacheKey();

	QPixmap cached;
	if (QPixmapCache::find(key, &cached))
		return cached;

	QPixmap item = QPixmap(AvatarRect.size());
	item.fill(QColor(0, 0, 0, 0));

	QPainter cachePainter;
	cachePainter.begin(&item);
	doPaint(&cachePainter, item.size());
	cachePainter.end();

	QPixmapCache::insert(key, item);

	return item;
}
コード例 #9
0
ファイル: SimApp01Dlg.cpp プロジェクト: Sky-High/Compare-IDE
//
//	---------- the action message callback ----------
// Windows sends its (event) messages to this procedure
//
INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
	case WM_COMMAND:	return doCommand(hDlg, LOWORD(wParam));
	case WM_CLOSE:		onClose(hDlg);		return TRUE;
	case WM_DESTROY:	PostQuitMessage(0);	return TRUE;
	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hDC = BeginPaint(hDlg, &ps);
			doPaint(hDC);
			EndPaint(hDlg, &ps);
		}
		return true;
	case WM_USER_SIMCONNECT:	fsxDispatch(hDlg);	return TRUE;
	// default: is not caught here so will be handled by DefWndProc
	}

	// indicate that message should (additionally) be processed by DefWndProc
	return FALSE;
}
コード例 #10
0
/*****************************************************
**
**   BasicWidget   ---   doExport
**
******************************************************/
void BasicWidget::doExport()
{
	int exporttype;
	wxString filename, e;

	GetExportSize( &xsize, &ysize );

	if ( config->showGraphicSizeDialog )
	{
		ExportDialog dialog( this, xsize, ysize );
		if ( dialog.ShowModal() != wxID_OK ) return;
		dialog.getSizes( xsize, ysize );
		config->showGraphicSizeDialog = ! dialog.getCheckShowDialog();
	}

	const static wxString filetypes =
	    wxT( "PNG (*.png)|*.png|JPG (*.jpg)|*.jpg|Bitmap (*.bmp)|*.bmp|PCX (*pcx)|*pcx|PNM (*.pnm)|*.pnm|TIFF (*.tif)|*.tif|All files (*)| *.*" );

	switch ( config->defGraphicExportType )
	{
	case 1:
		filename = wxT( "out.jpg"  );
		break;
	case 2:
		filename = wxT( "out.bmp"  );
		break;
	case 3:
		filename = wxT( "out.pcx"  );
		break;
	case 4:
		filename = wxT( "out.pnm"  );
		break;
	case 5:
		filename = wxT( "out.tif"  );
		break;
	default:
		filename = wxT( "out.png"  );
		break;
	}
	int style = wxFD_SAVE;
	if ( config->exportAskOnOverwrite ) style |= wxFD_OVERWRITE_PROMPT;

	wxFileDialog exportFileDialog( this, _("Export Picture" ), config->defExportPath, filename,
	                               filetypes, style, wxDefaultPosition );
	exportFileDialog.SetFilterIndex( config->defGraphicExportType );

	if ( exportFileDialog.ShowModal() == wxID_OK )
	{
		filename = exportFileDialog.GetDirectory() + wxFileName::GetPathSeparator() + exportFileDialog.GetFilename();
		e = exportFileDialog.GetFilename().Right(3).MakeLower();
		if ( e == wxT( "png" ))
		{
			exporttype = wxBITMAP_TYPE_PNG;
			config->defGraphicExportType = 0;
		}
		else if ( e == wxT( "jpg" ))
		{
			exporttype = wxBITMAP_TYPE_JPEG;
			config->defGraphicExportType = 0;
		}
		else if ( e == wxT( "jpeg" ))
		{
			exporttype = wxBITMAP_TYPE_JPEG;
			config->defGraphicExportType = 0;
		}
		else if ( e == wxT( "bmp" ))
		{
			exporttype = wxBITMAP_TYPE_BMP;
			config->defGraphicExportType = 0;
		}
		else if ( e == wxT( "pnm" ))
		{
			exporttype = wxBITMAP_TYPE_PNM;
			config->defGraphicExportType = 0;
		}
		else if ( e == wxT( "pcx" ))
		{
			exporttype = wxBITMAP_TYPE_PCX;
			config->defGraphicExportType = 0;
		}
		else if ( e == wxT( "tif" ))
		{
			exporttype = wxBITMAP_TYPE_TIF;
			config->defGraphicExportType = 0;
		}
		else
		{
			doMessageBox( this, wxString::Format( _( "Can't determine image handler for extension \"%s\", using default (PNG)" ), (const wxChar*)e));
			filename.Append( wxT ( ".png" ));
			exporttype = wxBITMAP_TYPE_PNG;
			config->defGraphicExportType = 0;
		}
		config->defExportPath = exportFileDialog.GetDirectory();
		wxBitmap bitmap( xsize, ysize );
		wxMemoryDC dc;
		dc.SelectObject( bitmap );
		painter = new DcPainter( &dc );
		exportMode = true;
		doPaint();
		exportMode = false;
		delete painter;
		painter = 0;
		if ( bitmap.SaveFile( filename, (wxBitmapType)exporttype ))
		{
			doMessageBox( this, wxString::Format( _("Picture exported to %s"), (const wxChar*)filename));
		}
	}
}
コード例 #11
0
ファイル: ZLEwlViewWidget.cpp プロジェクト: mhuber/fbreader
void ZLEwlViewWidget::repaint()	{
	doPaint();
}
コード例 #12
0
ファイル: glviewer.c プロジェクト: ematvey/NanoEngineer-1
int main(int argc, char **argv)
{
  XVisualInfo *vi;
  Colormap cmap;
  XSetWindowAttributes swa;
  Window win;
  GLXContext cx;
  XEvent event;
  fd_set readfds;
  struct timeval timeout;
  int xServerFD;
  int nselected;
    
  /* get a connection */
  xDisplay = XOpenDisplay(0);
  if (xDisplay == NULL) {
    fprintf(stderr, "can't open display\n");
    exit(1);
  }
    
  /* get an appropriate visual */
  vi = glXChooseVisual(xDisplay, DefaultScreen(xDisplay), attributeList);
  if (vi == NULL) {
    fprintf(stderr, "can't get visual\n");
    exit(1);
  }
    
  /* create a GLX context */
  cx = glXCreateContext(xDisplay, vi, 0, GL_FALSE);
  if (cx == NULL) {
    fprintf(stderr, "can't create GL context\n");
    exit(1);
  }
    
  /* create a color map */
  cmap = XCreateColormap(xDisplay, RootWindow(xDisplay, vi->screen), vi->visual, AllocNone);
    
  /* create a window */
  swa.colormap = cmap;
  swa.border_pixel = 0;
  swa.event_mask = StructureNotifyMask;

  windowWidth = 500;
  windowHeight = 500;
    
  win = XCreateWindow(xDisplay, RootWindow(xDisplay, vi->screen), 0, 0, windowWidth, windowHeight,
                      0, vi->depth, InputOutput, vi->visual,
                      CWBorderPixel|CWColormap|CWEventMask, &swa);

  XSelectInput(xDisplay, win, KeyPressMask | ExposureMask | StructureNotifyMask);
    
  XMapWindow(xDisplay, win);
  // wait for the window to be mapped
  XIfEvent(xDisplay, &event, WaitForNotify, (char*)win);
  /* connect the context to the window */
  glXMakeCurrent(xDisplay, win, cx);

  quad = gluNewQuadric();
  if (quad == NULL) {
    fprintf(stderr, "can't allocate quadric\n");
    exit(1);
  }

  resetEye();

  xServerFD = ConnectionNumber(xDisplay);
  XFlush(xDisplay);
  
  while (1) {
    while (processX()) {
    }
    if (needRepaint) {
      doPaint();
    }
    FD_ZERO(&readfds);
    if (!atEOF) {
      FD_SET(0, &readfds);
    }
    FD_SET(xServerFD, &readfds);
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;
    nselected = select(xServerFD+1, &readfds, NULL, NULL, atEOF ? &timeout : NULL);
    if (nselected < 0) {
      perror("select");
      continue;
    }
    if (nselected == 0) {
      continue;
    }
    if (FD_ISSET(0, &readfds)) {
      processStdin();
    }
  }
}
コード例 #13
0
ファイル: kis_brushop_test.cpp プロジェクト: KDE/krita
    void test(bool mirrorX, bool mirrorY, qreal rotation, bool mirrorDabX, bool mirrorDabY, qreal dabRotation) {

        KisSurrogateUndoStore *undoStore = new KisSurrogateUndoStore();
        KisImageSP image = createTrivialImage(undoStore);
        image->initialRefreshGraph();

        KisNodeSP paint1 = findNode(image->root(), "paint1");

        QVERIFY(paint1->extent().isEmpty());

        KisPainter gc(paint1->paintDevice());

        QScopedPointer<KoCanvasResourceManager> manager(
            utils::createResourceManager(image, 0, m_presetFileName));

        KisPaintOpPresetSP preset =
            manager->resource(KisCanvasResourceProvider::CurrentPaintOpPreset).value<KisPaintOpPresetSP>();

        preset->settings()->setCanvasRotation(rotation);
        preset->settings()->setCanvasMirroring(mirrorY, mirrorX);


        if (mirrorDabX || mirrorDabY) {
            KisPaintOpSettingsSP settings = preset->settings()->clone();

            KisPressureMirrorOption mirrorOption;
            mirrorOption.readOptionSetting(settings);

            mirrorOption.setChecked(true);
            mirrorOption.setCurveUsed(false);

            mirrorOption.enableHorizontalMirror(mirrorDabX);
            mirrorOption.enableVerticalMirror(mirrorDabY);

            mirrorOption.writeOptionSetting(settings.data());

            preset->setSettings(settings);
        }

        if (dabRotation != 0.0) {
            KisPaintOpSettingsSP settings = preset->settings()->clone();

            KisPressureRotationOption rotationOption;
            rotationOption.readOptionSetting(settings);

            rotationOption.setChecked(true);
            rotationOption.setCurveUsed(false);

            rotationOption.setValue(dabRotation / 360.0);

            rotationOption.writeOptionSetting(settings.data());

            preset->setSettings(settings);
        }


        QString testName =
            QString("%7_cmY_%1_cmX_%2_cR_%3_dmX_%4_dmY_%5_dR_%6")
            .arg(mirrorY)
            .arg(mirrorX)
            .arg(rotation)
            .arg(mirrorDabX)
            .arg(mirrorDabY)
            .arg(std::fmod(360.0 - dabRotation, 360.0))
            .arg(m_prefix);

        KisResourcesSnapshotSP resources =
            new KisResourcesSnapshot(image,
                                     paint1,
                                     manager.data());

        resources->setupPainter(&gc);

        doPaint(gc);

        checkOneLayer(image, paint1, testName);
    }
コード例 #14
0
ファイル: area_windows.c プロジェクト: AlexSteele/ui
static void paintArea(HWND hwnd, void *data)
{
	RECT xrect;
	PAINTSTRUCT ps;
	HDC hdc;
	HDC rdc;
	HBITMAP rbitmap, prevrbitmap;
	RECT rrect;
	BITMAPINFO bi;
	VOID *ppvBits;
	HBITMAP ibitmap;
	HDC idc;
	HBITMAP previbitmap;
	BLENDFUNCTION blendfunc;
	void *i;
	intptr_t dx, dy;
	int hscroll, vscroll;

	// FALSE here indicates don't send WM_ERASEBKGND
	if (GetUpdateRect(hwnd, &xrect, FALSE) == 0)
		return;		// no update rect; do nothing

	getScrollPos(hwnd, &hscroll, &vscroll);

	hdc = BeginPaint(hwnd, &ps);
	if (hdc == NULL)
		xpanic("error beginning Area repaint", GetLastError());

	// very big thanks to Ninjifox for suggesting this technique and helping me go through it

	// first let's create the destination image, which we fill with the windows background color
	// this is how we fake drawing the background; see also http://msdn.microsoft.com/en-us/library/ms969905.aspx
	rdc = CreateCompatibleDC(hdc);
	if (rdc == NULL)
		xpanic("error creating off-screen rendering DC", GetLastError());
	// the bitmap has to be compatible with the window
	// if we create a bitmap compatible with the DC we just created, it'll be monochrome
	// thanks to David Heffernan in http://stackoverflow.com/questions/23033636/winapi-gdi-fillrectcolor-btnface-fills-with-strange-grid-like-brush-on-window
	rbitmap = CreateCompatibleBitmap(hdc, xrect.right - xrect.left, xrect.bottom - xrect.top);
	if (rbitmap == NULL)
		xpanic("error creating off-screen rendering bitmap", GetLastError());
	prevrbitmap = (HBITMAP) SelectObject(rdc, rbitmap);
	if (prevrbitmap == NULL)
		xpanic("error connecting off-screen rendering bitmap to off-screen rendering DC", GetLastError());
	rrect.left = 0;
	rrect.right = xrect.right - xrect.left;
	rrect.top = 0;
	rrect.bottom = xrect.bottom - xrect.top;
	if (FillRect(rdc, &rrect, areaBackgroundBrush) == 0)
		xpanic("error filling off-screen rendering bitmap with the system background color", GetLastError());

	i = doPaint(&xrect, hscroll, vscroll, data, &dx, &dy);
	if (i == NULL)			// cliprect empty
		goto nobitmap;		// we need to blit the background no matter what

	// now we need to shove realbits into a bitmap
	// technically bitmaps don't know about alpha; they just ignore the alpha byte
	// AlphaBlend(), however, sees it - see http://msdn.microsoft.com/en-us/library/windows/desktop/dd183352%28v=vs.85%29.aspx
	ZeroMemory(&bi, sizeof (BITMAPINFO));
	bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
	bi.bmiHeader.biWidth = (LONG) dx;
	bi.bmiHeader.biHeight = -((LONG) dy);			// negative height to force top-down drawing
	bi.bmiHeader.biPlanes = 1;
	bi.bmiHeader.biBitCount = 32;
	bi.bmiHeader.biCompression = BI_RGB;
	bi.bmiHeader.biSizeImage = (DWORD) (dx * dy * 4);
	// this is all we need, but because this confused me at first, I will say the two pixels-per-meter fields are unused (see http://blogs.msdn.com/b/oldnewthing/archive/2013/05/15/10418646.aspx and page 581 of Charles Petzold's Programming Windows, Fifth Edition)
	// now for the trouble: CreateDIBSection() allocates the memory for us...
	ibitmap = CreateDIBSection(NULL,		// Ninjifox does this, so do some wine tests (http://source.winehq.org/source/dlls/gdi32/tests/bitmap.c#L725, thanks vpovirk in irc.freenode.net/#winehackers) and even Raymond Chen (http://blogs.msdn.com/b/oldnewthing/archive/2006/11/16/1086835.aspx), so.
		&bi, DIB_RGB_COLORS, &ppvBits, 0, 0);
	if (ibitmap == NULL)
		xpanic("error creating HBITMAP for image returned by AreaHandler.Paint()", GetLastError());

	// now we have to do TWO MORE things before we can finally do alpha blending
	// first, we need to load the bitmap memory, because Windows makes it for us
	// the pixels are arranged in RGBA order, but GDI requires BGRA
	// this turns out to be just ARGB in little endian; let's convert into this memory
	dotoARGB(i, (void *) ppvBits, FALSE);		// FALSE = not NRGBA

	// the second thing is... make a device context for the bitmap :|
	// Ninjifox just makes another compatible DC; we'll do the same
	idc = CreateCompatibleDC(hdc);
	if (idc == NULL)
		xpanic("error creating HDC for image returned by AreaHandler.Paint()", GetLastError());
	previbitmap = (HBITMAP) SelectObject(idc, ibitmap);
	if (previbitmap == NULL)
		xpanic("error connecting HBITMAP for image returned by AreaHandler.Paint() to its HDC", GetLastError());

	// AND FINALLY WE CAN DO THE ALPHA BLENDING!!!!!!111
	blendfunc.BlendOp = AC_SRC_OVER;
	blendfunc.BlendFlags = 0;
	blendfunc.SourceConstantAlpha = 255;		// only use per-pixel alphas
	blendfunc.AlphaFormat = AC_SRC_ALPHA;	// premultiplied
	if (AlphaBlend(rdc, 0, 0, (int) dx, (int) dy,		// destination
		idc, 0, 0, (int) dx, (int)dy,				// source
		blendfunc) == FALSE)
		xpanic("error alpha-blending image returned by AreaHandler.Paint() onto background", GetLastError());

	// clean up after idc/ibitmap here because of the goto nobitmap
	if (SelectObject(idc, previbitmap) != ibitmap)
		xpanic("error reverting HDC for image returned by AreaHandler.Paint() to original HBITMAP", GetLastError());
	if (DeleteObject(ibitmap) == 0)
		xpanic("error deleting HBITMAP for image returned by AreaHandler.Paint()", GetLastError());
	if (DeleteDC(idc) == 0)
		xpanic("error deleting HDC for image returned by AreaHandler.Paint()", GetLastError());

nobitmap:
	// and finally we can just blit that into the window
	if (BitBlt(hdc, xrect.left, xrect.top, xrect.right - xrect.left, xrect.bottom - xrect.top,
		rdc, 0, 0,			// from the rdc's origin
		SRCCOPY) == 0)
		xpanic("error blitting Area image to Area", GetLastError());

	// now to clean up
	if (SelectObject(rdc, prevrbitmap) != rbitmap)
		xpanic("error reverting HDC for off-screen rendering to original HBITMAP", GetLastError());
	if (DeleteObject(rbitmap) == 0)
		xpanic("error deleting HBITMAP for off-screen rendering", GetLastError());
	if (DeleteDC(rdc) == 0)
		xpanic("error deleting HDC for off-screen rendering", GetLastError());

	EndPaint(hwnd, &ps);
}