📄 housecontrol.c
字号:
}
#endif
}
/*********************************************************************
*
* _SerialInit
*/
static void _SerialInit(SERIAL_Callback* cb) {
#ifndef WIN32
OS_SetRxCallback(&_cbReceiveData);
_pfcbReceiveCommand = cb;
#endif
}
/*********************************************************************
*
* static code, helper functions
*
**********************************************************************
*/
/*********************************************************************
*
* _SetSliderValue
*/
static void _SetSliderValue(WM_HWIN hWin, int Id, int Min, int Max, int Value) {
WM_HWIN hItem;
hItem = WM_GetDialogItem(hWin, Id);
SLIDER_SetRange(hItem, Min, Max);
SLIDER_SetValue(hItem, Value);
}
/*********************************************************************
*
* _GetSliderValue
*/
static int _GetSliderValue(WM_HWIN hDlg, int Id) {
return SLIDER_GetValue(WM_GetDialogItem(hDlg, Id));
}
/*********************************************************************
*
* _AddDialog
*/
static WM_HWIN _AddDialog(const char* pText, const GUI_WIDGET_CREATE_INFO* pDialog, int NumItems,
WM_CALLBACK* cb, WM_HWIN hMultiPage) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(pDialog, NumItems, cb, WM_GetClientWindow(hMultiPage), 0, 0);
MULTIPAGE_AddPage(hMultiPage, 0, pText);
return hWin;
}
/*********************************************************************
*
* _SetDialogLight
*/
static void _SetDialogLight(void) {
if (_hDialogLight) {
_InitDialog = 1;
_SetSliderValue(_hDialogLight, GUI_ID_SLIDER0, 0, 100, _Level[0].Light.ActV);
_SetSliderValue(_hDialogLight, GUI_ID_SLIDER1, 0, 100, _Level[1].Light.ActV);
_SetSliderValue(_hDialogLight, GUI_ID_SLIDER2, 0, 100, _Level[2].Light.ActV);
_SetSliderValue(_hDialogLight, GUI_ID_SLIDER3, 0, 100, _Level[3].Light.ActV);
_SetSliderValue(_hDialogLight, GUI_ID_SLIDER4, 0, 100, _Level[4].Light.ActV);
_InitDialog = 0;
}
}
/*********************************************************************
*
* _InvalidateObject
*/
static void _InvalidateObject(WM_HWIN hWin, GUI_RECT r) {
r.y0 -= _Scroll.ActV;
r.y1 -= _Scroll.ActV;
WM_InvalidateRect(hWin, &r);
}
/*********************************************************************
*
* _InvalidateObject2
*/
static void _InvalidateObject2(WM_HWIN hWin, GUI_RECT r) {
WM_InvalidateRect(hWin, &r);
}
/*********************************************************************
*
* _InvalidateRect
*/
static void _InvalidateRect(WM_HWIN hWin, GUI_RECT r, int xOff, int yOff) {
r.x0 += xOff;
r.x1 += xOff;
r.y0 += yOff;
r.y1 += yOff;
WM_InvalidateRect(hWin, &r);
}
/*********************************************************************
*
* _AlertOn
*/
static void _AlertOn(int Index) {
if (_hAlert[Index] == 0) {
BUTTON_Handle hBut;
WM_HWIN hClient;
int Off = Index * 10;
_hAlert[Index] = FRAMEWIN_Create(_acAlertText[Index], 0, WM_CF_SHOW, 100 + Off, 85 + Off, 110, 60);
FRAMEWIN_SetMoveable(_hAlert[Index], 1);
FRAMEWIN_SetActive(_hAlert[Index], 1);
FRAMEWIN_SetBarColor(_hAlert[Index], 0, Index ? GUI_BLUE : GUI_RED);
hClient = WM_GetClientWindow(_hAlert[Index]);
WM_SetCallback(hClient, &_cbWinAlert);
hBut = BUTTON_CreateAsChild(20, 10, 65, 20, hClient, 1, WM_CF_SHOW);
BUTTON_SetText(hBut, "OK");
_AlertCnt[Index] = 250;
}
}
/*********************************************************************
*
* _AlertOff
*/
static void _AlertOff(int Index) {
if (_hAlert[Index]) {
WM_DeleteWindow(_hAlert[Index]);
_hAlert[Index] = 0;
_AlertCnt[Index] = 0;
}
}
/*********************************************************************
*
* _SlideValue
*/
static int _SlideValue(OBJECT* pObj, int Step) {
int DiffY = pObj->NewV - pObj->ActV;
if (DiffY != 0) {
if (DiffY < 0) {
pObj->ActV -= Step;
DiffY = -DiffY;
} else {
pObj->ActV += Step;
}
if ((DiffY - Step) < 0) {
pObj->ActV = pObj->NewV;
}
return 1;
}
return 0;
}
/*********************************************************************
*
* _SlideStatus
*/
static void _SlideStatus(void) {
int Step = ((GUI_GetTime() - _SlidePrevTime) * 5) >> 7;
if (Step != 0) {
_SlidePrevTime = GUI_GetTime();
if (_SlideValue(&_Garage, Step << 1)) {
_InvalidateObject(_hWinHouse, _Garage.Rect);
_InvalidateObject2(_hWinMap, _GarageSmall.Rect);
}
if (_SlideValue(&_Jalousie1, Step)) {
_InvalidateObject(_hWinHouse, _Jalousie1.Rect);
_InvalidateObject2(_hWinMap, _Jalousie1Small.Rect);
}
if (_SlideValue(&_Jalousie2, Step)) {
_InvalidateObject(_hWinHouse, _Jalousie2.Rect);
_InvalidateObject2(_hWinMap, _Jalousie2Small.Rect);
}
if (_SlideValue(&_Marquee1, Step)) {
_InvalidateObject(_hWinHouse, _Marquee1.Rect);
_InvalidateObject2(_hWinMap, _Marquee1Small.Rect);
}
if (_SlideValue(&_Marquee2, Step)) {
_InvalidateObject(_hWinHouse, _Marquee2.Rect);
_InvalidateObject2(_hWinMap, _Marquee2Small.Rect);
}
if (_SlideValue(&_Elevator.Itself, Step)) {
_InvalidateObject(_hWinHouse, _Elevator.Itself.Rect);
_InvalidateObject2(_hWinMap, _ElevatorSmall.Rect);
}
if (_SlideValue(&_Elevator.Door, Step << 1)) {
_InvalidateRect(_hWinHouse, _Elevator.Door.Rect, 0, _Elevator.Itself.ActV - _Scroll.ActV);
}
if (_AlertCnt[0]) {
_AlertCnt[0] -= Step;
if (_AlertCnt[0] <= 0) _AlertOff(0);
}
if (_AlertCnt[1]) {
_AlertCnt[1] -= Step;
if (_AlertCnt[1] <= 0) _AlertOff(1);
}
}
Step = GUI_GetTime() - _ScrollPrevTime;
if (Step != 0) {
_ScrollPrevTime = GUI_GetTime();
if (_SlideValue(&_Scroll, Step << 1)) {
SCROLLBAR_SetValue(_hScroll, _Scroll.ActV);
_InvalidateObject(_hWinHouse, _Scroll.Rect);
}
}
}
/*********************************************************************
*
* _Clip
*/
static int _Clip(int Value) {
Value = (Value < 100) ? Value : 100;
Value = (Value > 0) ? Value : 0;
return Value;
}
/*********************************************************************
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -