/*========================================================================= * * CPAdTip.cpp : TipOfDay Dialog - Implementation file * * * Version 1.0 * Creation date * Revision date * * Shaitan *=======================================================================*/ #include "stdafx.h" #ifdef ACTIVE_EDITOR #include "acp_base.h" #include "itf/CPAdTip.hpp" #include "itf/FrmGest.hpp" #include "acp_base.h" #include "itf/CPAMWorl.hpp" #include "itf/CPAProj.hpp" #include "x:\cpa\main\inc\_EditID.h" #include "TUT.h" typedef struct tdstBitmapTip_ { HBITMAP hBitmap; long lSizeX; long lSizeY; long lPos; } tdstBitmapTip; //################################################################################# // CPA_ColorEdit control //################################################################################# /*---------------------------------------- ----------------------------------------*/ CPA_ColorEdit::CPA_ColorEdit (void) { m_crTextColor = RGB(0, 0, 150); m_crBackColor = RGB(0, 200, 200); m_brBrush.CreateSolidBrush(m_crBackColor); } /*---------------------------------------- ----------------------------------------*/ void CPA_ColorEdit::fn_vSetColors (COLORREF crText, COLORREF crBack) { m_crTextColor = crText; m_crBackColor = crBack; m_brBrush.Detach(); m_brBrush.CreateSolidBrush(m_crBackColor); } /*---------------------------------------- ----------------------------------------*/ HBRUSH CPA_ColorEdit::CtlColor (CDC* pDC, UINT nCtlColor) { pDC->SetTextColor(m_crTextColor); pDC->SetBkColor(m_crBackColor); return m_brBrush; } /*---------------------------------------- ----------------------------------------*/ void CPA_ColorEdit::OnLButtonDown (UINT nFlags, CPoint point) { } /*---------------------------------------- ----------------------------------------*/ BEGIN_MESSAGE_MAP(CPA_ColorEdit, CEdit) //{{AFX_MSG_MAP(CPA_ColorEdit) ON_WM_CTLCOLOR_REFLECT() ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() //################################################################################# // CPA_DialogTip dialog //################################################################################# /*---------------------------------------- ----------------------------------------*/ CPA_DialogTip::CPA_DialogTip(CWnd* pParent /*=NULL*/) : CDialog(CPA_DialogTip::IDD, (pParent ? pParent : &g_oBaseFrame)) { //{{AFX_DATA_INIT(CPA_DialogTip) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // init parameters m_hTitle = NULL; } /*---------------------------------------- ----------------------------------------*/ void CPA_DialogTip::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPA_DialogTip) DDX_Control(pDX, CPA_IDC_TIPTEXT, m_cTipText); DDX_Control(pDX, CPA_IDC_NEXTTIP, m_cNextTip); DDX_Control(pDX, CPA_IDC_FIRSTONLY, m_cFirstOnly); //}}AFX_DATA_MAP } /*---------------------------------------- ----------------------------------------*/ BEGIN_MESSAGE_MAP(CPA_DialogTip, CDialog) //{{AFX_MSG_MAP(CPA_DialogTip) ON_BN_CLICKED(CPA_IDC_NEXTTIP, OnNextTip) ON_BN_CLICKED(CPA_IDC_CLOSETIP, OnCloseTip) ON_WM_CTLCOLOR() ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() //################################################################################# // EDT_DialogFlag message handlers //################################################################################# /*---------------------------------------- ----------------------------------------*/ void CPA_DialogTip::fn_vDoDialog (CString csEditor, CString csTag, CString csFile, long lCurrentTip) { // init tips parameters m_csFileName = csFile; m_csEditor = csEditor; m_csTag = csTag; m_lCurrentTip = lCurrentTip; // this dialog is modal DoModal(); } /*---------------------------------------- ----------------------------------------*/ BOOL CPA_DialogTip::OnInitDialog () { COLORREF crTextColor, crBackColor; HBITMAP hEditor; CRect rcTitle(100, 5, 290, 90); CRect rcEditor(150, 100, 190, 40); char szEditor[256], szCurrent[256], szBackGround[256]; char szMode[10], szText[10], szBack[10]; long lR,lG,lB; // Create the dialog CDialog::OnInitDialog(); // create Title bitmap if (!m_hTitle) m_hTitle = m_hLoadImage("EDT_Data\\Bitmaps\\TipOfDay.bmp",290,90); // set title if (m_hTitle) { m_cTitle.Create("TIP OF THE DAY", WS_CHILD|WS_BORDER|SS_BITMAP|SS_CENTERIMAGE, rcTitle, this); m_cTitle.ModifyStyleEx(NULL, WS_EX_CLIENTEDGE); m_cTitle.SetWindowPos(NULL, 0, 0, 290, 90, SWP_NOMOVE); m_cTitle.ShowWindow(TRUE); m_cTitle.SetBitmap(m_hTitle); } else { m_cTitle.Create("TIP OF THE DAY", WS_CHILD|WS_BORDER, rcTitle, this); m_cTitle.ModifyStyleEx(NULL, WS_EX_CLIENTEDGE); m_cTitle.SetWindowPos(NULL, 0, 0, 290, 90, SWP_NOMOVE); m_cTitle.ShowWindow(TRUE); m_cTitle.SetWindowText("TIP OF THE DAY"); } // create Editor bitmap sprintf(szEditor, "EDT_Data\\Bitmaps\\%s\\%s.bmp", m_csTag, m_csTag); hEditor = m_hLoadImage(szEditor, 190, 40); // set title if (hEditor) { m_cEditor.Create(m_csEditor, WS_CHILD|WS_BORDER|SS_BITMAP|SS_CENTERIMAGE, rcEditor, this); m_cTitle.ModifyStyleEx(NULL, WS_EX_CLIENTEDGE); m_cEditor.SetWindowPos(NULL, 0, 0, 190, 40, SWP_NOMOVE); m_cEditor.ShowWindow(TRUE); m_cEditor.SetBitmap(hEditor); } else { m_cEditor.Create(m_csEditor, WS_CHILD|WS_BORDER, rcEditor, this); m_cTitle.ModifyStyleEx(NULL, WS_EX_CLIENTEDGE); m_cEditor.SetWindowPos(NULL, 0, 0, 190, 40, SWP_NOMOVE); m_cEditor.ShowWindow(TRUE); m_cEditor.SetWindowText(m_csEditor); } // get editor colors sprintf(szText, "%s_Text", m_csTag); sprintf(szBack, "%s_Back", m_csTag); GetPrivateProfileString ("Colors", szText, "", szCurrent, 256, (char*)(LPCSTR)m_csFileName); GetPrivateProfileString ("Colors", szBack, "", szBackGround, 256, (char*)(LPCSTR)m_csFileName); if ((strlen(szCurrent) > 0) && (strlen(szBackGround) > 0)) { // get text color sscanf(szCurrent, "R%ld,G%ld,B%ld", &lR, &lG, &lB); crTextColor = RGB(lR, lG, lB); // get back color sscanf(szBackGround, "R%ld,G%ld,B%ld", &lR, &lG, &lB); crBackColor = RGB(lR, lG, lB); // init tip colors m_cTipText.fn_vSetColors(crTextColor, crBackColor); } else { // get default text color crTextColor = RGB(0, 0, 0); // get default back color crBackColor = RGB(250, 250, 250); // init tip colors m_cTipText.fn_vSetColors(crTextColor, crBackColor); } // get mode sprintf(szMode, "%s_Mode", m_csTag); GetPrivateProfileString ("TipOfDay", szMode, "Always", szCurrent, 256, (char*)(LPCSTR)m_csFileName); // set checkbox m_cFirstOnly.SetCheck(!strcmp(szCurrent, "FirstOnly")); // set tip text fn_vGetNextTip(); // register controls TUT_M_vGetTutDll(); TUT_M_vRegisterControlID( CPA_IDC_TIPTEXT, "ITF_TIPS_TEXT", TUT_e_TextEdit ); TUT_M_vRegisterControlID( CPA_IDC_NEXTTIP, "ITF_TIPS_NEXT", TUT_e_Button ); TUT_M_vRegisterControlID( CPA_IDC_FIRSTONLY, "ITF_TIPS_FIRSTONLY", TUT_e_Button ); TUT_M_vRegisterControlID( CPA_IDC_CLOSETIP, "ITF_TIPS_CLOSETIP", TUT_e_Button ); return TRUE; } /*---------------------------------------- ----------------------------------------*/ void CPA_DialogTip::OnNextTip () { fn_vGetNextTip(); } /*---------------------------------------- ----------------------------------------*/ void CPA_DialogTip::fn_vGetNextTip (void) { char szCurrentTip[10]; char szCurrentText[255]; char szCurrentBitmap[255]; char szRealText[255]; char szText[10]; char szBitmap[10]; char szTip[10]; long lLine = 1; CList stBitmapList; // reinit text and bitmap list m_csText = ""; while (m_stListOfBitmaps.GetCount()) { CStatic *p_cBitmap = m_stListOfBitmaps.RemoveHead(); p_cBitmap->DestroyWindow(); delete (p_cBitmap); } sprintf(szCurrentTip, "%s%ld", m_csTag, m_lCurrentTip); // get corresponding text while (lLine > 0) { // Get text sprintf(szText, "L%ld", lLine); GetPrivateProfileString (szCurrentTip, szText, "", szCurrentText, 256, (char*)(LPCSTR)m_csFileName); // check if there is a text if (strlen(szCurrentText) > 0) { char *p_szSymbol; // new line if (!strcmp(szCurrentText, ".")) strcpy(szRealText, " "); else { strcpy(szRealText, szCurrentText); // tabulations while ((p_szSymbol = strstr(szRealText, "/t")) != NULL) { strcpy(szCurrentText, p_szSymbol+2); strcpy(p_szSymbol, "\t"); strcat(szRealText, szCurrentText); } // espaces de début de ligne while ((p_szSymbol = strstr(szRealText, "/e")) != NULL) { strcpy(szCurrentText, p_szSymbol+2); strcpy(p_szSymbol, " "); strcat(szRealText, szCurrentText); } } // update text m_csText += szRealText; m_csText += "\r\n"; lLine++; } else lLine = -1; // Get bitmap sprintf(szBitmap, "B%ld", lLine-1); GetPrivateProfileString (szCurrentTip, szBitmap, "", szCurrentBitmap, 256, (char*)(LPCSTR)m_csFileName); // check if there is a text if (strlen(szCurrentBitmap) > 0) { HBITMAP hBitmap; char szBitmapName[255]; char *p_szSize; long lSizeX = 0; long lSizeY = 0; // get bitmap size p_szSize = strstr(szCurrentBitmap, ",Y"); if (p_szSize) { lSizeY = atol(p_szSize+2); strcpy(p_szSize, "\0"); } p_szSize = strstr(szCurrentBitmap, ",X"); if (p_szSize) { lSizeX = atol(p_szSize+2); strcpy(p_szSize, "\0"); } // get bitmap name sprintf(szBitmapName, "EDT_Data\\Bitmaps\\%s\\%s", m_csTag, szCurrentBitmap); // load the bitmap hBitmap = m_hLoadImage(szBitmapName, lSizeX, lSizeY); if (hBitmap) { tdstBitmapTip *p_stBitmap = new tdstBitmapTip; long lAdd; // create bitmap tip p_stBitmap->hBitmap = hBitmap; p_stBitmap->lSizeX = lSizeX; p_stBitmap->lSizeY = lSizeY; p_stBitmap->lPos = m_csText.GetLength(); // add dit to the list stBitmapList.AddTail(p_stBitmap); // add lines to the text for (lAdd = 0; lAdd < (lSizeY / 18) + 1; lAdd++) m_csText += "\r\n"; } } } // display text of the tip m_cTipText.SetWindowText(m_csText); // display bitmaps while (stBitmapList.GetCount()) { // get bitmap parameters tdstBitmapTip *p_stBitmap = stBitmapList.RemoveHead(); CStatic *p_cBitmap = new CStatic; CPoint oPoint = m_cTipText.PosFromChar(p_stBitmap->lPos); CRect rcBitmap(0, oPoint.y+1, p_stBitmap->lSizeX, oPoint.y+1+p_stBitmap->lSizeY); // create static control p_cBitmap->Create(szCurrentTip, WS_CHILD|SS_BITMAP|SS_CENTERIMAGE, rcBitmap, &m_cTipText); p_cBitmap->SetWindowPos(NULL, 0, 0, p_stBitmap->lSizeX, p_stBitmap->lSizeY, SWP_NOMOVE); p_cBitmap->ShowWindow(TRUE); p_cBitmap->SetBitmap(p_stBitmap->hBitmap); // add it to the list m_stListOfBitmaps.AddTail(p_cBitmap); // free bitmap // delete (p_stBitmap); } // get next current tip or return to first one sprintf(szCurrentTip, "%s%ld", m_csTag, m_lCurrentTip+1); GetPrivateProfileString (szCurrentTip, "L1", "", szCurrentText, 256, (char*)(LPCSTR)m_csFileName); // check if there is a text m_lCurrentTip = (strlen(szCurrentText) > 0) ? m_lCurrentTip + 1 : 1; sprintf(szCurrentTip, "%ld", m_lCurrentTip); // register this new curent tip sprintf(szTip, "%s_nTip", m_csTag); WritePrivateProfileString ("TipOfDay", szTip, szCurrentTip, (char*)(LPCSTR)m_csFileName); } /*---------------------------------------- ----------------------------------------*/ HBRUSH CPA_DialogTip::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hBrush; switch (nCtlColor) { case CTLCOLOR_EDIT: pDC->SetBkColor(RGB(0,200,200)); pDC->SetTextColor(RGB(0,0,100)); hBrush = HBRUSH(pDC->GetCurrentBrush()); break; default: hBrush = CWnd::OnCtlColor(pDC, pWnd, nCtlColor); break; } return hBrush; } /*---------------------------------------- ----------------------------------------*/ void CPA_DialogTip::OnCloseTip () { char szMode[10]; // write state for this editor sprintf(szMode, "%s_Mode", m_csTag); WritePrivateProfileString ("TipOfDay", szMode, m_cFirstOnly.GetCheck() ? "FirstOnly" : "Always", (char*)(LPCSTR)m_csFileName); // quit CDialog::OnOK(); } /*---------------------------------------- ----------------------------------------*/ void CPA_DialogTip::OnCancel () { char szMode[10]; // write state for this editor sprintf(szMode, "%s_Mode", m_csTag); WritePrivateProfileString ("TipOfDay", szMode, m_cFirstOnly.GetCheck() ? "FirstOnly" : "Always", (char*)(LPCSTR)m_csFileName); // quit CDialog::OnCancel(); } /*---------------------------------------- ----------------------------------------*/ HBITMAP CPA_DialogTip::m_hLoadImage(CString _csName, int _cx, int _cy) { HBITMAP hBitmap = NULL; CString csExtension = strrchr(LPCTSTR(_csName), '.'); short wImageType; if ( !csExtension.CompareNoCase(".bmp") ) // load a bmp file wImageType = 'BM'; else if ( !csExtension.CompareNoCase(".tga") ) // load a tga file wImageType = 'TG'; else wImageType = 0; if ( wImageType ) { FILE *p_stTextureFile; p_stTextureFile = fopen(LPCTSTR(_csName),"rb"); if ( p_stTextureFile ) { BITMAPINFO stBitmapInfo; unsigned char aDEF_ucReadBuffer[512L*4L]; short wTgaWidth, wTgaHeight; unsigned char ucBBP; if ( wImageType == 'BM' ) // load a bmp file { BITMAPFILEHEADER bf; BITMAPINFOHEADER bi; fread(&bf, 1, sizeof(bf), p_stTextureFile); fread(&bi, 1, sizeof(bi), p_stTextureFile); stBitmapInfo.bmiHeader = bi; wTgaWidth = (short) bi.biWidth; wTgaHeight = (short) bi.biHeight; ucBBP = (unsigned char) bi.biBitCount; } else if ( wImageType == 'TG' ) // load a bmp file { //read TGA header fread(aDEF_ucReadBuffer,18,1,p_stTextureFile); //get image width and height wTgaWidth = (aDEF_ucReadBuffer[13]<<8) + aDEF_ucReadBuffer[12]; wTgaHeight = (aDEF_ucReadBuffer[15]<<8) + aDEF_ucReadBuffer[14]; ucBBP = aDEF_ucReadBuffer[16]; } else { fclose(p_stTextureFile); return NULL; } //here, we have read the header of the image file, either BMP or TGA //here, the file has a size that we accept if ( wImageType == 'BM' ) // load a bmp file with the Windows API { fclose(p_stTextureFile); hBitmap = (HBITMAP) LoadImage(NULL, _csName, IMAGE_BITMAP, _cx, _cy, LR_LOADFROMFILE|LR_CREATEDIBSECTION); } else if ( wImageType = 'TG' ) // load a tga file { BITMAPINFO stBitmapInfo; unsigned char *pRawBits; //we load only true color images if ( ucBBP != 24 && ucBBP != 32 ) { fclose(p_stTextureFile); return NULL; } //get the number of bytes per pixel (3 or 4) ucBBP >>= 3; ASSERT(wTgaWidth * ucBBP <= sizeof(aDEF_ucReadBuffer)); //fill the other useful fields of the header stBitmapInfo.bmiHeader.biWidth = _cx; stBitmapInfo.bmiHeader.biHeight = _cy; stBitmapInfo.bmiHeader.biPlanes = 1; stBitmapInfo.bmiHeader.biBitCount = 24; //we dont care about alpha channel here, so we wont save it stBitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); stBitmapInfo.bmiHeader.biCompression = BI_RGB; stBitmapInfo.bmiHeader.biSizeImage = 0 /*stBitmapInfo.bmiHeader.biWidth * stBitmapInfo.bmiHeader.biHeight * ucBBP*/; stBitmapInfo.bmiHeader.biXPelsPerMeter = 0; stBitmapInfo.bmiHeader.biYPelsPerMeter = 0; stBitmapInfo.bmiHeader.biClrUsed = 0; stBitmapInfo.bmiHeader.biClrImportant = 0; //create the bitmap image of the size we want (_cx, _cy) hBitmap = CreateDIBSection(NULL, &stBitmapInfo, DIB_RGB_COLORS, (void **) &pRawBits, NULL, 0); //copy/stretch the tga raw data in the image's bits area if ( hBitmap && pRawBits ) { long lDestLine, lSrcLine, lOldSrcLine = -1; for ( lDestLine = 0; lDestLine < _cy; lDestLine ++ ) { lSrcLine = (lDestLine * wTgaHeight) / _cy; //read as many lines in the as required to reach the proper source data while ( lSrcLine != lOldSrcLine ) { lOldSrcLine ++; //read a line in the file fread((void*)aDEF_ucReadBuffer, ucBBP, wTgaWidth, p_stTextureFile); } unsigned char *pSrcLine = aDEF_ucReadBuffer; unsigned char *pDestLine = pRawBits + lDestLine * _cx * 3; long lDestPixel, lSrcPixel; for ( lDestPixel = 0; lDestPixel < _cx; lDestPixel ++ ) { lSrcPixel = (lDestPixel * wTgaWidth) / _cx; unsigned char *pSrcPixel = pSrcLine + lSrcPixel * ucBBP; unsigned char *pDestPixel = pDestLine + lDestPixel * 3; *(pDestPixel ++) = *(pSrcPixel ++); *(pDestPixel ++) = *(pSrcPixel ++); *(pDestPixel ++) = *(pSrcPixel ++); } //column scan loop } //image scan loop } //bitmap creation test else hBitmap = NULL; fclose(p_stTextureFile); } //image type test } //file open test }//image type test return hBitmap; } /*---------------------------------------- ----------------------------------------*/ void CPA_DialogTip::OnDestroy() { // register controls TUT_M_vGetTutDll(); TUT_M_vUnregisterControlID( CPA_IDC_TIPTEXT ); TUT_M_vUnregisterControlID( CPA_IDC_NEXTTIP ); TUT_M_vUnregisterControlID( CPA_IDC_FIRSTONLY ); TUT_M_vUnregisterControlID( CPA_IDC_CLOSETIP ); CDialog::OnDestroy(); } #endif // ACTIVE_EDITOR