/***********************************************************************/ /* Copyright (C) 2002 Definitive Solutions, Inc. All Rights Reserved. */ /* THIS COMPUTER PROGRAM IS PROPRIETARY AND CONFIDENTIAL TO DEFINITIVE */ /* SOLUTIONS, INC. AND ITS LICENSORS AND CONTAINS TRADE SECRETS OF */ /* DEFINITIVE SOLUTIONS, INC. THAT ARE PROVIDED PURSUANT TO A WRITTEN */ /* AGREEMENT CONTAINING RESTRICTIONS ON USE AND DISCLOSURE. ANY USE, */ /* REPRODUCTION, OR TRANSFER EXCEPT AS PROVIDED IN SUCH AGREEMENT */ /* IS STRICTLY PROHIBITED. */ /***********************************************************************/ #if !defined(AFX_FLOATINGTEXT_H__7BEE02B8_7EF6_11D2_BC22_00805F718BD8__INCLUDED_) #define AFX_FLOATINGTEXT_H__7BEE02B8_7EF6_11D2_BC22_00805F718BD8__INCLUDED_ #pragma once ///////////////////////////////////////////////////////////////////////////// // How to use this class: // // Add FloatingText.h and FloatingText.cpp to your project. // // Add a button to a dialog box, and make the member variable an instance of // the "FloatingText" class instead of the default "CButton". You'll have to // add this line to the top of the dialog's header file: // // #include "FloatingText.h" // // Make sure the button has the "Owner Drawn" checkbox checked. // // Add at least one string to the string table for the floating text string; // the id names and values don't matter, but they *must* be contingous. // // In your dialog's OnInitDialog() handler, add the following code: // // // Set up the floating text window (no finale). // FLOATINGTEXTDATA ftd = { 0 }; // ftd.pParent = this; // ftd.uiFirstStringID = IDS_FLOATINGTEXT_0; // ftd.bParseToWords = false; // ftd.bPuzzleFinale = false; // ftd.bBackgroundColorDrift = true; // lstrcpy(ftd.szFinale, "Something"); // ftd.nMaxPointSize = 72; // ftd.nMinPointSize = 8; // ftd.nFinaleSecsMS = 0; // ftd.nTimerMS = 200; // ftd.nDurationMS = 5000; // ftd.crBackground = RGB_WHITE; // // VERIFY(m_floatingtext.Start(&ftd)); // m_floatingtext.ShowWindow(SW_NORMAL); // ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Floater class Floater : public CObject { friend class FloatingText; // Construction. public: Floater(FloatingText* pFloatingText, int nFloater, const CString& sText); virtual ~Floater(); // Deliberately declared but not defined. private: Floater(const Floater& rhs); Floater& operator=(const Floater& rhs); // Interface. public: void Step(CDC* pDC, const CRect& rcParent); // Implementation. private: #ifdef _DEBUG void AssertValid() const; #endif // Data. private: FloatingText* m_pFloatingText; // Back pointer. int m_nFloater; // Zero-based floater number. CString m_sText; // What this floater displays. CFont m_font; // The font its text uses. CPoint m_pt; // Current position. COLORREF m_cr; // Its text color. int m_nDX; // How far it moves on this axis - part of slope (dy/dx) int m_nDY; // How far it moves on this axis - part of slope (dy/dx) int m_nRColorDrift; // Which direction background color moves. int m_nGColorDrift; // Which direction background color moves. int m_nBColorDrift; // Which direction background color moves. bool m_bFreezing; // In its slot, but not atopped moving. bool m_bFrozen; // Has finally stopped moving. CRect m_rcFullSlot; // Just the raw cell; no gaps. CPoint m_ptTarget; // How we know when to stop moving. CSize m_sizExtent; // Size of the text on the screen. }; ///////////////////////////////////////////////////////////////////////////// // Structures. // Defines a pointer to a function that returns a CString. typedef CString (*ADDSTRINGCB)(); // Allows user to easily pass a myriad of options. typedef struct FLOATINGTEXTDATAtag { CWnd* pParent; // Parent window. UINT uiFirstStringID; // First string id from string table. char szRegistryKey[255]; // In HKCU, the key holding the "Floater%d" strings. bool bParseToWords; // Carve the first string (only) into words. bool bPuzzleFinale; // Do the puzzle finale. bool bBackgroundColorDrift; // Allow slow bkgnd color change? char szFinale[255]; // Text that all floaters become at end. int nMinPointSize; // Smallest point size of floater allowed. int nMaxPointSize; // Largest point size of floater allowed. int nAnimationMS; // How fast to update the display. int nFinaleMS; // How long before the finale starts. int nDurationMS; // How long the animation lasts. COLORREF crBackground; // Background starts out white, changes. ADDSTRINGCB pfAddString; // Pointer to callback add string. } FLOATINGTEXTDATA, * PFLOATINGTEXTDATA; ///////////////////////////////////////////////////////////////////////////// // FloatingText window class FloatingText : public CButton { friend class Floater; // Construction. public: FloatingText(); virtual ~FloatingText(); // Operations. public: bool Start(PFLOATINGTEXTDATA pftd); void Pause(); void Resume(); //{{AFX_VIRTUAL(FloatingText) public: virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); //}}AFX_VIRTUAL // Generated message map functions. protected: //{{AFX_MSG(FloatingText) afx_msg void OnTimer(UINT nIDEvent); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnClicked(); afx_msg void OnDestroy(); //}}AFX_MSG DECLARE_MESSAGE_MAP() // Implementation. private: void DoFinale(); Floater* FindFloater(const CString& sText); static void ChangeColor(bool bEnoughColors, COLORREF& cr, bool bLightColors, int& nRColorDrift, int& nGColorDrift, int& nBColorDrift); static void ChangeColorPart(int& nX, int& nDriftX, bool bLightColors); static int CALLBACK MyEnumFontCallback(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam); // Data. private: int m_nRColorDrift; // Which direction background color moves. int m_nGColorDrift; // Which direction background color moves. int m_nBColorDrift; // Which direction background color moves. int m_nAnimationCount; // WM_TIMER message counter for animation. FLOATINGTEXTDATA m_ftd; // Parameters that are user settable. bool m_bEnoughColors; // Some effects don't work with LE 256 colors. CStringArray m_saFaceNames; // All TrueType fonts' face names. CObList m_olFloaters; // The "Floater" objects that will be drawn. }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_FLOATINGTEXT_H__7BEE02B8_7EF6_11D2_BC22_00805F718BD8__INCLUDED_)