Ejemplo n.º 1
0
//
// WriteLog
//
void Logger::WriteLog(std::wstringstream & log_message, const std::wstring log_level)
{
    std::string _log_message, _log_level;
    UnicodeToAnsi(log_message.str(), &_log_message);
    UnicodeToAnsi(log_level, &_log_level);

    SYSTEMTIME st;
    std::stringstream timestamp;
    std::stringstream formatted_message;
    unsigned long bytes_writen;

    GetLocalTime(&st);
    timestamp << st.wYear << "-"
        << std::setw(2) << std::setfill('0') << st.wMonth << "-"
        << std::setw(2) << std::setfill('0') << st.wDay
        << " "
        << std::setw(2) << std::setfill('0') << st.wHour << ":"
        << std::setw(2) << std::setfill('0') << st.wMinute << ":"
        << std::setw(2) << std::setfill('0') << st.wSecond << ","
        << std::setw(3) << std::setfill('0') << st.wMilliseconds;

    formatted_message << timestamp.str() << " " << _log_level << " ";
    if (!this->log_prefix.empty()) { formatted_message << this->log_prefix << " "; }
    formatted_message << _log_message << std::endl;

    if (this->log_to_stdout) { std::cout << formatted_message.str(); }
    
    if (this->log_file_handle != NULL) {
        WriteFile(this->log_file_handle, formatted_message.str().c_str(), strlen(formatted_message.str().c_str()), &bytes_writen, NULL);
    }
    
    log_message.str(L""); // clear message
}
Ejemplo n.º 2
0
const wchar_t* ConcatpwChar(const wchar_t* pwChar1, const wchar_t* pwChar2)
{
	wss.str(L"");
	wss.clear();
	wss << pwChar1 << pwChar2;
	return wss.str().c_str();
}
Ejemplo n.º 3
0
const wchar_t* LocToWChar(int x, int y, int z) 
{
	wssChunk.str(L"");
	wssChunk.clear();
	wssChunk << x << L"_" <<  y << L"_" << z;
	free(sssChunk);
	sssChunk = (wchar_t*) malloc(wssChunk.str().length()*2+2);
	wcscpy(sssChunk, wssChunk.str().c_str());
	return wssChunk.str().c_str();
}
Ejemplo n.º 4
0
/* ConcatpwChar *****************************
 *	result is only valid til the next call
 * use sss/ sssChunk as result after the call
 */
const wchar_t* ConcatpwChar(const wchar_t* pwChar1, const wchar_t* pwChar2, const wchar_t* pwChar3)
{
	wss.str(L"");
	wss.clear();
	wss << pwChar1 << pwChar2 << pwChar3;
	free(sss);
	sss = (wchar_t*) malloc(wss.str().length()*2+2);
	wcscpy(sss, wss.str().c_str());
	return wss.str().c_str();
}
Ejemplo n.º 5
0
// **************************************************************************** //
// Load a map a generate a new one if file does not exists
__declspec(dllexport) bool LoadBlockMap(wchar_t* _pcFileName)
{
	ConcatpwChar(_pcFileName, L"\\");
	Map.Dir = (wchar_t*) malloc(wss.str().length()+1);
	wcscpy(Map.Dir, wss.str().c_str());
	CreateDirectoryW(_pcFileName, NULL);
	Map.IndexHigh = 0;
	Map.Ini();//inizialise, pointers get NULLed
	if(!loadChunk(0,0,0)) //ini map with 1 chunk loaded so that pChunkArray[0] is spezified
		createChunk( 0, 0, 0);
	Map.pChunkArray[0] = Map.pChunkArray[1]; 

	// Errors are not supported!
	// Try open
	ConcatpwChar(Map.Dir,_pcFileName, L".map");
	FILE* pFile = _wfopen(sss, L"rb");
	if(!pFile)
	{
		// Seed random to file name
		uint32 dwSeed = 0;
		while(*_pcFileName)
		{
			dwSeed += *_pcFileName;
			// Only remark the real file not the path
			if(*_pcFileName == '/' || *_pcFileName == '\\') dwSeed = 0;
			++_pcFileName;
		}
		PerlinObject2D.SetSeed(dwSeed);
		PerlinObject3D.SetSeed(dwSeed*1009 + 71);

		return false;
	} else {
		// Read and check for version...
		FileHeader FH;
		fread(&FH, sizeof(FileHeader), 1, pFile);
		if(FH.uiFileSignature != *(unsigned int*)FILE_SIGNATURE) return false;

		PerlinObject2D.SetSeed(FH.uiSeed2D);
		PerlinObject3D.SetSeed(FH.uiSeed3D);

		fclose(pFile);
		return true;
	}
}
Ejemplo n.º 6
0
//
// Debug
//
void Logger::Debug(std::wstringstream & log_message)
{
    if (this->log_debug) { this->WriteLog(log_message, L"DEBUG"); }
    log_message.str(L""); // clear message
}
Ejemplo n.º 7
0
BOOL CALLBACK DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static bool isEnabled = false;
	RECT rect;
	static int dx, dy;
	static bool isClick = false;

	switch (msg)
	{
	case WM_COMMAND:
	{
		switch (wParam)
		{
		case IDC_BTNONOFF:
			isEnabled = !isEnabled;
			isEnabled ? SetWindowText(hBtn, TEXT("Off")) : SetWindowText(hBtn, TEXT("On"));
			EnableWindow(hEdit, isEnabled);
			return TRUE;
		default:
			return FALSE;
		}
	}
		return TRUE;
	case WM_LBUTTONDOWN:
	{	
		int x = LOWORD(lParam);
		int y = HIWORD(lParam);

		sbuf.str(TEXT(""));
		sbuf << TEXT("x: ") << x << TEXT(" y: ") << y <<
			TEXT(" dx: ") << dx << TEXT(" dy: ") << dy;

		SetWindowText(hWnd, sbuf.str().data());
		
		GetWindowRect(hStatic, &rect);
		dx = rect.left - x - 6;
		dy = rect.top - y;

		if (x > rect.left && x < rect.right && y > rect.top && y < rect.bottom)
		{
			isClick = true;
		}
	}
	return TRUE;
	case WM_MOUSEMOVE:
	{
		if (isClick)
		{
			int x = LOWORD(lParam);
			int y = HIWORD(lParam);

			RECT rect;
			GetWindowRect(hStatic, &rect);
			int height = rect.bottom - rect.top;
			int width  = rect.right  - rect.left;
			
			sbuf.str(TEXT(""));
			sbuf << TEXT("x: ") << x << TEXT(" y: ") << y << std::endl <<
				TEXT(" left: ") << rect.left << TEXT(" top: ") << rect.top;
			SetWindowText(hStatic, sbuf.str().data());

			MoveWindow(hStatic, 
				       x + dx, y - dy, 
				       width, height, TRUE);
		}
	}
		return TRUE;
	case WM_LBUTTONUP:
		isClick = false;
		return TRUE;
	case WM_INITDIALOG:
		hStatic = GetDlgItem(hWnd, IDC_STATICMOVE);
		
		hEdit = GetDlgItem(hWnd, IDC_EDITTEXT);
		EnableWindow(hEdit, isEnabled);
		hBtn = GetDlgItem(hWnd, IDC_BTNONOFF);
		return TRUE;
	case WM_CLOSE:
		DestroyWindow(hWnd);
		PostQuitMessage(0);
		return TRUE;
	default:
		return FALSE;
	}
	return FALSE;
}
Ejemplo n.º 8
0
// STATICALLY LINKED UTILS - START
static void LogMessageFromStream(const std::wstringstream& stream, osDebugLogSeverity severity)
{
    dmnUtils::LogMessage(stream.str(), severity);
}
Ejemplo n.º 9
0
    void Update()
    {
        if(m_text==m_ss.str()){
            return;
        }

        m_text=m_ss.str();

        m_image->Clear();
        BYTE *data=m_image->GetSample();
        int pitch=m_image->GetWidth()*4;

        // フォントの生成
        LOGFONT lf = {m_fontsize, 0, 0, 0, 0, 0, 0, 0, 
            SHIFTJIS_CHARSET, OUT_TT_ONLY_PRECIS,
            CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FIXED_PITCH | FF_MODERN, _T("MS 明朝")};
        HFONT hFont=CreateFontIndirect(&lf);
        if(!(hFont)){
            return;
        }

        // デバイスコンテキスト取得
        // デバイスにフォントを持たせないとGetGlyphOutline関数はエラーとなる
        HDC hdc = GetDC(NULL);
        HFONT oldFont = (HFONT)SelectObject(hdc, hFont);

        std::vector<BYTE> gryph;
        int x_pos=0;
        int y_pos=0;
        int col_size=m_fontsize/2;
        for(auto c=m_text.begin(); c!=m_text.end(); ++c){

            if(y_pos>=m_row*m_fontsize){
                break;
            }

            if(*c==L'\n'){
                y_pos+=m_fontsize+5;
                x_pos=0;
                continue;
            }

            if(x_pos+col_size>=m_col*col_size){
                y_pos+=m_fontsize+5;
                x_pos=0;
            }

            // フォントビットマップ取得
            TEXTMETRIC TM;
            GetTextMetrics( hdc, &TM );
            GLYPHMETRICS GM;
            CONST MAT2 Mat = {{0,1},{0,0},{0,0},{0,1}};
            DWORD size = GetGlyphOutline(hdc, *c, GGO_GRAY4_BITMAP, &GM, 0, NULL, &Mat);

            if(size>0){
                gryph.resize(size);
                GetGlyphOutline(hdc, *c, GGO_GRAY4_BITMAP, &GM, gryph.size(), &gryph[0], &Mat);

                // フォント情報の書き込み
                // iOfs_x, iOfs_y : 書き出し位置(左上)
                // iBmp_w, iBmp_h : フォントビットマップの幅高
                // Level : α値の段階 (GGO_GRAY4_BITMAPなので17段階)
                int iOfs_x = x_pos+GM.gmptGlyphOrigin.x;
                int iOfs_y = y_pos+TM.tmAscent - GM.gmptGlyphOrigin.y;
                int iBmp_w = GM.gmBlackBoxX + (4-(GM.gmBlackBoxX%4))%4;
                int iBmp_h = GM.gmBlackBoxY;
                int Level = 17;
                DWORD Alpha, Color;
                for(int y=iOfs_y; y<iOfs_y+iBmp_h; y++){
                    for(size_t x=iOfs_x; x<iOfs_x+GM.gmBlackBoxX; x++){
                        Alpha = (255 * gryph[x-iOfs_x + iBmp_w*(y-iOfs_y)]) / (Level-1);
                        Color = 0x00ffffff | (Alpha<<24);
                        memcpy((BYTE*)data + pitch*y + 4*x, &Color, sizeof(DWORD));
                    }
                }
                x_pos+=iBmp_w;
            }
            else{
                x_pos+=col_size;
            }
        }

        // デバイスコンテキストとフォントハンドルの開放
        SelectObject(hdc, oldFont);
        DeleteObject(hFont);
        ReleaseDC(NULL, hdc);
    }
Ejemplo n.º 10
0
 void SetText(const std::wstring &text)
 {
     m_ss.clear();
     m_ss << text;
 }