OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [demos/] [mwin/] [malpha.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*
2
 * Copyright (c) 2000 Greg Haerr <greg@censoft.com>
3
 *
4
 * Microwindows alpha blending demo
5
 *
6
 * This demo requires UPDATEREGIONS=N in microwin/src/config
7
 */
8
#include "windows.h"
9
#include "wintern.h"            /* for MwSetDesktopWallpaper*/
10
#include "wintools.h"
11
 
12
extern MWIMAGEHDR image_car8;
13
 
14
#define APPCLASS        "test"
15
 
16
/* forward decls*/
17
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wp,LPARAM lp);
18
LRESULT CALLBACK ChildWndProc(HWND hwnd,UINT uMsg,WPARAM wp,LPARAM lp);
19
 
20
int
21
RegisterAppClass(void)
22
{
23
        WNDCLASS        wc;
24
 
25
        wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;
26
        wc.lpfnWndProc = (WNDPROC)WndProc;
27
        wc.cbClsExtra = 0;
28
        wc.cbWndExtra = 0;
29
        wc.hInstance = 0;
30
        wc.hIcon = 0; /*LoadIcon(GetHInstance(), MAKEINTRESOURCE( 1));*/
31
        wc.hCursor = 0; /*LoadCursor(NULL, IDC_ARROW);*/
32
        wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
33
        wc.lpszMenuName = NULL;
34
        wc.lpszClassName =  APPCLASS;
35
        RegisterClass( &wc);
36
 
37
        return 1;
38
}
39
 
40
HWND
41
CreateAppWindow(void)
42
{
43
        HWND    hwnd;
44
        int     width, height;
45
        RECT    r;
46
        static int nextid = 0;
47
 
48
        GetWindowRect(GetDesktopWindow(), &r);
49
        width = height = r.right / 2;
50
 
51
        hwnd = CreateWindowEx(WS_EX_LAYERED, APPCLASS,
52
                "Microwindows Alpha Blending",
53
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
54
                CW_USEDEFAULT, CW_USEDEFAULT,
55
                width, height,
56
                NULL, (HMENU)++nextid, NULL, NULL);
57
 
58
        return hwnd;
59
}
60
 
61
LRESULT CALLBACK
62
WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
63
{
64
        PAINTSTRUCT     ps;
65
        HWND            sibwp;
66
        HDC             hdcMem;
67
        HBITMAP         hbmp, hbmpOrg;
68
        HBRUSH          hbr;
69
        RECT            rc;
70
        extern int mwpaintSerial;
71
 
72
        switch(msg) {
73
        case WM_ERASEBKGND:
74
                /* don't erase with screen dc, must alpha blend bkgnd*/
75
                return 1;
76
 
77
        case WM_PAINT:
78
                /* NOTE: this routine needs to be generalized
79
                 * for arbitrary deep child relationships and
80
                 * moved into the Microwindows kernel.  In addition,
81
                 * the lower window repainting needs to occur
82
                 * offscreen and alpha blended offscreen with
83
                 * a final blit to the device screen.
84
                 */
85
                /* force NC painting - current NC regions don't work
86
                 * with this alpha blend algorithm
87
                 */
88
                mwforceNCpaint = TRUE;
89
 
90
                /* repaint lower windows before alpha blending this window*/
91
                ++hwnd->unmapcount;     /* tricky don't clip this window*/
92
                SendMessage(rootwp, WM_PAINT, 0, 0);
93
                for(sibwp=hwnd->siblings; sibwp; sibwp=sibwp->siblings)
94
                        SendMessage(sibwp, WM_PAINT, 0, 0);
95
                --hwnd->unmapcount;
96
 
97
                /* then queue repaint for higher windows*/
98
                for(sibwp=hwnd->parent->children; sibwp != hwnd;
99
                                                        sibwp=sibwp->siblings)
100
                        /* don't paint if already painted by above code*/
101
                        if(sibwp->paintSerial != mwpaintSerial)
102
                                PostMessage(sibwp, WM_PAINT, 0, 0);
103
 
104
                /* now paint this window offscreen and blend with screen*/
105
                BeginPaint(hwnd, &ps);
106
                GetClientRect(hwnd, &rc);
107
 
108
                /* redirect painting to offscreen dc*/
109
                hdcMem = CreateCompatibleDC(ps.hdc);
110
                hbmp = CreateCompatibleBitmap(hdcMem, rc.right, rc.bottom);
111
                hbmpOrg = SelectObject(hdcMem, hbmp);
112
 
113
                /* paint window to offscreen*/
114
                hbr = (HBRUSH)GetClassLong(hwnd, GCL_HBRBACKGROUND);
115
                FillRect(hdcMem, &rc, hbr);
116
                SelectObject(hdcMem, GetStockObject(DEFAULT_GUI_FONT));
117
                SetBkMode(hdcMem, TRANSPARENT);
118
#define TEXTSTRING      "This demonstrates alpha blending"
119
                TextOut(hdcMem, 0, 20, TEXTSTRING, strlen(TEXTSTRING));
120
 
121
                /* alpha blend blit offscreen map with physical screen*/
122
                BitBlt(ps.hdc, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0,
123
                        MWROP_BLENDCONSTANT | 150);
124
                DeleteObject(SelectObject(hdcMem, hbmpOrg));
125
                DeleteDC(hdcMem);
126
 
127
                EndPaint(hwnd, &ps);
128
                break;
129
 
130
        default:
131
                return DefWindowProc( hwnd, msg, wp, lp);
132
        }
133
        return( 0);
134
}
135
 
136
int WINAPI
137
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
138
        int nShowCmd)
139
{
140
        MSG msg;
141
 
142
        /* Force XORMOVE window redraw algorithm, required
143
         * for this version of alpha blend painting
144
         */
145
        mwERASEMOVE = FALSE;
146
 
147
        RegisterAppClass();
148
 
149
        /* set background wallpaper*/
150
        MwSetDesktopWallpaper(&image_car8);
151
 
152
        /* must update root window until alpha blend blitting
153
         * uses off screen memory for hidden windows, rather than
154
         * screen memory*/
155
        UpdateWindow(GetDesktopWindow());
156
 
157
        CreateAppWindow();
158
        CreateAppWindow();
159
 
160
        /* type ESC to quit...*/
161
        while( GetMessage(&msg, NULL, 0, 0)) {
162
                TranslateMessage(&msg);
163
                DispatchMessage(&msg);
164
        }
165
        return 0;
166
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.