/****f* LCD.SDK/SetText(HANDLE.handle,LPCTSTR.text,BOOL.resetScrollingTextPosition) * NAME * HRESULT SetText(HANDLE handle, * LPCTSTR text, * BOOL resetScrollingTextPosition = FALSE) -- Sets the text in the * control on the page being worked on. * INPUTS * handle - handle to the object. * text - text string. * resetScrollingTextPosition - indicates if position of scrolling * text needs to be reset. * RETURN VALUE * S_OK if succeeded. * E_FAIL otherwise. ****** */ HRESULT CEzLcd::SetText(HANDLE handle, LPCTSTR text, BOOL resetScrollingTextPosition) { CLCDBase* myObject = (CLCDBase*)handle; if (NULL != myObject) { if (!((LG_STATIC_TEXT == myObject->GetObjectType() || LG_SCROLLING_TEXT == myObject->GetObjectType()))) return E_FAIL; if (LG_STATIC_TEXT == myObject->GetObjectType()) { CLCDText* staticText = static_cast<CLCDText*>(myObject); if (NULL == staticText) return E_FAIL; staticText->SetText(text); return S_OK; } else if (LG_SCROLLING_TEXT == myObject->GetObjectType()) { CLCDStreamingText* streamingText = static_cast<CLCDStreamingText*>(myObject); if (NULL == streamingText) return E_FAIL; streamingText->SetText(text); if (resetScrollingTextPosition) { streamingText->ResetUpdate(); } return S_OK; } } return E_FAIL; }
/****f* EZ.LCD.Wrapper/CEzLcd::SetText * NAME * HRESULT CEzLcd::SetText -- Set text * INPUTS * handle - handle to the object. * text - text string. * RETURN VALUE * E_FAIL if there was an error. * S_OK if no error. ****** */ HRESULT CEzLcd::SetText(HANDLE handle, LPCTSTR text) { CLCDBase* myObject = GetObject(handle); if (NULL != myObject) { assert(LG_STATIC_TEXT == myObject->GetObjectType() || LG_SCROLLING_TEXT == myObject->GetObjectType()); if (LG_STATIC_TEXT == myObject->GetObjectType()) { CLCDText* staticText = static_cast<CLCDText*>(myObject); assert(NULL != staticText); staticText->SetText(text); return S_OK; } else if (LG_SCROLLING_TEXT == myObject->GetObjectType()) { CLCDStreamingText* streamingText = static_cast<CLCDStreamingText*>(myObject); assert(NULL != streamingText); streamingText->SetText(text); return S_OK; } } return E_FAIL; }
void CLCDStreamingText::ApplyOrigins(int nOffset) { // draw everyone to the left by the offset LCD_OBJECT_LIST::iterator it = m_Objects.begin(); while(it != m_Objects.end()) { CLCDBase* pObject = *it; CLCDText* pText = (CLCDText*)pObject; assert(NULL != pObject); POINT& ptOrigin = pText->GetLogicalOrigin(); pText->SetLogicalOrigin(ptOrigin.x + nOffset, ptOrigin.y); ++it; } // If the active box is no longer visible, // pop it off the push it to the end of the list if (abs(m_pQueueHead->GetLogicalOrigin().x) >= m_pQueueHead->GetHExtent().cx) { m_Objects.pop_front(); m_Objects.push_back(m_pQueueHead); RecalcTextBoxOrigins(); m_pQueueHead = (CLCDText*)*m_Objects.begin(); } }
void CLCDStreamingText::RecalcTextBoxOrigins() { if (m_Objects.size() <= 1) return; // draw everyone to the left by the offset int nOrgOffset = 0; LCD_OBJECT_LIST::iterator it = m_Objects.begin(); while(it != m_Objects.end()) { CLCDBase* pObject = *it; CLCDText* pText = (CLCDText*)pObject; assert(NULL != pObject); pText->SetLogicalSize(pText->GetHExtent().cx, pText->GetHExtent().cy); // string can be empty which generates zero logical space //assert(pText->GetLogicalSize().cx); //assert(pText->GetLogicalSize().cy); POINT& ptOrigin = pText->GetLogicalOrigin(); if (nOrgOffset == 0) { nOrgOffset = pText->GetLogicalOrigin().x; } pText->SetLogicalOrigin(nOrgOffset, ptOrigin.y); nOrgOffset += pText->GetHExtent().cx; ++it; } }
int CLCDStreamingText::AddText(LPCTSTR szText) { CLCDText* pText = new CLCDText; pText->Initialize(); pText->SetText(szText); pText->SetOrigin(GetOrigin().x, GetOrigin().y); pText->SetLogicalOrigin(GetLogicalOrigin().x, GetLogicalOrigin().y); pText->SetSize(GetWidth(), GetHeight()); pText->SetBackgroundMode(OPAQUE); LOGFONT lf; GetObject(m_hFont, sizeof(LOGFONT), &lf); pText->SetFont(lf); m_bRecalcExtent = TRUE; m_Objects.push_back(pText); if (NULL == m_pQueueHead) { m_pQueueHead = pText; } // return the zero-based index return (int)(m_Objects.size()-1); }
BOOL CLCDStreamingText::RecalcTextBoxes(CLCDGfx &rGfx) { // check if we need to add another text box LCD_OBJECT_LIST::iterator it = m_Objects.begin(); if (it == m_Objects.end()) return FALSE; CLCDBase* pObject = *it; CLCDText* pText = (CLCDText*)pObject; assert(NULL != pObject); LOGFONT lf; GetObject(m_hFont, sizeof(LOGFONT), &lf); pText->SetFont(lf); // this will re-evaluate the main text object assert(m_Objects.size() == 1); CLCDCollection::OnDraw(rGfx); if (it != m_Objects.end()) { if (pText->GetHExtent().cx > GetWidth()) { pText->SetAlignment(DT_LEFT); // add a gap AddText(m_szGapText); // add another text AddText(m_szText); // add last gap AddText(m_szGapText); } else { pText->SetAlignment(m_nTextAlignment); } } // this will re-evaluate the other text objects CLCDCollection::OnDraw(rGfx); RecalcTextBoxOrigins(); return TRUE; }
HRESULT CEzLcdPage::SetText(HANDLE handle, LPCTSTR text, BOOL resetScrollingTextPosition) { CLCDBase* myObject = GetObject(handle); if (NULL != myObject) { if (!((LG_STATIC_TEXT == myObject->GetObjectType() || LG_SCROLLING_TEXT == myObject->GetObjectType() || LG_RIGHTFOCUS_TEXT == myObject->GetObjectType() ))) return E_FAIL; if (LG_STATIC_TEXT == myObject->GetObjectType()) { CLCDText* staticText = static_cast<CLCDText*>(myObject); if (NULL == staticText) return E_FAIL; staticText->SetText(text); return S_OK; } else if (LG_SCROLLING_TEXT == myObject->GetObjectType()) { CLCDStreamingText* streamingText = static_cast<CLCDStreamingText*>(myObject); if (NULL == streamingText) return E_FAIL; streamingText->SetText(text); if (resetScrollingTextPosition) { streamingText->ResetUpdate(); } return S_OK; } else if (LG_RIGHTFOCUS_TEXT == myObject->GetObjectType()) { CLCDText* rightFocusText = static_cast<CLCDText*>(myObject); if (NULL == rightFocusText) return E_FAIL; rightFocusText->SetText(text); rightFocusText->CalculateExtent(true); // if out of focus, set alignment to right in order to follow what is written if (rightFocusText->GetHExtent().cx>=rightFocusText->GetSize().cx) rightFocusText->SetAlignment(DT_RIGHT); else rightFocusText->SetAlignment(DT_LEFT); return S_OK; } } return E_FAIL; }
/****f* EZ.LCD.Wrapper/CEzLcd::AddText * NAME * HANDLE CEzLcd::AddText -- Add a text object to the LCD * INPUTS * type - specifies whether the text is static or * scrolling. Possible types are: LG_SCROLLING_TEXT, * LG_STATIC_TEXT * size - size of the text. Choose between these three: * LG_SMALL, LG_MEDIUM or LG_BIG. * alignment - alignment of the text. Values are: DT_LEFT, * DT_CENTER, DT_RIGHT. * maxLengthPixels - max length in pixels of the text. If the text is * longer and of type LG_STATIC_TEXT, it will be cut * off. If the text is longer and of type * LG_SCROLLING_TEXT, it will scroll. * RETURN VALUE * Handle for this object. * SEE ALSO * CEzLcd::AddIcon * CEzLcd::AddProgressBar ****** */ HANDLE CEzLcd::AddText(LGObjectType type, LGTextSize size, INT alignment, INT maxLengthPixels) { assert(LG_SCROLLING_TEXT == type || LG_STATIC_TEXT == type); CLCDText* staticText; CLCDStreamingText* streamingText; INT boxHeight = LG_MEDIUM_FONT_TEXT_BOX_HEIGHT; INT fontSize = LG_MEDIUM_FONT_SIZE; INT localOriginY = LG_MEDIUM_FONT_LOGICAL_ORIGIN_Y; switch (type) { case LG_SCROLLING_TEXT: streamingText = new CLCDStreamingText(); assert(NULL != streamingText); streamingText->Initialize(); streamingText->SetOrigin(0, 0); streamingText->SetFontFaceName(_T("Tahoma")); streamingText->SetAlignment(alignment); streamingText->SetText(_T(" ")); streamingText->SetGapText(LG_SCROLLING_GAP_TEXT); streamingText->SetSpeed(LG_SCROLLING_SPEED); streamingText->SetScrollingStep(LG_SCROLLING_STEP); streamingText->SetStartDelay(LG_SCROLLING_DELAY_MS); if (LG_SMALL == size) { boxHeight = LG_SMALL_FONT_TEXT_BOX_HEIGHT; fontSize = LG_SMALL_FONT_SIZE; localOriginY = LG_SMALL_FONT_LOGICAL_ORIGIN_Y; } else if (LG_MEDIUM == size) { boxHeight = LG_MEDIUM_FONT_TEXT_BOX_HEIGHT; fontSize = LG_MEDIUM_FONT_SIZE; localOriginY = LG_MEDIUM_FONT_LOGICAL_ORIGIN_Y; } else if (LG_BIG == size) { streamingText->SetFontWeight(FW_BOLD); boxHeight = LG_BIG_FONT_TEXT_BOX_HEIGHT; fontSize = LG_BIG_FONT_SIZE; localOriginY = LG_BIG_FONT_LOGICAL_ORIGIN_Y; } streamingText->SetSize(maxLengthPixels, boxHeight); streamingText->SetFontPointSize(fontSize); streamingText->SetLogicalOrigin(0, localOriginY); streamingText->SetObjectType(LG_SCROLLING_TEXT); AddObject(streamingText); return streamingText; break; case LG_STATIC_TEXT: staticText = new CLCDText(); assert(NULL != staticText); staticText->Initialize(); staticText->SetOrigin(0, 0); staticText->SetFontFaceName(_T("Tahoma")); staticText->SetAlignment(alignment); staticText->SetBackgroundMode(OPAQUE); staticText->SetText(_T(" ")); if (LG_SMALL == size) { boxHeight = LG_SMALL_FONT_TEXT_BOX_HEIGHT; fontSize = LG_SMALL_FONT_SIZE; localOriginY = LG_SMALL_FONT_LOGICAL_ORIGIN_Y; } else if (LG_MEDIUM == size) { boxHeight = LG_MEDIUM_FONT_TEXT_BOX_HEIGHT; fontSize = LG_MEDIUM_FONT_SIZE; localOriginY = LG_MEDIUM_FONT_LOGICAL_ORIGIN_Y; } else if (LG_BIG == size) { staticText->SetFontWeight(FW_BOLD); boxHeight = LG_BIG_FONT_TEXT_BOX_HEIGHT; fontSize = LG_BIG_FONT_SIZE; localOriginY = LG_BIG_FONT_LOGICAL_ORIGIN_Y; } staticText->SetSize(maxLengthPixels, boxHeight); staticText->SetFontPointSize(fontSize); staticText->SetLogicalOrigin(0, localOriginY); staticText->SetObjectType(LG_STATIC_TEXT); AddObject(staticText); return staticText; break; default: Printf(_T("ERROR: trying to add text object with undefined type\n")); } return NULL; }
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_LCDUISAMPLE, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_LCDUISAMPLE)); /* Here we initialize our connection */ //Create a connection context and connect to LCDMon lgLcdConnectContextEx ConnectCtx; ConnectCtx.appFriendlyName = g_AppletTitle; //This part tells LCDMon what you want to display on. //Use LGLCD_APPLET_CAP_BW for monochrome, and //LGLCD_APPLET_CAP_QVGA for color. Or them together //to be dual mode. See the lgcd.h documentation //for more details on dual mode applets. ConnectCtx.dwAppletCapabilitiesSupported = LGLCD_APPLET_CAP_BW | LGLCD_APPLET_CAP_QVGA; //We don't want to autostart a sample ConnectCtx.isAutostartable = FALSE; //Persistence has been deprecated, so we will skip that field //ConnectCtx.isPersistent = doesn't matter //This example does not cover the configure callback, but it //is very similar to setting up notifications. ConnectCtx.onConfigure.configCallback = NULL; ConnectCtx.onConfigure.configContext = NULL; //In this sample, we are using the default notification ConnectCtx.onNotify.notificationCallback = NULL; ConnectCtx.onNotify.notifyContext = NULL; //Let's use our softbutton callback g_SBContext.softbuttonsChangedCallback = OnButtonCB; g_SBContext.softbuttonsChangedContext = g_hwnd; //Initialize your connection //We are using our own softbutton callback if( FALSE == g_Connection.Initialize(ConnectCtx, &g_SBContext) ) { return -1; } //Add your monochrome page CLCDOutput* pMonoOutput = g_Connection.MonoOutput(); CLCDPage m_MonoPage; pMonoOutput->ShowPage(&m_MonoPage); //For monochrome, let's just display some text g_MonoText.SetText( _T("Hello monochrome display.\n") ); g_MonoText.SetOrigin(0,0); g_MonoText.SetSize(160, 16); g_MonoText.SetFontPointSize(8); m_MonoPage.AddObject(&g_MonoText); //Add your color page CLCDOutput* pColorOutput = g_Connection.ColorOutput(); CLCDPage m_ColorPage; pColorOutput->ShowPage(&m_ColorPage); //Add our new OpenGL object //We're going to take up the entire screen with it g_OGLObj.Initialize(320,240); m_ColorPage.AddObject(&g_OGLObj); //Let's setup some OpenGL stuff in this function g_OGLObj.MakeCurrent(); SetupRendering(); // Main message loop: BOOL Done = FALSE; DWORD timestamp; while(!Done) { if( PeekMessage(&msg,NULL,0,0,PM_REMOVE) ) { if (msg.message==WM_QUIT) { Done = TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { timestamp = GetTickCount(); g_OGLObj.BeginDraw(); //Do OpenGL rendering here //One perk of OpenGL is that we do not have to put this rendering code //inside of COGLObject's OnDraw class. DoRendering(timestamp); g_OGLObj.EndDraw(); //The update will do the rendering of any LCDUI objects we added to pages g_Connection.Update(); //This loop goes very fast, so let's throttle it a bit Sleep(33); } } //Shutdown the connection //(also called in the destructor) g_Connection.Shutdown(); return (int) msg.wParam; }