Exemplo n.º 1
0
void do_clear()
{
	object* ob;
	int i;
	ob = users();

	for ( i=0;i<sizeof(ob); i++ ) 
	add_title(ob[i],"");
}
Exemplo n.º 2
0
/*-------------------------------------------
	save log data
---------------------------------------------*/
void Log(HWND hwndSNTP, const char *msg)
{
	SYSTEMTIME st;
	char s[160];
	
	GetLocalTime(&st);
	wsprintf(s, "%04d/%02d/%02d %02d:%02d:%02d ",
		st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
	strcat(s, msg);
	strcat(s, "\r\n");
	
	// save to edit control
	if(g_hwndLog)
	{
		int pos = (int)SendMessage(g_hwndLog, WM_GETTEXTLENGTH, 0, 0);
		SendMessage(g_hwndLog, EM_SETSEL, pos, pos);
		SendMessage(g_hwndLog, EM_REPLACESEL, 0, (LPARAM)s);
	}
	
	// save to file
	if(m_bSaveLog)
	{
		HANDLE hf;
		DWORD dwWritten;
		char fname[MAX_PATH];
		
		strcpy(fname, g_mydir);
		add_title(fname, SNTPLOG);
		hf = CreateFile(fname, GENERIC_WRITE, 0,
			NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		if(hf == INVALID_HANDLE_VALUE)
			return;
		SetFilePointer(hf, 0, NULL, FILE_END);
		WriteFile(hf, s, (int)strlen(s), &dwWritten, NULL);
		CloseHandle(hf);
	}
	
	// update log window
	if(!g_hwndLog)
	{
		HWND hwnd = NULL;
		while(1)
		{
			hwnd = FindWindowEx(NULL, hwnd, CLASS_TCLOCKSNTP, NULL);
			if(hwnd == NULL)
				break;
			if(hwnd != hwndSNTP)
			{
				PostMessage(hwnd, SNTPM_LOADLOG, 0, 0);
				break;
			}
		}
	}
}
Exemplo n.º 3
0
/*-------------------------------------------
  initialize
---------------------------------------------*/
void InitTCPlayer(void)
{
	GetModuleFileName(g_hInst, g_mydir, MAX_PATH);
	del_title(g_mydir);
	strcpy(g_inifile, g_mydir);
	add_title(g_inifile, "tclock.ini");
	g_bIniSetting = TRUE;
	
	// common/langcode.c
	FindFileWithLangCode(g_langfile, GetUserDefaultLangID(), TCLANGTXT);
	g_hfontDialog = CreateDialogFont();
	
	g_hwndClock = GetClockWindow();
	
	SetOnContextMenu();
}
Exemplo n.º 4
0
/*------------------------------------------------
 ショートカットの作成
--------------------------------------------------*/
BOOL CreateLink(LPCSTR fname, LPCSTR dstpath, LPCSTR name)
{
	HRESULT hres;
	IShellLink* psl;

	CoInitialize(NULL);

	hres = CoCreateInstance(&CLSID_ShellLink, NULL,
		CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
	if(SUCCEEDED(hres))
	{
		IPersistFile* ppf;
		char path[MAX_PATH];

/*		path[0] = '\"';
		strcpy(path+1, fname);
		strcat(path, "\"");*/
		psl->lpVtbl->SetPath(psl, fname);
		psl->lpVtbl->SetDescription(psl, name);
		strcpy(path, fname);
		del_title(path);
		psl->lpVtbl->SetWorkingDirectory(psl, path);

		hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
			&ppf);

		if(SUCCEEDED(hres))
		{
			WORD wsz[MAX_PATH];
			char lnkfile[MAX_PATH];
			strcpy(lnkfile, dstpath);
			add_title(lnkfile, (char*)name);
			strcat(lnkfile, ".lnk");

			MultiByteToWideChar(CP_ACP, 0, lnkfile, -1,
				wsz, MAX_PATH);

			hres = ppf->lpVtbl->Save(ppf, wsz, TRUE);
			ppf->lpVtbl->Release(ppf);
		}
		psl->lpVtbl->Release(psl);
	}
	CoUninitialize();

	if(SUCCEEDED(hres)) return TRUE;
	else return FALSE;
}
Exemplo n.º 5
0
/*-------------------------------------------
  initialize
---------------------------------------------*/
void InitTCProp(void)
{
	GetModuleFileName(g_hInst, g_mydir, MAX_PATH);
	del_title(g_mydir);
	strcpy(g_inifile, g_mydir);
	add_title(g_inifile, "tclock.ini");
	g_bIniSetting = TRUE;
	
	// common/langcode.c
	FindFileWithLangCode(g_langfile, GetUserDefaultLangID(), TCLANGTXT);
	g_hfontDialog = CreateDialogFont();
	
	g_winver = CheckWinVersion();
	
	g_hIconPlay = LoadImage(g_hInst, MAKEINTRESOURCE(IDI_PLAY), IMAGE_ICON,
		16, 16, LR_DEFAULTCOLOR|LR_SHARED);
	g_hIconStop = LoadImage(g_hInst, MAKEINTRESOURCE(IDI_STOP), IMAGE_ICON,
		16, 16, LR_DEFAULTCOLOR|LR_SHARED);
}
Exemplo n.º 6
0
//=================================================================
//--------------------------+++--> toggle calendar (close or open):
void ToggleCalendar(int type)   //---------------------------+++-->
{
	HWND calendar = api.GetCalendar();
	int is_custom = api.GetInt("Calendar", "bCustom", 0);
	if(calendar){
		if(is_custom)
			SetForegroundWindow(calendar);
		return;
	}
	if(api.OS >= TOS_VISTA && (!is_custom && type!=1)){
		// Windows 10 workaround as SendMessage doesn't work any longer (no error given)
		SendMessageCallback(g_hwndClock, WM_USER+102, 1, 0, ToggleCalendar_done, 0);//1=open, 0=close
	}else{
		char cal[MAX_PATH];
		memcpy(cal, api.root, api.root_len+1);
		add_title(cal,"misc\\XPCalendar.exe");
		api.Exec(cal,NULL,g_hwndTClockMain);
	}
}
Exemplo n.º 7
0
/*-------------------------------------------
  Show "TClock Help"
---------------------------------------------*/
void MyHelp(HWND hwnd, const char *section)
{
	char helpurl[MAX_PATH], title[MAX_PATH];
	
	if(!g_langfile[0]) return;
	
	GetMyRegStr(NULL, "HelpURL", helpurl, MAX_PATH, "");
	if(helpurl[0] == 0)
	{
		if(GetPrivateProfileString("Main", "HelpURL", "", helpurl,
			MAX_PATH, g_langfile) == 0) return;
	}
	
	if(GetPrivateProfileString(section, "HelpURL", "", title,
			MAX_PATH, g_langfile) == 0) return;
	
	if(strlen(helpurl) > 0 && helpurl[ strlen(helpurl) - 1 ] != '/')
		del_title(helpurl);
	add_title(helpurl, title);
	
	ShellExecute(hwnd, NULL, helpurl, NULL, "", SW_SHOW);
}
Exemplo n.º 8
0
//==========================
//--+++--> Create Launch T-Clock on Windows Startup ShortCut:
int CreateLink(LPCSTR fname, LPCSTR dstpath, LPCSTR name)
{
	HRESULT hres;
	IShellLink* psl;
	
	CoInitializeEx(NULL,COINIT_APARTMENTTHREADED);
	
	hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void**)&psl);
	if(SUCCEEDED(hres)) {
		IPersistFile* ppf;
		char path[MAX_PATH];
		
		psl->lpVtbl->SetPath(psl, fname);
		psl->lpVtbl->SetDescription(psl, name);
		strncpy_s(path,MAX_PATH,fname,_TRUNCATE);
		del_title(path);
		psl->lpVtbl->SetWorkingDirectory(psl, path);
		
		hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, (void**)&ppf);
		if(SUCCEEDED(hres)) {
			WORD wsz[MAX_PATH];
			char lnkfile[MAX_PATH];
			strncpy_s(lnkfile, MAX_PATH, dstpath, _TRUNCATE);
			add_title(lnkfile, (char*)name);
			strcat(lnkfile, ".lnk");
			
			MultiByteToWideChar(CP_ACP, 0, lnkfile, -1, wsz, MAX_PATH);
			
			hres = ppf->lpVtbl->Save(ppf, wsz, TRUE);
			ppf->lpVtbl->Release(ppf);
		}
		psl->lpVtbl->Release(psl);
	}
	CoUninitialize();
	
	if(SUCCEEDED(hres))
		return 1;
	return 0;
}
Exemplo n.º 9
0
int observe(object ob1,object ob2)
{

 	if(ob2->query("name")!=query("candidate")->query("name"))
	{
	call_out("observe",0,ob2,ob1);
	return 1;
	}

	if(ob1->is_fighting()) 
	{
		call_out("observe",1,ob1,ob2);
		return 1;
	}

	this_object()->delete_temp("busy");
        ob1->delete_temp("pending/fight");
        ob2->delete_temp("pending/fight");

	if ( !present(ob1, environment()) ) 
	{
		command("chat " + ob1->query("name") + "落荒而逃了!\n");
		command("chat " + ob2->query("name") 
			+ "比武战胜" + ob1->query("name") + "!\n");

		add("win_times",1);
		if(this_object()->query("win_times")==15)
                {
		command("chat " + ob2->query("name") 
			+ "获得本次比武大会天下第三的称号!\n");
		add_title(ob2,"本月天下第三");

		command("chat 比武大会结束!\n");
		this_object()->delete("candidate");
		this_object()->delete("win_times");
		return 1;
		}		
Exemplo n.º 10
0
/*-------------------------------------------
	save log data
---------------------------------------------*/
void Log(const char* msg)
{
	SYSTEMTIME st;
	char s[160];
	int count, index;

	GetLocalTime(&st);
	wsprintf(s, "%02d/%02d %02d:%02d:%02d ",
		st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
	strcat(s, msg);

	// save to listbox
	count = SendMessage(hwndSNTPLog, LB_GETCOUNT, 0, 0);
	if(count > 100)
		SendMessage(hwndSNTPLog, LB_DELETESTRING, 0, 0);
	index = SendMessage(hwndSNTPLog, LB_ADDSTRING, 0, (LPARAM)s);
	SendMessage(hwndSNTPLog, LB_SETCURSEL, index, 0);

	// save to file
	if(GetMyRegLong("SNTP", "SaveLog", TRUE))
	{
		HFILE hf;
		char fname[MAX_PATH];

		strcpy(fname, g_mydir);
		add_title(fname, "SNTP.txt");
		hf = _lopen(fname, OF_WRITE);
		if(hf == HFILE_ERROR)
			hf = _lcreat(fname, 0);
		if(hf == HFILE_ERROR) return;
		_llseek(hf, 0, 2);
		_lwrite(hf, s, strlen(s));
		_lwrite(hf, "\x0d\x0a", 2);
		_lclose(hf);
	}
}
Exemplo n.º 11
0
//	2002/11/26 - H.N. Neri-uma added.
//	2002/11/27 - 635 modified.
//-------------------------------------------------
//	GetTooltipText
//		Tooltipのテキストを、レジストリからではなく、テキストファイルから読み込みます。
//	引数:	[char * pszText]	読み込んだ文字列を格納する変数へのポインタ
//	戻り値:0		エラー。テキストファイルが存在しなかった。ファイルは存在したが、空だった。など
//			0以外	成功
//-------------------------------------------------
static BOOL GetTooltipText(PSTR pszText)
{
	HANDLE	hFile;
	char	szFilePath[MAX_PATH];	//	テキストファイルのパス
	DWORD	dwReadSize;
	DWORD	dwFileSize;
	size_t	len;
	BOOL	bAbsPath;

//	{
//		GetCurrentDirectory(MAX_PATH, pszText);
//		return TRUE;
//	}

	if(!pszText)
	{
		//	値を格納するアドレスが存在しないので、FALSEを返して終了
		return FALSE;
	}

	//	テキストファイルのパス作成
	//GetModuleFileName(hmod, szFilePath, sizeof(szFilePath));
	//del_title(szFilePath);
	//add_title(szFilePath, TIPTEXTFILENAME);

	// \\NAME\C\path\path\filename.txt
	// C:\path\path\filename.txt
	// 以上の絶対パス以外を相対パスと判断して
	// その前にTClockのパスを基準ディレクトリとして付加
	bAbsPath = FALSE;
	len = strlen(pszText);
	if (len >= 2) {
		if ((*pszText == '\\') && (*(pszText + 1) == '\\')) {
			//UNC name
			bAbsPath = TRUE;
		} else if (*(pszText + 1) == ':') {
			bAbsPath = TRUE;
		}
	}
	if (bAbsPath == FALSE) {
		// TClockの位置を基準パスとして指定文字列を相対パスとして追加
		GetModuleFileName(hmod, szFilePath, sizeof(szFilePath));
		del_title(szFilePath);
		if (len + strlen(szFilePath) >= MAX_PATH) {
			return FALSE;
		}
		add_title(szFilePath, pszText);
		*pszText = '\0';
	} else {
		//635@p5 ファイル名を取得してツールチップをクリア。
		strcpy(szFilePath, pszText);
		*pszText = '\0';
	}

	//	ファイルを読み込む
	hFile = CreateFile(szFilePath,
					   GENERIC_READ,
					   FILE_SHARE_READ,
					   NULL,
					   OPEN_EXISTING,
					   FILE_ATTRIBUTE_NORMAL,
					   NULL);
	if(hFile == INVALID_HANDLE_VALUE)
	{
		//	ファイルが存在しないので、FALSEを返して終了
		return FALSE;
	}

	dwFileSize = GetFileSize(hFile, NULL);

	if ( dwFileSize > (DWORD)LEN_TOOLTIP)
		dwFileSize = (DWORD)(LEN_TOOLTIP-1);

	//	ファイル読み込み
	ReadFile(hFile, pszText, dwFileSize, &dwReadSize, NULL);
	//	ファイルをクローズ
	CloseHandle(hFile);

	if(strcmp(pszText, "") == 0)
	{
		//	文字列取得に失敗。レジストリ取得へ走らせるためにFALSEを返して終了
		return FALSE;
	}

	//	文字列の末尾に、強制的にNULL Stringを付加(^^;
	pszText[dwFileSize] = '\0';

	//	成功したのでTRUEを返す
	return TRUE;
}
Exemplo n.º 12
0
ERRORCODE Calendar::build_weekly(CTextStyle* pTitleStyle)
{
	COLOR shadow_color = 0;
	SHORT shadow_pattern = 0;
	PBOX r;
	CHAR buffer[45];
//	WEEKDAY weekday;
	SHORT weekday;
	SHORT i, day;
	PCOORD label_width;
	BOOL stop_looking;
	GroupObjectPtr skeleton_group, date_group, text_group, graphic_group;
	ERRORCODE error;
	CTextStyle text_style(database);
	FontServerPtr font_server = database->get_font_server();

/* Compute shadow parameter. */

	if (has_shadow)
	{
	/* Set the shadow color. */

		switch (get_info().style.shadow_style)
		{
			case CAL_SHADOW_BLACK:
			case CAL_SHADOW_GRAY:
			case CAL_SHADOW_LIGHT_GRAY:
			{
				shadow_color = COLOR_BLACK;
				break;
			}
			case CAL_SHADOW_100:
			case CAL_SHADOW_50:
			case CAL_SHADOW_25:
			{
				shadow_color = get_info().style.color;
				break;
			}
			default:
			{
				return ERRORCODE_IntError;
			}
		}

	/* Set the shadow pattern. */

		switch (get_info().style.shadow_style)
		{
			case CAL_SHADOW_BLACK:
			case CAL_SHADOW_100:
			{
				shadow_pattern = 0;
				break;
			}
			case CAL_SHADOW_GRAY:
			case CAL_SHADOW_50:
			{
				shadow_pattern = 50;
				break;
			}
			case CAL_SHADOW_LIGHT_GRAY:
			case CAL_SHADOW_25:
			{
				shadow_pattern = 75;
				break;
			}
			default:
			{
				return ERRORCODE_IntError;
			}
		}
	}

/* Create the groups. */

	if (!build_calendar_groups(&skeleton_group, &date_group,
								&graphic_group, &text_group))
	{
		return ERRORCODE_Memory;
	}

/* Add a title to the calendar. */

	if ((error = add_title(skeleton_group->object_list(), pTitleStyle)) != ERRORCODE_None)
	{
		return error;
	}

	if (has_border)
	{
		if ((error = add_box(&bound, 0, get_info().style.color, SKELETON_PANEL, line_thickness, skeleton_group->object_list())) != ERRORCODE_None)
		{
			return error;
		}
	}

	switch (get_info().style.label_style)
	{
		case CAL_LABEL_TEXT:
		{
			break;
		}
		case CAL_LABEL_BOXED:
		{
			if ((error = add_box(&label, 0, get_info().style.color, LABEL_PANEL, line_thickness, skeleton_group->object_list())) != ERRORCODE_None)
			{
				return error;
			}
			break;
		}
		case CAL_LABEL_INVERTED:
		{
			if ((error = add_line(&label, 0, get_info().style.color, LABEL_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
			{
				return error;
			}
			break;
		}
		default:
		{
			break;
		}
	}

/* Draw the horizontal lines. */

	switch (get_info().style.line_style)
	{
		case CAL_LINES_ALL:
		case CAL_LINES_HORIZONTAL:
		{
		/* Draw horizontal lines. */

			r.x0 = bound.x0;
			r.x1 = bound.x1;

			if (get_info().style.label_style == CAL_LABEL_INVERTED)
			{
				r.x0 = label.x1;
			}

			r.y0 = bound.y0;

			for (i = 0; i <= days_in_week; i++)
			{
				r.y1 = r.y0 + line_thickness;
				if ((error = add_line(&r, 0, get_info().style.color, SKELETON_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
				{
					return error;
				}

				if (get_info().style.label_style == CAL_LABEL_INVERTED
						&& i != 0
						&& i != days_in_week)
				{
					PBOX r2;
					r2.y0 = r.y0;
					r2.y1 = r.y1;

					r2.x0 = label.x0;
 					if (has_border)
					{
						r2.x0 += line_thickness;
					}
					r2.x1 = label.x1;
					if ((error = add_line(&r2, 100, get_info().style.color, SKELETON_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
					{
						return error;
					}
				}
				r.y0 += cell_height;
			}
			break;
		}
		default:
		{
			break;
		}
	}

	if (has_shadow)
	{
	/* Right piece. */

		r.x0 = bound.x1;
		r.x1 = r.x0+shadow_thickness;
		r.y0 = bound.y0+shadow_thickness;
		r.y1 = bound.y1+shadow_thickness;
		if ((error = add_line(&r, shadow_pattern, shadow_color, SHADOW_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
		{
			return error;
		}

	/* Bottom piece. */

		r.x0 = bound.x0+shadow_thickness;
		r.x1 = bound.x1+shadow_thickness;
		r.y0 = bound.y1;
		r.y1 = r.y0+shadow_thickness;
		if ((error = add_line(&r, shadow_pattern, shadow_color, SHADOW_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
		{
			return error;
		}
	}

/*
// Draw the calendar text.
*/

/* Draw the label text. */

	r.x0 = label.x0 + 2*line_thickness;
	r.y0 = label.y0 + 2*line_thickness;
	r.x1 = label.x1 + cell_width;
	r.y1 = label.y0 + cell_height;

	SHORT size= (SHORT)scale_pcoord(cell_height, 72/6, PAGE_RESOLUTION);

	m_LabelFontStyle.BaseSize(MakeFixed(size));
	m_LabelFontStyle.Size(MakeFixed(size));

/*
// Calculate the size of the text for these labels.
// If the text falls outside the frame, keep making it smaller.
*/

	label_width = label.x1 - r.x0
						- InchesToPage(m_LabelFontStyle.LeftMargin() + m_LabelFontStyle.RightMargin());

	for (stop_looking = FALSE; !stop_looking;)
	{
		BOOL too_big = FALSE;

		m_LabelFontStyle.UpdateFontMetrics();

		for (weekday = first_day, i = 0;
							i < days_in_week && !too_big;
	 						i++, weekday = next_weekday(weekday))
		{
//			CHAR *p;
			TCHAR *p;
			PCOORD size;

#ifdef LOCALIZE
			CurrentLocale.WeekDayName((WEEKDAY) weekday, buffer, sizeof(buffer));
#else
			// JRO strcpy(buffer, weekday_name[weekday]);
	         strcpy(buffer, GET_PMWAPP()->GetResourceStringPointer (weekday_name_id[weekday]));
#endif

			switch (get_info().style.weekday_style)
			{
				case WEEKDAY_STYLE_INITIALS:
				{
					buffer[1] = '\0';
					break;
				}
				case WEEKDAY_STYLE_ABBREV:
				{
#ifdef LOCALIZE
					CurrentLocale.AbbrevWeekDayName((WEEKDAY)weekday, buffer, sizeof(buffer));
#else
					buffer[3] = '\0';
#endif
					break;
				}
				default:
				{
					break;
				}
			}



		/* Compute the size for the text. */

			for (size = 0, p = buffer; *p != '\0'; )
			{
				size += font_server->GetAdvanceWidth(&m_LabelFontStyle, (CHARACTER)*p);
				p = CharNext(p);
			}

		/* See if we are too big. */

			if (size > label_width)
			{
				int nNewSize = (int)scale_pcoord(FixedInteger(m_LabelFontStyle.Size()), label_width, size);
				CFixed lNewSize = MakeFixed(nNewSize);
				m_LabelFontStyle.BaseSize(lNewSize);
				m_LabelFontStyle.Size(lNewSize);

				too_big = TRUE;

				if (nNewSize < MINIMUM_LABEL_POINT_SIZE)
				{
					m_LabelFontStyle.Size(MakeFixed(MINIMUM_LABEL_POINT_SIZE));
					m_LabelFontStyle.BaseSize(MakeFixed(MINIMUM_LABEL_POINT_SIZE));
					m_LabelFontStyle.UpdateFontMetrics();
					stop_looking = TRUE;
				}
			}
		}
		if (!too_big)
		{
		/* All done! */
			stop_looking = TRUE;
		}
	}

	m_LabelFontStyle.Alignment(ALIGN_left);

	text_style = m_LabelFontStyle;

	if (get_info().style.label_style == CAL_LABEL_INVERTED)
	{
		if (text_style.FillForegroundColor() == get_info().style.color
					&& text_style.FillPattern() == 0)
		{
			text_style.FillForegroundColor(COLOR_WHITE);
		}
	}
	else
	{
		if (text_style.FillForegroundColor() == COLOR_WHITE)
		{
			text_style.FillForegroundColor(COLOR_BLACK);
		}
	}

/*
// Run through the days now and add all the frames.
*/

	ObjectListPtr skeleton_list = skeleton_group->object_list();

	for (weekday = first_day, i = 0;
						i < days_in_week;
 						i++, weekday = next_weekday(weekday))
	{

#ifdef LOCALIZE
			CurrentLocale.WeekDayName((WEEKDAY)weekday, buffer, sizeof(buffer));
#else
			// JRO strcpy(buffer, weekday_name[weekday]);
	         strcpy(buffer, GET_PMWAPP()->GetResourceStringPointer (weekday_name_id[weekday]));

#endif

			switch (get_info().style.weekday_style)
			{
				case WEEKDAY_STYLE_INITIALS:
				{
					buffer[1] = '\0';
					break;
				}
				case WEEKDAY_STYLE_ABBREV:
				{
#ifdef LOCALIZE
					CurrentLocale.AbbrevWeekDayName((WEEKDAY)weekday, buffer, sizeof(buffer));
#else
					buffer[3] = '\0';
#endif
					break;
				}
				default:
				{
					break;
				}
			}


	/* Add the actual text. */

		if ((error = add_frame(&r,
 							buffer,
 							ALIGN_left,
 							ALIGN_top,
 							LABEL_FRAME_PANEL+i,
 							0,
							0,
 							skeleton_list,
							OBJECT_TYPE_Frame,
							&text_style)) != ERRORCODE_None)
		{
			return error;
		}

		PMGPageObjectPtr object = (PMGPageObjectPtr)skeleton_list->last_object();
		object->add_flags(OBJECT_FLAG_locked);

		r.y0 += cell_height;
		r.y1 += cell_height;
	}

/* Draw the numbers if this is a weekly calendar. */

	r.x0 = label.x0;
	r.y0 = label.y0;
	r.x1 = label.x1 + cell_width;
	r.y1 = label.y0 + cell_height;

	*buffer = '\0';					/* In case of GENERIC. */

	day = first_day_of_month;

	if (get_info().year == 1752 && get_info().month == SEPTEMBER)
	{
		if (day >= 3)
		{
			day += 14-3;
		}
	}

	m_NumberFontStyle.Alignment(ALIGN_center);

	for (i = 0; i < days_in_week; i++, day++)
	{
		short days_in_month = days_in_a_month(get_info().year, get_info().month);
		
		if (day > days_in_month)
			day = 1;

		if (get_info().style.type == WEEKLY)
		{
			itoa(day, buffer, 10);
		}

	/* Add the actual text. */

		if ((error = add_frame(&r,
							buffer,
							ALIGN_center,
							ALIGN_middle,
							i+DATE_PANEL,
							0,
							SELECT_FLAG_boundary | SELECT_FLAG_drag_handle | SELECT_FLAG_solo_select,
							date_group->object_list(),
							OBJECT_TYPE_CalendarDate,
							&m_NumberFontStyle)) != ERRORCODE_None)
		{
			return error;
		}

		r.y0 += cell_height;
		r.y1 += cell_height;

		if (get_info().year == 1752 && get_info().month == SEPTEMBER && day == 2)
		{
			day = 13;
		}
	}

	skeleton_group->establish();
	date_group->establish();
	text_group->establish();
	graphic_group->establish();

	return ERRORCODE_None;
}
Exemplo n.º 13
0
//================================================================================================
//--------------------------------------------------==-+++--> Entry Point of Program Using WinMain:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASS wndclass;
	HWND hwndMain;
	MSG msg;
	int updated;
	
	(void)hPrevInstance;
	(void)nCmdShow;
	
	#if defined(__GNUC__) && defined(_DEBUG)
	#	ifdef _WIN64
	#		define LoadExcHndl() LoadLibraryExA("dbg\\64\\exchndl", NULL, LOAD_WITH_ALTERED_SEARCH_PATH)
	#	else
	#		define LoadExcHndl() LoadLibraryExA("dbg\\exchndl", NULL, LOAD_WITH_ALTERED_SEARCH_PATH)
	#	endif
	#else
	#	define LoadExcHndl()
	#endif
	LoadExcHndl(); // LOAD_WITH_ALTERED_SEARCH_PATH works :P At least since Win2k
	
	g_instance = hInstance;
	if(LoadClockAPI("misc/T-Clock" ARCH_SUFFIX, &api)){
		MessageBox(NULL, "Error loading: T-Clock" ARCH_SUFFIX ".dll", "API error", MB_OK|MB_ICONERROR);
		return 2;
	}
	chdir(api.root); // make sure we've got the right working directory
	
	// Make sure we're running Windows 2000 and above
	if(!api.OS) {
		MessageBox(NULL,"T-Clock requires Windows 2000 or newer","old OS",MB_OK|MB_ICONERROR);
		return 1;
	}
	
	// make sure ObjectBar isn't running -> From Original Code/Unclear if This is Still a Conflict. (test suggested not really.. no crash but no clock either :P)
	if(FindWindow("ObjectBar Main","ObjectBar")) {
		MessageBox(NULL,"ObjectBar and T-Clock can't be run together","ObjectBar detected!",MB_OK|MB_ICONERROR);
		return 1;
	}
	
	// Load ALL of the Global Resources
	g_hIconTClock = LoadIcon(api.hInstance, MAKEINTRESOURCE(IDI_MAIN));
	g_hIconPlay = LoadImage(g_instance, MAKEINTRESOURCE(IDI_PLAY), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	g_hIconStop = LoadImage(g_instance, MAKEINTRESOURCE(IDI_STOP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	g_hIconDel  = LoadImage(g_instance, MAKEINTRESOURCE(IDI_DEL), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	
//	FindTrayServer(hwndMain);
	
	// Make sure we're not running 32bit on 64bit OS / start the other one
	#ifndef _WIN64
	if(IsWow64()){
		hwndMain = FindWindow(g_szClassName, NULL);
		if(hwndMain) { // send commands to existing instance
			ProcessCommandLine(hwndMain,lpCmdLine);
		}else{ // start new instance
			char clock64[MAX_PATH];
			memcpy(clock64, api.root, api.root_len+1);
			add_title(clock64,"Clock" ARCH_SUFFIX_64 ".exe");
			api.Exec(clock64,lpCmdLine,NULL);
		}
		return 0;
	}
	#endif // _WIN64
	
	// Do Not Allow the Program to Execute Twice!
	updated = 25; /**< wait up to 5 sec in 1/5th seconds for other instance */
	do{
		HANDLE processlock=CreateMutex(NULL,FALSE,g_szClassName); // we leak handle here, but Windows closes on process exit anyway (so why do it manually?)
		if(processlock && GetLastError()==ERROR_ALREADY_EXISTS){
			CloseHandle(processlock);
			hwndMain = FindWindow(g_szClassName, NULL);
			if(hwndMain) { // This One Sends Commands to the Instance
				ProcessCommandLine(hwndMain,lpCmdLine); // That is Currently Running.
				return 0;
			}
			Sleep(200);
			continue;
		}
		break;
	}while(updated--);
	
	// Update settings if required and setup defaults
	if((updated=CheckSettings())<0){
		return 1;
	}
	CancelAllTimersOnStartUp();
	
	// Message of the taskbar recreating - Special thanks to Mr.Inuya
	g_WM_TaskbarCreated = RegisterWindowMessage("TaskbarCreated");
	
	// register a window class
	wndclass.style         = 0;
	wndclass.lpfnWndProc   = WndProc;
	wndclass.cbClsExtra    = 0;
	wndclass.cbWndExtra    = 0;
	wndclass.hInstance     = g_instance;
	wndclass.hIcon         = g_hIconTClock;
	wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH)(intptr_t)(COLOR_WINDOW+1);
	wndclass.lpszMenuName  = NULL;
	wndclass.lpszClassName = g_szClassName;
	g_atomTClock = RegisterClass(&wndclass);
	
	if(api.OS >= TOS_VISTA) { // allow non elevated processes to send control messages (eg, App with admin rights, explorer without)
		#define MSGFLT_ADD 1
		#define MSGFLT_REMOVE 2
		typedef BOOL (WINAPI* ChangeWindowMessageFilter_t)(UINT message,DWORD dwFlag);
		ChangeWindowMessageFilter_t ChangeWindowMessageFilter=(ChangeWindowMessageFilter_t)GetProcAddress(GetModuleHandle("user32"), "ChangeWindowMessageFilter");
		if(ChangeWindowMessageFilter){
			int msgid;
			ChangeWindowMessageFilter(g_WM_TaskbarCreated,MSGFLT_ADD);
			ChangeWindowMessageFilter(WM_COMMAND,MSGFLT_ADD);
			for(msgid=WM_MOUSEFIRST; msgid<=WM_MOUSELAST; ++msgid)
				ChangeWindowMessageFilter(msgid,MSGFLT_ADD);
			for(msgid=MAINMFIRST; msgid<=MAINMLAST; ++msgid)
				ChangeWindowMessageFilter(msgid,MSGFLT_ADD);
		}
	}
	
	// create a hidden window
	g_hwndTClockMain = hwndMain = CreateWindowEx(WS_EX_NOACTIVATE, MAKEINTATOM(g_atomTClock),NULL, 0, 0,0,0,0, NULL,NULL,g_instance,NULL);
	// This Checks for First Instance Startup Options
	ProcessCommandLine(hwndMain,lpCmdLine);
	
	GetHotKeyInfo(hwndMain);
	
	if(api.OS > TOS_2000) {
		if(api.GetInt("Desktop", "MonOffOnLock", 0))
			RegisterSession(hwndMain);
	}
	if(updated==1){
		PostMessage(hwndMain,WM_COMMAND,IDM_SHOWPROP,0);
	}
	while(GetMessage(&msg, NULL, 0, 0)) {
		if(!(g_hwndSheet && IsWindow(g_hwndSheet) && PropSheet_IsDialogMessage(g_hwndSheet,&msg))
		&& !(g_hDlgTimer && IsWindow(g_hDlgTimer) && IsDialogMessage(g_hDlgTimer,&msg))
		&& !(g_hDlgTimerWatch && IsWindow(g_hDlgTimerWatch) && IsDialogMessage(g_hDlgTimerWatch,&msg))
		&& !(g_hDlgStopWatch && IsWindow(g_hDlgStopWatch) && IsDialogStopWatchMessage(g_hDlgStopWatch,&msg))){
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	
	UnregisterHotKey(hwndMain, HOT_TIMER);
	UnregisterHotKey(hwndMain, HOT_WATCH);
	UnregisterHotKey(hwndMain, HOT_STOPW);
	UnregisterHotKey(hwndMain, HOT_PROPR);
	UnregisterHotKey(hwndMain, HOT_CALEN);
	UnregisterHotKey(hwndMain, HOT_TSYNC);
	
	UnregisterSession(hwndMain);
	
	EndNewAPI(NULL);
	
	return (int)msg.wParam;
}
Exemplo n.º 14
0
ERRORCODE Calendar::build_monthly(CTextStyle* pTitleStyle)
{
	PBOX r;
	SHORT i;
	COLOR shadow_color = 0;
	SHORT shadow_pattern = 0;
	ALIGN_TYPE h_align;
	VERT_ALIGN_TYPE v_align;
	SHORT day, week;
//	WEEKDAY weekday;
	SHORT weekday;
	CHAR buffer[45];
	GroupObjectPtr skeleton_group, date_group, text_group, graphic_group;
	BOOL stop_looking;
	ERRORCODE error;
	CTextStyle text_style(database);
	FontServerPtr font_server = database->get_font_server();

/* Compute shadow parameter. */

	if (has_shadow)
	{
	/* Set the shadow color. */

		switch (get_info().style.shadow_style)
		{
			case CAL_SHADOW_BLACK:
			case CAL_SHADOW_GRAY:
			case CAL_SHADOW_LIGHT_GRAY:
			{
				shadow_color = COLOR_BLACK;
				break;
			}
			case CAL_SHADOW_100:
			case CAL_SHADOW_50:
			case CAL_SHADOW_25:
			{
				shadow_color = get_info().style.color;
				break;
			}
			default:
			{
				return ERRORCODE_IntError;
			}
		}

	/* Set the shadow pattern. */

		switch (get_info().style.shadow_style)
		{
			case CAL_SHADOW_BLACK:
			case CAL_SHADOW_100:
			{
				shadow_pattern = 0;
				break;
			}
			case CAL_SHADOW_GRAY:
			case CAL_SHADOW_50:
			{
				shadow_pattern = 50;
				break;
			}
			case CAL_SHADOW_LIGHT_GRAY:
			case CAL_SHADOW_25:
			{
				shadow_pattern = 75;
				break;
			}
			default:
			{
				return ERRORCODE_IntError;
			}
		}
	}

/* Create the groups. */

	if (!build_calendar_groups(&skeleton_group, &date_group,
								&graphic_group, &text_group))
	{
		return ERRORCODE_Memory;
	}

/* Add a default calendar title. */

	if ((error = add_title(skeleton_group->object_list(), pTitleStyle)) != ERRORCODE_None)
	{
		return error;
	}

/* Draw the label. */

	switch (get_info().style.label_style)
	{
		case CAL_LABEL_TEXT:
		{
			break;
		}
		case CAL_LABEL_BOXED:
		{
			if ((error = add_box(&label, 0, get_info().style.color, LABEL_PANEL, line_thickness, skeleton_group->object_list())) != ERRORCODE_None)
			{
				return error;
			}
			break;
		}
		case CAL_LABEL_INVERTED:
		{
			if ((error = add_line(&label, 0, get_info().style.color, LABEL_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
			{
				return error;
			}
			break;
		}
		default:
		{
			break;
		}
	}

/* Draw the calendar frame. */

	if (has_border)
	{
	/*
	// Draw calendar with outline.
	*/

	/* Draw the outline. */

		if ((error = add_box(&bound, 0, get_info().style.color, SKELETON_PANEL, line_thickness, skeleton_group->object_list())) != ERRORCODE_None)
		{
			return error;
		}

	/* Draw the horizontal lines. */

		switch (get_info().style.line_style)
		{
			case CAL_LINES_ALL:
			{
			/* Draw vertical lines. */

				r.y0 = bound.y0;
				r.y1 = bound.y1;
				r.x0 = bound.x0 + cell_width;
				for (weekday = (WEEKDAY)1; weekday < days_in_week; weekday++)
				{
					r.x1 = r.x0 + line_thickness;
					if ((error = add_line(&r, 0, get_info().style.color, SKELETON_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
					{
						return error;
					}
					r.x0 += cell_width;
				}

			/* Fall through to... */
			}
			case CAL_LINES_HORIZONTAL:
			{
			/* Draw horizontal lines. */

				r.x0 = bound.x0;
				r.x1 = bound.x1;
				r.y0 = bound.y0 + cell_height;
				for (week = 1; week < weeks_in_month; week++)
				{
					r.y1 = r.y0 + line_thickness;
					if ((error = add_line(&r, 0, get_info().style.color, SKELETON_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
					{
						return error;
					}
					r.y0 += cell_height;
				}
				break;
			}
			default:
			{
				break;
			}
		}

		if (has_shadow)
		{
		/* Right piece. */

			r.x0 = bound.x1;
			r.x1 = r.x0 + shadow_thickness;
			r.y0 = (has_label ? label.y0 : bound.y0)+shadow_thickness;
			r.y1 = bound.y1+shadow_thickness;
			if ((error = add_line(&r, shadow_pattern, shadow_color, SHADOW_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
			{
				return error;
			}

		/* Bottom piece. */

			r.x0 = bound.x0+shadow_thickness;
			r.x1 = bound.x1+shadow_thickness;
			r.y0 = bound.y1;
			r.y1 = r.y0 + shadow_thickness;
			if ((error = add_line(&r, shadow_pattern, shadow_color, SHADOW_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
			{
				return error;
			}
		}
	}
	else
	{
	/*
	// Draw calendar without outline.
	*/

	/* Draw the horizontal lines. */

		switch (get_info().style.line_style)
		{
			case CAL_LINES_ALL:
			{
			/* Draw vertical lines. */

				r.x0 = bound.x0;

				for (weekday = (WEEKDAY)0; weekday <= days_in_week; weekday++)
				{
					r.y0 = bound.y0;
					r.y1 = bound.y1;

					if (weekday < skewed_first_day)
					{
						r.y0 += cell_height;
					}
					if (weekday > skewed_last_day+1)
					{
						r.y1 -= cell_height;
					}

					r.x1 = r.x0 + line_thickness;
					if ((error = add_line(&r, 0, get_info().style.color, SKELETON_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
					{
						return error;
					}
					r.x0 += cell_width;
				}

			/* Fall through to... */
			}
			case CAL_LINES_HORIZONTAL:
			{
			/* Draw horizontal lines. */

				r.x0 = bound.x0;
				r.x1 = bound.x1;
				r.y0 = bound.y0;

				for (week = 0; week <= weeks_in_month; week++)
				{
					if (get_info().style.line_style == CAL_LINES_ALL)
					{
						r.x0 = bound.x0;
						r.x1 = bound.x1;

						if (week == 0)
						{
							r.x0 += skewed_first_day*cell_width;
						}
						if (week == weeks_in_month)
						{
							r.x1 -= (days_in_week-(skewed_last_day+1))*cell_width;
						}
					}

					r.y1 = r.y0 + line_thickness;
					if ((error = add_line(&r, 0, get_info().style.color, SKELETON_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
					{
						return error;
					}
					r.y0 += cell_height;
				}
				break;
			}
			default:
			{
				break;
			}
		}

		if (has_shadow)
		{
			BOOL full_shadow = skewed_last_day+1 == days_in_week;

		/* Right piece. */

			r.x0 = bound.x1;
			r.x1 = r.x0 + shadow_thickness;
			r.y0 = (has_label ? label.y0 : bound.y0)+shadow_thickness;
			r.y1 = bound.y1+shadow_thickness;
			if (!full_shadow)
			{
				r.y1 -= cell_height;
			}
			if ((error = add_line(&r, shadow_pattern, shadow_color, SHADOW_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
			{
				return error;
			}

			if (!full_shadow)
			{
			/* Mid horizontal piece. */

				r.y0 = r.y1 - shadow_thickness;
				r.x0 = bound.x1 - (days_in_week-(skewed_last_day+1))*cell_width;
				if ((error = add_line(&r, shadow_pattern, shadow_color, SHADOW_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
				{
					return error;
				}

			/* Mid vertical piece. */

				r.x1 = r.x0 + shadow_thickness;
				r.y1 = bound.y1 + shadow_thickness;
				if ((error = add_line(&r, shadow_pattern, shadow_color, SHADOW_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
				{
					return error;
				}
			}

		/* Bottom piece. */

			r.x0 = bound.x0+shadow_thickness;
			r.y0 = bound.y1;
			if ((error = add_line(&r, shadow_pattern, shadow_color, SHADOW_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
			{
				return error;
			}

		/* Draw the label shadow if it has a label. */

			if (has_label)
			{
			/* Bottom of label where there is no calendar. */

				r.y0 = label.y1;
				r.x0 = label.x0 + shadow_thickness;
				r.x1 = label.x1 + shadow_thickness;

				r.y1 = r.y0 + shadow_thickness;
				if ((error = add_line(&r, shadow_pattern, shadow_color, SHADOW_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
				{
					return error;
				}

			/* Little white gap in shadow on right. */

				r.x0 = label.x1;
				r.y0 = label.y1 + shadow_thickness;
				r.y1 = r.y0 + 3*shadow_thickness/2;
				/* 100 == white */
				if ((error = add_line(&r, 100, shadow_color, SHADOW_PANEL, skeleton_group->object_list())) != ERRORCODE_None)
				{
					return error;
				}
			}
		}
	}

/*
// Draw the calendar text.
*/

/* Draw the label text. */

	r.y0 = label.y0;
	r.x0 = label.x0;
	r.y1 = label.y1;

	m_LabelFontStyle.Size(MakeFixed(heading_size));
	m_LabelFontStyle.BaseSize(MakeFixed(heading_size));

/*
// Calculate the size of the text for these labels.
// If the text falls outside the frame, keep making it smaller.
*/

	for (stop_looking = FALSE; !stop_looking;)
	{
		BOOL too_big = FALSE;

		m_LabelFontStyle.UpdateFontMetrics();

		for (weekday = get_info().first_day_of_week, i = 0;
							i < days_in_week && !too_big;
	 						i++, weekday = next_weekday(weekday))
		{
			// CHAR *p;
			TCHAR *p;
			PCOORD size;

#ifdef LOCALIZE
			CurrentLocale.WeekDayName((WEEKDAY) weekday, buffer, sizeof(buffer));
#else
			// JRO strcpy(buffer, weekday_name[weekday]);
			strcpy(buffer, GET_PMWAPP()->GetResourceStringPointer (weekday_name_id[weekday]));
#endif


			switch (get_info().style.weekday_style)
			{
				case WEEKDAY_STYLE_INITIALS:
				{
					buffer[1] = '\0';
					break;
				}
				case WEEKDAY_STYLE_ABBREV:
				{
#ifdef LOCALIZE
					CurrentLocale.AbbrevWeekDayName((WEEKDAY)weekday, buffer, sizeof(buffer));
#else
					buffer[3] = '\0';
#endif
					break;
				}
				default:
				{
					break;
				}
			}

		/* Compute the size for the text. */

			for (size = 0, p = buffer; *p != '\0'; )
			{
				size += font_server->GetAdvanceWidth(&m_LabelFontStyle, (CHARACTER)*p);
				p = CharNext(p);
			}

		/* See if we are too big. */

			if (size > cell_width)
			{
				int nNewSize = (int)scale_pcoord(FixedInteger(m_LabelFontStyle.Size()), cell_width, size);
				CFixed lNewSize = MakeFixed(nNewSize);
				m_LabelFontStyle.Size(lNewSize);
				m_LabelFontStyle.BaseSize(lNewSize);
				too_big = TRUE;
				if (lNewSize < MINIMUM_LABEL_POINT_SIZE)
				{
					m_LabelFontStyle.Size(MakeFixed(MINIMUM_LABEL_POINT_SIZE));
					m_LabelFontStyle.BaseSize(MakeFixed(MINIMUM_LABEL_POINT_SIZE));
					m_LabelFontStyle.UpdateFontMetrics();

					stop_looking = TRUE;
				}
			}
		}
		if (!too_big)
		{
		/* All done! */
			stop_looking = TRUE;
		}
	}

	m_LabelFontStyle.Alignment(ALIGN_center);
	m_LabelFontStyle.UpdateFontMetrics();

	text_style = m_LabelFontStyle;

	if (get_info().style.label_style == CAL_LABEL_INVERTED)
	{
		if (text_style.FillForegroundColor() == get_info().style.color
					&& text_style.FillPattern() == 0)
		{
			text_style.FillForegroundColor(COLOR_WHITE);
		}
	}
	else
	{
		if (text_style.FillForegroundColor() == COLOR_WHITE)
		{
			text_style.FillForegroundColor(COLOR_BLACK);
		}
	}

	ObjectListPtr skeleton_list = skeleton_group->object_list();

	for (weekday = get_info().first_day_of_week, i = 0;
									i < days_in_week;
 									i++, weekday = next_weekday(weekday))
	{
#ifdef LOCALIZE
		CurrentLocale.WeekDayName((WEEKDAY)weekday, buffer, sizeof(buffer));
#else
		// JRO strcpy(buffer, weekday_name[weekday]);
      strcpy(buffer, GET_PMWAPP()->GetResourceStringPointer (weekday_name_id[weekday]));
#endif

		switch (get_info().style.weekday_style)
		{
			case WEEKDAY_STYLE_INITIALS:
			{
				buffer[1] = '\0';
				break;
			}
			case WEEKDAY_STYLE_ABBREV:
			{
#ifdef LOCALIZE
				CurrentLocale.AbbrevWeekDayName((WEEKDAY)weekday, buffer, sizeof(buffer));
#else
				buffer[3] = '\0';
#endif
				break;
			}
			default:
			{
				break;
			}
		}

	/* Add a frame for the next string. */

		r.x1 = r.x0 + cell_width;
		if ((error = add_frame(&r,
 							buffer,
 							ALIGN_center,
 							ALIGN_middle,
 							LABEL_FRAME_PANEL+i,
 							0,
							0,
 							skeleton_list,
							OBJECT_TYPE_Frame,
							&text_style)) != ERRORCODE_None)
		{
			return error;
		}
		PMGPageObjectPtr object = (PMGPageObjectPtr)skeleton_list->last_object();
		object->add_flags(OBJECT_FLAG_locked);
		r.x0 += cell_width;
	}

/* We want the point size to be 1/6 the height of a cell. */

	r.y0 = bound.y0;
	r.y1 = r.y0 + cell_height;
	r.x0 = bound.x0 + skewed_first_day*cell_width;
	r.x1 = r.x0 + cell_width;

	SHORT size;

	if (get_info().style.line_style == CAL_LINES_NONE)
	{
		h_align = ALIGN_center;
		v_align = ALIGN_middle;
	}
	else
	{
		h_align = ALIGN_right;
		v_align = ALIGN_top;
	}

	// font size needs to be larger to be legible on a yearly calendar
	short type = get_info().style.type;
	if (type == YEARLY)
	{
		PCOORD height = (bound.y1 - bound.y0 - line_thickness)/5;
		size = (SHORT)scale_pcoord(height, 72/4, PAGE_RESOLUTION);
	}
	else
		size = (SHORT)scale_pcoord(cell_height, 72/6, PAGE_RESOLUTION);

	m_NumberFontStyle.BaseSize(MakeFixed(size));
	m_NumberFontStyle.Size(MakeFixed(size));

	m_NumberFontStyle.Alignment(h_align);
	m_NumberFontStyle.UpdateFontMetrics();

	for (i = DATE_PANEL, weekday = skewed_first_day, day = first_day_of_month;
									i < last_day_of_month+DATE_PANEL;
									i++, day++)
	{
		itoa(day, buffer, 10);

		if ((error = add_frame(&r,
 					buffer,
 					h_align,
 					v_align,
 					i,
					0,
					SELECT_FLAG_boundary | SELECT_FLAG_drag_handle | SELECT_FLAG_solo_select,
 					date_group->object_list(),
					OBJECT_TYPE_CalendarDate,
					&m_NumberFontStyle)) != ERRORCODE_None)
		{
			return error;
		}

		if (++weekday == days_in_week)
		{
			weekday = (WEEKDAY)0;

#if 0
			r.x0 = bound.x0 + 1;
			r.x1 = r.x0 + cell_width - 2;
#else
			r.x0 = bound.x0;
			r.x1 = r.x0 + cell_width;
//			r.x0 += line_thickness + line_thickness;
#endif

			r.y0 += cell_height;
			r.y1 += cell_height;
			day += DAYS_IN_FULL_WEEK - days_in_week;
		}
		else
		{
			r.x0 += cell_width;
			r.x1 += cell_width;
		}

	/* If this is the unusual month, fix the day now. */

		if (get_info().year == 1752
					&& get_info().month == SEPTEMBER
					&& day == 2)
		{
			day = 13;
		}
	}
	skeleton_group->establish();
	date_group->establish();
	text_group->establish();
	graphic_group->establish();

//	printf("Objects created: %d\n", listlen(CurrentDocument->CurrentList));
	return ERRORCODE_None;
}
Exemplo n.º 15
0
/*
 * This routine assumes that the line is a valid Unicode Character Database
 * entry.
 */
static void
read_cdata(FILE *in)
{
    ac_uint4 i, lineno, skip, code, ccl_code;
    short wnum, neg, number[2], compat;
    char line[512], *s, *e;

    lineno = skip = 0;
    while (fgets(line, sizeof(line), in)) {
	if( (s=strchr(line, '\n')) ) *s = '\0';
        lineno++;

        /*
         * Skip blank lines and lines that start with a '#'.
         */
        if (line[0] == 0 || line[0] == '#')
          continue;

        /*
         * If lines need to be skipped, do it here.
         */
        if (skip) {
            skip--;
            continue;
        }

        /*
         * Collect the code.  The code can be up to 6 hex digits in length to
         * allow surrogates to be specified.
         */
        for (s = line, i = code = 0; *s != ';' && i < 6; i++, s++) {
            code <<= 4;
            if (*s >= '0' && *s <= '9')
              code += *s - '0';
            else if (*s >= 'A' && *s <= 'F')
              code += (*s - 'A') + 10;
            else if (*s >= 'a' && *s <= 'f')
              code += (*s - 'a') + 10;
        }

        /*
         * Handle the following special cases:
         * 1. 4E00-9FA5 CJK Ideographs.
         * 2. AC00-D7A3 Hangul Syllables.
         * 3. D800-DFFF Surrogates.
         * 4. E000-F8FF Private Use Area.
         * 5. F900-FA2D Han compatibility.
	 * ...Plus additional ranges in newer Unicode versions...
         */
        switch (code) {
	  case 0x3400:
	    /* CJK Ideograph Extension A */
            add_range(0x3400, 0x4db5, "Lo", "L");

            add_range(0x3400, 0x4db5, "Cp", 0);

	    skip = 1;
	    break;
          case 0x4e00:
            /*
             * The Han ideographs.
             */
            add_range(0x4e00, 0x9fff, "Lo", "L");

            /*
             * Add the characters to the defined category.
             */
            add_range(0x4e00, 0x9fa5, "Cp", 0);

            skip = 1;
            break;
          case 0xac00:
            /*
             * The Hangul syllables.
             */
            add_range(0xac00, 0xd7a3, "Lo", "L");

            /*
             * Add the characters to the defined category.
             */
            add_range(0xac00, 0xd7a3, "Cp", 0);

            skip = 1;
            break;
          case 0xd800:
            /*
             * Make a range of all surrogates and assume some default
             * properties.
             */
            add_range(0x010000, 0x10ffff, "Cs", "L");
            skip = 5;
            break;
          case 0xe000:
            /*
             * The Private Use area.  Add with a default set of properties.
             */
            add_range(0xe000, 0xf8ff, "Co", "L");
            skip = 1;
            break;
          case 0xf900:
            /*
             * The CJK compatibility area.
             */
            add_range(0xf900, 0xfaff, "Lo", "L");

            /*
             * Add the characters to the defined category.
             */
            add_range(0xf900, 0xfaff, "Cp", 0);

            skip = 1;
	    break;
	  case 0x20000:
	    /* CJK Ideograph Extension B */
            add_range(0x20000, 0x2a6d6, "Lo", "L");

            add_range(0x20000, 0x2a6d6, "Cp", 0);

	    skip = 1;
	    break;
	  case 0xf0000:
	    /* Plane 15 private use */
	    add_range(0xf0000, 0xffffd, "Co", "L");
	    skip = 1;
	    break;

	  case 0x100000:
	    /* Plane 16 private use */
	    add_range(0x100000, 0x10fffd, "Co", "L");
	    skip = 1;
	    break;
        }

        if (skip)
          continue;

        /*
         * Add the code to the defined category.
         */
        ordered_range_insert(code, "Cp", 2);

        /*
         * Locate the first character property field.
         */
        for (i = 0; *s != 0 && i < 2; s++) {
            if (*s == ';')
              i++;
        }
        for (e = s; *e && *e != ';'; e++) ;
    
        ordered_range_insert(code, s, e - s);

        /*
         * Locate the combining class code.
         */
        for (s = e; *s != 0 && i < 3; s++) {
            if (*s == ';')
              i++;
        }

        /*
         * Convert the combining class code from decimal.
         */
        for (ccl_code = 0, e = s; *e && *e != ';'; e++)
          ccl_code = (ccl_code * 10) + (*e - '0');

        /*
         * Add the code if it not 0.
         */
        if (ccl_code != 0)
          ordered_ccl_insert(code, ccl_code);

        /*
         * Locate the second character property field.
         */
        for (s = e; *s != 0 && i < 4; s++) {
            if (*s == ';')
              i++;
        }
        for (e = s; *e && *e != ';'; e++) ;

        ordered_range_insert(code, s, e - s);

        /*
         * Check for a decomposition.
         */
        s = ++e;
        if (*s != ';') {
	    compat = *s == '<';
	    if (compat) {
		/*
		 * Skip compatibility formatting tag.
		 */
		while (*s++ != '>');
	    }
            /*
             * Collect the codes of the decomposition.
             */
            for (dectmp_size = 0; *s != ';'; ) {
                /*
                 * Skip all leading non-hex digits.
                 */
                while (!ishdigit(*s))
 		  s++;

                for (dectmp[dectmp_size] = 0; ishdigit(*s); s++) {
                    dectmp[dectmp_size] <<= 4;
                    if (*s >= '0' && *s <= '9')
                      dectmp[dectmp_size] += *s - '0';
                    else if (*s >= 'A' && *s <= 'F')
                      dectmp[dectmp_size] += (*s - 'A') + 10;
                    else if (*s >= 'a' && *s <= 'f')
                      dectmp[dectmp_size] += (*s - 'a') + 10;
                }
                dectmp_size++;
            }

            /*
             * If there are any codes in the temporary decomposition array,
             * then add the character with its decomposition.
             */
            if (dectmp_size > 0) {
		if (!compat) {
		    add_decomp(code, 0);
		}
		add_decomp(code, 1);
	    }
        }

        /*
         * Skip to the number field.
         */
        for (i = 0; i < 3 && *s; s++) {
            if (*s == ';')
              i++;
        }

        /*
         * Scan the number in.
         */
        number[0] = number[1] = 0;
        for (e = s, neg = wnum = 0; *e && *e != ';'; e++) {
            if (*e == '-') {
                neg = 1;
                continue;
            }

            if (*e == '/') {
                /*
                 * Move the the denominator of the fraction.
                 */
                if (neg)
                  number[wnum] *= -1;
                neg = 0;
                e++;
                wnum++;
            }
            number[wnum] = (number[wnum] * 10) + (*e - '0');
        }

        if (e > s) {
            /*
             * Adjust the denominator in case of integers and add the number.
             */
            if (wnum == 0)
              number[1] = 1;

            add_number(code, number[0], number[1]);
        }

        /*
         * Skip to the start of the possible case mappings.
         */
        for (s = e, i = 0; i < 4 && *s; s++) {
            if (*s == ';')
              i++;
        }

        /*
         * Collect the case mappings.
         */
        cases[0] = cases[1] = cases[2] = 0;
        for (i = 0; i < 3; i++) {
            while (ishdigit(*s)) {
                cases[i] <<= 4;
                if (*s >= '0' && *s <= '9')
                  cases[i] += *s - '0';
                else if (*s >= 'A' && *s <= 'F')
                  cases[i] += (*s - 'A') + 10;
                else if (*s >= 'a' && *s <= 'f')
                  cases[i] += (*s - 'a') + 10;
                s++;
            }
            if (*s == ';')
              s++;
        }
        if (cases[0] && cases[1])
          /*
           * Add the upper and lower mappings for a title case character.
           */
          add_title(code);
        else if (cases[1])
          /*
           * Add the lower and title case mappings for the upper case
           * character.
           */
          add_upper(code);
        else if (cases[0])
          /*
           * Add the upper and title case mappings for the lower case
           * character.
           */
          add_lower(code);
    }
}
Exemplo n.º 16
0
/*------------------------------------------------
  initialize the clock
--------------------------------------------------*/
void InitClock(HWND hwnd)
{
	RECT rc;
	
	if(g_bInitClock) return;
	g_bInitClock = TRUE;
	
	g_hInst = GetModuleHandle(DLLFILENAME);
	
	g_winver = CheckWinVersion();       // common/utl.c
	g_bVisualStyle = IsXPVisualStyle(); // common/utl.c
	
#if 0
	if(!(g_winver&WIN10RS1))
	{
		// check subclassification
		if(IsSubclassed(hwnd))
		{
			SendMessage(g_hwndTClockMain, TCM_CLOCKERROR, 0, 6);
			return;
		}
	}
#endif
	
	GetModuleFileName(g_hInst, g_mydir, MAX_PATH);
	del_title(g_mydir);
	
	strcpy(g_inifile, g_mydir);
	add_title(g_inifile, "tclock.ini");
	g_bIniSetting = TRUE;
/*  g_bIniSetting = FALSE;
	if(IsFile(g_inifile)) g_bIniSetting = TRUE; */
	
	// Save the original window size
	GetWindowRect(hwnd, &rc);
	g_OrigClockWidth = rc.right - rc.left;
	g_OrigClockHeight = rc.bottom - rc.top;
	// Save taskbar direction
	g_bVertTaskbar = IsVertTaskbar(GetParent(GetParent(hwnd)));
	g_bTaskbarPosChanging = FALSE;
	
	// tell tclock.exe clock's HWND
	PostMessage(g_hwndTClockMain, TCM_HWNDCLOCK, 0, (LPARAM)hwnd);
	
	// read settings
	LoadSetting(hwnd);
	
	InitTooltip(hwnd); // tooltip.c
	InitUserStr();     // userstr.c
	
	// subclassfy the clock window !!
	if(g_winver&WIN10RS1)
	{
		SetWindowSubclass(GetParent(hwnd), SubclassTrayProc,
				SUBCLASSTRAY_ID, (DWORD_PTR)hwnd);
	}
	SetWindowSubclass(hwnd, SubclassProc, SUBCLASS_ID, 0);
	
	// don't accept double clicks
	SetClassLong(hwnd, GCL_STYLE,
		GetClassLong(hwnd, GCL_STYLE) & ~CS_DBLCLKS);
	
#if TC_ENABLE_STARTBUTTON
	InitStartButton(hwnd); // startbtn.c
#endif
#if TC_ENABLE_STARTMENU
	InitStartMenu(hwnd);   // startmenu.c
#endif
#if TC_ENABLE_TASKBAR
	InitTaskbar(hwnd);     // taskbar.c
#endif
#if TC_ENABLE_TASKSWITCH
	InitTaskSwitch(hwnd);  // taskswitch.c
#endif
#if TC_ENABLE_TRAYNOTIFY
	InitTrayNotify(hwnd);  // traynotify.c
#endif
#if TC_ENABLE_VOLUME
	InitMixer();           // mixer.c
#endif
#if TC_ENABLE_SYSINFO
	InitSysInfo(hwnd);     // sysinfo.c
#endif
	
#if TC_ENABLE_TASKBAR
	RefreshTaskbar(hwnd);  // taskbar.c
#else
	PostMessage(GetParent(GetParent(hwnd)), WM_SIZE, SIZE_RESTORED, 0);
	InvalidateRect(GetParent(GetParent(hwnd)), NULL, TRUE);
#endif
	
	SetTimer(hwnd, IDTIMER_MAIN, 1000, NULL);
	
#if TC_ENABLE_DESKTOPICON
	SetDesktopIcons();     // desktop.c
#endif
}
Exemplo n.º 17
0
//---------------------------------------------------------------------------------------
ImoObj* Linker::add_child_to_model(ImoObj* pParent, ImoObj* pChild, int ldpChildType)
{
    //If the object (or its content, for DTOs) is added to the model it must return NULL.
    //Othewise, it must return the received object. This behaviour is necessary to
    //simplify unit tests of LdpAnalyser

    m_ldpChildType = ldpChildType;
    m_pParent = pParent;

    switch(pChild->get_obj_type())
    {
        case k_imo_bezier_info:
            return add_bezier(static_cast<ImoBezierInfo*>(pChild));

        case k_imo_content:
            return add_content(static_cast<ImoContent*>(pChild));

        case k_imo_cursor_info:
            return add_cursor(static_cast<ImoCursorInfo*>(pChild));

        case k_imo_font_style_dto:
            return add_font_style(static_cast<ImoFontStyleDto*>(pChild));

        case k_imo_instrument:
            return add_instrument(static_cast<ImoInstrument*>(pChild));

        case k_imo_instr_group:
            return add_instruments_group(static_cast<ImoInstrGroup*>(pChild));

        case k_imo_listitem:
            return add_listitem(static_cast<ImoListItem*>(pChild));

        case k_imo_midi_info:
            return add_midi_info(static_cast<ImoMidiInfo*>(pChild));

        case k_imo_music_data:
            return add_child(k_imo_instrument, pChild);

        case k_imo_option:
            return add_option(static_cast<ImoOptionInfo*>(pChild));

        case k_imo_page_info:
            return add_page_info(static_cast<ImoPageInfo*>(pChild));

        case k_imo_param_info:
            return add_param_info(static_cast<ImoParamInfo*>(pChild));

        case k_imo_score_text:
            return add_text(static_cast<ImoScoreText*>(pChild));

        case k_imo_score_title:
            return add_title(static_cast<ImoScoreTitle*>(pChild));

        case k_imo_staff_info:
            return add_staff_info(static_cast<ImoStaffInfo*>(pChild));

        case k_imo_styles:
            return add_child(k_imo_document, pChild);

        case k_imo_system_info:
            return add_system_info(static_cast<ImoSystemInfo*>(pChild));

        case k_imo_style:
            return add_style(static_cast<ImoStyle*>(pChild));

        case k_imo_table_row:
        {
            if (m_pParent)
            {
                if (m_pParent->is_table_head())
                    return add_child(k_imo_table_head, pChild);
                else if (m_pParent->is_table_body())
                    return add_child(k_imo_table_body, pChild);
                else
                    return pChild;
            }
            else
                return pChild;
        }

        case k_imo_table_head:
        case k_imo_table_body:
        {
            if (m_pParent && m_pParent->is_table())
                return add_child(k_imo_table, pChild);
            else
                return pChild;
        }

        default:
            if (pChild->is_block_level_obj())
                return add_block_level_item(static_cast<ImoBlockLevelObj*>(pChild));
            else if (pChild->is_inline_level_obj())
                return add_inline_level_item(static_cast<ImoInlineLevelObj*>(pChild));
            else if (pChild->is_staffobj())
                return add_staffobj(static_cast<ImoStaffObj*>(pChild));
            else if (pChild->is_relobj())
                return add_relation(static_cast<ImoRelObj*>(pChild));
            else if (pChild->is_auxobj())
                return add_attachment(static_cast<ImoAuxObj*>(pChild));
            else
                return pChild;
    }
}
Exemplo n.º 18
0
World::World(WindowFramework* windowFrameworkPtr)
   : m_windowFrameworkPtr(windowFrameworkPtr)
   {
   // preconditions
   if(m_windowFrameworkPtr == NULL)
      {
      nout << "ERROR: World::World(WindowFramework* windowFrameworkPtr) parameter windowFrameworkPtr cannot be NULL." << endl;
      return;
      }

   m_keyMap.resize(K_keys);
   m_keyMap[K_left     ] = false;
   m_keyMap[K_right    ] = false;
   m_keyMap[K_forward  ] = false;
   m_keyMap[K_cam_left ] = false;
   m_keyMap[K_cam_right] = false;
   m_windowFrameworkPtr->set_background_type(WindowFramework::BT_black);

   // Post the instructions

   m_titleNp = add_title("Panda3D Tutorial: Roaming Ralph (Walking on Uneven Terrain)");
   m_inst1Np = add_instructions(0.95, "[ESC]: Quit");
   m_inst2Np = add_instructions(0.90, "[Left Arrow]: Rotate Ralph Left");
   m_inst3Np = add_instructions(0.85, "[Right Arrow]: Rotate Ralph Right");
   m_inst4Np = add_instructions(0.80, "[Up Arrow]: Run Ralph Forward");
   m_inst6Np = add_instructions(0.70, "[A]: Rotate Camera Left");
   m_inst7Np = add_instructions(0.65, "[S]: Rotate Camera Right");

   // Set up the environment
   //
   // This environment model contains collision meshes.  If you look
   // in the egg file, you will see the following:
   //
   //    <Collide> { Polyset keep descend }
   //
   // This tag causes the following mesh to be converted to a collision
   // mesh -- a mesh which is optimized for collision, not rendering.
   // It also keeps the original mesh, so there are now two copies ---
   // one optimized for rendering, one for collisions.

   NodePath modelsNp = m_windowFrameworkPtr->get_panda_framework()->get_models();
   m_environNp = m_windowFrameworkPtr->load_model(modelsNp, "../models/world");
   NodePath renderNp = m_windowFrameworkPtr->get_render();
   m_environNp.reparent_to(renderNp);
   m_environNp.set_pos(0,0,0);

   // Create the main character, Ralph
   LPoint3f ralphStartPos = m_environNp.find("**/start_point").get_pos();
   CActor::AnimMap ralphAnims;
   ralphAnims["../models/ralph-run"].push_back("run");
   ralphAnims["../models/ralph-walk"].push_back("walk");
   m_ralph.load_actor(m_windowFrameworkPtr,
                      "../models/ralph",
                      &ralphAnims,
                      PartGroup::HMF_ok_wrong_root_name|
                      PartGroup::HMF_ok_anim_extra|
                      PartGroup::HMF_ok_part_extra);
   m_ralph.reparent_to(renderNp);
   m_ralph.set_scale(0.2);
   m_ralph.set_pos(ralphStartPos);

   // Create a floater object.  We use the "floater" as a temporary
   // variable in a variety of calculations.

   m_floaterNp = NodePath("floater");
   m_floaterNp.reparent_to(renderNp);

   // Accept the control keys for movement and rotation
   m_windowFrameworkPtr->enable_keyboard();
   m_windowFrameworkPtr->get_panda_framework()->define_key("escape"        , "sysExit"    , sys_exit                        , NULL);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_left"    , "left"       , call_set_key<K_left     , true >, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_right"   , "right"      , call_set_key<K_right    , true >, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_up"      , "forward"    , call_set_key<K_forward  , true >, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("a"             , "cam-left"   , call_set_key<K_cam_left , true >, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("s"             , "cam-right"  , call_set_key<K_cam_right, true >, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_left-up" , "leftUp"     , call_set_key<K_left     , false>, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_right-up", "rightUp"    , call_set_key<K_right    , false>, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_up-up"   , "forwardUp"  , call_set_key<K_forward  , false>, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("a-up"          , "cam-leftUp" , call_set_key<K_cam_left , false>, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("s-up"          , "cam-rightUp", call_set_key<K_cam_right, false>, this);

   PT(GenericAsyncTask) taskPtr = new GenericAsyncTask("moveTask", call_move, this);
   if(taskPtr != NULL)
      {
      AsyncTaskManager::get_global_ptr()->add(taskPtr);
      }

   // Game state variables
   m_isMoving = false;

   // Set up the camera

   // Note: no need to disable the mouse in C++
   NodePath cameraNp = m_windowFrameworkPtr->get_camera_group();
   cameraNp.set_pos(m_ralph.get_x(), m_ralph.get_y()+10, 2);

   // We will detect the height of the terrain by creating a collision
   // ray and casting it downward toward the terrain.  One ray will
   // start above ralph's head, and the other will start above the camera.
   // A ray may hit the terrain, or it may hit a rock or a tree.  If it
   // hits the terrain, we can detect the height.  If it hits anything
   // else, we rule that the move is illegal.

   NodePath ralphGroundColNp;
   m_ralphGroundRayPtr = new CollisionRay();
   if(m_ralphGroundRayPtr != NULL)
      {
      m_ralphGroundRayPtr->set_origin(0, 0, 1000);
      m_ralphGroundRayPtr->set_direction(0, 0, -1);
      m_ralphGroundColPtr = new CollisionNode("ralphRay");
      if(m_ralphGroundColPtr != NULL)
         {
         m_ralphGroundColPtr->add_solid(m_ralphGroundRayPtr);
         m_ralphGroundColPtr->set_from_collide_mask(BitMask32::bit(0));
         m_ralphGroundColPtr->set_into_collide_mask(BitMask32::all_off());
         ralphGroundColNp = m_ralph.attach_new_node(m_ralphGroundColPtr);
         m_ralphGroundHandlerPtr = new CollisionHandlerQueue();
         if(m_ralphGroundHandlerPtr != NULL)
            {
            m_collisionTraverser.add_collider(ralphGroundColNp, m_ralphGroundHandlerPtr);
            }
         }
      }

   NodePath camGroundColNp;
   m_camGroundRayPtr = new CollisionRay();
   if(m_camGroundRayPtr != NULL)
      {
      m_camGroundRayPtr->set_origin(0, 0, 1000);
      m_camGroundRayPtr->set_direction(0, 0, -1);
      m_camGroundColPtr = new CollisionNode("camRay");
      if(m_camGroundColPtr != NULL)
         {
         m_camGroundColPtr->add_solid(m_camGroundRayPtr);
         m_camGroundColPtr->set_from_collide_mask(BitMask32::bit(0));
         m_camGroundColPtr->set_into_collide_mask(BitMask32::all_off());
         camGroundColNp = cameraNp.attach_new_node(m_camGroundColPtr);
         m_camGroundHandlerPtr = new CollisionHandlerQueue();
         if(m_camGroundHandlerPtr != NULL)
            {
            m_collisionTraverser.add_collider(camGroundColNp, m_camGroundHandlerPtr);
            }
         }
      }

   // Uncomment this line to see the collision rays
   //ralphGroundColNp.show();
   //camGroundColNp.show();

   // Uncomment this line to show a visual representation of the
   // collisions occuring
   //m_collisionTraverser.show_collisions(renderNp);

   // Create some lighting
   PT(AmbientLight) ambientLightPtr = new AmbientLight("ambientLight");
   if(ambientLightPtr != NULL)
      {
      ambientLightPtr->set_color(Colorf(.3, .3, .3, 1));
      renderNp.set_light(renderNp.attach_new_node(ambientLightPtr));
      }
   PT(DirectionalLight) directionalLightPtr = new DirectionalLight("directionalLightPtr");
   if(directionalLightPtr != NULL)
      {
      directionalLightPtr->set_direction(LVecBase3f(-5, -5, -5));
      directionalLightPtr->set_color(Colorf(1, 1, 1, 1));
      directionalLightPtr->set_specular_color(Colorf(1, 1, 1, 1));
      renderNp.set_light(renderNp.attach_new_node(directionalLightPtr));
      }
   }
Exemplo n.º 19
0
World::World(WindowFramework* windowFramework)
    : m_windowFramework(windowFramework),
      m_title(),
      m_inst1(),
      m_inst2(),
      m_inst3(),
      m_inst4(),
      m_altCam(),
      m_teapot(),
      m_teapotInterval(),
      m_bufferViewer(NULL)
      // m_tvMen
{
    // Note: set background color here
    m_windowFramework->get_graphics_output()->get_active_display_region(0)->
    set_clear_color(Colorf(0, 0, 0, 1));

    // Post the instructions.
    m_title = add_title("Panda3D: Tutorial - Using Render-to-Texture");
    m_inst1 = add_instructions(0.95,"ESC: Quit");
    m_inst2 = add_instructions(0.90,"Up/Down: Zoom in/out on the Teapot");
    m_inst3 = add_instructions(0.85,"Left/Right: Move teapot left/right");
    m_inst4 = add_instructions(0.80,"V: View the render-to-texture results");

    //we get a handle to the default window
    PT(GraphicsOutput) mainWindow = m_windowFramework->get_graphics_output();

    // we now get buffer thats going to hold the texture of our new scene
    PT(GraphicsOutput) altBuffer = mainWindow->make_texture_buffer(
                                       "hello", 256, 256);

    // now we have to setup a new scene graph to make this scene
    NodePath altRender("new render");

    // this takes care of setting up the camera properly
    m_altCam = m_windowFramework->make_camera();
    // Note: set the size and shape of the "film" within the lens equal to the
    //       buffer of our new scene
    DCAST(Camera, m_altCam.node())->get_lens()->set_film_size(
        altBuffer->get_x_size(), altBuffer->get_y_size());
    // Note: make a DisplayRegion for the camera
    PT(DisplayRegion) dr = altBuffer->make_display_region(0, 1, 0, 1);
    dr->set_sort(0);
    dr->set_camera(m_altCam);
    m_altCam.reparent_to(altRender);
    m_altCam.set_pos(0, -10, 0);

    // get the teapot and rotates it for a simple animation
    const NodePath& models =
        m_windowFramework->get_panda_framework()->get_models();
    m_teapot = m_windowFramework->load_model(models, "../models/teapot");
    m_teapot.reparent_to(altRender);
    m_teapot.set_pos(0, 0, -1);

    const bool bakeInStart = true;
    const bool fluid = false;
    m_teapotInterval = new CLerpNodePathInterval("teapotInterval", 1.5,
            CLerpInterval::BT_no_blend, bakeInStart, fluid, m_teapot, NodePath());
    m_teapotInterval->set_start_hpr(m_teapot.get_hpr());
    m_teapotInterval->set_end_hpr(LVecBase3f(m_teapot.get_h()+360,
                                  m_teapot.get_p()+360,
                                  m_teapot.get_r()+360));
    m_teapotInterval->loop();

    // put some lighting on the teapot
    PT(DirectionalLight) dlight = new DirectionalLight("dlight");
    PT(AmbientLight) alight = new AmbientLight("alight");
    NodePath dlnp = altRender.attach_new_node(dlight);
    NodePath alnp = altRender.attach_new_node(alight);
    dlight->set_color(Colorf(0.8, 0.8, 0.5, 1));
    alight->set_color(Colorf(0.2, 0.2, 0.2, 1));
    dlnp.set_hpr(0, -60, 0);
    altRender.set_light(dlnp);
    altRender.set_light(alnp);

    // Panda contains a built-in viewer that lets you view the results of
    // your render-to-texture operations.  This code configures the viewer.

    WORLD_DEFINE_KEY("v", "toggleBufferViewer", toggle_buffer_viewer);
    m_bufferViewer = new CBufferViewer(m_windowFramework);
    m_bufferViewer->set_position(CBufferViewer::CP_llcorner);
    m_bufferViewer->set_card_size(1.0, 0.0);

    // Create the tv-men. Each TV-man will display the
    // offscreen-texture on his TV screen.
    make_tv_man(-5, 30,  1, altBuffer->get_texture(), 0.9);
    make_tv_man( 5, 30,  1, altBuffer->get_texture(), 1.4);
    make_tv_man( 0, 23, -3, altBuffer->get_texture(), 2.0);
    make_tv_man(-5, 20, -6, altBuffer->get_texture(), 1.1);
    make_tv_man( 5, 18, -5, altBuffer->get_texture(), 1.7);

    WORLD_DEFINE_KEY("escape", "exit", quit);
    WORLD_DEFINE_KEY("arrow_up", "zoomIn", zoom_in);
    WORLD_DEFINE_KEY("arrow_down", "zoomOut", zoom_out);
    WORLD_DEFINE_KEY("arrow_left", "moveLeft", move_left);
    WORLD_DEFINE_KEY("arrow_right", "moveRight", move_right);

    WORLD_ADD_TASK("worldAsyncTask", async_task);
}