📄 widget_effectvga.c
字号:
int Len = strlen(acBuffer);
acBuffer[Len - 1] = '1' + i;
DROPDOWN_AddString(_ahWin[DROPDOWN0], acBuffer);
}
/* Init edit widget */
EDIT_SetText(_ahWin[EDIT0], "Edit");
/* Init listbox widget */
LISTBOX_SetAutoScrollV(_ahWin[LISTBOX0], 1);
for (i = 0; i < 4; i++) {
char acBuffer[] = {"Item x"};
int Len = strlen(acBuffer);
acBuffer[Len - 1] = '1' + i;
LISTBOX_AddString(_ahWin[LISTBOX0], acBuffer);
}
/* Init listview widget */
for (i = 0; i < 2; i++) {
char acBuffer[] = {"Col. x"};
int Len = strlen(acBuffer);
acBuffer[Len - 1] = '1' + i;
LISTVIEW_AddColumn(_ahWin[LISTVIEW0], 60, acBuffer, GUI_TA_CENTER);
}
for (i = 0; i < 9; i++) {
int j;
LISTVIEW_AddRow(_ahWin[LISTVIEW0], NULL);
for (j = 0; j < (int)LISTVIEW_GetNumColumns(_ahWin[LISTVIEW0]); j++) {
char acBuffer[] = {"Rx/Cx"};
acBuffer[1] = '1' + i;
acBuffer[4] = '1' + j;
LISTVIEW_SetItemText(_ahWin[LISTVIEW0], j, i, acBuffer);
}
}
LISTVIEW_SetGridVis(_ahWin[LISTVIEW0], 1);
SCROLLBAR_CreateAttached(_ahWin[LISTVIEW0], SCROLLBAR_CF_VERTICAL);
/* Init multiedit widget */
MULTIEDIT_SetText(_ahWin[MULTIEDIT0], "This text could be modified by the MULTIEDIT widget");
MULTIEDIT_SetWrapWord(_ahWin[MULTIEDIT0]);
MULTIEDIT_SetAutoScrollV(_ahWin[MULTIEDIT0], 1);
/* Init progbar widget */
WIDGET_SetEffect(_ahWin[PROGBAR0], &WIDGET_Effect_3D);
/* Init graph widget */
for (i = 0; i < GUI_COUNTOF(_aColor); i++) {
_aValue[i] = rand() % 95;
_ahData[i] = GRAPH_DATA_YT_Create(_aColor[i], 500, 0, 0);
GRAPH_AttachData(_ahWin[GRAPH0], _ahData[i]);
}
GRAPH_SetGridDistY(_ahWin[GRAPH0], 25);
GRAPH_SetGridVis(_ahWin[GRAPH0], 1);
GRAPH_SetGridFixedX(_ahWin[GRAPH0], 1);
GRAPH_SetBorder(_ahWin[GRAPH0], 20, 4, 5, 4);
/* Create and add vertical scale of graph widget */
hScaleV = GRAPH_SCALE_Create(18, GUI_TA_RIGHT, GRAPH_SCALE_CF_VERTICAL, 25);
GRAPH_SCALE_SetTextColor(hScaleV, GUI_RED);
GRAPH_AttachScale(_ahWin[GRAPH0], hScaleV);
/* Create and add horizontal scale of graph widget */
hScaleH = GRAPH_SCALE_Create(46, GUI_TA_HCENTER | GUI_TA_VCENTER, GRAPH_SCALE_CF_HORIZONTAL, 50);
GRAPH_SCALE_SetTextColor(hScaleH, GUI_DARKGREEN);
GRAPH_AttachScale(_ahWin[GRAPH0], hScaleH);
/* Init multipage widget */
MULTIPAGE_AddPage(_ahWin[MULTIPAGE0],
GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbDialogPage, WM_UNATTACHED, 0, 0),
"Page 1");
MULTIPAGE_AddPage(_ahWin[MULTIPAGE0],
GUI_CreateDialogBox(_aDialogCreate2, GUI_COUNTOF(_aDialogCreate2), &_cbDialogPage, WM_UNATTACHED, 0, 0),
"Page 2");
/* Create and attach menu */
hMenu = _CreateMenu(hDlg);/**/
break;
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* _cbCallbackFramewin
*
* Purpose:
* Handles the scroll messages of the scrollbar
*/
static void _cbCallbackFramewin(WM_MESSAGE * pMsg) {
WM_HWIN hDlg;
hDlg = pMsg->hWin;
switch (pMsg->MsgId) {
case WM_NOTIFY_PARENT:
if (pMsg->Data.v == WM_NOTIFICATION_VALUE_CHANGED) {
if (pMsg->hWinSrc == WM_GetScrollbarH(hDlg)) {
int xPos, yPos;
WM_SCROLL_STATE ScrollState;
WM_GetScrollState(pMsg->hWinSrc, &ScrollState);
xPos = WM_GetWindowOrgX(WM_GetParent(_hDlg)) - ScrollState.v;
yPos = WM_GetWindowOrgY(_hDlg);
WM_MoveTo(_hDlg, xPos, yPos);
}
}
break;
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* _cbCallbackOptions
*
* Purpose:
* Callback of the options dialog box, sets the widget effects
*/
static void _cbCallbackOptions(WM_MESSAGE * pMsg) {
WM_HWIN hDlg, hItem;
hDlg = pMsg->hWin;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
/* Init check box */
hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK0);
CHECKBOX_Check(hItem);
CHECKBOX_SetText(hItem, "Auto");
/* Init radio button */
hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
RADIO_SetText(hItem, "3D", 0);
RADIO_SetText(hItem, "Simple", 1);
RADIO_SetText(hItem, "None", 2);
break;
case WM_NOTIFY_PARENT:
if (pMsg->Data.v == WM_NOTIFICATION_VALUE_CHANGED) {
hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
if (pMsg->hWinSrc == hItem) {
_SetEffect(RADIO_GetValue(hItem));
}
} else if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) {
hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK0);
if (pMsg->hWinSrc == hItem) {
_AutoMode = CHECKBOX_IsChecked(hItem);
}
}
break;
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* MainTask
*
* Demonstrates the use of widget effects
*
**********************************************************************
*/
void MainTask(void) {
WM_HWIN hScrollbar, hDlgOptions;
GUI_RECT RectDlg, RectClient;
int Cnt = 0, IndexEffect = 0, ButtonState = 0, DropdownState = 0;
int ProgbarValue = 0, ProgbarInc = 1;
int SliderValue = 0, SliderInc = 1;
int ScrollbarValue = 0, ScrollbarInc = 1;
int ListViewInc = 1;
int ListBoxInc = 1;
int MultiEditInc = 1;
int Vz = 1;
const WIDGET_EFFECT * _apEffect[] = {&WIDGET_Effect_3D, /* Array of effects */
&WIDGET_Effect_Simple,
&WIDGET_Effect_None};
const char * _apEffects[] = {"Widget effect: 3D", "Widget effect: Simple", "Widget effect: None"};
GUI_Init();
GUI_CURSOR_Show();
WM_SetCallback(WM_HBKWIN, _cbBkWindow);
WM_SetCreateFlags(WM_CF_MEMDEV); /* Use memory devices on all windows to avoid flicker */
WM_EnableMemdev(WM_HBKWIN); /* Enable use of memory devices for desktop windows */
/* Create framewindow and set its properties */
_hFrameWin = FRAMEWIN_CreateEx(0, 0, 640, 480, 0, WM_CF_SHOW, 0, 0, "", &_cbCallbackFramewin);
FRAMEWIN_SetMoveable(_hFrameWin, 1);
FRAMEWIN_SetText(_hFrameWin, _apEffects[0]);
FRAMEWIN_SetFont(_hFrameWin, &GUI_Font13B_ASCII);
/* Create main dialog window as child from framewindows client window */
_hDlg = GUI_CreateDialogBox(_aDlgWidgets,
GUI_COUNTOF(_aDlgWidgets),
&_cbCallbackWidgets,
WM_GetClientWindow(_hFrameWin), 0, 0);
/* Attach scrollbar to framewindows client window and set its properties */
hScrollbar = SCROLLBAR_CreateAttached(WM_GetClientWindow(_hFrameWin), 0);
WM_GetWindowRectEx(_hDlg, &RectDlg);
WM_GetClientRectEx(WM_GetClientWindow(_hFrameWin), &RectClient);
SCROLLBAR_SetNumItems(hScrollbar, RectDlg.x1);
SCROLLBAR_SetPageSize(hScrollbar, RectClient.x1);
/* Create options dialog with 'stay on top' and 'moveable' attribute */
hDlgOptions = GUI_CreateDialogBox(_aDlgOptions,
GUI_COUNTOF(_aDlgOptions),
&_cbCallbackOptions,
WM_HBKWIN, 0, 0);
FRAMEWIN_SetMoveable(hDlgOptions, 1);
WM_SetStayOnTop(hDlgOptions, 1);
/* Main loop for modifying the widgets */
while (1) {
if (_AutoMode) {
Cnt++;
/* Modify progbar */
if ((Cnt % 2) == 0) {
ProgbarValue += ProgbarInc;
if ((ProgbarValue == 110) || (ProgbarValue == -10)) {
ProgbarInc *= -1;
}
PROGBAR_SetValue(_ahWin[PROGBAR0], ProgbarValue);
}
/* Modify slider */
if ((Cnt % 2) == 0) {
int j;
SliderValue += SliderInc;
if ((SliderValue == 100) || (SliderValue == 0)) {
SliderInc *= -1;
}
for (j = 0; j < 3; j++) {
SLIDER_SetValue(_ahWin[SLIDER0 + j], SliderValue);
}
}
/* Modify scrollbar */
if ((Cnt % 3) == 0) {
int j;
ScrollbarValue += ScrollbarInc;
if ((ScrollbarValue == 90) || (ScrollbarValue == 0)) {
ScrollbarInc *= -1;
}
for (j = 0; j < 3; j++) {
SCROLLBAR_SetValue(_ahWin[SCROLLBAR0 + j], ScrollbarValue);
}
}
/* Modify multipage */
if ((Cnt % 120) == 0) {
MULTIPAGE_SelectPage(_ahWin[MULTIPAGE0], MULTIPAGE_GetSelection(_ahWin[MULTIPAGE0]) ^ 1);
}
/* Modify dropdown */
if ((Cnt % 120) == 0) {
DropdownState ^= 1;
if (DropdownState) {
DROPDOWN_Expand(_ahWin[DROPDOWN0]);
} else {
DROPDOWN_Collapse(_ahWin[DROPDOWN0]);
}
}
/* Modify button */
if ((Cnt % 40) == 0) {
ButtonState ^= 1;
BUTTON_SetPressed(_ahWin[BUTTON0], ButtonState);
}
/* Modify listbox */
if ((Cnt % 30) == 0) {
int Sel;
Sel = LISTBOX_GetSel(_ahWin[LISTBOX0]);
if (Sel < 0) {
Sel = 0;
}
LISTBOX_SetSel(_ahWin[LISTBOX0], Sel + ListBoxInc);
Sel = LISTBOX_GetSel(_ahWin[LISTBOX0]);
if ((Sel == (int)LISTBOX_GetNumItems(_ahWin[LISTBOX0]) - 1) || (Sel == 0)) {
ListBoxInc *= -1;
}
}
/* Modify listview */
if ((Cnt % 50) == 0) {
int Sel;
Sel = LISTVIEW_GetSel(_ahWin[LISTVIEW0]);
if (Sel < 0) {
Sel = 0;
}
LISTVIEW_SetSel(_ahWin[LISTVIEW0], Sel + ListViewInc);
Sel = LISTVIEW_GetSel(_ahWin[LISTVIEW0]);
if ((Sel == (int)LISTVIEW_GetNumRows(_ahWin[LISTVIEW0]) - 1) || (Sel == 0)) {
ListViewInc *= -1;
}
}
/* Modify multiedit */
if ((Cnt % 5) == 0) {
int Sel, Len;
char acBuffer[100];
MULTIEDIT_SetCursorOffset(_ahWin[MULTIEDIT0], MULTIEDIT_GetCursorCharPos(_ahWin[MULTIEDIT0]) + MultiEditInc);
MULTIEDIT_GetText(_ahWin[MULTIEDIT0], acBuffer, sizeof(acBuffer));
Sel = MULTIEDIT_GetCursorCharPos(_ahWin[MULTIEDIT0]);
Len = strlen(acBuffer);
if ((Sel == (Len - 1)) || (Sel == 0)) {
MultiEditInc *= -1;
}
if (!DropdownState) {
WM_SetFocus(_ahWin[MULTIEDIT0]);
}
}
/* Modify graph */
_AddValues(_ahWin[GRAPH0], 95);
/* Move window */
if ((Cnt % 1200) == 0) {
int Inc;
WM_HWIN hScroll;
WM_SCROLL_STATE ScrollState;
hScroll = WM_GetScrollbarH(WM_GetClientWindow(_hFrameWin));
WM_GetScrollState(hScroll, &ScrollState);
Inc = (ScrollState.NumItems - ScrollState.PageSize) / 2;
ScrollState.v += Inc * Vz;
if ((ScrollState.v >= Inc * 2) || (ScrollState.v <= 0)) {
Vz *= -1;
}
SCROLLBAR_SetValue(hScroll, ScrollState.v);
}
/* Change effect */
if ((Cnt % 400) == 0) {
int Index;
WM_HWIN hWin;
IndexEffect++;
Index = IndexEffect % GUI_COUNTOF(_apEffect);
_SetEffect(Index);
hWin = WM_GetDialogItem(hDlgOptions, GUI_ID_RADIO0);
RADIO_SetValue(hWin, Index);
}
}
/* Wait a while */
GUI_Delay(10);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -