/************************************************************************************************* * roadmap_canvas_new() * Memory allocation for the new canvas */ EXTERN_C void roadmap_canvas_new () { int lBytes2Allocate; int lStride; roadmap_log( ROADMAP_INFO, "Canvas new .... \n" ); // The gAndrCanvas has to be initialized before calling this function if ( !gAndrCanvas.width || !gAndrCanvas.height ) { roadmap_log( ROADMAP_ERROR, "Canvas failed - canvas properties are incorrect or weren't set \n" ); return; } // If canvas already allocated - free the memory if ( gAndrCanvas.pCanvasBuf ) { free( gAndrCanvas.pCanvasBuf ); gAndrCanvas.pCanvasBuf = NULL; } // Allocate the memory for the canvas lStride = DEFAULT_BPP * gAndrCanvas.width; lBytes2Allocate = lStride * gAndrCanvas.height; gAndrCanvas.pCanvasBuf = ( unsigned int * ) calloc( lBytes2Allocate, 1 ); if ( !gAndrCanvas.pCanvasBuf ) { roadmap_log( ROADMAP_ERROR, "Canvas allocation failed \n" ); return; } // There are no alignment problems .... roadmap_canvas_agg_configure( ( unsigned char* ) gAndrCanvas.pCanvasBuf, gAndrCanvas.width, gAndrCanvas.height, lStride ); // Run the configurator (*RoadMapCanvasConfigure) (); // Notify about system event roadmap_device_event_notification( device_event_window_orientation_changed); // Restore keyboard if suppposed to be visible if ( roadmap_native_keyboard_visible() ) { RMNativeKBParams params; roadmap_native_keyboard_get_params( ¶ms ); roadmap_native_keyboard_show( ¶ms ); } }
HWND roadmap_canvas_new (HWND hWnd, HWND tool_bar) { HDC hdc; static BITMAPINFO* bmp_info = (BITMAPINFO*) malloc(sizeof(BITMAPINFO) + (sizeof(RGBQUAD)*3)); HBITMAP bmp; void* buf = 0; memset(bmp_info, 0, sizeof(BITMAPINFO) + sizeof(RGBQUAD)*3); if (RoadMapDrawingBuffer != NULL) { DeleteObject(SelectObject(RoadMapDrawingBuffer, OldBitmap)); DeleteDC(RoadMapDrawingBuffer); } hdc = GetDC(RoadMapDrawingArea); RoadMapDrawingArea = hWnd; GetClientRect(hWnd, &ClientRect); if (tool_bar != NULL) { RECT tb_rect; GetClientRect(tool_bar, &tb_rect); if (tb_rect.bottom < (ClientRect.bottom-2)) { ClientRect.top += tb_rect.bottom + 2; } } RoadMapDrawingBuffer = CreateCompatibleDC(hdc); bmp_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmp_info->bmiHeader.biWidth = ClientRect.right; bmp_info->bmiHeader.biHeight = ClientRect.bottom; bmp_info->bmiHeader.biPlanes = 1; bmp_info->bmiHeader.biBitCount = 16; bmp_info->bmiHeader.biCompression = BI_BITFIELDS; bmp_info->bmiHeader.biSizeImage = 0; bmp_info->bmiHeader.biXPelsPerMeter = 0; bmp_info->bmiHeader.biYPelsPerMeter = 0; bmp_info->bmiHeader.biClrUsed = 0; bmp_info->bmiHeader.biClrImportant = 0; ((DWORD*)bmp_info->bmiColors)[0] = 0xF800; ((DWORD*)bmp_info->bmiColors)[1] = 0x07E0; ((DWORD*)bmp_info->bmiColors)[2] = 0x001F; bmp = CreateDIBSection( RoadMapDrawingBuffer, bmp_info, DIB_RGB_COLORS, &buf, 0, 0 ); int stride = ((ClientRect.right * 2 + 3) >> 2) << 2; roadmap_canvas_agg_configure((unsigned char*)buf, ClientRect.right, ClientRect.bottom, -stride); OldBitmap = (HBITMAP)SelectObject(RoadMapDrawingBuffer, bmp); DeleteDC(hdc); (*RoadMapCanvasConfigure) (); return RoadMapDrawingArea; }