Click here to Skip to main content
Click here to Skip to main content
Go to top

eGUI, a anmiated UI develop kit

, 16 Dec 2007
Rate this:
Please Sign up or sign in to vote.
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.


	// will be used a a root container

	CContainerWidget* m_pRootContainer;	

        // will be used a CDisplayManager

	CDisplayManage*  m_pDisplayManage;


2. Define a listener used to listen the animate event.

        //event listener

	ModelListener m_animateListener;

        //event listener handler

	static  void HandleAnimateListener(void *pUserData, ModelEvent *pEvent);


3. Init the root container and displaymanger
int CwidgetExampleDlg::IniteGui(void)

{


	   //Start the animate Engine


		StartAnimateEngine(30);


		//Init the animate listener

		m_animateListener.pfnListener = HandleAnimateListener;

		m_animateListener.pListenerData=this;

		m_animateListener.bEnableEventHandle=true;



		CRect wrc;

		GetWindowRect(&wrc);

		//Create Display Manager

		this->m_pDisplayManage=new CDisplayManage(this->m_hWnd,wrc.Width(),wrc.Height());

		//Create RootContainer

		this->m_pRootContainer=new CContainerWidget();

		//Register Container

		m_pDisplayManage->RegisterRootContainer(m_pRootContainer);

		//set displaymanger

		m_pRootContainer->SetDisplayManage(this->m_pDisplayManage);



		//Set the position of widget

		WRect rootRc;

		CRECT_TO_WRECT(wrc,rootRc);

		rootRc.x=0;

		rootRc.y=0;

		m_pRootContainer->SetRect(&rootRc,false);


		CBackGroundWidget* pBkW=new CBackGroundWidget();


		//insert wiget to RootContainer,

		WRect rc;

		m_pRootContainer->GetRect(&rc);

		rc.x=0;

		rc.y=0;

		m_pRootContainer->InsertWidget(pBkW,Z_ORDER_BACKGROUND);

		pBkW->SetRect(&rc);

	
		pBkW->SetBackgroundColor(0x0);


	

		//Draw RootContainer

		m_pRootContainer->InvalidateContent(0);

	return 0;

}

4. Hook the windows mouse, key, paint event to egui
BOOL CwidgetExampleDlg::PreTranslateMessage(MSG* pMsg)

{


		if(pMsg->message == WM_KEYDOWN )

		{
			//(wParam), LOWORD(lParam), HIWORD(lParam)

			WKEY_EVENT_T key_evt;

			key_evt.key_code=pMsg->wParam;;

			key_evt.rpt_cnt=LOWORD(pMsg->lParam);

			key_evt.flag=HIWORD(pMsg->wParam);	
		
			m_pRootContainer->HandleEvent(KEY_EVENT_DOWN,(int)(&key_evt),0);		

		}


		if( pMsg->message ==WM_KEYUP)

		{

			WKEY_EVENT_T key_evt;

			key_evt.key_code=pMsg->wParam;;

			key_evt.rpt_cnt=LOWORD(pMsg->lParam);

			key_evt.flag=HIWORD(pMsg->wParam);

			m_pRootContainer->HandleEvent(KEY_EVENT_UP,(int)(&key_evt),0);		

		}


		if(pMsg->message==WM_LBUTTONUP)

		{

			WPoint ptScreen;

			CPoint pt;

			pt.x=pMsg->pt.x;

			pt.y=pMsg->pt.y;

			this->ScreenToClient(&pt);

			ptScreen.x=pt.x;

			ptScreen.y=pt.y;

			m_pRootContainer->HandleEvent(MOUSE_LBUTTON_UP,(int)(&ptScreen),pMsg->lParam);			

		}


		
	...

	return CDialog::PreTranslateMessage(pMsg);

}

5. hook the paint event
void CwidgetExampleDlg::OnPaint() 

{


	m_pRootContainer->InvalidateContent(0);


}

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)

Share

About the Author

Yang XiaoWang
Software Developer (Senior) Motorola
China China
I like C/C++.
The photo is my lovely son,not meSmile | :)

Comments and Discussions

 
Question开源网站上发这种东西说明什么呢 Pinmemberxunonxyz25-Jul-12 4:10 
AnswerRe: 开源网站上发这种东西说明什么呢 Pinmemberszcathay14-Aug-12 5:12 
GeneralRe: 开源网站上发这种东西说明什么呢 Pinmembersht7019-Dec-13 18:44 
AnswerRe: 开源网站上发这种东西说明什么呢 Pinmemberzf21877-Sep-12 4:10 
General丑陋的中国人 Pinmemberxindeng21-Dec-08 20:33 
GeneralRe: 丑陋的中国人 Pinmemberhpking15-May-11 2:42 
GeneralRe: 丑陋的中国人 Pinmemberxunonxyz25-Jul-12 4:11 
GeneralGreat, but not for VC6 and some memory leaks, asserts... PinmemberThierry Maurel3-Jan-08 22:30 
Generalno lib source - VS2002 Pinmembergrandmasta116-Dec-07 21:08 
Generali'm sorry Pinmemberwlwlxj16-Dec-07 16:09 
GeneralOnly header files and lib PinmemberSatervalley16-Dec-07 14:05 

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.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 16 Dec 2007
Article Copyright 2007 by Yang XiaoWang
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid