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); }
/****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; }