|
|
| version 1.1, 2003/10/21 14:57:41 | version 1.3, 2003/11/21 07:43:52 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #include <gx.h> | #include <gx.h> |
| #include "bmpdata.h" | |
| #include "scrnmng.h" | #include "scrnmng.h" |
| // #include "pccore.h" | #include "scrndraw.h" |
| // #include "scrndraw.h" | #include "vramhdl.h" |
| // #include "palettes.h" | #include "menubase.h" |
| // #include "menu.h" | #include "nekop2.res" |
| GXDisplayProperties gx_dp; | typedef struct { |
| BOOL rotate; | |
| static HWND TagWnd = NULL; | VRAMHDL vram; |
| static BOOL TagRot = FALSE; | UINT posx; |
| static DWORD TagPosx = 0; | UINT posy; |
| static DWORD TagPosy = 0; | int width; |
| static DWORD TagWidth = 0; | int height; |
| static DWORD TagHeight = 0; | long start; |
| static long TagStart = 0; | long xalign; |
| static BYTE gx_disable = 1; | long yalign; |
| } SCRNMNG; | |
| static const TCHAR errmsg[] = STRLITERAL("Error"); | |
| typedef struct { | |
| int width; | |
| int height; | |
| } SCRNSTAT; | |
| GXDisplayProperties gx_dp; | |
| #if 0 | static SCRNMNG scrnmng; |
| void gdraws_enable(BOOL enable) { | static SCRNSTAT scrnstat; |
| static SCRNSURF scrnsurf; | |
| if (enable) { | static BYTE gx_disable = 1; |
| gx_disable &= ~2; | |
| } | |
| else { | |
| gx_disable |= 2; | |
| } | |
| } | |
| BOOL gdraws_mousepos(LPARAM *lp) { | static const TCHAR errmsg[] = STRLITERAL("Error"); |
| DWORD x, y; | |
| if (!TagRot) { | typedef struct { |
| x = LOWORD(*lp) - TagPosx; | int xalign; |
| y = HIWORD(*lp) - TagPosy; | int yalign; |
| } | int width; |
| else { | int height; |
| x = TagWidth - HIWORD(*lp) - 1 - TagPosy; | int srcpos; |
| y = LOWORD(*lp) - TagPosx; | int dstpos; |
| } DRAWRECT; | |
| static BOOL calcdrawrect(DRAWRECT *dr, VRAMHDL s, const RECT_T *rt) { | |
| int pos; | |
| dr->xalign = scrnmng.xalign; | |
| dr->yalign = scrnmng.yalign; | |
| dr->srcpos = 0; | |
| dr->dstpos = scrnmng.start; | |
| dr->width = min(scrnmng.width, s->width); | |
| dr->height = min(scrnmng.height, s->height); | |
| if (rt) { | |
| pos = max(rt->left, 0); | |
| dr->srcpos += pos; | |
| dr->dstpos += pos * dr->xalign; | |
| dr->width = min(rt->right, dr->width) - pos; | |
| pos = max(rt->top, 0); | |
| dr->srcpos += pos * s->width; | |
| dr->dstpos += pos * dr->yalign; | |
| dr->height = min(rt->bottom, dr->height) - pos; | |
| } | } |
| if ((x >= TagWidth) || (y >= TagHeight)) { | if ((dr->width <= 0) || (dr->height <= 0)) { |
| return(FAILURE); | return(FAILURE); |
| } | } |
| *lp = (x & 0xffff) | ((y << 16) & 0xffff0000); | |
| return(SUCCESS); | return(SUCCESS); |
| } | } |
| void gdraws_keybinds(struct GXKeyList *gxkey) { | void scrnmng_keybinds(struct GXKeyList *gxkey) { |
| short tmp; | short tmp; |
| if (TagRot) { | if (scrnmng.rotate) { |
| tmp = gxkey->vkLeft; | tmp = gxkey->vkLeft; |
| gxkey->vkLeft = gxkey->vkDown; | gxkey->vkLeft = gxkey->vkDown; |
| gxkey->vkDown = gxkey->vkRight; | gxkey->vkDown = gxkey->vkRight; |
| Line 65 void gdraws_keybinds(struct GXKeyList *g | Line 85 void gdraws_keybinds(struct GXKeyList *g |
| } | } |
| } | } |
| long gdraws_getyalign(void) { | |
| if (!TagRot) { | |
| return(gx_dp.cbyPitch); | |
| } | |
| else { | |
| return(gx_dp.cbxPitch); | |
| } | |
| } | |
| #endif | |
| // ---- | |
| typedef struct { | |
| int width; | |
| int height; | |
| } SCRNSTAT; | |
| static SCRNSTAT scrnstat; | |
| static SCRNSURF scrnsurf; | |
| // ---- | // ---- |
| Line 98 void scrnmng_initialize(void) { | Line 96 void scrnmng_initialize(void) { |
| BOOL scrnmng_create(HWND hWnd, LONG width, LONG height) { | BOOL scrnmng_create(HWND hWnd, LONG width, LONG height) { |
| BOOL ret = SUCCESS; | TCHAR msg[32]; |
| if ((width <= 0) || (height <= 0)) { | if ((width <= 0) || (height <= 0)) { |
| return(FAILURE); | return(FAILURE); |
| Line 122 BOOL scrnmng_create(HWND hWnd, LONG widt | Line 120 BOOL scrnmng_create(HWND hWnd, LONG widt |
| if ((gx_dp.cxWidth >= (DWORD)width) && | if ((gx_dp.cxWidth >= (DWORD)width) && |
| (gx_dp.cyHeight >= (DWORD)height)) { | (gx_dp.cyHeight >= (DWORD)height)) { |
| TagRot = FALSE; | scrnmng.rotate = FALSE; |
| } | } |
| else if ((gx_dp.cxWidth >= (DWORD)height) && | else if ((gx_dp.cxWidth >= (DWORD)height) && |
| (gx_dp.cyHeight >= (DWORD)width)) { | (gx_dp.cyHeight >= (DWORD)width)) { |
| TagRot = TRUE; | scrnmng.rotate = TRUE; |
| } | } |
| else { | else { |
| TCHAR msg[32]; | |
| wsprintf(msg, STRLITERAL("Required %dx%d..."), width, height); | wsprintf(msg, STRLITERAL("Required %dx%d..."), width, height); |
| MessageBox(hWnd, msg, errmsg, MB_OK | MB_ICONSTOP); | MessageBox(hWnd, msg, errmsg, MB_OK | MB_ICONSTOP); |
| return(FAILURE); | return(FAILURE); |
| } | } |
| if (!TagRot) { | if (!scrnmng.rotate) { |
| TagPosx = ((gx_dp.cxWidth - width) / 2); | scrnmng.posx = ((gx_dp.cxWidth - width) / 2); |
| TagPosy = ((gx_dp.cyHeight - height) / 2); | scrnmng.posy = ((gx_dp.cyHeight - height) / 2); |
| TagStart = TagPosx * gx_dp.cbxPitch + TagPosy * gx_dp.cbyPitch; | scrnmng.start = scrnmng.posx * gx_dp.cbxPitch + |
| TagWidth = width; | scrnmng.posy * gx_dp.cbyPitch; |
| TagHeight = height; | scrnmng.width = width; |
| scrnmng.height = height; | |
| scrnmng.xalign = gx_dp.cbxPitch; | |
| scrnmng.yalign = gx_dp.cbyPitch; | |
| } | } |
| else { | else { |
| TagPosx = ((gx_dp.cxWidth - height) / 2); | scrnmng.posx = ((gx_dp.cxWidth - height) / 2); |
| TagPosy = ((gx_dp.cyHeight - width) / 2); | scrnmng.posy = ((gx_dp.cyHeight - width) / 2); |
| TagStart = ((TagPosy + width - 1) * gx_dp.cbyPitch) + | scrnmng.start = ((scrnmng.posy + width - 1) * gx_dp.cbyPitch) + |
| (TagPosx * gx_dp.cbxPitch); | (scrnmng.posx * gx_dp.cbxPitch); |
| TagWidth = width; | scrnmng.width = width; |
| TagHeight = height; | scrnmng.height = height; |
| scrnmng.xalign = -gx_dp.cbyPitch; | |
| scrnmng.yalign = gx_dp.cbxPitch; | |
| } | } |
| gx_disable = 0; | gx_disable = 0; |
| scrnmng_clear(TRUE); | |
| return(SUCCESS); | return(SUCCESS); |
| } | } |
| Line 165 RGB16 scrnmng_makepal16(RGB32 pal32) { | Line 168 RGB16 scrnmng_makepal16(RGB32 pal32) { |
| RGB16 ret; | RGB16 ret; |
| ret = (pal32.p.r & 0xf8) << 8; | ret = (pal32.p.r & 0xf8) << 8; |
| #if defined(SIZE_QVGA) | |
| ret += (pal32.p.g & 0xfc) << (3 + 16); | ret += (pal32.p.g & 0xfc) << (3 + 16); |
| #else | |
| ret += (pal32.p.g & 0xfc) << 3; | |
| #endif | |
| ret += pal32.p.b >> 3; | ret += pal32.p.b >> 3; |
| return(ret); | return(ret); |
| } | } |
| Line 185 const SCRNSURF *scrnmng_surflock(void) { | Line 192 const SCRNSURF *scrnmng_surflock(void) { |
| if (gx_disable) { | if (gx_disable) { |
| return(NULL); | return(NULL); |
| } | } |
| scrnsurf.ptr = (BYTE *)GXBeginDraw() + TagStart; | if (scrnmng.vram == NULL) { |
| if (!TagRot) { | scrnsurf.ptr = (BYTE *)GXBeginDraw() + scrnmng.start; |
| scrnsurf.xalign = gx_dp.cbxPitch; | scrnsurf.xalign = scrnmng.xalign; |
| scrnsurf.yalign = gx_dp.cbyPitch; | scrnsurf.yalign = scrnmng.yalign; |
| } | } |
| else { | else { |
| scrnsurf.xalign = -gx_dp.cbyPitch; | scrnsurf.ptr = scrnmng.vram->ptr; |
| scrnsurf.yalign = gx_dp.cbxPitch; | scrnsurf.xalign = 2; |
| scrnsurf.yalign = scrnmng.vram->yalign; | |
| } | } |
| scrnsurf.width = min(scrnstat.width, 640); | scrnsurf.width = min(scrnstat.width, 640); |
| scrnsurf.height = min(scrnstat.height, 400); | scrnsurf.height = min(scrnstat.height, 400); |
| Line 201 const SCRNSURF *scrnmng_surflock(void) { | Line 209 const SCRNSURF *scrnmng_surflock(void) { |
| return(&scrnsurf); | return(&scrnsurf); |
| } | } |
| static void draw_onmenu(void) { | |
| RECT_T rt; | |
| DRAWRECT dr; | |
| const BYTE *p; | |
| BYTE *q; | |
| const BYTE *a; | |
| int salign; | |
| int dalign; | |
| int r; | |
| rt.left = 0; | |
| rt.top = 0; | |
| rt.right = min(scrnstat.width, 640); | |
| rt.bottom = min(scrnstat.height, 400); | |
| #if defined(SIZE_QVGA) | |
| rt.right >>= 1; | |
| rt.bottom >>= 1; | |
| #endif | |
| if (calcdrawrect(&dr, menuvram, &rt) != SUCCESS) { | |
| return; | |
| } | |
| p = scrnmng.vram->ptr + (dr.srcpos * 2); | |
| q = (BYTE *)GXBeginDraw() + dr.dstpos; | |
| a = menuvram->alpha + dr.srcpos; | |
| salign = menuvram->width - dr.width; | |
| dalign = dr.yalign - (dr.width * dr.xalign); | |
| do { | |
| r = dr.width; | |
| do { | |
| if (a[0] == 0) { | |
| *(UINT16 *)q = *(UINT16 *)p; | |
| } | |
| p += 2; | |
| q += dr.xalign; | |
| a += 1; | |
| } while(--r); | |
| p += salign * 2; | |
| q += dalign; | |
| a += salign; | |
| } while(--dr.height); | |
| GXEndDraw(); | |
| } | |
| void scrnmng_surfunlock(const SCRNSURF *surf) { | void scrnmng_surfunlock(const SCRNSURF *surf) { |
| if (surf) { | if (surf) { |
| GXEndDraw(); | if (scrnmng.vram == NULL) { |
| GXEndDraw(); | |
| } | |
| else { | |
| if (menuvram) { | |
| draw_onmenu(); | |
| } | |
| } | |
| } | } |
| } | } |
| void scrnmng_update(void) { | void scrnmng_update(void) { |
| } | } |
| // ---- for wince | |
| void scrnmng_enable(BOOL enable) { | |
| if (enable) { | |
| gx_disable &= ~2; | |
| } | |
| else { | |
| gx_disable |= 2; | |
| } | |
| } | |
| BOOL scrnmng_mousepos(LPARAM *lp) { | |
| UINT x; | |
| UINT y; | |
| if (!scrnmng.rotate) { | |
| x = LOWORD(*lp) - scrnmng.posx; | |
| y = HIWORD(*lp) - scrnmng.posy; | |
| } | |
| else { | |
| x = scrnmng.width - HIWORD(*lp) - 1 - scrnmng.posy; | |
| y = LOWORD(*lp) - scrnmng.posx; | |
| } | |
| if ((x >= (UINT)scrnmng.width) || (y >= (UINT)scrnmng.height)) { | |
| return(FAILURE); | |
| } | |
| *lp = (x & 0xffff) | ((y << 16) & 0xffff0000); | |
| return(SUCCESS); | |
| } | |
| // ---- for menubase | |
| BOOL scrnmng_entermenu(SCRNMENU *smenu) { | |
| if (smenu == NULL) { | |
| goto smem_err; | |
| } | |
| vram_destroy(scrnmng.vram); | |
| scrnmng.vram = vram_create(scrnmng.width, scrnmng.height, FALSE, 16); | |
| if (scrnmng.vram == NULL) { | |
| goto smem_err; | |
| } | |
| scrndraw_redraw(); | |
| smenu->width = scrnmng.width; | |
| smenu->height = scrnmng.height; | |
| smenu->bpp = 16; | |
| return(SUCCESS); | |
| smem_err: | |
| return(FAILURE); | |
| } | |
| void scrnmng_leavemenu(void) { | |
| VRAM_RELEASE(scrnmng.vram); | |
| } | |
| void scrnmng_menudraw(const RECT_T *rct) { | |
| DRAWRECT dr; | |
| const BYTE *p; | |
| const BYTE *q; | |
| BYTE *r; | |
| BYTE *a; | |
| int salign; | |
| int dalign; | |
| int x; | |
| if ((gx_disable) || (menuvram == NULL)) { | |
| return; | |
| } | |
| if (calcdrawrect(&dr, menuvram, rct) != SUCCESS) { | |
| return; | |
| } | |
| p = scrnmng.vram->ptr + (dr.srcpos * 2); | |
| q = menuvram->ptr + (dr.srcpos * 2); | |
| r = (BYTE *)GXBeginDraw() + dr.dstpos; | |
| a = menuvram->alpha + dr.srcpos; | |
| salign = menuvram->width; | |
| dalign = dr.yalign - (dr.width * dr.xalign); | |
| do { | |
| x = 0; | |
| do { | |
| if (a[x]) { | |
| if (a[x] & 2) { | |
| *(UINT16 *)r = *(UINT16 *)(q + x * 2); | |
| } | |
| else { | |
| a[x] = 0; | |
| *(UINT16 *)r = *(UINT16 *)(p + x * 2); | |
| } | |
| } | |
| r += dr.xalign; | |
| } while(++x < dr.width); | |
| p += salign * 2; | |
| q += salign * 2; | |
| r += dalign; | |
| a += salign; | |
| } while(--dr.height); | |
| GXEndDraw(); | |
| } | |
| // ---- clear | |
| static void np2open_draw(BYTE *dst, BMPFILE *bf) { | |
| const BMPINFO *bi; | |
| const BYTE *pal; | |
| BMPDATA inf; | |
| BYTE *src; | |
| int bmpalign; | |
| long yalign; | |
| UINT pals; | |
| UINT16 paltbl[16]; | |
| UINT c; | |
| int x; | |
| int y; | |
| if (bf == NULL) { | |
| goto nod_err; | |
| } | |
| bi = (BMPINFO *)(bf + 1); | |
| pal = (BYTE *)(bi + 1); | |
| if (((bf->bfType[0] != 'B') && (bf->bfType[1] != 'M')) || | |
| (bmpdata_getinfo(bi, &inf) != SUCCESS) || (inf.bpp != 4)) { | |
| goto nod_err; | |
| } | |
| src = (BYTE *)bf + (LOADINTELDWORD(bf->bfOffBits)); | |
| bmpalign = bmpdata_getalign(bi); | |
| if (inf.height > 0) { | |
| src += (inf.height - 1) * bmpalign; | |
| bmpalign *= -1; | |
| } | |
| else { | |
| inf.height *= -1; | |
| } | |
| if ((scrnmng.width < inf.width) || (scrnmng.height < inf.height)) { | |
| goto nod_err; | |
| } | |
| dst += scrnmng.start; | |
| dst += ((scrnmng.width - inf.width) / 2) * scrnmng.xalign; | |
| dst += ((scrnmng.height - inf.height) / 2) * scrnmng.yalign; | |
| yalign = scrnmng.yalign - (inf.width * scrnmng.xalign); | |
| pals = LOADINTELDWORD(bi->biClrUsed); | |
| pals = min(pals, 16); | |
| ZeroMemory(paltbl, sizeof(paltbl)); | |
| for (c=0; c<pals; c++) { | |
| paltbl[c] = ((pal[c*4+2] & 0xf8) << 8) + | |
| ((pal[c*4+1] & 0xfc) << 3) + (pal[c*4+0] >> 3); | |
| } | |
| for (y=0; y<inf.height; y++) { | |
| for (x=0; x<inf.width; x++) { | |
| if (!(x & 1)) { | |
| c = src[x >> 1] >> 4; | |
| } | |
| else { | |
| c = src[x >> 1] & 15; | |
| } | |
| *(UINT16 *)dst = paltbl[c]; | |
| dst += scrnmng.xalign; | |
| } | |
| src += bmpalign; | |
| dst += yalign; | |
| } | |
| nod_err: | |
| return; | |
| } | |
| void scrnmng_clear(BOOL logo) { | |
| BMPFILE *bf; | |
| BYTE *p; | |
| BYTE *q; | |
| int y; | |
| int x; | |
| long yalign; | |
| if (gx_disable) { | |
| return; | |
| } | |
| bf = NULL; | |
| if (logo) { | |
| bf = (BMPFILE *)bmpdata_solvedata(nekop2_bmp); | |
| } | |
| p = (BYTE *)GXBeginDraw(); | |
| q = p; | |
| y = gx_dp.cyHeight; | |
| yalign = gx_dp.cbyPitch - (gx_dp.cbxPitch * gx_dp.cxWidth); | |
| do { | |
| x = gx_dp.cxWidth; | |
| do { | |
| *(UINT16 *)q = 0; | |
| q += gx_dp.cbxPitch; | |
| } while(--x); | |
| q += yalign; | |
| } while(--y); | |
| if (bf) { | |
| np2open_draw(p, bf); | |
| } | |
| GXEndDraw(); | |
| if (bf) { | |
| _MFREE(bf); | |
| } | |
| } | |