mrpdev/smp_stylebox.c

414 lines
9.9 KiB
C
Raw Normal View History

2019-03-21 13:34:44 +08:00
#include "smp_stylebox.h"
#include "smp.h"
#include "bmp.h"
#include "mrc_exb.h"
#include "types.h"
#define SMP_BOX_RECOVER_SPEED 3 //<2F><><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ļ<EFBFBD><C4BC>ٶȣ<D9B6><C8A3><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F>Σ<EFBFBD>
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>Ϣ*/
typedef struct SMP_ItemData{
int index; //<2F><><EFBFBD><EFBFBD>
int width; //<2F><><EFBFBD><EFBFBD>
int height; //<2F>߶<EFBFBD>
HBITMAP hBmp; //ͼƬ<CDBC><C6AC><EFBFBD><EFBFBD>
}SMPITEMDATA, *PSMPITEMDATA;
/*<2A><><EFBFBD>ڽṹ<DABD><E1B9B9>*/
typedef struct
{
int num; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BOOL focus; //<2F>Ƿ<EFBFBD><C7B7>н<EFBFBD><D0BD><EFBFBD>
int onewidth; //һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int oneheight;
int rows; //<2F><>
int stand; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int topmagin; //<2F><><EFBFBD><EFBFBD>ʱ <20><><EFBFBD><EFBFBD><EFBFBD>߾<EFBFBD>
int leftmagin;
int highlight; //<2F>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>
}BOXDATA, *PBOXDATA;
#define SMP_STYLEBOX_MAX 10
static SMPITEMDATA BoxItem[SMP_STYLEBOX_MAX]; //<2F>Ź<EFBFBD><C5B9><EFBFBD>ÿһ<C3BF><D2BB>
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ*/
VOID SMP_Stylewnd_SetItem(HWND hWnd, const DWORD* bmps, int size)
{
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
int i;
if(size>SMP_STYLEBOX_MAX || !bmps)
return;
for (i=0; i<size; i++)
{
BoxItem[i].index = i;
BoxItem[i].hBmp = SGL_LoadBitmap(bmps[i], &BoxItem[i].width, &BoxItem[i].height);
}
pBoxData->num = size;
pBoxData->highlight = 4; //Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD>ý<EFBFBD><C3BD><EFBFBD>
pBoxData->onewidth = _WIDTH(hWnd)/3;
pBoxData->oneheight = _HEIGHT(hWnd)/3;
pBoxData->topmagin = 0;
pBoxData->leftmagin = 0;
pBoxData->rows = 3; //Ĭ<><C4AC>3*3 <20>Ź<EFBFBD><C5B9><EFBFBD>
pBoxData->stand = 3;
}
VOID SMP_Update_OneBox(HWND hWnd, int index)
{
int hx, hy; //<2F><><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>꣨hx, hy<68><79>
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
hx = _LEFT(hWnd) + pBoxData->onewidth*(index%3);
hy = _TOP(hWnd) + pBoxData->oneheight*(index/3);
if (hy + pBoxData->topmagin >= _TOP(hWnd) && hy+pBoxData->topmagin+pBoxData->highlight <= _TOP(hWnd)+_HEIGHT(hWnd))
{
if (pBoxData->highlight == index)//<2F><><EFBFBD><EFBFBD>
GAL_FillRoundRrct(hx+(pBoxData->onewidth - BoxItem[index].width)/2 + pBoxData->leftmagin-3,
hy+(pBoxData->oneheight - BoxItem[index].height)/2 + pBoxData->topmagin-2,
BoxItem[index].width+6, BoxItem[index].height+4, COLOR_focus);
else
GAL_FillBox(PHYSICALGC, hx, hy, pBoxData->onewidth, pBoxData->oneheight, _BGCOLOR(hWnd));
mrc_bitmapShowEx(BoxItem[index].hBmp,
hx+(pBoxData->onewidth - BoxItem[index].width)/2 + pBoxData->leftmagin,
hy+(pBoxData->oneheight - BoxItem[index].height)/2 + pBoxData->topmagin,
BoxItem[index].width, BoxItem[index].width, BoxItem[index].height, BM_TRANSPARENT, 0, 0);
GAL_FlushRegion(PHYSICALGC, hx + pBoxData->leftmagin, hy + pBoxData->topmagin, pBoxData->onewidth, pBoxData->oneheight);
}
}
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEA3AC>Ҫ<EFBFBD><D2AA>ƽ<EFBFBD><C6BD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>ʱ<EFBFBD><CAB1>
* û<EFBFBD>в<EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>ˢ<EFBFBD>£<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ػ<EFBFBD>ˢ<EFBFBD><EFBFBD>
*/
VOID SMP_DrawStyleBox(HWND hWnd)
{
int i, j, index = 0;
int x, y, w, h; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EAA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int hx, hy; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
x = _LEFT(hWnd);
y = _TOP(hWnd);
w = _WIDTH(hWnd);
h = _HEIGHT(hWnd);
hy = y;
for (i=0; i<pBoxData->rows; i++)//<2F><>
{
hx = x;
for (j=0; j<pBoxData->stand; j++)//<2F><>
{
if (pBoxData->highlight == index)//<2F><><EFBFBD><EFBFBD>
GAL_FillRoundRrct(hx+(pBoxData->onewidth - BoxItem[index].width)/2 + pBoxData->leftmagin-3,
hy+(pBoxData->oneheight - BoxItem[index].height)/2 + pBoxData->topmagin-2,
BoxItem[index].width+6, BoxItem[index].height+4, COLOR_focus);
mrc_bitmapShowEx(BoxItem[index].hBmp,
hx+(pBoxData->onewidth - BoxItem[index].width)/2 + pBoxData->leftmagin,
hy+(pBoxData->oneheight - BoxItem[index].height)/2 + pBoxData->topmagin,
BoxItem[index].width, BoxItem[index].width, BoxItem[index].height, BM_TRANSPARENT, 0, 0);
hx+=pBoxData->onewidth;
index++;
}
hy+=pBoxData->oneheight;
}
}
/*<2A><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD> <20>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD>¼<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>(int)lParam<61><6D><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
int SMP_Box_GetHilightId(HWND hWnd)
{
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
return pBoxData->highlight;
}
/*<2A>ɿ<EFBFBD><C9BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߰<EFBFBD><DFB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭλ<D4AD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ָ<EFBFBD>ԭλ*/
VOID SMP_Box_RecoverLoaction(HWND hWnd)
{
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
int i;
//int x_step = 1;
int y_step = 1; //<2F><EFBFBD><E4B5B1><EFBFBD>ٶ<EFBFBD>
if(pBoxData->leftmagin==0 && pBoxData->topmagin==0)
return;
if(pBoxData->topmagin>0)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
for (i=0; i<=pBoxData->topmagin; i++, y_step+=SMP_BOX_RECOVER_SPEED)//<2F><> <20>ٶ<EFBFBD>Ϊ1
{
if(pBoxData->topmagin - y_step<0)
pBoxData->topmagin = 0;
else
pBoxData->topmagin-= y_step;
SGL_TRACE("%d", pBoxData->topmagin);
SGL_UpdateWindow(hWnd);
}
}else if(pBoxData->topmagin<0)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
for(i=0; i>=pBoxData->topmagin; i--, y_step+=SMP_BOX_RECOVER_SPEED)
{
if(pBoxData->topmagin + y_step>0)
pBoxData->topmagin = 0;
else
pBoxData->topmagin+=y_step;
SGL_TRACE("%d", pBoxData->topmagin);
SGL_UpdateWindow(hWnd);
}
}
}
LRESULT SMP_Box_WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
//static int start_x = 0;
static int start_y = 0;
static int click_count = 0;
static int key_step = 0; //<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><E2BBAC><EFBFBD>ٶ<EFBFBD>
switch(Msg)
{
case WM_CREATE:
{
//request memory and initialize members
pBoxData = (PBOXDATA)SGL_MALLOC(sizeof(BOXDATA));
if(!pBoxData){
SGL_TRACE("%s, %d: memory out\n", __FILE__, __LINE__);
return 1;
}
SGL_MEMSET(pBoxData, 0, sizeof(BOXDATA));
_SET_WINDATA(hWnd, pBoxData);
return 0;
}
case WM_DESTROY:
{
if(pBoxData) SGL_FREE(pBoxData);
return 0;
}
case WM_SHOW:
{
return 0;
}
case WM_PAINT:
{
_BGCOLOR(hWnd) = 0x00ddeeff;
GAL_FillBox(PHYSICALGC, _LEFT(hWnd), _TOP(hWnd), _WIDTH(hWnd), _HEIGHT(hWnd), _BGCOLOR(hWnd));
SMP_DrawStyleBox(hWnd);
return 0;
}
case WM_MOUSEDOWN:
{
int index_x = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>(index_x,index_y)
int index_y = 0;
int oldhl = pBoxData->highlight; //<2F>ɸ<EFBFBD><C9B8><EFBFBD>ͼ<EFBFBD><CDBC>
index_x = ((int)wParam)/pBoxData->onewidth;
index_y = ((int)lParam)/pBoxData->oneheight;
pBoxData->highlight = (index_x+3*index_y);
if (oldhl == pBoxData->highlight)
{
click_count ++;
SGL_NotifyParent(hWnd, SMP_BOXI_CLICKED, pBoxData->highlight);
}
else if (oldhl != pBoxData->highlight)//<2F><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
{
click_count = 1;
SMP_Update_OneBox(hWnd, oldhl); //ˢ<><CBA2>ͼ<EFBFBD><CDBC>
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
}
//λ<>ø<EFBFBD>ԭ
if (!pBoxData->leftmagin|| !pBoxData->topmagin)
SMP_Box_RecoverLoaction(hWnd);
//////////////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>ǰ<EFBFBD><C7B0>Y<EFBFBD><59><EFBFBD><EFBFBD>
start_y = (int)lParam;
return 0;
}
case WM_MOUSEMOVE:
{
//pBoxData->leftmagin = ((int)wParam - start_x);
pBoxData->topmagin = ((int)lParam - start_y);
SGL_UpdateWindow(hWnd);
SGL_NotifyParent(hWnd, SMP_BOXI_MOUSEMOVE, 0);
return 0;
}
case WM_MOUSEUP:
{
int index_x = 0;
int index_y = 0;
int oldhl = pBoxData->highlight;
index_x = ((int)wParam)/pBoxData->onewidth;
index_y = ((int)lParam)/pBoxData->oneheight;
pBoxData->highlight = (index_x+3*index_y);
if (oldhl == pBoxData->highlight)
{
if (click_count == 2)//<2F>ڶ<EFBFBD><DAB6>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD>
{
click_count = 1;
SGL_NotifyParent(hWnd, SMP_BOXI_SELECTED, pBoxData->highlight);
}
}else if (oldhl != pBoxData->highlight)//<2F><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
{
SMP_Update_OneBox(hWnd, oldhl); //ˢ<><CBA2>ͼ<EFBFBD><CDBC>
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
}
//λ<>ø<EFBFBD>ԭ
if (!pBoxData->leftmagin|| !pBoxData->topmagin)
SMP_Box_RecoverLoaction(hWnd);
return 0;
}
case WM_KEYDOWN:
case WM_KEYDOWNREPEAT:
{
int oldhl = pBoxData->highlight;
switch(wParam)
{
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>*/
case MR_KEY_UP:
{
if (pBoxData->highlight>2)
pBoxData->highlight-=3;
else
pBoxData->highlight+=6;
SMP_Update_OneBox(hWnd, oldhl); //ˢ<><CBA2>ͼ<EFBFBD><CDBC>
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
return 1;
}
case MR_KEY_DOWN:
{
if (pBoxData->highlight<6)
pBoxData->highlight+=3;
else
pBoxData->highlight-=6;
SMP_Update_OneBox(hWnd, oldhl); //ˢ<><CBA2>ͼ<EFBFBD><CDBC>
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
return 1;
}
case MR_KEY_LEFT:
{
if (pBoxData->highlight>0)
pBoxData->highlight--;
else
pBoxData->highlight = 8;
SMP_Update_OneBox(hWnd, oldhl); //ˢ<><CBA2>ͼ<EFBFBD><CDBC>
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
return 1;
}
case MR_KEY_RIGHT:
{
if (pBoxData->highlight<8)
pBoxData->highlight++;
else
pBoxData->highlight = 0;
SMP_Update_OneBox(hWnd, oldhl); //ˢ<><CBA2>ͼ<EFBFBD><CDBC>
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
return 1;
}
case MR_KEY_2://<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><E2A3AC><EFBFBD>ϻ<EFBFBD><CFBB><EFBFBD>
{
if(pBoxData->topmagin>(-_HEIGHT(hWnd))+30)
{
key_step +=5;
pBoxData->topmagin -= key_step;
SGL_UpdateWindow(hWnd);
SGL_NotifyParent(hWnd, SMP_BOXI_MOUSEMOVE, 0);
}
return 1;
}
case MR_KEY_8://<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><E2A3AC><EFBFBD>»<EFBFBD><C2BB><EFBFBD>
{
if(pBoxData->topmagin<_HEIGHT(hWnd)-30)
{
key_step +=5;
pBoxData->topmagin += key_step;
SGL_UpdateWindow(hWnd);
SGL_NotifyParent(hWnd, SMP_BOXI_MOUSEMOVE, 0);
}
return 1;
}
}
return 0;
}
case WM_KEYUP:
{
/*ѡ<><D1A1>*/
if(wParam == MR_KEY_SELECT)
{
SGL_NotifyParent(hWnd, SMP_BOXI_SELECTED, pBoxData->highlight);
return 1;
}
//λ<>ø<EFBFBD>ԭ
if (!pBoxData->leftmagin|| !pBoxData->topmagin)
SMP_Box_RecoverLoaction(hWnd);
key_step = 0;
}
// case WM_COMMAND:
// {
// WORD id = LOWORD(wParam);
// WORD code = HIWORD(wParam);
// switch(id)
// {
// case WM_COMMAND:
// {
// if (code == WM_COMMAND)
// {
// //
// }
// break;
// }
// }
// return 0;
// }
case WM_SETFOCUS:
case WM_KILLFOCUS:
{
SGL_UpdateWindow(hWnd);
break;
}
}
return 0;
}