Click here to Skip to main content
Licence CPOL
First Posted 16 Dec 2007
Views 32,977
Downloads 299
Bookmarked 12 times

eGUI, a anmiated UI develop kit

By | 16 Dec 2007 | Article
A easy-to-use widget libary to develop the animation GUI based on Windows GDI
Screenshot -

Introduction

eGUI is a windows GDI based UI developer kit, which implement a Widget based on UI framework and much usefully function of bitmap opeartion like transparent, rotate , moving, zooming, also it include a effeciently dirty area management machnism to help the devloper easily develop advanced application.

Background

The eGUI is from the idea of I want to develop a Chinese GO game, but I found it is hard to use the windows GDI to develop such application maybe involved much Bitmap operation, so I decide to develop a new GUI libary for this purpose.

Using the code

eGUI include below basic classes: CWidget: which is base class of each UI widget. CContainerWidget: which is the container will be used to hold and display all kinds of widget. CDisplayManager: which keep the windows draw context, and will be used to draw on the screen,and also implement the dirty area management. CFrameSurface: which is used to implement many kinds of draw opeation like, text drawing, bitmap drawing, transparent drawing,also it will be used as surface during the animating. CAnimateEngine: which implement a engine to trigger the surface drawing. CAnimateThread: each widget animation will be handled by a Thread. CAnimateController: each animation will mapped to a animate controller for the actually animation calculation.

1. define the root container and display manage.

<br>
	// will be used a a root container<br>
	CContainerWidget* m_pRootContainer;	<br>
        // will be used a CDisplayManager<br>
	CDisplayManage*  m_pDisplayManage;<br>

2. Define a listener used to listen the animate event.
<br>
        //event listener<br>
	ModelListener m_animateListener;<br>
        //event listener handler<br>
	static  void HandleAnimateListener(void *pUserData, ModelEvent *pEvent);<br>

3. Init the root container and displaymanger
int CwidgetExampleDlg::IniteGui(void)<br>
{<br>

	   //Start the animate Engine<br>

		StartAnimateEngine(30);<br>

		//Init the animate listener<br>
		m_animateListener.pfnListener = HandleAnimateListener;<br>
		m_animateListener.pListenerData=this;<br>
		m_animateListener.bEnableEventHandle=true;<br>


		CRect wrc;<br>
		GetWindowRect(&wrc);<br>
		//Create Display Manager<br>
		this->m_pDisplayManage=new CDisplayManage(this->m_hWnd,wrc.Width(),wrc.Height());<br>
		//Create RootContainer<br>
		this->m_pRootContainer=new CContainerWidget();<br>
		//Register Container<br>
		m_pDisplayManage->RegisterRootContainer(m_pRootContainer);<br>
		//set displaymanger<br>
		m_pRootContainer->SetDisplayManage(this->m_pDisplayManage);<br>


		//Set the position of widget<br>
		WRect rootRc;<br>
		CRECT_TO_WRECT(wrc,rootRc);<br>
		rootRc.x=0;<br>
		rootRc.y=0;<br>
		m_pRootContainer->SetRect(&rootRc,false);<br>

		CBackGroundWidget* pBkW=new CBackGroundWidget();<br>

		//insert wiget to RootContainer,<br>
		WRect rc;<br>
		m_pRootContainer->GetRect(&rc);<br>
		rc.x=0;<br>
		rc.y=0;<br>
		m_pRootContainer->InsertWidget(pBkW,Z_ORDER_BACKGROUND);<br>
		pBkW->SetRect(&rc);<br>
	
		pBkW->SetBackgroundColor(0x0);<br>

	

		//Draw RootContainer<br>
		m_pRootContainer->InvalidateContent(0);<br>
	return 0;<br>
}<br>
4. Hook the windows mouse, key, paint event to egui
BOOL CwidgetExampleDlg::PreTranslateMessage(MSG* pMsg)<br>
{<br>

		if(pMsg->message == WM_KEYDOWN )<br>
		{
			//(wParam), LOWORD(lParam), HIWORD(lParam)<br>
			WKEY_EVENT_T key_evt;<br>
			key_evt.key_code=pMsg->wParam;;<br>
			key_evt.rpt_cnt=LOWORD(pMsg->lParam);<br>
			key_evt.flag=HIWORD(pMsg->wParam);	<br>		
			m_pRootContainer->HandleEvent(KEY_EVENT_DOWN,(int)(&key_evt),0);		<br>
		}<br>

		if( pMsg->message ==WM_KEYUP)<br>
		{<br>
			WKEY_EVENT_T key_evt;<br>
			key_evt.key_code=pMsg->wParam;;<br>
			key_evt.rpt_cnt=LOWORD(pMsg->lParam);<br>
			key_evt.flag=HIWORD(pMsg->wParam);<br>
			m_pRootContainer->HandleEvent(KEY_EVENT_UP,(int)(&key_evt),0);		<br>
		}<br>

		if(pMsg->message==WM_LBUTTONUP)<br>
		{<br>
			WPoint ptScreen;<br>
			CPoint pt;<br>
			pt.x=pMsg->pt.x;<br>
			pt.y=pMsg->pt.y;<br>
			this->ScreenToClient(&pt);<br>
			ptScreen.x=pt.x;<br>
			ptScreen.y=pt.y;<br>
			m_pRootContainer->HandleEvent(MOUSE_LBUTTON_UP,(int)(&ptScreen),pMsg->lParam);			<br>
		}<br>

		
	...<br>
	return CDialog::PreTranslateMessage(pMsg);<br>
}<br>
5. hook the paint event
void CwidgetExampleDlg::OnPaint() <br>
{<br>

	m_pRootContainer->InvalidateContent(0);<br>

}<br>

History

Initial version by XIAOWANG YANG

Reference

1. Daniel godson for his CEnBitmap implementation. 2.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Yang XiaoWang

Software Developer (Senior)
Motorola
China China

Member

I like C/C++.
The photo is my lovely son,not meSmile | :)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Layout  Per page   
  Refresh
General丑陋的中国人 Pinmemberxindeng20:33 21 Dec '08  
GeneralRe: 丑陋的中国人 Pinmemberhpking2:42 15 May '11  
GeneralGreat, but not for VC6 and some memory leaks, asserts... PinmemberThierry Maurel22:30 3 Jan '08  
Generalno lib source - VS2002 Pinmembergrandmasta121:08 16 Dec '07  
Generali'm sorry Pinmemberwlwlxj16:09 16 Dec '07  
GeneralOnly header files and lib PinmemberSatervalley14:05 16 Dec '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 16 Dec 2007
Article Copyright 2007 by Yang XiaoWang
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid