static int DrawYSpace ( HDC hdc, int x, int y, int w, int h, PSCOLORDIA scld) { int i; Uint8 r, g, b; HDC mdc; mdc = CreateCompatibleDCEx (hdc, scld->ysp_w, 256); for (i = 0; i < 256; i ++) { HSV2RGB (scld->clrh, scld->clrs, i, &r, &g, &b ); SetPenColor (mdc, RGB2Pixel(mdc, r, g, b)); MoveTo (mdc, 0, i); LineTo (mdc, 20 * scld->SCALE_W, i); } SetBrushColor (mdc, PIXEL_lightgray); FillBox (mdc, 21 * scld->SCALE_W, 0, scld->ysp_w * scld->SCALE_W, 256); scld->pz = scld->clrv ; SetPenColor (mdc, RGB2Pixel(mdc, 0, 0, 0)); MoveTo ( mdc, 21 * scld->SCALE_W, scld->pz); LineTo ( mdc, 28 * scld->SCALE_W, scld->pz-3); MoveTo ( mdc, 21 * scld->SCALE_W, scld->pz); LineTo ( mdc, 28 * scld->SCALE_W, scld->pz+3); StretchBlt (mdc, 0, 0, scld->ysp_w, 256, hdc, x, y, w, h, 0); DeleteMemDC (mdc); return 0; }
static int DrawColorSpace (HDC hdc, int x, int y, int w, int h, PSCOLORDIA scld) { HDC mdc; mdc = CreateCompatibleDCEx (hdc, scld->sp_w, scld->sp_h); BitBlt (scld->SpaceDC, 0,0, scld->sp_w, scld->sp_h, mdc, 0 , 0, 0); DrawIndication (mdc, scld); BitBlt (mdc, 0, 0, scld->sp_w, scld->sp_h, hdc, x, y, 0); DeleteMemDC (mdc); return 0; }
static int DrawSelSpace (HDC hdc, int x, int y, int w, int h, PSCOLORDIA scld) { Uint8 r, g, b; HDC mdc; mdc = CreateCompatibleDCEx (hdc, w, h); HSV2RGB (scld->clrh, scld->clrs, scld->clrv, &r, &g, &b); SetBrushColor (mdc, RGB2Pixel(mdc, r, g, b)); FillBox (mdc, 0, 0, w, h); BitBlt (mdc, 0, 0, w, h, hdc, x, y, 0); DeleteMemDC (mdc); return 0; }
//------------------------------------------------------------------------ platform_specific::~platform_specific() { int i; for(i = platform_support::max_images - 1; i >= 0; --i) { if(m_surf_img[i]) { #ifndef _MG_MINIMALGRAF UnloadBitmap(m_surf_img[i]); #endif free(m_surf_img[i]); m_surf_img[i]=NULL; } } if(m_surf_window) DeleteMemDC(m_surf_window); }
void DestroyAnimation (ANIMATION* anim, BOOL free_it) { ANIMATIONFRAME *tmp, *frame; frame = anim->frames; while (frame) { tmp = frame->next; if (frame->mem_dc) DeleteMemDC (frame->mem_dc); if (frame->bits) free (frame->bits); free (frame); frame = tmp; } if (free_it) free (anim); else memset (anim, 0, sizeof (ANIMATION)); }
static int ColorDlgProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam) { PSCOLORDIA scld; switch (message) { case MSG_INITDIALOG: { int i, j; Uint8 r, g, b; HDC hdc, mdc; scld = (PSCOLORDIA)lParam; SetWindowAdditionalData (hDlg, (LPARAM)scld); hdc = GetClientDC (hDlg); scld->SpaceDC = CreateCompatibleDCEx(hdc, scld->sp_w, scld->sp_h); mdc = CreateCompatibleDCEx (hdc, 360, 256); for (i = 0; i < 360; i ++) { for (j = 0; j < 256; j ++) { HSV2RGB (i, j, 200, &r, &g, &b); SetPixelRGB(mdc, i, 256-j, r, g, b); } } StretchBlt(mdc, 0, 0, 360, 256, scld->SpaceDC, 0, 0, scld->sp_w, scld->sp_h, 0); DeleteMemDC(mdc); ReleaseDC(hdc); } break; case MSG_CLOSE: EndDialog (hDlg, SELCOLOR_CANCEL); break; case MSG_DESTROY: scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg); DeleteMemDC (scld->SpaceDC); break; case MSG_PAINT: { HDC hdc; scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg); hdc = BeginPaint (hDlg); DrawAllSpace (hdc, scld); EndPaint (hDlg, hdc); return 0; } case MSG_COMMAND: { int msg = HIWORD(wParam); int id = LOWORD(wParam); scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg); if (msg == EN_CONTCHANGED) { UpdateValue (hDlg, id, scld); } switch(id) { case IDC_CANCEL: EndDialog (hDlg, SELCOLOR_CANCEL); break; case IDC_OK: scld->H = scld->clrh; scld->S = scld->clrs; scld->V = scld->clrv; HSV2RGB (scld->clrh, scld->clrs, scld->clrv, &scld->R, &scld->G, &scld->B); scld->PIXEL = RGB2Pixel (HDC_SCREEN, scld->R, scld->G, scld->B); EndDialog (hDlg, SELCOLOR_OK); break; } break; } case MSG_LBUTTONDOWN: { int x = LOSWORD (lParam); int y = HISWORD (lParam); scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg); if (PtInRect (&scld->rcSpace, x, y)) { HDC dc = GetClientDC (hDlg); scld->clrh = (x-scld->rcSpace.left)*360/RECTW(scld->rcSpace); scld->clrs = 256-(y-scld->rcSpace.top)*256/RECTH(scld->rcSpace); DrawAllSpace (dc, scld); SetValue (hDlg, scld); ReleaseDC (dc); } if (PtInRect(&scld->rcYSpace, x,y)) { HDC dc = GetClientDC (hDlg); scld->clrv = (y-scld->rcYSpace.top)*256 / RECTH(scld->rcYSpace); DrawAllSpace (dc, scld); SetValue (hDlg, scld); ReleaseDC (dc); } } } return DefaultDialogProc (hDlg, message, wParam, lParam); }
static int PlatformProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam) { switch (message) { case MSG_CREATE: { if (!hmWnd) hmWnd = hWnd; unsigned char* pdr = 0; int w,h,p; RECT r; key_down = FALSE; GetClientRect(hWnd, &r); #if RGB555 sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0x7C00, 0x3E0, 0x1F, 0x8000); #else sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0xF800, 0x7E0, 0x1F, 0x00); #endif pdr = LockDC(sdc, &r, &w, &h, &p); UnlockDC(sdc); #if RGB555 fmt = COLOR_FORMAT_RGB555; #else fmt = COLOR_FORMAT_RGB565; #endif ps_initialize(); canvas = ps_canvas_create_with_data(pdr, fmt, w, h, p); context = ps_context_create(canvas, 0); on_init(context, width, height); } break; case MSG_TIMER: on_timer(); break; case MSG_PAINT: { HDC hdc = BeginPaint(hWnd); on_draw(context); BitBlt(sdc, 0, 0, width, height, hdc, 0, 0, 0); EndPaint(hWnd, hdc); } return 0; case MSG_ERASEBKGND: return 0; case MSG_LBUTTONDOWN: { key_down = TRUE; on_mouse_event(LEFT_BUTTON_DOWN, key_conv(wParam), LOSWORD(lParam), HISWORD(lParam)); } break; case MSG_LBUTTONUP: { key_down = FALSE; on_mouse_event(LEFT_BUTTON_UP, key_conv(wParam), LOSWORD(lParam), HISWORD(lParam)); } break; case MSG_MOUSEMOVE: { DWORD k = key_conv(wParam); if (key_down) k |= EVT_LBUTTON; on_mouse_event(MOUSE_MOVE, k, LOSWORD(lParam), HISWORD(lParam)); } break; case MSG_KEYDOWN: on_key_event(KEY_EVENT_DOWN, get_virtual_key(wParam)); break; case MSG_KEYUP: on_key_event(KEY_EVENT_UP, get_virtual_key(wParam)); break; case MSG_SIZECHANGED: { RECT r; int w,h,p; unsigned char* pdr = 0; ps_canvas* old_canvas = 0; RECT* rc = (RECT*)lParam; width = RECTWP(rc); height = RECTHP(rc); if (sdc) DeleteMemDC(sdc); if (width < 1) width = 1; if (height < 1) height = 1; #if RGB555 sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0x7C00, 0x3E0, 0x1F, 0x8000); #else sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0xF800, 0x7E0, 0x1F, 0x00); #endif GetClientRect(hWnd, &r); pdr = LockDC(sdc, &r, &w, &h, &p); UnlockDC(sdc); canvas = ps_canvas_create_with_data(pdr, fmt, w, h, p); old_canvas = ps_context_set_canvas(context, canvas); ps_canvas_unref(old_canvas); on_size(width, height); } break; case MSG_CLOSE: on_term(context); ps_context_unref(context); ps_canvas_unref(canvas); ps_shutdown(); DeleteMemDC(sdc); DestroyMainWindow (hWnd); PostQuitMessage (hWnd); return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam); }
//------------------------------------------------------------------------ bool platform_support::init(unsigned width, unsigned height, unsigned flags) { m_window_flags = flags; unsigned wflags = MEMDC_FLAG_SWSURFACE; if(m_window_flags & window_hw_buffer) { wflags = MEMDC_FLAG_HWSURFACE; } /* if(m_window_flags & window_resize) { wflags |= GAL_RESIZABLE; } */ //SDL_WM_SetCaption(m_caption, 0); if(m_specific->m_surf_window) DeleteMemDC(m_specific->m_surf_window); #if 0 printf("init memdc: w=%d, h=%d, m_bpp=%d, wflags=%d\n", width, height, m_bpp, wflags); printf("init memdc: m_rmask=%x, m_gmask=%x, m_bmask=%x, m_amask=%x\n", m_specific->m_rmask, m_specific->m_gmask, m_specific->m_bmask, m_specific->m_amask); #endif m_specific->m_surf_window = CreateMemDC( width, height, m_bpp, wflags, m_specific->m_rmask, m_specific->m_gmask, m_specific->m_bmask, m_specific->m_amask); if(m_specific->m_surf_window == 0) { fprintf(stderr, "Unable to create image buffer %dx%d %d bpp: %s\n", width, height, m_bpp, //SDL_GetError()); "failed"); return false; } int pitch = width * (m_bpp/8); //printf("init, pitch=%d\n", pitch); #if 0 m_rbuf_window.attach((unsigned char*)PIXEL(SURFACE(m_specific->m_surf_window)), width, height, m_flip_y ? -pitch:pitch); #else m_rbuf_window.attach((unsigned char*)LockDC(m_specific->m_surf_window, NULL, NULL, NULL, NULL), width, height, m_flip_y ? -pitch:pitch); #endif if(!m_specific->m_initialized) { m_initial_width = width; m_initial_height = height; on_init(); m_specific->m_initialized = true; } on_resize(m_rbuf_window.width(), m_rbuf_window.height()); m_specific->m_update_flag = true; return true; }