📄 guiparser.cpp
字号:
//Find neighbour buttons if any for(RMuint8 c = 0; c < page->nbButtons; c++){ if( page->buttons[c]->object.state != STATE_DISABLED){ targetX = page->buttons[c]->object.x; targetY = page->buttons[c]->object.y; if((b != c) && (targetX == currentX)){ if((currentY > targetY) && (lowY < targetY)) {lowY = targetY; up = c+1;} if((currentY < targetY) && (highY > targetY)) {highY = targetY; down = c+1;} } else if((b != c) && (targetY == currentY)){ if((currentX > targetX) && (lowX < targetX)) {lowX = targetX; left = c+1;} if((currentX < targetX) && (highX > targetX)) {highX = targetX; right = c+1;} } } } //Assign neighbour buttons if available and not previously assigned if(up && page->buttons[b]->keyup == (RMascii*)NULL) page->buttons[b]->keyup = STRDUP(page->buttons[up-1]->name); if(down && page->buttons[b]->keydown == (RMascii*)NULL) page->buttons[b]->keydown = STRDUP(page->buttons[down-1]->name); if(left && page->buttons[b]->keyleft == (RMascii*)NULL) page->buttons[b]->keyleft = STRDUP(page->buttons[left-1]->name); if(right && page->buttons[b]->keyright == (RMascii*)NULL) page->buttons[b]->keyright = STRDUP(page->buttons[right-1]->name); RMDBGLOG((GUIPARSERDBG, "Assigning index: up = %d down = %d left = %d right = %d\n", up, down, left, right));// printf("Assigning index: up = %d down = %d left = %d right = %d\n", up, down, left, right); up = 0; down = 0; left = 0; right = 0; lowX = 0; lowY = 0; highX = 1000; highY = 1000; } // menus within page for(RMuint8 i = 0; i < page->nbMenus; i++){ if(page->menus[i]->nbItems ){ for(RMuint8 j = 0; j < page->menus[i]->nbItems; j++){ if(page->menus[i]->items[j]->nbButtons > 1){ //if(debug)printf("\n*** Page menuButton autonavigation starts for page index: %d\n", a); for(RMuint8 b=0; b < page->menus[i]->items[j]->nbButtons; b++){ currentX = page->menus[i]->items[j]->buttons[b]->object.x; currentY = page->menus[i]->items[j]->buttons[b]->object.y; RMDBGLOG((GUIPARSERDBG, "Menuitem button found with coordinates: x %d, y %d\n", currentX, currentY)); //Find neighbour buttons if any for(RMuint8 c=0; c < page->menus[i]->items[j]->nbButtons; c++){ if( page->menus[i]->items[j]->buttons[c]->object.state != STATE_DISABLED){ targetX = page->menus[i]->items[j]->buttons[c]->object.x; targetY = page->menus[i]->items[j]->buttons[c]->object.y; if((b != c) && (targetX == currentX)){ if((currentY > targetY) && (lowY < targetY)) {lowY = targetY; up = c+1;} if((currentY < targetY) && (highY > targetY)) {highY = targetY; down = c+1;} } else if((b != c) && (targetY == currentY)){ if((currentX > targetX) && (lowX < targetX)) {lowX = targetX; left = c+1;} if((currentX < targetX) && (highX > targetX)) {highX = targetX; right = c+1;} } } } //Assign neighbour buttons if available and not previously assigned if(up && page->menus[i]->items[j]->buttons[b]->keyup == (RMascii*)NULL) page->menus[i]->items[j]->buttons[b]->keyup = STRDUP(page->menus[i]->items[j]->buttons[up-1]->name); if(down && page->menus[i]->items[j]->buttons[b]->keydown == (RMascii*)NULL) page->menus[i]->items[j]->buttons[b]->keydown = STRDUP(page->menus[i]->items[j]->buttons[down-1]->name); if(left && page->menus[i]->items[j]->buttons[b]->keyleft == (RMascii*)NULL) page->menus[i]->items[j]->buttons[b]->keyleft = STRDUP(page->menus[i]->items[j]->buttons[left-1]->name); if(right && page->menus[i]->items[j]->buttons[b]->keyright == (RMascii*)NULL) page->menus[i]->items[j]->buttons[b]->keyright = STRDUP(page->menus[i]->items[j]->buttons[right-1]->name); RMDBGLOG((GUIPARSERDBG, "Assigning index: up = %d down = %d left = %d right = %d\n", up, down, left, right)); up = 0; down = 0; left = 0; right = 0; lowX = 0; lowY = 0; highX = 1000; highY = 1000; } } } } } return RM_OK;}////////////////////////////////////////////////////////////////////////////////// EVENTS////////////////////////////////////////////////////////////////////////////////RMstatus RMcuracaoGuiParser::GetEvents( guiEventType *events[MAX_GUI_EVENTS], RMuint16 *nEvents){ if(m_nbEvents){ RMMemcpy(events, m_Events, sizeof(m_Events)); *nEvents = m_nbEvents; } return RM_OK;}RMstatus RMcuracaoGuiParser::ParseEventList(TiXmlElement *pnode){ TiXmlElement *ptempNode; const RMascii *str; for(ptempNode = pnode->FirstChildElement(); ptempNode != NULL; ptempNode = ptempNode->NextSiblingElement()) { str = ptempNode->Value(); if (str == (RMascii *)NULL) continue; if (RMCompareAsciiCaseInsensitively (str, XMLEVENT_NODE)) { if(m_nbEvents < MAX_GUI_EVENTS) { m_Events[m_nbEvents] = ParseEvent(ptempNode); if(m_Events[m_nbEvents] != (guiEventType*)NULL){ m_nbEvents++; } } else{ RMDBGLOG((GUIPARSERDBG, "Exceed max number of global events (=%d)\n", MAX_GUI_EVENTS)); } } else { RMDBGLOG((GUIPARSERDBG, "unknown node [%s] in global eventList\n", str)); } } return RM_OK;}RMstatus RMcuracaoGuiParser::ParseEventList( TiXmlElement *pnode, guiEventType *events[MAX_GUI_EVENTS], RMuint16 *nbEvents){ TiXmlElement *ptempNode; const RMascii *str; *nbEvents = 0; for(ptempNode = pnode->FirstChildElement(); ptempNode != NULL; ptempNode = ptempNode->NextSiblingElement()) { str = ptempNode->Value(); if (str == (RMascii *)NULL) continue; if (RMCompareAsciiCaseInsensitively (str, XMLEVENT_NODE)) { if((*nbEvents) < MAX_GUI_EVENTS){ (events[*nbEvents]) = ParseEvent(ptempNode); if((events[*nbEvents]) != (guiEventType*)NULL){ (*nbEvents)++; } } else{ RMDBGLOG((GUIPARSERDBG, "Exceed max number of events (=%d)\n", MAX_GUI_EVENTS)); } } else { RMDBGLOG((GUIPARSERDBG, "unknown node [%s] in eventList\n", str)); } } return RM_OK;}guiEventType *RMcuracaoGuiParser::ParseEvent(TiXmlElement *pnode){ const RMascii *str; guiEventType *event; event = (guiEventType*) CALLOC(1, sizeof(guiEventType)); str = pnode->Attribute(XMLNAME_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read name of event (ParseEvent) ... error\n")); goto invalidEvent; } else { event->name = STRDUP(str); } str = pnode->Attribute(XMLCOMMAND_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read name of event (ParseEvent) ... error\n")); goto invalidEvent; } else { event->command = STRDUP(str);#ifdef GUI_REFID_2 event->pMetaData = CommandMetaData::create(str); event->pMetaData->parseData(pnode);#endif } str = pnode->Attribute(XMLLINK_NODE, true); if (str != (RMascii *)NULL) { event->link = STRDUP(str); } str = pnode->Attribute(XMLVALUE_NODE, true); if (str != (RMascii *)NULL) { event->value = STRDUP(str); } RMDBGLOG((GUIPARSERDBG, "Event : name : %s, command : %s, link : %s\n", event->name, event->command, event->link)); return event; invalidEvent: FreeEvent(event); return (guiEventType*)NULL;}void RMcuracaoGuiParser::FreeEvent(guiEventType *event){ if(event == NULL) return; if(event->name != (RMascii *)NULL){ RFREE(event->name); event->name = NULL; } if(event->command != (RMascii *)NULL){ RFREE(event->command); event->command = NULL; } if(event->link != (RMascii *)NULL){ RFREE(event->link); event->link = NULL; } if(event->value != (RMascii *)NULL){ RFREE(event->value); event->value = NULL; } RFREE(event);}////////////////////////////////////////////////////////////////////////////////// BUTTONS////////////////////////////////////////////////////////////////////////////////RMstatus RMcuracaoGuiParser::ParseButtonList( TiXmlElement *pnode, guiButtonType *buttons[MAX_GUI_BUTTONS], RMuint16 *nbButtons, guiMenuType *pMenu){ TiXmlElement *ptempNode; const RMascii *str; *nbButtons = 0; for(ptempNode = pnode->FirstChildElement(); ptempNode != NULL; ptempNode = ptempNode->NextSiblingElement()) { str = ptempNode->Value(); if (str == (RMascii *)NULL) continue; if (RMCompareAsciiCaseInsensitively (str, XMLBUTTON_NODE)) { if((*nbButtons) < MAX_GUI_BUTTONS){ (buttons[*nbButtons]) = ParseButton(ptempNode, pMenu); if((buttons[*nbButtons]) != (guiButtonType*)NULL){ (*nbButtons)++; } } else{ RMDBGLOG((GUIPARSERDBG, "Exceed max number of buttons (=%d)\n", MAX_GUI_BUTTONS)); } } else { RMDBGLOG((GUIPARSERDBG, "unknown node [%s] in buttonList\n", str)); } } return RM_OK;}guiButtonType *RMcuracaoGuiParser::ParseButton( TiXmlElement *pnode, guiMenuType *pMenu){ TiXmlElement *ptempNode; const RMascii *str; guiButtonType *button; RMGuiObjectState state; RMuint64 color; button = (guiButtonType*) CALLOC(1, sizeof(guiButtonType)); RMMemset(&button->object, 0, sizeof(RMButtonObject)); str = pnode->Attribute(XMLNAME_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read name of button (ParseButton) ... error\n")); goto invalidButton; } else { button->name = STRDUP(str); } str = pnode->Attribute(XMLFILE_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read file (ParseButton) ... optional\n")); } else { button->object.file = RMCatAscii(m_bitmapsPath, "/", str, NULL); } str = pnode->Attribute(XMLSELECTOVERLAY_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read file (ParseButton) ... optional\n")); } else { button->object.selectOverlay = RMCatAscii(m_bitmapsPath, "/", str, NULL); } str = pnode->Attribute(XMLSELECTEDFILE_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read selected file (ParseButton) ... file will be taken as 3 state\n")); } else { button->object.selectedFile = RMCatAscii(m_bitmapsPath, "/", str, NULL); }#ifdef GUI_REFID_2 str = pnode->Attribute(XMLHEIGHT_NODE, true); if (RMCompareAscii(str, "KBD_MATRIX")){ //do kbd calculation RMuint16 temp = 0; button->object.height = (RMuint16) KEYBOARD_HEIGHT; str = pnode->Attribute(XMLWIDTH_NODE, true); if (RMCompareAscii(str, "WIDE")){ button->object.width = (RMuint16) KEYBOARD_WIDTH_WIDE; str = pnode->Attribute(XMLX_NODE, true); RMasciiToUInt16 (str, &temp); if(temp == 10) button->object.x = (RMuint16) (temp * KEYBOARD_WIDTH_REGULAR + KEYBOARD_X_OFFSET); else button->object.x = (RMuint16) (temp * KEYBOARD_WIDTH_WIDE + KEYBOARD_X_OFFSET); } else{ button->object.width = (RMuint16) KEYBOARD_WIDTH_REGULAR; str = pnode->Attribute(XMLX_NODE, true); RMasciiToUInt16 (str, &temp); button->object.x = (RMuint16) (temp * KEYBOARD_WIDTH_REGULAR + KEYBOARD_X_OFFSET); } str = pnode->Attribute(XMLY_NODE, true); RMasciiToUInt16 (str, &temp); button->object.y = (RMuint16) (temp * KEYBOARD_HEIGHT + KEYBOARD_Y_OFFSET); button->object.backgroundcolor = 0x0; //button->object.transparentcolor = 0x080ff0000; //button->object.usetransparentcolor = TRUE; goto skipCoordinates; } else if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read height of button (ParseButton) ... error\n")); goto invalidButton; } else { RMasciiToUInt16 (str, &(button->object.height)); } str = pnode->Attribute(XMLWIDTH_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read width of button (ParseButton) ... error\n")); goto invalidButton; } else { RMasciiToUInt16 (str, &(button->object.width)); } str = pnode->Attribute(XMLX_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read x of button (ParseButton) ... error\n")); goto invalidButton; } else { RMasciiToUInt16 (str, &(button->object.x)); } str = pnode->Attribute(XMLY_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read x of button (ParseButton) ... error\n")); goto invalidButton; } else { RMasciiToUInt16 (str, &(button->object.y)); } str = pnode->Attribute(XMLBACKGROUNDCOLOR_NODE, true); if (str == (RMascii *)NULL) { RMasciiHexToUint64(DEFAULT_BUTTON_BACKGROUNDCOLOR+2, &color); button->object.backgroundcolor = (RMuint32)color; } else { if((str[0] == '0') && (str[1] == 'x')) { // hexa RMasciiHexToUint64(str+2, &color); button->object.backgroundcolor = (RMuint32)color; } else { RMasciiToUInt32 (str, &(button->object.backgroundcolor)); } } str = pnode->Attribute(XMLTRANSPARENTCOLOR_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read button transparent color... error\n")); } else { if((str[0] == '0') && (str[1] == 'x')) { // hexa RMasciiHexToUint64(str+2, &color); button->object.transparentcolor = (RMuint32)color; } else { RMasciiToUInt32 (str, &(button->object.transparentcolor)); } } str = pnode->Attribute(XMLUSETRANSPARENTCOLOR_NODE, true); if (str != (RMascii *)NULL) { if (RMCompareAsciiCaseInsensitively (str, "TRUE")) { button->object.usetransparentcolor = TRUE; } else if (RMCompareAsciiCaseInsensitively (str, "FALSE")) { button->object.usetransparentcolor = FALSE; } else { RMDBGLOG((GUIPARSERDBG, "Invalid usetransparentcolor value of button ... error\n")); goto invalidButton; } } else button->object.usetransparentcolor = FALSE; str = pnode->Attribute(XMLOUTLINECOLOR_NODE, true); if (str == (RMascii *)NULL) { if(pMenu){ RMDBGLOG((GUIPARSERDBG, "Reading outline color from parent menu (ParseButton)\n")); button->object.outlinecolor = pMenu->object.outlinecolor; } } else { if((str[0] == '0') && (str[1] == 'x')) { // hexa RMasciiHexToUint64(str+2, &color); button->object.outlinecolor = (RMuint32)color; } else { RMasciiToUInt32 (str, &(button->object.outlinecolor)); } }skipCoordinates:#else str = pnode->Attribute(XMLX_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read x of button (ParseButton) ... error\n")); goto invalidButton; } else { RMasciiToUInt16 (str, &(button->object.x)); } str = pnode->Attribute(XMLY_NODE, true); if (str == (RMascii *)NULL) { RMDBGLOG((GUIPARSERDBG, "Could not read x of button (ParseButton) ... error\n")); goto invalidButton; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -