Пример #1
0
espeak_ERROR sync_espeak_Synth_Mark(unsigned int unique_identifier, const void *text, size_t size,
			   const char *index_mark, unsigned int end_position,
			   unsigned int flags, void* user_data)
{//=========================================================================
	espeak_ERROR aStatus;

	InitText(flags);

	my_unique_identifier = unique_identifier;
	my_user_data = user_data;

	if(index_mark != NULL)
		{
		strncpy0(skip_marker, index_mark, sizeof(skip_marker));
		skipping_text = 1;
		}

	end_character_position = end_position;


	aStatus = Synthesize(unique_identifier, text, flags | espeakSSML);
	SHOW_TIME("LEAVE sync_espeak_Synth_Mark");

	return (aStatus);
}  //  end of sync_espeak_Synth_Mark
Пример #2
0
int main()
{
	int key = 0;
	setlocale(LC_ALL, "rus");
	printf("Enter '1' if you want to sort poem in forward order \n"
		"Enter '2' if you want to sort poem in reverse order and get new part of poem \n"
		"You choise > ");
	if (!scanf_s("%d", &key) || (key != 1 && key != 2))
	{
		printf("Wrong format. Try again (maybe without brackets)\n"
			"> ");
		key = getchar();
		if (!scanf_s("%d", &key)) printf("Sorry, I'm closing.\n");
	}
	//unsigned int start_time = clock();

	int StringCount = 0;
	size_t Textlen = 0;
	Text_t *text = InitText(&StringCount, &Textlen);

	int isOkSort = sortText(text, key, &StringCount, Textlen);
	assert(isOkSort);
	int isOkPrint = printText(text, StringCount, key);
	assert(isOkPrint);
	int isOkMemory = Struct_Destrucktor(text);
	assert(isOkMemory);

	//unsigned int end_time = clock();
	//unsigned int search_time = end_time - start_time;
	//printf("%u\n", search_time);
	return 0;
}
Пример #3
0
int _tmain(int argc, _TCHAR* argv[])
{
	setlocale(LC_ALL, "rus");
	int key = 0;
	//char codeWord[8] = {};
	printf("Enter '1' if you want to sort poem in forward order \n"
		   "Enter '2' if you want to sort poem in reverse order and get new part of poem \n"
		   "You choise: ");
	scanf_s("%d", &key);

	//unsigned int start_time = clock();

	int count = 0;
	size_t len = 0;
	char** text = InitText(&count,&len);

	int isOkSort = sortText(text, key, &count, len);
	assert(isOkSort);
	int isOkPrint = printText(text, count, key);
	assert(isOkPrint);
	int isOkMemory = freeMemory(text);
	assert(isOkMemory);

	//unsigned int end_time = clock();
	//unsigned int search_time = end_time - start_time;
	//printf("%u\n", search_time);
	return 0;
}
Пример #4
0
void TranslDlg::SpeakFile(void)
{//============================
	wxString file;
	wxFileName fname;
	FILE *f_text;
	char buf[200];

	fname = wxFileName(path_speaktext);

	file = wxFileSelector(_T("Text file to speak"),fname.GetPath(),fname.GetName(),_T(""),_T("*"),wxOPEN);
	if(file == wxEmptyString) return;

	strcpy(buf,file.mb_str(wxConvLocal));
	f_text = fopen(buf,"r");
	if(f_text == NULL)
	{
		wxLogError(_T("Failed to read: ")+file);
		return;
	}

	path_speaktext = file;

	InitText(0);
	SpeakNextClause(f_text,NULL,0);
	return;
}  //  end of SpeakFile
Пример #5
0
void InitState_HowToPlay()
{
	// initialize the text
	InitText();
	
	// draw the text
	PrintStr(1, 1, "How To Play:");
	SetTile(2, 3, 20);
	PrintStr(4, 3, "This is a two-player game");
	PrintStr(4, 4, "so get a friend!");
	SetTile(2, 6, 20);
	PrintStr(4, 6, "First player places their");
	PrintStr(4, 7, "marble on an empty board");
	PrintStr(4, 8, "space");
	SetTile(2, 10, 20);
	PrintStr(4, 10, "That player then rotates");
	PrintStr(4, 11, "one of the sub-boards by");
	PrintStr(4, 12, "90 degrees. Turn is over");
	SetTile(2, 14, 20);
	PrintStr(4, 14, "Whoever can get 5 of");
	PrintStr(4, 15, "their marbles in a row");
	PrintStr(4, 16, "(straight or diagonal)");
	PrintStr(4, 17, "first, at any time, wins!");
	
	PrintStr(1, 26, "Press B to return...");
	
	// fade in
	FadeIn(1, true);
}
Пример #6
0
void 
ScrnInit(void)
{
    InitText();

    signal(SIGINT, SevereErrorSIGINT);
    signal(SIGSEGV, SevereErrorSIGSEGV);
#ifdef SIGQUIT
    signal(SIGQUIT, SevereErrorSIGQUIT);
#endif

    LastCheck = StartTime = (long)I_FloatTime();

    SetForeColor(ANSI_WHITE);
    SetBackColor(ANSI_BLUE);
    DrawFilledBox(0, 0, ScrnWidth, ScrnHeight);

    StatusLine = 5;

    MoveCurs(2, 1);
    SetForeColor(ANSI_WHITE);
    SetBackColor(ANSI_BLUE);
    DrawVLine(45, 5, ScrnHeight - 6);
    DrawHLine(1, 4, ScrnWidth - 2);
    DrawHLine(1, 2, ScrnWidth - 2);
    MoveCurs(2, 3);
    CPrintf("$f3Elapsed time: $f200:00:00                       $f7By Lee Smith <[email protected]$f7>$f3");
    remove("error.log");
}
Пример #7
0
void InformationState::Init(sf::RenderWindow* screen)
{

	LoadResources(screen);

	InitFont();
	InitText();

}
Пример #8
0
 int CALLBACK WinMain(HINSTANCE inst, HINSTANCE prevInst,
					 LPSTR cmdLine, int cmdShow) {
	
	
	WNDCLASS windowCls = {};
	windowCls.hInstance = inst;
	windowCls.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
	windowCls.lpfnWndProc = MyGuiWindowProc;
	windowCls.lpszClassName = "my-gui-window";

	RegisterClass(&windowCls);

	HWND window = CreateWindow(windowCls.lpszClassName, "Tile Mapper", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 50, 50, 1280, 720, 0, 0, inst, 0);

	WindowObj windowObjVal = {};
	windowObjVal.hwnd = window;

	windowObj = &windowObjVal;

	windowObj->hwnd = window;
	
	char* commandLine = cmdLine;
	arg1Str = commandLine + strspn(commandLine, "\n ");
	arg1Length = strcspn(arg1Str, "\n ");

	InitText("C:/Program Files/Java/jdk1.8.0_65/jre/lib/fonts/LucidaSansRegular.ttf", 18);

	Init();

	bool isRunning = true;
	while (isRunning) {
		tagMSG msg;

		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE | PM_QS_INPUT))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);

			//TODO: Why the f--k is this 161, not WM_QUIT?
			if (msg.message == 161 && msg.wParam == 20) {
				isRunning = false;
			}
		}

		RunFrame();
		
		WindowsPaintWindow(window);
	}

}
Пример #9
0
espeak_ERROR sync_espeak_Synth(unsigned int unique_identifier, const void *text, size_t size,
		      unsigned int position, espeak_POSITION_TYPE position_type,
		      unsigned int end_position, unsigned int flags, void* user_data)
{//===========================================================================

#ifdef DEBUG_ENABLED
	ENTER("sync_espeak_Synth");
	SHOW("sync_espeak_Synth > position=%d, position_type=%d, end_position=%d, flags=%d, user_data=0x%x, text=%s\n", position, position_type, end_position, flags, user_data, text);
#endif

	espeak_ERROR aStatus;

	InitText(flags);
	my_unique_identifier = unique_identifier;
	my_user_data = user_data;

	for (int i=0; i < N_SPEECH_PARAM; i++)
		saved_parameters[i] = param_stack[0].parameter[i];

	switch(position_type)
		{
		case POS_CHARACTER:
			skip_characters = position;
			break;

		case POS_WORD:
			skip_words = position;
			break;

		case POS_SENTENCE:
			skip_sentences = position;
			break;

		}
	if(skip_characters || skip_words || skip_sentences)
		skipping_text = 1;

	end_character_position = end_position;

	aStatus = Synthesize(unique_identifier, text, flags);
	#ifdef USE_ASYNC
	wave_flush(my_audio);
	#endif

	SHOW_TIME("LEAVE sync_espeak_Synth");
	return aStatus;
}  //  end of sync_espeak_Synth
Пример #10
0
// init the state
void InitState_MainMenu()
{
	// initialize the text
	InitText();
	
	// draw the menu
	PrintStr(9, 9, "Pentago!");
	PrintStr(11, 11, "New Game");
	PrintStr(11, 13, "How To Play");
	PrintStr(11, 15, "Credits");
	
	// draw the selector
	SetTile(10, 11 + (2 * currentOpt), 127);
	
	// fade in
	FadeIn(1, true);
}
Пример #11
0
ScoreDialog::ScoreDialog(int score, std::function<void()> callback) :
_Score(score),
_CloseCallBack(callback)
{
	InitBackImg();

	InitStarImg();

	InitText();

	float elapseTime = 0.f;

	elapseTime = ActionBackImg(elapseTime);
	elapseTime = ActionStarImg(elapseTime);
	elapseTime = ActionText(elapseTime);

	ZeroMemory(_Name, sizeof(_Name));
}
Пример #12
0
espeak_ng_STATUS sync_espeak_Synth_Mark(unsigned int unique_identifier, const void *text,
                                        const char *index_mark, unsigned int end_position,
                                        unsigned int flags, void *user_data)
{
	InitText(flags);

	my_unique_identifier = unique_identifier;
	my_user_data = user_data;

	if (index_mark != NULL) {
		strncpy0(skip_marker, index_mark, sizeof(skip_marker));
		skipping_text = true;
	}

	end_character_position = end_position;

	return Synthesize(unique_identifier, text, flags | espeakSSML);
}
Пример #13
0
espeak_ng_STATUS sync_espeak_Synth(unsigned int unique_identifier, const void *text,
                                   unsigned int position, espeak_POSITION_TYPE position_type,
                                   unsigned int end_position, unsigned int flags, void *user_data)
{
	InitText(flags);
	my_unique_identifier = unique_identifier;
	my_user_data = user_data;

	for (int i = 0; i < N_SPEECH_PARAM; i++)
		saved_parameters[i] = param_stack[0].parameter[i];

	switch (position_type)
	{
	case POS_CHARACTER:
		skip_characters = position;
		break;
	case POS_WORD:
		skip_words = position;
		break;
	case POS_SENTENCE:
		skip_sentences = position;
		break;

	}
	if (skip_characters || skip_words || skip_sentences)
		skipping_text = true;

	end_character_position = end_position;

	espeak_ng_STATUS aStatus = Synthesize(unique_identifier, text, flags);
#ifdef HAVE_PCAUDIOLIB_AUDIO_H
	if ((my_mode & ENOUTPUT_MODE_SPEAK_AUDIO) == ENOUTPUT_MODE_SPEAK_AUDIO) {
		int error = (aStatus == ENS_SPEECH_STOPPED)
		          ? audio_object_flush(my_audio)
		          : audio_object_drain(my_audio);
		if (error != 0)
			fprintf(stderr, "error: %s\n", audio_object_strerror(my_audio, error));
	}
#endif

	return aStatus;
}
Пример #14
0
// init the state
void InitState_GameOver()
{
	// initialize the text
	InitText();
	
	// draw it out
	PrintStr(10, 1, "Game Over!");
	
	if(wonPlayer == 0)
		PrintStr(10, 13, "Tie Game!");
	else if(wonPlayer == 1)
		PrintStr(8, 13, "Player 1 Won!");
	else if(wonPlayer == 2)
		PrintStr(8, 13, "Player 2 Won!");
	
	PrintStr(1, 26, "Press B to return to menu");
	
	// fade in
	FadeIn(1, true);
}
Пример #15
0
nResult n2dFontImpl::PrintFontImpl(n2dGraphics2D* pGraphic, ncTStr str, nFloat x, nFloat y, nFloat scale)
{
	nLen tLen = std::char_traits<nTChar>::length(str);
	nFloat currentx = x, currenty = y;
	for (nLen i = 0; i < tLen; ++i)
	{
		auto mapitea = m_FontCache.find(str[i]);
		if (mapitea == m_FontCache.end())
		{
			InitText(&str[i], 1);
			if ((mapitea = m_FontCache.find(str[i])) == m_FontCache.end())
			{
				return NatErr_InternalErr;
			}
		}

		if (mapitea->first == '\n')
		{
			currentx = x;
			currenty += mapitea->second.adv_y;
			continue;
		}

		auto w = mapitea->second.Width * scale, h = mapitea->second.Height * scale;
		auto xPos = currentx + mapitea->second.bearing_x * scale;
		auto yPos = currenty - (mapitea->second.Height - mapitea->second.bearing_y) * scale;

		pGraphic->DrawQuad(mapitea->second.CharTexture,
			{ { xPos, yPos + h, 0.f }, 0,{ 0.f, 0.f } },
			{ { xPos, yPos, 0.f }, 0,{ 0.f, 1.f } },
			{ { xPos + w, yPos, 0.f }, 0,{ 1.f, 1.f } },
			{ { xPos + w, yPos + h, 0.f }, 0,{ 1.f, 0.f } });

		currentx += mapitea->second.adv_x * scale;
	}

	return NatErr_OK;
}
Пример #16
0
BOOL CALLBACK AboutDlg::runProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
	case WM_INITDIALOG:
		{
			InitText();
			_qMeLink.init(_hinst, _hWnd);
			_qMeLink.create(HwndFromId(IDS_Q_ME),
				_T("http://wpa.qq.com/msgrd?v=1&uin=551907703&site=qq&menu=yes"));
				//_T("tencent://message/?uin=551907703"));

			_tinyLink.init(_hinst, _hWnd);
			_tinyLink.create(HwndFromId(IDS_TINY), _T("http://www.movie007.com/space-uid-8498.html"));
		}
		return TRUE;

	case WM_CLOSE:
		Destroy();
		break;
	}

	return FALSE;
}
Пример #17
0
void CCreditsThread::CreateCredits()
{
	InitFonts();
	InitColors();
	InitText();

	m_dc.SelectClipRgn(&m_rgnScreen);

	m_dcScreen.CreateCompatibleDC(&m_dc);
	m_bmpScreen.CreateCompatibleBitmap(&m_dc, m_rectScreen.Width(), m_rectScreen.Height());
	m_pbmpOldScreen = m_dcScreen.SelectObject(&m_bmpScreen);

	m_nCreditsBmpWidth = m_rectScreen.Width();
	m_nCreditsBmpHeight = CalcCreditsHeight();

	m_dcCredits.CreateCompatibleDC(&m_dc);
	m_bmpCredits.CreateCompatibleBitmap(&m_dc, m_nCreditsBmpWidth, m_nCreditsBmpHeight);
	m_pbmpOldCredits = m_dcCredits.SelectObject(&m_bmpCredits);

	m_dcCredits.FillSolidRect(0, 0, m_nCreditsBmpWidth, m_nCreditsBmpHeight, MASK_RGB);

	CFont* pOldFont;

	pOldFont  = m_dcCredits.SelectObject(m_arFonts.GetAt(0));

	m_dcCredits.SetBkMode(TRANSPARENT);

	int y = 0;

	int nFont;
	int nColor;

	int nLastFont = -1;
	int nLastColor = -1;

	int nTextHeight = m_dcCredits.GetTextExtent(_T("Wy")).cy;

	for(int n = 0; n < m_arCredits.GetSize(); n++)
	{
		CString sType = m_arCredits.GetAt(n).Left(1);

		if(sType == 'B')
		{
			// it's a bitmap

			CBitmap bmp;
			if(! bmp.LoadBitmap(m_arCredits.GetAt(n).Mid(2)))
			{
				CString str; 
				str.Format(_T("Could not find bitmap resource \"%s\". Be sure to assign the bitmap a QUOTED resource name"), m_arCredits.GetAt(n).Mid(2)); 
				AfxMessageBox(str); 
				return; 
			}

			BITMAP bmInfo;
			bmp.GetBitmap(&bmInfo);

			CDC dc;
			dc.CreateCompatibleDC(&m_dcCredits);
			CBitmap* pOldBmp = dc.SelectObject(&bmp);

			// draw the bitmap
			m_dcCredits.BitBlt((m_rectScreen.Width() - bmInfo.bmWidth) / 2, y, bmInfo.bmWidth, bmInfo.bmHeight, &dc, 0, 0, SRCCOPY);

			dc.SelectObject(pOldBmp);
			bmp.DeleteObject();

			y += bmInfo.bmHeight;
		}
		else if(sType == 'S')
		{
			// it's a vertical space

			y += _ttoi(m_arCredits.GetAt(n).Mid(2));
		}
		else
		{
			// it's a text string

			nFont = _ttoi(m_arCredits.GetAt(n).Left(2));
			nColor = _ttoi(m_arCredits.GetAt(n).Mid(3,2));

			if(nFont != nLastFont)
			{
				m_dcCredits.SelectObject(m_arFonts.GetAt(nFont));
				nTextHeight = m_arFontHeights.GetAt(nFont);
			}

			if(nColor != nLastColor)
			{
				m_dcCredits.SetTextColor(m_arColors.GetAt(nColor));
			}

			CRect rect(0, y, m_rectScreen.Width(), y + nTextHeight);

			m_dcCredits.DrawText(m_arCredits.GetAt(n).Mid(6), &rect, DT_CENTER);

			y += nTextHeight;
		}
	}

	m_dcCredits.SetBkColor(MASK_RGB);
	m_dcCredits.SelectObject(pOldFont);

	// create the mask bitmap
	m_dcMask.CreateCompatibleDC(&m_dcScreen);
	m_bmpMask.CreateBitmap(m_nCreditsBmpWidth, m_nCreditsBmpHeight, 1, 1, NULL);

	// select the mask bitmap into the appropriate dc
	m_pbmpOldMask = m_dcMask.SelectObject(&m_bmpMask);

	// build mask based on transparent color
	m_dcMask.BitBlt(0, 0, m_nCreditsBmpWidth, m_nCreditsBmpHeight, &m_dcCredits, 0, 0, SRCCOPY);
}
Пример #18
0
void TranslDlg::OnCommand(wxCommandEvent& event)
{//=============================================
	#define N_PH_LIST  N_PHONEME_LIST

	void *vp;
	int translate_text = 0;
	char buf[1000];
	char phon_out[N_PH_LIST*2];
	int clause_tone;
	int clause_count;
	int use_ipa = 0;
	FILE *f;
	int  fd_temp;
	char fname_temp[100];
	static int n_ph_list;
	static PHONEME_LIST ph_list[N_PH_LIST+1];

	if(translator==NULL)
	{
		wxLogError(_T("Voice not set"));
		return;
	}

	option_phonemes = 0;

	switch(event.GetId())
	{
	case T_RULES:
	case MENU_SPEAK_RULES:
#ifdef PLATFORM_POSIX
		strcpy(fname_temp,"/tmp/espeakXXXXXX");
		if((fd_temp = mkstemp(fname_temp)) >= 0)
		{
			close(fd_temp);

			if((f = fopen(fname_temp,"w+")) != NULL)
			{
				f_trans = f;   // write translation rule trace to a temp file
			}
		}
#else
		strcpy(fname_temp,tmpnam(NULL));
		if((f = fopen(fname_temp,"w+")) != NULL)
		{
			f_trans = f;   // write translation rule trace to a temp file
		}
#endif
		t_phonetic->SetDefaultStyle(style_phonetic);
		translate_text = 2;
		break;

	case T_TRANSLATE:
	case MENU_SPEAK_TRANSLATE:
		t_phonetic->SetDefaultStyle(style_phonetic);
		translate_text = 1;
		break;

	case T_TRANSLATE_IPA:
	case MENU_SPEAK_IPA:
		t_phonetic->SetDefaultStyle(style_phonetic_large);

		translate_text = 3;
		use_ipa = 1;
		break;

	case T_PROCESS:
	case MENU_SPEAK_TEXT:
        myframe->OnProsody(event);
		prosodycanvas->LayoutData(ph_list,n_ph_list);
        myframe->Refresh();
		option_phoneme_events = espeakINITIALIZE_PHONEME_EVENTS;
		option_log_frames = 1;
		MakeWave2(ph_list,n_ph_list);
		option_log_frames = 0;
		break;
	}

	if(translate_text)
	{
		option_phonemes = translate_text;

		option_multibyte = espeakCHARS_AUTO;
		SpeakNextClause(NULL,NULL,2);  // stop speaking file

		strncpy0(buf,t_source->GetValue().mb_str(wxConvUTF8),sizeof(buf));
		phon_out[0] = 0;
		n_ph_list = 0;
		clause_count = 0;

		vp = buf;
		InitText(0);
		while((vp != NULL) && (n_ph_list < N_PH_LIST))
		{
			vp = TranslateClause(translator,NULL,vp,&clause_tone,NULL);
			CalcPitches(translator,clause_tone);
			CalcLengths(translator);

			GetTranslatedPhonemeString(translator->phon_out, sizeof(translator->phon_out), use_ipa);
			if(clause_count++ > 0)
				strcat(phon_out," ||");
			strcat(phon_out,translator->phon_out);
			t_phonetic->SetValue(wxString(translator->phon_out,wxConvUTF8));

			if((n_ph_list + n_phoneme_list) >= N_PH_LIST)
			{
				n_phoneme_list = N_PH_LIST - n_ph_list;
			}

			memcpy(&ph_list[n_ph_list],phoneme_list,sizeof(PHONEME_LIST)*n_phoneme_list);
			n_ph_list += n_phoneme_list;
		}

        ph_list[N_PH_LIST].ph = NULL;  // to recognize overrun off list (in Generate() )

		t_phonetic->Clear();
		if(option_phonemes == 2)
		{
			option_phonemes=0;
			rewind(f_trans);
			while(fgets(buf,sizeof(buf),f_trans) != NULL)
			{
				t_phonetic->AppendText(wxString(buf,wxConvUTF8));
			}
			t_phonetic->AppendText(_T("---\n"));
			if(f_trans != NULL)
				fclose(f_trans);
			remove(fname_temp);
		}
		t_phonetic->AppendText(wxString(phon_out,wxConvUTF8));
	}
}  // end of TranslDlg::OnCommand
Пример #19
0
void CHomonymBase::Init(const Wtroka& lemma, const TGrammarBunch& formsgrammars, bool isDictHom) {
    InitText(lemma, isDictHom);
    SetGrammems(formsgrammars);
}
Пример #20
0
void
Pass1(int argc, char *argv[]) {
	register int n;

	InitText(argc);
	InitTokenArray();

	/* assume all texts to be new */
	NumberOfNewTexts = NumberOfTexts;

	/* read the files */
	for (n = 0; n < NumberOfTexts; n++) {
		register char *fname = argv[n];
		register struct text *txt = &Text[n];

		fprintf(OutputFile, "File %s: ", fname);

		txt->tx_fname = fname;
		txt->tx_pos = 0;
		txt->tx_start =
		txt->tx_limit = TextLength();
		if (strcmp(fname, "/") == 0) {
			fprintf(OutputFile, "separator\n");
			NumberOfNewTexts = n;
		}
		else {
			if (!OpenText(First, txt)) {
				fprintf(OutputFile, ">>>> cannot open <<<< ");
				/*	the file has still been opened
					with a null file for uniformity
				*/
			}
			while (NextTextTokenObtained(First)) {
				if (!TOKEN_EQ(lex_token, EOL)) {
					StoreToken();
				}
			}
			CloseText(First, txt);
			txt->tx_limit = TextLength();

			/* report */
			print_count(txt->tx_limit - txt->tx_start, "token");
			if (lex_non_ascii_cnt) {
				fprintf(DebugFile, ", ");
				print_count(lex_non_ascii_cnt,
					"non-ASCII character"
				);
			}
			fprintf(OutputFile, "\n");
#ifdef	DB_TEXT
			db_print_text(txt);
#endif	/* DB_TEXT */
		}
		fflush(OutputFile);
	}

	/* report total */
	fprintf(OutputFile, "Total: ");
	print_count(TextLength() - 1, "token");
	fprintf(OutputFile, "\n\n");
	fflush(OutputFile);
}
Пример #21
0
void SpeechBubble::Init(const string phrase)
{
	// Render this as UI
	m_renderPriority = LAYER_UI;

	// Get the speech bubble resource sheet
	if (m_imageSurface == nullptr) 
		m_imageSurface = g_resources->GetSpeechBubble();

	// Initialise the text surface
	InitText(phrase);

	// Fit the speechbubble around the text
	const Dimensions textSize = Dimensions(m_TextSurface->w, m_TextSurface->h);
	Dimensions bubbleSize = Dimensions(textSize.x / TILE_SIZE, textSize.y / TILE_SIZE); // In terms of tiles
	bubbleSize.x = (int)(bubbleSize.x + 1); // Round up
	bubbleSize.y = (int)bubbleSize.y; // Round down
	bubbleSize.x++; // Increment for margin.
	bubbleSize.y++; // Increment for margin.

	int textTileWidth = bubbleSize.x;
	int textTileHeight = bubbleSize.y;

	// Construct the speechbubble image
	Dimensions imageSize = Dimensions((textTileWidth +1)*TILE_SIZE,
									  (textTileHeight+1)*TILE_SIZE);

	// Initialise the speech bubble segment information (rendering pairs)
	int count = 0;
	m_RenderPairs.clear();
	for (int i = 0; i <= textTileWidth; i++) // Note: Inclusive of textTile size bounds, as a minimum size speech bubble will be 2x2 tiles (four corners)
	{
		for (int j = 0; j <= textTileHeight; j++)
		{
			count++;

			int horiIndex;
			int vertIndex;
			
			if (i == 0)					 horiIndex = 0; // Left
			else if (i == textTileWidth) horiIndex = 2; // Right
			else						 horiIndex = 1; // Mid
			//horiIndex = rand() % 3; // Manual override for testing
			//horiIndex = 2; // Manual override for testing
			
			if (j == 0)					  vertIndex = 0; // Top
			else if (j == textTileHeight) vertIndex = 2; // Bottom
			else						  vertIndex = 1; // Mid
			//vertIndex = rand() % 3; // Manual override for testing
			//vertIndex = 2; // Manual override for testing

			// Use this to figure out the rendering information for this segment
			SDL_Rect* smartClip = new SDL_Rect();
			smartClip->x = horiIndex*TILE_SIZE;
			smartClip->y = vertIndex*TILE_SIZE;
			smartClip->w = smartClip->h = TILE_SIZE;

			Position pos(i*TILE_SIZE, j*TILE_SIZE);

			m_RenderPairs.push_back(pair<SDL_Rect*, Position>(smartClip, pos));
		}
	}

	// Calculate the rendering position of the text surface
	Position bubbleCenter((textTileWidth+1)*TILE_SIZE/2, (textTileHeight+1)*TILE_SIZE/2);
	m_TextPosition = Position(bubbleCenter.x-textSize.x/2, bubbleCenter.y-textSize.y/2);

	// Round the pixels to avoid decimal blur
	m_TextPosition.x = (int)m_TextPosition.x;
	m_TextPosition.y = (int)m_TextPosition.y;
}
Пример #22
0
LRESULT CALLBACK FormTagManager::DlgProc(     
	_In_  HWND hwnd,     
	_In_  UINT uMsg,     
	_In_  WPARAM wParam,     
	_In_  LPARAM lParam     
	)     
{
	//::PrintLog(L"Message: 0x%x, wParam = 0x%x, lParam = 0x%x, hwnd = 0x%x", uMsg, wParam, lParam, hwnd);

	switch(uMsg)     
	{   
	case WM_INITDIALOG:
		{
			::PrintLog(L"Message: WM_INITDIALOG");

			// init
			this->_hwnd = hwnd;
			this->_handler = (CHandler *)lParam;

			this->_handler->AddRef();	// to keep the instance after the Form opend, will be released in WM_NCDESTROY.

			SHGetImageList(SHIL_SMALL,IID_IImageList,(void **)&_sysImgList);
			_sysImgList->AddRef();	// will be released in ~ctor.

			_hErrorInfo = GetDlgItem(_hwnd,IDC_TAGMANAGER_STATIC_ERROR_INFO);
			_hListTags = GetDlgItem(_hwnd,IDC_TAGMANAGER_LIST_TAGS);
			_hListFiles = GetDlgItem(_hwnd,IDC_TAGMANAGER_LIST_SelectedFiles);
			_hEditCtlNewTag = GetDlgItem(_hwnd,IDC_TAGMANAGER_EDIT_TagWord);
			_hCheckAttachToFiles = GetDlgItem(_hwnd, IDC_TAGMANAGER_CHECK_AttachNewTagToFiles);
			_hBuAdd = GetDlgItem(_hwnd,IDC_TAGMANAGER_BU_ADD);
			_hBuEdit = GetDlgItem(_hwnd,IDC_TAGMANAGER_BU_EDIT);
			_hBuDel = GetDlgItem(_hwnd,IDC_TAGMANAGER_BU_DEL);

			InitText();
			InitTagList();
			InitFileList();

			Button_SetCheck(_hCheckAttachToFiles,BST_CHECKED);
			Button_Enable(_hBuAdd,false);
			Edit_TakeFocus(_hEditCtlNewTag);

			break;
		}
	case MSG_TRANSFER_INSTANCES:
		::PrintLog(L"Message: MSG_TRANSFER_INSTANCES: wParam: %d, lParam: %d",wParam, lParam);
		break;
	case WM_CTLCOLORSTATIC:
		{
			// change the text color of static label ERROR_INFO
			if( (UINT)lParam == (UINT)_hErrorInfo){
				HDC hdcStatic = (HDC) wParam;
				SetTextColor(hdcStatic, _msgColor);

				// the background color will be changed to white, that is not what I want, so, restore the background color manual.
				auto oldBkColor = GetSysColor(CTLCOLOR_DLG);
				SetBkColor(hdcStatic,oldBkColor);

				if (_hbrBkgnd == NULL)
				{
					_hbrBkgnd = CreateSolidBrush(oldBkColor);
				}

				// the return value is a handle to a brush that the system uses to paint the background of the static control.
				// http://msdn.microsoft.com/en-us/library/windows/desktop/bb787524(v=vs.85).aspx
				return (INT_PTR)_hbrBkgnd;
			}
		}
	case WM_SYSCOMMAND:
		{
			switch (wParam)
			{
			case SC_KEYMENU:
				{
					::PrintLog(L"Message: SC_KEYMENU: wParam: %d, lParam: %d",wParam, lParam);
					break;
				}
			case SC_CLOSE:
				{
					DestroyWindow(hwnd);
					break;
				}
			default:
				break;
			}
		}
		break;
	case WM_COMMAND:
		{
			::PrintLog(L"Message: WM_COMMAND");
			switch(LOWORD(wParam))     
			{    
			case IDC_TAGMANAGER_BU_DEL:
				{
					DelTags();
					break;
				}
			case IDC_TAGMANAGER_BU_EDIT:
				{
					EditTag();
					break;
				}
			case IDC_TAGMANAGER_BU_ADD:
				{
					AddTag();
					break;
				}
			case IDC_TAGMANAGER_CHECK_AttachNewTagToFiles:
				::PrintLog(L"Message: IDC_CHECK_AttachNewTagToFiles");
				break;
			case IDC_TAGMANAGER_BU_CANCEL:
				DestroyWindow(hwnd);
				break;
			case IDC_TAGMANAGER_EDIT_TagWord:
				{
					OnNewTagChanged(wParam,lParam);
					break;
				}
			default:
				break;
			}
		}
		break;
		//case WM_SIZE:
		//	{
		//		auto hTreeView = GetDlgItem(hdlg, IDC_TREE1);  
		//		if(hTreeView!=NULL)
		//		{

		//		}
		//		return 0;
		//	}
	case WM_KEYDOWN:
		{
			::PrintLog(L"Message: WM_KEYDOWN");
		}
		break;
	case WM_KEYUP:
		{
			::PrintLog(L"Message: WM_KEYUP");
			if(wParam==VK_ESCAPE)
			{
				DestroyWindow(hwnd);
			}
			else if( wParam == VK_RETURN )
			{
				// simulate text changed to validate the new tag.
				OnNewTagChanged(MAKEWPARAM(IDC_TAGMANAGER_EDIT_TagWord, EN_SETFOCUS),(LPARAM)_hEditCtlNewTag);
				// simulate the button ADD to be Clicked.
				SendMessage(_hwnd,WM_COMMAND, MAKEWPARAM(IDC_TAGMANAGER_BU_ADD, BN_CLICKED),(LPARAM)_hBuAdd);
			}
		}
		break;
	case WM_CHAR:
		{
			::PrintLog(L"Message: WM_CHAR");
		}
		break;
	case WM_SYSCHAR:
		{
			::PrintLog(L"Message: WM_SYSCHAR");
		}
		break;
	case WM_DEADCHAR:
		{
			::PrintLog(L"Message: WM_DEADCHAR");
		}
		break;
	case WM_SYSDEADCHAR:
		{
			::PrintLog(L"Message: WM_SYSDEADCHAR");
		}
		break;
	case WM_NOTIFY:
		{
			LPNMHDR pNmhdr = (LPNMHDR) lParam;
			switch (pNmhdr->idFrom)
			{
			case IDC_TAGMANAGER_LIST_TAGS:
				{
					WM_NOTIFY_LIST_Tags(wParam,lParam);
					break;
				}
			case IDC_TAGMANAGER_LIST_SelectedFiles:
				{
					WM_NOTIFY_LIST_Files(wParam,lParam);
					break;
				}
			default:
				break;
			}
		}
		break;
	case WM_DESTROY:     
		{
			PostQuitMessage(0);
		}
		break;
	case WM_NCDESTROY:
		{
			::PrintLog(L"Message: WM_NCDESTROY");
			if(this->_handler != NULL){
				auto x = this->_handler->Release();
				if( x == 0 ){
					this->_handler = NULL;
				}
			}
		}
		break;
	default:
		break;
	}

	return (INT_PTR)FALSE;
}
Пример #23
0
void UIManager::Initialize(TextClass* tc)
{
	m_textClass = tc;
	InitText();
}