Beispiel #1
0
int task_led_second_handler(void *task, const void *msg)
{
    if (MSG_TIMER_1S == SYS_MSG) {
        if (g_is_second_led_on) {
            bsp_led_off(g_current_led);
            g_is_second_led_on = FALSE;
        } else {
            bsp_led_on(g_current_led);
            g_is_second_led_on = TRUE;
        }
    } else if (MSG_KEY_PRESS == SYS_MSG) {
        bsp_led_off(g_current_led);
        switch (get_virtual_key())
        {
        case VKEY_0: g_current_led = LED_RED; break;
        case VKEY_1: g_current_led = LED_YELLOW; break;
        case VKEY_2: g_current_led = LED_GREEN; break;
        case VKEY_3: g_current_led = LED_BLUE; break;
        default: break;
        }
    }

    return OSM_IGNORE;
}
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);
}