static void cdcreatecanvas(cdCanvas* canvas, void *data) { cdCtxCanvas* ctxcanvas; cairo_surface_t *surface; HWND hWnd = (HWND)data; HDC ScreenDC, hDC; HRGN clip_hrgn; ScreenDC = GetDC(NULL); canvas->bpp = GetDeviceCaps(ScreenDC, BITSPIXEL); canvas->xres = (float)(((double)GetDeviceCaps(ScreenDC, LOGPIXELSX)) / 25.4); canvas->yres = (float)(((double)GetDeviceCaps(ScreenDC, LOGPIXELSY)) / 25.4); ReleaseDC(NULL, ScreenDC); if (!data) { hDC = GetDC(NULL); canvas->w = GetDeviceCaps(hDC, HORZRES); canvas->h = GetDeviceCaps(hDC, VERTRES); } else { RECT rect; hWnd = (HWND)data; hDC = GetDC(hWnd); GetClientRect(hWnd, &rect); canvas->w = rect.right - rect.left; canvas->h = rect.bottom - rect.top; } /* initial clip extents controls size */ clip_hrgn = CreateRectRgn(0, 0, canvas->w, canvas->h); SelectClipRgn(hDC, clip_hrgn); DeleteObject(clip_hrgn); surface = cairo_win32_surface_create(hDC); canvas->w_mm = ((double)canvas->w) / canvas->xres; canvas->h_mm = ((double)canvas->h) / canvas->yres; ctxcanvas = cdcairoCreateCanvas(canvas, cairo_create(surface)); cairo_surface_destroy(surface); ctxcanvas->hDC = hDC; ctxcanvas->hWnd = hWnd; if (hWnd) { LONG style = GetClassLong(hWnd, GCL_STYLE); ctxcanvas->isOwnedDC = (int) ((style & CS_OWNDC) || (style & CS_CLASSDC)); } else ctxcanvas->isOwnedDC = 1; }
HRESULT WinCE_DoDragDrop(LPDATAOBJECT pDataObj, LPDROPSOURCE pDropSource, DWORD dwOKEffects, LPDWORD pdwEffect) { MSG msg; POINT dest = {0,0}; POINT lastDraw = {-1,-1}; DWORD effect = DROPEFFECT_NONE; DWORD lastEffect = -1; IDropTarget * currentTarget = NULL; IWebViewPrivate * webView = NULL; IDataObject * dataObject = pDataObj; IDropSource * dropSource = pDropSource; HRESULT feedbackHR = DRAGDROP_S_USEDEFAULTCURSORS; HCURSOR startCursor = ::GetCursor(); HCURSOR noCursor = LoadCursor(NULL, IDC_NO); // If there is a change in the keyboard or mouse button state, DoDragDrop calls // IDropSource::QueryContinueDrag and determines whether to continue the drag, to // drop the data, or to cancel the operation based on the return value. BOOL escapePressed = FALSE; DWORD keyState = MK_LBUTTON; if (GetKeyState(VK_CONTROL) & HIGH_BIT_MASK_SHORT) keyState |= MK_CONTROL; if (GetKeyState(VK_SHIFT) & HIGH_BIT_MASK_SHORT) keyState |= MK_SHIFT; HRESULT result = dropSource->QueryContinueDrag(escapePressed, keyState); bool dragActive = (result == S_OK); POINTL screenPoint; while (dragActive && GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); // Filter all mouse and key events during the drag and drop: if (msg.message == WM_LBUTTONUP || msg.message == WM_LBUTTONDOWN || msg.message == WM_RBUTTONUP || msg.message == WM_RBUTTONDOWN || msg.message == WM_MOUSEMOVE || msg.message == WM_KEYDOWN || msg.message == WM_KEYUP || msg.message == WM_CHAR || msg.message == WM_SYSKEYDOWN || msg.message == WM_SYSKEYUP || msg.message == WM_SYSCHAR) { if (msg.message == WM_MOUSEMOVE) { PERFORMANCE_START(WTF::PerformanceTrace::InputEvent,"DragDropManager: Mouse Move"); } else if (msg.message == WM_LBUTTONUP) { PERFORMANCE_START(WTF::PerformanceTrace::InputEvent,"DragDropManager: Mouse Up"); } else { PERFORMANCE_START(WTF::PerformanceTrace::InputEvent,"DragDropManager: Other Input"); } bool stateChanged = false; if (msg.message == WM_MOUSEMOVE || msg.message == WM_LBUTTONUP) { POINT pt = {GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam)}; ::ClientToScreen(msg.hwnd, &pt); screenPoint.x = pt.x; screenPoint.y = pt.y; dest.x = pt.x - currentDragImage.ptOffset.x; dest.y = pt.y - currentDragImage.ptOffset.y; if (msg.message == WM_MOUSEMOVE) { // Which window is my mouse over? HWND mouseWnd = WindowFromPoint(dest); IDropTarget * newTarget = NULL; if (mouseWnd != NULL && dragMap) { DragWindowMap::iterator it = dragMap->find(mouseWnd); if (it != dragMap->end()) newTarget = it->second; } if (currentTarget && currentTarget != newTarget) { currentTarget->DragLeave(); feedbackHR = dropSource->GiveFeedback(DROPEFFECT_NONE); } if (newTarget) { effect = DROPEFFECT_NONE; //is this the correct way to set effect? if (pdwEffect) effect = *pdwEffect; if (currentTarget != newTarget) { newTarget->DragEnter(dataObject, keyState, screenPoint, &effect); feedbackHR = dropSource->GiveFeedback(effect); // Find out if the target is a webview now. if (webView) webView->Release(); newTarget->QueryInterface(IID_IWebViewPrivate, (void**) &webView); } else if (currentTarget) { currentTarget->DragOver(keyState, screenPoint, &effect); feedbackHR = dropSource->GiveFeedback(effect); } } if (webView) { dragImageVisible = true; dragAreaInvalid = true; } if (feedbackHR == DRAGDROP_S_USEDEFAULTCURSORS && effect != lastEffect) { switch (effect) { case DROPEFFECT_NONE: ::SetCursor(noCursor); break; /* MS doesn't give us these cursors!!! case DROPEFFECT_COPY: break; case DROPEFFECT_MOVE: break; case DROPEFFECT_LINK: break; */ default: ::SetCursor(startCursor); break; } lastEffect = effect; } currentTarget = newTarget; } else if (msg.message == WM_LBUTTONUP) { keyState = 0; stateChanged = true; } } else if (msg.message == WM_KEYDOWN) { if (msg.wParam == VK_ESCAPE) { escapePressed = TRUE; stateChanged = true; } } else if (msg.message == WM_KEYUP) { if (msg.wParam == VK_ESCAPE) { escapePressed = FALSE; stateChanged = true; } } if (stateChanged) { result = dropSource->QueryContinueDrag(escapePressed, keyState); if (result != S_OK) { dragImageVisible = false; dragAreaInvalid = true; if (currentTarget && effect && result == DRAGDROP_S_DROP) { effect = DROPEFFECT_NONE; //FIXME: should we reset effect or not? result = currentTarget->Drop(dataObject, keyState, screenPoint, &effect); if (SUCCEEDED(result)) { result = DRAGDROP_S_DROP; if (pdwEffect) *pdwEffect = effect; } } else { result = DRAGDROP_S_CANCEL; } dragActive = false; } } PERFORMANCE_END(WTF::PerformanceTrace::InputEvent); } else { DispatchMessage(&msg); } if (dragAreaInvalid && webView && dragImageCairo) { PERFORMANCE_START(WTF::PerformanceTrace::Paint, "DragDropManager::Paint"); HDC screenDC = ::GetDC(NULL); cairo_surface_t * screenSurface = cairo_win32_surface_create(screenDC); cairo_t *crScreen = cairo_create(screenSurface); HWND wnd; webView->viewWindow((OLE_HANDLE*) &wnd); RECT dirty; if (invalidDragRect.left != -1) { dirty = invalidDragRect; } else { POINT p = {0, 0}; ::ClientToScreen(wnd, &p); ::GetClientRect(wnd, &dirty); dirty.left += p.x; dirty.top += p.y; dirty.right += p.x; dirty.bottom += p.y; } if (dragImageVisible) { POINT * prevDraw = NULL; if (lastDraw.x != -1 && (lastDraw.x != dest.x || lastDraw.y != dest.y)) prevDraw = &lastDraw; drawDragImage(crScreen, dest, prevDraw, webView, wnd, true, &dirty); lastDraw = dest; invalidDragRect.left = -1; } else { // erase the drag image wherever we last put it: drawDragImage(crScreen, lastDraw, NULL, webView, wnd, false, &dirty); } cairo_destroy(crScreen); cairo_surface_destroy(screenSurface); ::ReleaseDC(NULL, screenDC); dragAreaInvalid = false; PERFORMANCE_END(WTF::PerformanceTrace::Paint); } } if (currentTarget && result != DRAGDROP_S_DROP) { currentTarget->DragLeave(); } ::SetCursor(startCursor); if (webView) webView->Release(); if (dragImageCairo) { cairo_surface_destroy(dragImageCairo); dragImageCairo = NULL; } return result; }
static cairo_t* createCairoContextWithHDC(HDC hdc, bool hasAlpha) { #if !OS(WINCE) // Put the HDC In advanced mode so it will honor affine transforms. SetGraphicsMode(hdc, GM_ADVANCED); #endif cairo_surface_t* surface = 0; HBITMAP bitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP)); BITMAP info; if (!GetObject(bitmap, sizeof(info), &info)) surface = cairo_win32_surface_create(hdc); else { ASSERT(info.bmBitsPixel == 32); surface = cairo_image_surface_create_for_data((unsigned char*)info.bmBits, CAIRO_FORMAT_ARGB32, info.bmWidth, info.bmHeight, info.bmWidthBytes); } cairo_t* context = cairo_create(surface); cairo_surface_destroy(surface); return context; }
void gfxWindowsSurface::InitWithDC(uint32_t flags) { if (flags & FLAG_IS_TRANSPARENT) { Init(cairo_win32_surface_create_with_alpha(mDC)); } else { Init(cairo_win32_surface_create(mDC)); } }
/** * cairo_win32_surface_create_with_ddb: * @hdc: a DC compatible with the surface to create * @format: format of pixels in the surface to create * @width: width of the surface, in pixels * @height: height of the surface, in pixels * * Creates a device-dependent-bitmap surface not associated with * any particular existing surface or device context. The created * bitmap will be uninitialized. * * Return value: the newly created surface * * Since: 1.4 **/ cairo_surface_t * cairo_win32_surface_create_with_ddb (HDC hdc, cairo_format_t format, int width, int height) { cairo_win32_display_surface_t *new_surf; HBITMAP ddb; HDC screen_dc, ddb_dc; HBITMAP saved_dc_bitmap; if (format != CAIRO_FORMAT_RGB24) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); /* XXX handle these eventually format != CAIRO_FORMAT_A8 || format != CAIRO_FORMAT_A1) */ if (!hdc) { screen_dc = GetDC (NULL); hdc = screen_dc; } else { screen_dc = NULL; } ddb_dc = CreateCompatibleDC (hdc); if (ddb_dc == NULL) { new_surf = (cairo_win32_display_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); goto FINISH; } ddb = CreateCompatibleBitmap (hdc, width, height); if (ddb == NULL) { DeleteDC (ddb_dc); /* Note that if an app actually does hit this out of memory * condition, it's going to have lots of other issues, as * video memory is probably exhausted. However, it can often * continue using DIBs instead of DDBs. */ new_surf = (cairo_win32_display_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); goto FINISH; } saved_dc_bitmap = SelectObject (ddb_dc, ddb); new_surf = (cairo_win32_display_surface_t*) cairo_win32_surface_create (ddb_dc); new_surf->bitmap = ddb; new_surf->saved_dc_bitmap = saved_dc_bitmap; new_surf->is_dib = FALSE; FINISH: if (screen_dc) ReleaseDC (NULL, screen_dc); return &new_surf->win32.base; }
static PyObject * win32_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { int hdc; if (!PyArg_ParseTuple(args, "i:Win32Surface.__new__", &hdc)) return NULL; return PycairoSurface_FromSurface ( cairo_win32_surface_create ((HDC)hdc), NULL); }
SurfaceGdi::SurfaceGdi( HDC hdc ) : SurfaceBase(), mDc( hdc ) { mCairoSurface = cairo_win32_surface_create( hdc ); RECT rect; ::GetClipBox( hdc, &rect ); mWidth = rect.right - rect.left; mHeight = rect.bottom - rect.top; }
void CairoGLRenderer::ResizeDemo(HWND hWnd, const RECT& rect) { ::ReleaseDC(hWnd, m_hdc); m_hdc = ::GetDC(hWnd); cairo_destroy(m_cr); cairo_surface_destroy(m_surface); m_surface = cairo_win32_surface_create(m_hdc); m_cr = cairo_create(m_surface); }
GraphicsContext::GraphicsContext(HDC dc) : m_common(createGraphicsContextPrivate()) , m_data(new GraphicsContextPlatformPrivate) { if (dc) { cairo_surface_t* surface = cairo_win32_surface_create(dc); m_data->cr = cairo_create(surface); } else { setPaintingDisabled(true); m_data->cr = 0; } }
gfxWindowsSurface::gfxWindowsSurface(HDC dc, PRUint32 flags) : mOwnsDC(PR_FALSE), mForPrinting(PR_FALSE), mDC(dc), mWnd(nsnull) { if (flags & FLAG_TAKE_DC) mOwnsDC = PR_TRUE; if (flags & FLAG_FOR_PRINTING) { Init(cairo_win32_printing_surface_create(mDC)); mForPrinting = PR_TRUE; } else { Init(cairo_win32_surface_create(mDC)); } }
void draw(HDC hdc) { cairo_surface_t *surface =cairo_win32_surface_create (hdc); // cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 640, 120); cairo_t *cr = cairo_create (surface); cairo_select_font_face (cr, "Consolas", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size (cr, 90.0); cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); cairo_move_to (cr, 20.0, 240.0); cairo_show_text (cr, "Hello,World!"); // cairo_destroy (cr); // cairo_surface_write_to_png (surface, "hello.png"); // cairo_surface_destroy (surface); // printf("Create hello.png file ok.\n"); }
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; switch (msg) { case WM_CREATE: ClientResize(hWnd, 1000, 450); OnWindowCreate(hWnd); break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); { cairo_surface_t *surface = cairo_win32_surface_create(hdc); cairo_t *cr = cairo_create(surface); cairo_surface_t *shell = cairo_image_surface_create_from_png("../res/smatch-shell.png"); cairo_set_source_surface(cr, shell, 0, 0); cairo_paint(cr); cairo_surface_finish(surface); // Cleanup. cairo_destroy(cr); cairo_surface_destroy(surface); } EndPaint(hWnd, &ps); break; case WM_COMMAND: OnCommand(hWnd, msg, wParam, lParam); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, msg, wParam, lParam); break; } return 0; }
cairo_surface_t* cairo_box::set_surface(int wo, int ho) { #ifdef WIN32 #warning win32 mode /* Get a Cairo surface for the current DC */ HDC dc = fl_gc; /* Exported by fltk */ return cairo_win32_surface_create(dc); #elif defined (__APPLE__) #warning Apple Quartz mode /* Get a Cairo surface for the current CG context */ CGContext *ctx = fl_gc; return cairo_quartz_surface_create_for_cg_context(ctx, wo, ho); #else /* Get a Cairo surface for the current display */ return cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, wo, ho); #endif }
static int new_Win32Surface (lua_State *L) { HDC hdc; cairo_surface_t *cs; lua_remove(L, 1); // remove cairo.Win32Surface //FIXME //{"create_with_ddb", l_cairo_win32_surface_create_with_ddb}, //{"create_with_dib", l_cairo_win32_surface_create_with_dib}, //{"create", l_cairo_win32_surface_create}, hdc = (HDC) check_lightuserdata(L, 1); cs = cairo_win32_surface_create(hdc); return new_Surface(L, LUACAIRO ".Win32Surface.mt", cs, CAIRO_SURFACE_TYPE_WIN32, 1); }
cairo_t* wxGISDisplay::CreateContext(wxDC* dc) { cairo_t *cr(NULL); #ifdef __WXMSW__ //#if CAIRO_HAS_WIN32_SURFACE HDC hdc = (HDC)dc->GetHDC(); cr = cairo_create(cairo_win32_surface_create( hdc )); #endif #ifdef __WXGTK__ wxGraphicsRenderer * const renderer = wxGraphicsRenderer::GetCairoRenderer(); wxWindowDC* pwdc = wxDynamicCast(dc, wxWindowDC); wxGraphicsContext * gc = renderer->CreateContext(*pwdc); if(gc) cr = (cairo_t*)gc->GetNativeContext(); #endif return cr; }
GraphicsContext::GraphicsContext(HDC dc, bool hasAlpha) : m_common(createGraphicsContextPrivate()) , m_data(new GraphicsContextPlatformPrivate) { if (dc) { cairo_surface_t* surface = cairo_win32_surface_create(dc); m_data->cr = cairo_create(surface); m_data->m_hdc = dc; } else { setPaintingDisabled(true); m_data->cr = 0; m_data->m_hdc = 0; } if (m_data->cr) { // Make sure the context starts in sync with our state. setPlatformFillColor(fillColor()); setPlatformStrokeColor(strokeColor()); } }
static PyObject * win32_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { int hdc; cairo_surface_t *surface; PyObject *o; if (!PyArg_ParseTuple(args, "i:Win32Surface.__new__", &hdc)) return NULL; o = type->tp_alloc(type, 0); if (o) { surface = cairo_win32_surface_create ((HDC)hdc); if (Pycairo_Check_Status (cairo_surface_status (surface))) { cairo_surface_destroy (surface); Py_DECREF(o); return NULL; } ((PycairoPSSurface *)o)->surface = surface; } return o; }
int cdactivate(cdCtxCanvas *ctxcanvas) { if (ctxcanvas->hWnd) { RECT rect; GetClientRect(ctxcanvas->hWnd, &rect); ctxcanvas->canvas->w = rect.right - rect.left; ctxcanvas->canvas->h = rect.bottom - rect.top; ctxcanvas->canvas->bpp = cdGetScreenColorPlanes(); } /* Se nao e' ownwer, tem que restaurar o contexto */ if (!ctxcanvas->isOwnedDC) { cairo_surface_t *surface; if (ctxcanvas->hDC) /* deactivate not called */ { cairo_destroy(ctxcanvas->cr); ReleaseDC(ctxcanvas->hWnd, ctxcanvas->hDC); } ctxcanvas->hDC = GetDC(ctxcanvas->hWnd); surface = cairo_win32_surface_create(ctxcanvas->hDC); ctxcanvas->cr = cairo_create(surface); cairo_surface_destroy(surface); } ctxcanvas->canvas->w_mm = ((double)ctxcanvas->canvas->w) / ctxcanvas->canvas->xres; ctxcanvas->canvas->h_mm = ((double)ctxcanvas->canvas->h) / ctxcanvas->canvas->yres; if (ctxcanvas->canvas->use_matrix) ctxcanvas->canvas->cxTransform(ctxcanvas, ctxcanvas->canvas->matrix); return CD_OK; }
void GraphicsContextPlatformPrivate::flush() { cairo_surface_t* surface = cairo_win32_surface_create(m_hdc); cairo_surface_flush(surface); cairo_surface_destroy(surface); }
bool DatabaseTask::DrawResult(Lum::OS::Window* window, Lum::OS::DrawInfo* draw, int x, int y, size_t width, size_t height, double lon, double lat, const osmscout::Magnification& magnification, osmscout::Projection& projection) { Lum::OS::Guard<Lum::OS::Mutex> guard(mutex); if (finishedCairo==NULL) { std::cout << "No map available!" << std::endl; return false; } projection.Set(finishedLon,finishedLat, finishedMagnification, finishedWidth,finishedHeight); double lonMin,lonMax,latMin,latMax; projection.GetDimensions(lonMin,latMin,lonMax,latMax); double dx=0; double dy=0; if (lon!=finishedLon || lat!=finishedLat) { dx+=(lon-finishedLon)*width/(lonMax-lonMin); dy+=(lat-finishedLat)*height/(latMax-latMin); } draw->PushClip(x,y,width,height); #if defined(LUM_HAVE_LIB_CAIRO) if (dynamic_cast<Lum::OS::Cairo::DrawInfo*>(draw)!=NULL) { cairo_t* cairo=dynamic_cast<Lum::OS::Cairo::DrawInfo*>(draw)->cairo; cairo_set_source_surface(cairo,finishedSurface,x-dx,y+dy); cairo_rectangle(cairo,x,y,finishedWidth,finishedHeight); cairo_fill(cairo); } #endif #if defined(LUM_HAVE_LIB_WIN32) if (dynamic_cast<Lum::OS::Win32::DrawInfo*>(draw)!=NULL) { Lum::OS::Win32::DrawInfo *win32Draw=dynamic_cast<Lum::OS::Win32::DrawInfo*>(draw); cairo_surface_t *surface=cairo_win32_surface_create(win32Draw->dc); cairo_t* cairo=cairo_create(surface); cairo_set_source_surface(cairo,finishedSurface,x-dx,y+dy); cairo_rectangle(cairo,x,y,finishedWidth,finishedHeight); cairo_fill(cairo); cairo_destroy(cairo), cairo_surface_destroy(surface); } #endif draw->PopClip(); return finishedWidth==width && finishedHeight==height && finishedLon==lon && finishedLat==lat && finishedMagnification==magnification; }
imageObj* createImageCairo(int width, int height, outputFormatObj *format,colorObj* bg) { imageObj *image = NULL; cairo_renderer *r=NULL; if (format->imagemode != MS_IMAGEMODE_RGB && format->imagemode!= MS_IMAGEMODE_RGBA) { msSetError(MS_MISCERR, "Cairo driver only supports RGB or RGBA pixel models.","msImageCreateCairo()"); return image; } if (width > 0 && height > 0) { image = (imageObj *) calloc(1, sizeof(imageObj)); r = (cairo_renderer*)calloc(1,sizeof(cairo_renderer)); if(!strcasecmp(format->driver,"cairo/pdf")) { r->outputStream = (bufferObj*)malloc(sizeof(bufferObj)); msBufferInit(r->outputStream); r->surface = cairo_pdf_surface_create_for_stream( _stream_write_fn, r->outputStream, width,height); } else if(!strcasecmp(format->driver,"cairo/svg")) { r->outputStream = (bufferObj*)malloc(sizeof(bufferObj)); msBufferInit(r->outputStream); r->surface = cairo_svg_surface_create_for_stream( _stream_write_fn, r->outputStream, width,height); } else if(!strcasecmp(format->driver,"cairo/winGDI") && format->device) { #if CAIRO_HAS_WIN32_SURFACE r->outputStream = NULL; r->surface = cairo_win32_surface_create(format->device); #else msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.", "msImageCreateCairo()"); #endif } else if(!strcasecmp(format->driver,"cairo/winGDIPrint") && format->device) { #if CAIRO_HAS_WIN32_SURFACE r->outputStream = NULL; r->surface = cairo_win32_printing_surface_create(format->device); #else msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.", "msImageCreateCairo()"); #endif } else { r->outputStream = NULL; r->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); } r->cr = cairo_create(r->surface); if(format->transparent || !bg || !MS_VALID_COLOR(*bg)) { r->use_alpha = 1; cairo_set_source_rgba (r->cr, 0,0,0,0); } else { r->use_alpha = 0; msCairoSetSourceColor(r->cr,bg); } cairo_save (r->cr); cairo_set_operator (r->cr, CAIRO_OPERATOR_SOURCE); cairo_paint (r->cr); cairo_restore (r->cr); cairo_set_line_cap (r->cr,CAIRO_LINE_CAP_ROUND); cairo_set_line_join(r->cr,CAIRO_LINE_JOIN_ROUND); image->img.plugin = (void*)r; } else { msSetError(MS_RENDERERERR, "Cannot create cairo image of size %dx%d.", "msImageCreateCairo()", width, height); } return image; }
LONG WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ){ tWindow* p = (tWindow*)GetWindowLongPtr(hwnd,GWLP_USERDATA); int bpaint=0; if(vb) printf("tWindow:%p msg:%d\n",p,msg); switch(msg){ case WM_ERASEBKGND: return 1; break; case WM_ACTIVATE: if(vb) printf("wm_activating - eg. focus\n"); break; case WM_MOVE: if(vb) printf("wm_move\n"); break; case WM_CREATE: if(vb) printf("wm_create\n"); return 0; case WM_SIZE: { tMsg m; m.id = TMSG_RESIZE; m.width = LOWORD(lParam); m.height = HIWORD(lParam); tWindow_message(p,m); if(vb) printf("wn_resize\n"); p->width = LOWORD(lParam); p->height = HIWORD(lParam); bpaint=1; } break; case WM_KEYDOWN:{ tMsg m; int i=0; if(vb)printf("win32 key down\n"); if ((int)wParam==VK_ESCAPE){ PostQuitMessage(0); } m.id = TMSG_KEYDOWN; while (vk_key_table[i][0]!=KEY_NULL){ if (vk_key_table[i][1] == (int)wParam){ m.key_id=vk_key_table[i][0]; tWindow_message(p,m); break; } i++; }; } break; case WM_KEYUP:{ tMsg m; int i=0; if(vb)printf("win32 key up\n"); m.id = TMSG_KEYUP; while (vk_key_table[i][0]!=KEY_NULL){ if (vk_key_table[i][1] == (int)wParam){ m.key_id=vk_key_table[i][0]; tWindow_message(p,m); break; } i++; }; } break; case WM_LBUTTONDOWN: case WM_RBUTTONDOWN:{ tMsg m; if(vb)printf("win32 Button Press\n"); m.id = (msg==WM_LBUTTONDOWN)?TMSG_MOUSE_BUTTON1_PRESS:TMSG_MOUSE_BUTTON2_PRESS; m.x = LOWORD(lParam); m.y = HIWORD(lParam); tWindow_message(p,m); } break; case WM_LBUTTONUP: case WM_RBUTTONUP:{ tMsg m; if(vb)printf("win32 Button Release\n"); m.id = (msg==WM_LBUTTONUP)?TMSG_MOUSE_BUTTON1_RELEASE:TMSG_MOUSE_BUTTON2_RELEASE; m.x = LOWORD(lParam); m.y = HIWORD(lParam); tWindow_message(p,m); } break; case WM_MOUSEMOVE:{ int mx = LOWORD(lParam); int my = HIWORD(lParam); /* if(vb)printf("win32 Mouse move:%d,%d\n",mx,my);*/ tMsg m; m.id = TMSG_MOUSE_MOVE; m.x = mx; m.y = my; tWindow_message(p,m); } break; case WM_SYNCPAINT: case WM_PAINT:{ if(vb) printf("wm_paint please..\n"); bpaint=1; } break; case WM_GETMINMAXINFO:{ MINMAXINFO FAR *info; if (p==NULL) break; if(vb) printf("wm_getminmaxinfo p: %p minsize:%d,%d\n",p, p->width, p->height); info=(MINMAXINFO FAR *)lParam; info->ptMinTrackSize.x = p->min_width; info->ptMinTrackSize.y = p->min_height+16; /* +16 border */ } break; case WM_CLOSE: if(vb) printf("wm_close\n"); PostQuitMessage(0); /* GetMessage returns false after this */ return 0; case WM_DESTROY: if(vb) printf("wm_destroy\n"); PostQuitMessage(0); return 0; }; if (bpaint){ tMsg m; cairo_surface_t* ps; cairo_t *cr; HDC hdc; m.id = TMSG_PAINT; m.width = -1; m.height = -1; tWindow_message(p,m); /* copy cairo surface direct on DC */ hdc = GetDC(p->hwnd);/*, NULL, DCX_CACHE); */ ps = cairo_win32_surface_create(hdc); cr = cairo_create(ps); /* simple blit */ /* cairo_set_source_surface( cr, p->surf, 0,0 ); */ /* cairo_rectangle(cr, 0,0,p->width,p->height); */ /* cairo_fill(cr); */ /* centred blit */ { float margx = (p->width - p->surf_width)/2; float margy = (p->height - p->surf_height)/2; float x1=0,x2=margx,x3=p->width-margx,x4=p->width; float y1=0,y2=margy,y3=p->height-margy,y4=p->height; if (vb) printf("centered blit, %d,%d %d,%d\n",p->width,p->height,p->surf_width,p->surf_height); cairo_set_source_rgba(cr,0.5,0.5,0.6,1.0); cairo_rectangle(cr, x1,y1,x2,y4); /* left */ cairo_rectangle(cr, x3,y1,x4,y4); /* right */ cairo_rectangle(cr, x2,y1,x3,y2); /* middle upper */ cairo_rectangle(cr, x2,y3,x3,y4); /* middle lower */ cairo_fill(cr); /* doesn't like translate of 0.5 here.. */ if (vb) printf("marge:%g,%g\n",margx,margy); cairo_translate(cr,(int)margx,(int)margy); } mutex_lock(&p->mutex); if (p->surf!=NULL){ cairo_set_source_surface(cr,p->surf,0,0); cairo_surface_flush(p->surf); cairo_paint(cr); cairo_surface_flush(ps); } mutex_unlock(&p->mutex); cairo_destroy(cr); cairo_surface_destroy(ps); ReleaseDC(p->hwnd, hdc); /* InvalidateRect( p->hwnd, NULL, true); */ } return DefWindowProc(hwnd,msg,wParam,lParam); }
LRESULT CALLBACK cg_canvas_win32_proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { widget_t *w; canvas_widget_t *cvsw; native_canvas_widget_t *nw; RECT r; PAINTSTRUCT ps; HDC hdc, mdc, odc; HBITMAP bmp, obmp; w = cg_find_by_native( hWnd ); if ( w == 0 ) return DefWindowProc( hWnd, uMsg, wParam, lParam ); cvsw = (canvas_widget_t *)w; nw = (native_canvas_widget_t *)w->ndata; switch ( uMsg ) { case WM_ERASEBKGND: return 1; case WM_PAINT: case WM_PRINTCLIENT: if ( uMsg == WM_PAINT ) { if ( !cg_isxplater ) { odc = BeginPaint( hWnd, &ps ); mdc = CreateCompatibleDC( odc ); GetClientRect( hWnd, &r ); if ( nw->bmp == 0 ) nw->bmp = CreateCompatibleBitmap( odc, r.right, r.bottom ); obmp = SelectObject( mdc, nw->bmp ); hdc = mdc; } else { hdc = BeginPaint( hWnd, &ps ); } } else hdc = wParam; GetClientRect( hWnd, &r ); FillRect( hdc, &r, (HBRUSH) (COLOR_WINDOW) ); cvsw->surfdata = hdc; if ( w->font.native != 0 ) SelectObject( hdc, w->font.native ); #ifndef NO_CAIRO cairo_surface_destroy( cvsw->surface ); cvsw->surface = 0; if ( cvsw->surface == 0 ) { cvsw->surface = cairo_win32_surface_create( hdc ); } cvsw->cr = cairo_create( cvsw->surface ); #endif /* cairo_rectangle( cvsw->cr, r.left, r.top, r.right - r.left, r.bottom - r.top ); cairo_clip( cvsw->cr ); */ #ifdef NO_CAIRO event_send( OBJECT(w), "redraw", "" ); #else event_send( OBJECT(w), "redraw", "p", "cairo_context", cvsw->cr ); #endif #ifndef NO_CAIRO cairo_destroy( cvsw->cr ); #endif if ( uMsg == WM_PAINT && !cg_isxplater ) { BitBlt( odc, 0, 0, r.right, r.bottom, hdc, 0, 0, SRCCOPY ); SelectObject( mdc, obmp ); EndPaint( hWnd, &ps ); } else if ( uMsg == WM_PAINT ) { EndPaint( hWnd, &ps ); } //cairo_surface_flush( cvsw->surface ); break; case WM_SIZE: if ( !cg_isxplater ) { if ( nw->bmp != 0 ) DeleteObject( nw->bmp ); hdc = GetDC( hWnd ); GetClientRect( hWnd, &r ); nw->bmp = CreateCompatibleBitmap( hdc, r.right, r.bottom ); ReleaseDC( hWnd, hdc ); } InvalidateRgn( hWnd, 0, 0 ); break; case WM_LBUTTONDOWN: event_send( OBJECT(w), "clicked", "ii", "x", LOWORD(lParam), "y", HIWORD(lParam) ); break; case WM_LBUTTONUP: event_send( OBJECT(w), "released", "ii", "x", LOWORD(lParam), "y", HIWORD(lParam) ); break; case WM_RBUTTONDOWN: event_send( OBJECT(w), "right_clicked", "ii", "x", LOWORD(lParam), "y", HIWORD(lParam) ); break; case WM_RBUTTONUP: event_send( OBJECT(w), "right_released", "ii", "x", LOWORD(lParam), "y", HIWORD(lParam) ); break; case WM_MOUSEMOVE: if ( wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON) || w->notify_flags & cNotifyMouse ) { event_send( OBJECT(w), "mouse_moved", "ii", "x", LOWORD(lParam), "y", HIWORD(lParam) ); // will this work fine here? hmm. TRACKMOUSEEVENT tme; tme.cbSize = sizeof( TRACKMOUSEEVENT ); tme.dwFlags = TME_LEAVE; tme.hwndTrack = hWnd; tme.dwHoverTime = 0; TrackMouseEvent( &tme ); } break; case WM_MOUSELEAVE: event_send( OBJECT(w), "mouse_leave", "" ); break; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
gfxWindowsSurface::gfxWindowsSurface(HWND wnd) : mOwnsDC(PR_TRUE), mForPrinting(PR_FALSE), mWnd(wnd) { mDC = ::GetDC(mWnd); Init(cairo_win32_surface_create(mDC)); }
void HippoCanvas::onPaint(WPARAM wParam, LPARAM lParam) { RECT region; if (GetUpdateRect(window_, ®ion, true)) { int regionWidth = region.right - region.left; int regionHeight = region.bottom - region.top; #if 0 g_debug("SIZING: %p paint region %d,%d %dx%d", window_, region.left, region.top, regionWidth, regionHeight); #endif // go ahead and request/resize if necessary, so we paint the right thing ensureRequestAndAllocation(); PAINTSTRUCT paint; HDC hdc = BeginPaint(window_, &paint); //g_debug("paint.fErase=%d", paint.fErase); cairo_surface_t *surface = cairo_win32_surface_create(hdc); cairo_surface_t *buffer = cairo_surface_create_similar(surface, CAIRO_CONTENT_COLOR, regionWidth, regionHeight); cairo_t *cr = cairo_create(buffer); hippo_canvas_context_win_update_pango(context_, cr); // make the buffer's coordinates look like the real coordinates cairo_translate(cr, - region.left, - region.top); // Paint a background rectangle to the buffer cairo_rectangle(cr, region.left, region.top, regionWidth, regionHeight); cairo_clip(cr); // FIXME not the right background color (on linux it's the default gtk background) // should use system color, maybe GetThemeSysColorBrush is right. Note that // this rectangle draws the little corner between the scrollbars in // addition to the viewport background. hippo_cairo_set_source_rgba32(cr, 0xffffffff); cairo_paint(cr); // Draw canvas item to the buffer if (root_ != (HippoCanvasItem*) NULL) { RECT viewport; HippoRectangle viewport_hippo; HippoRectangle region_hippo; getViewport(&viewport); hippo_rectangle_from_rect(&viewport_hippo, &viewport); hippo_rectangle_from_rect(®ion_hippo, ®ion); if (hippo_rectangle_intersect(&viewport_hippo, ®ion_hippo, ®ion_hippo)) { // we have to clip so we don't draw outside the viewport - the canvas // doesn't have its own window cairo_save(cr); cairo_rectangle(cr, region_hippo.x, region_hippo.y, region_hippo.width, region_hippo.height); cairo_clip(cr); int x, y; getCanvasOrigin(&x, &y); hippo_canvas_item_process_paint(root_, cr, ®ion_hippo, x, y); cairo_restore(cr); } } // pop the update region clip and the translation off the buffer cairo_destroy(cr); // Copy the buffer to the window cairo_t *window_cr = cairo_create(surface); cairo_rectangle(window_cr, region.left, region.top, regionWidth, regionHeight); cairo_clip(window_cr); cairo_set_source_surface(window_cr, buffer, region.left, region.top); cairo_paint(window_cr); cairo_destroy(window_cr); cairo_surface_destroy(buffer); cairo_surface_destroy(surface); EndPaint(window_, &paint); } }
static VALUE cr_win32_surface_initialize (int argc, VALUE *argv, VALUE self) { cairo_surface_t *surface = NULL; VALUE arg1, arg2, arg3, arg4; VALUE hdc, format, width, height; rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4); switch (argc) { case 1: hdc = arg1; surface = cairo_win32_surface_create (NUM2PTR (hdc)); break; case 2: width = arg1; height = arg2; surface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32, NUM2INT (width), NUM2INT (height)); break; case 3: if (NIL_P (arg1) || (rb_cairo__is_kind_of (arg1, rb_cNumeric) && NUM2INT (arg1) != CAIRO_FORMAT_RGB24)) { # if CAIRO_CHECK_VERSION(1, 4, 0) HDC win32_hdc; hdc = arg1; width = arg2; height = arg3; win32_hdc = NIL_P (hdc) ? NULL : NUM2PTR (hdc); surface = cairo_win32_surface_create_with_ddb (win32_hdc, CAIRO_FORMAT_RGB24, NUM2INT (width), NUM2INT (height)); # else rb_raise (rb_eArgError, "Cairo::Win32Surface.new(hdc, width, height) " "is available since cairo >= 1.4.0"); # endif } else { format = arg1; width = arg2; height = arg3; surface = cairo_win32_surface_create_with_dib (RVAL2CRFORMAT (format), NUM2INT (width), NUM2INT (height)); } break; case 4: { # if CAIRO_CHECK_VERSION(1, 4, 0) HDC win32_hdc; hdc = arg1; format = arg2; width = arg3; height = arg4; win32_hdc = NIL_P (hdc) ? NULL : (HDC) NUM2UINT (hdc); surface = cairo_win32_surface_create_with_ddb (win32_hdc, RVAL2CRFORMAT (format), NUM2INT (width), NUM2INT (height)); # else rb_raise (rb_eArgError, "Cairo::Win32Surface.new(hdc, format, width, height) " "is available since cairo >= 1.4.0"); # endif } break; } if (!surface) rb_cairo_check_status (CAIRO_STATUS_INVALID_FORMAT); cr_surface_check_status (surface); DATA_PTR (self) = surface; if (rb_block_given_p ()) yield_and_finish (self); return Qnil; }