void CAnimationEditorDlg::UpdateList()
{
	m_Frames.SetRedraw(false);
	m_ImageList.DeleteImageList();
	m_Frames.DeleteAllItems();

	if(!m_CurrentAnimation)
		return;
	
	m_ImageList.Create(32, 32, ILC_COLOR24, 3, 3);
	m_Frames.SetImageList(&m_ImageList, LVSIL_NORMAL);
	
	for (int i = 0; i < m_CurrentAnimation->m_Images.size(); i++)
	{
		// Create thumbnail & add to filmstrip
		CImageResource* image = m_pApplication->FindImageResourceFromNumber(m_CurrentAnimation->m_Images[i]);

		if(image)
		{
				
				HBITMAP Bitmap = image->GetHBitmap(true,false);
				ImageList_Add(m_ImageList.m_hImageList, Bitmap, Bitmap);

				CString name;
				name.Format("%d", i+1);
				m_Frames.InsertItem(i, name, i);
		}
	}

	m_Frames.SetRedraw(true);
	m_Frames.Invalidate();
}
示例#2
0
void AnimatorBar::UpdateFilmStrip()
{
	film_strip.SetRedraw(false);
	m_ImageList.DeleteImageList();
	film_strip.DeleteAllItems();

	if(!m_pCurrentAnimation)
		return;
	
	m_ImageList.Create(32, 32, ILC_COLOR24, 3, 3);
	film_strip.SetImageList(&m_ImageList, LVSIL_NORMAL);
	
	for (int i = 0; i < m_pCurrentAnimation->m_Images.size(); i++)
	{
		// Create thumbnail & add to filmstrip
		CImageResource* pImage = application->resources.FindImageResourceFromNumber(m_pCurrentAnimation->m_Images[i]);

		if(pImage)
		{
			HBITMAP Bitmap = pImage->GetHBitmap(true,false);
			ImageList_Add(m_ImageList.m_hImageList, Bitmap, Bitmap);


			CString Name;
			Name.Format("%d", i + 1);
			film_strip.InsertItem(i, Name, i);
		}
	}

	film_strip.SetRedraw(true);
	film_strip.Invalidate();
}
示例#3
0
void AnimatorBar::FrameSerialize(CArchive& ar)
{
	if(ar.IsLoading())
	{
		POSITION Pos = film_strip.GetFirstSelectedItemPosition();
		
		int Count;
		ar >> Count;
		vector<int> ToSelect;

		for(int a = 0; a < Count; a ++)
		{
			application->resources.images.push_back(CImageResource());
			application->resources.images_changed = true;
			CImageResource* image = &application->resources.images.back();
			image->Serialize(ar);
			image->m_FixedID = application->m_ImageFixID++;

			POSITION pos = film_strip.GetFirstSelectedItemPosition();
		
			if(pos)
			{
				if(m_pCurrentAnimation->supportsFrames())
				{
					int nItem = film_strip.GetNextSelectedItem(pos);
					m_pCurrentAnimation->m_Images.insert( m_pCurrentAnimation->m_Images.begin() + nItem + a, image->m_FixedID);
					ToSelect.push_back(nItem + a);
				}
			}

			else
			{
				if(m_pCurrentAnimation->supportsFrames())
				{
					m_pCurrentAnimation->m_Images.push_back( image->m_FixedID);
					ToSelect.push_back(m_pCurrentAnimation->m_Images.size());
				}
			}			

			int iFrameTime = 0;
			ar >> iFrameTime;
			
			if(m_pCurrentAnimation->supportsFrames())
			{
				m_pCurrentAnimation->m_FrameTimes.push_back(iFrameTime);
			}
		}

		UpdateFilmStrip();
		for(int c = 0 ; c < ToSelect.size(); c++)
			film_strip.SetItemState (ToSelect[c], LVIS_SELECTED, LVIS_SELECTED);
	}
示例#4
0
文件: ship.cpp 项目: jfreax/Ufs
CShip::CShip()
{
	alpha_ = 255;
	spriteType_ = SHIP;
	
	/* Imageresourcen manager */
	CImageResource* imageResource = GetGameClass()->GetImgResource();

	/* Load picture of the ship model TODO example! */
	miniImage_ = imageResource->Get( "images/ship/human/hunter-001.png" );
	backgroundStatic_ = new sf::Sprite (  *(imageResource->Get( "images/ship/human/hunter-001.png" )) );
	
	/* Add to graphic list */
	graphics_.Add ( backgroundStatic_ );
	
	/* Set properties */
	this->SetZoomFactor( 0.04 );
	this->SetZoomLevel ( 1 );
}
void CAnimationEditorDlg::FrameSerialize(CArchive& ar)
{
	// This function is only called for copying and pasting frames

	if(ar.IsLoading())
	{
		POSITION pos = m_Frames.GetFirstSelectedItemPosition();
		int count;
		ar >> count;
		vector<int> ToSelect;
		for(int a = 0; a < count; a ++)
		{
			m_pApplication->m_imageBank.push_back(CImageResource());
			m_pApplication->m_imageBankHasChanged = true;
			CImageResource* image = &m_pApplication->m_imageBank.back();
			image->Serialize(ar);
			image->m_FixedID = m_pApplication->m_ImageFixID++;

			POSITION pos = m_Frames.GetFirstSelectedItemPosition();
			if(pos)
			{
				int nItem = m_Frames.GetNextSelectedItem(pos);
				m_CurrentAnimation->m_Images.insert( m_CurrentAnimation->m_Images.begin() + nItem + a, image->m_FixedID);
				ToSelect.push_back(nItem + a);
			}
			else
			{
				m_CurrentAnimation->m_Images.push_back( image->m_FixedID);
				ToSelect.push_back(m_CurrentAnimation->m_Images.size());
			}			

			int iFrameTime = 0;
			ar >> iFrameTime;
			m_CurrentAnimation->m_FrameTimes.push_back(iFrameTime);
		}

		UpdateList();
		for(int c = 0 ; c < ToSelect.size(); c++)
			m_Frames.SetItemState (ToSelect[c], LVIS_SELECTED, LVIS_SELECTED);

	}
示例#6
0
文件: planet.cpp 项目: jfreax/Ufs
CPlanet::CPlanet()
{
	spriteType_ = PLANET;
	
	/* Imageresourcen manager */
	CImageResource* imageResource = GetGameClass()->GetImgResource();
	
	/* load pictures */
	backgroundStatic_ = new sf::Sprite ( *imageResource->Get ( "images/planet/002.png" ) );

	this->SetCenter ( backgroundStatic_->GetSize().x * 0.5, backgroundStatic_->GetSize().y * 0.5 );
	backgroundStatic_->SetCenter ( GetCenter() );
	
	shadow_ = new sf::Sprite ( *imageResource->Get ( "images/planet/shadow.png" ) );
	shadow_->SetCenter ( GetCenter() );
	
	cloud1_ = new sf::Sprite ( *imageResource->Get ( "images/planet/clouds_001.png" ) );
	cloud1_->SetCenter ( GetCenter() );
	
	cloud2_ = new sf::Sprite ( *imageResource->Get ( "images/planet/clouds_002.png" ) );
	cloud2_->SetCenter ( GetCenter() );
	
	atmosphere_ = new sf::Sprite ( *imageResource->Get ( "images/planet/atmosphere_001.png" ) );
	atmosphere_->SetCenter ( GetCenter() );
	
	/* Set color of planet TODO EXAMPLE DATA! */
	planetColor_ = sf::Color ( 160, 220, 255, 255 );
	
	backgroundStatic_->SetColor ( planetColor_ );
	atmosphere_->SetColor ( planetColor_ );
	
	/* Add to graphic list */
	graphics_.Add ( backgroundStatic_ );
	graphics_.Add ( atmosphere_ );
	graphics_.Add ( cloud1_ );
	graphics_.Add ( cloud2_ );
	graphics_.Add ( shadow_ );
	
	/* Set properties */
	this->SetZoomFactor( 0.1 );
	this->SetZoomLevel ( 0.2 );
}
示例#7
0
void AnimatorBar::OnRClickFilmStrip(NMHDR *pNMHDR, LRESULT *pResult)
{
	if (m_pCurrentAnimation == NULL)
		return;

	POINT MousePosition;
	GetCursorPos(&MousePosition);

	CExtPopupMenuWnd * popup = new CExtPopupMenuWnd;
	popup->LoadMenu(m_hWnd, IDR_BLANK, true, false);
	popup->ItemRemove(0);

	UINT ChosenItem = 0;

	// Add frame
	popup->ItemInsertCommand(1, -1, "Add frame", NULL, NULL);

	bool bIsSel = false;

	POSITION Pos = film_strip.GetFirstSelectedItemPosition();

	if(!m_pCurrentAnimation)
		return;

	if(!m_pCurrentAnimation->supportsFrames())
		return;

	while(Pos)
	{
		int Item = film_strip.GetNextSelectedItem(Pos);
		if (Item != -1)
			bIsSel = true;
	}

	// Import
	popup->ItemInsertCommand(3, -1, AB_IMPORTFRAME, NULL, NULL);
	popup->ItemBoldGet(0);

	// Copy/paste
	popup->ItemInsertCommand();

	// Remove frame(s)
	if (bIsSel)
		popup->ItemInsertCommand(2, -1, AB_REMOVEFRAME, NULL, NULL);

	if (film_strip.GetItemCount() != 1)
		popup->ItemInsertCommand(7, -1, AB_CUTFRAMES, NULL, NULL);

	popup->ItemInsertCommand(4, -1, AB_COPYFRAMES, NULL, NULL);
	popup->ItemInsertCommand(5, -1, AB_PASTEFRAMES, NULL, NULL);
	popup->ItemInsertCommand(10, -1, AB_DUPLICATEFRAMES, NULL, NULL);

	popup->ItemInsertCommand();

	// flip vertical/horizontal
	popup->ItemInsertCommand(8, -1, AB_MIRRORFRAMES, NULL, NULL);
	popup->ItemInsertCommand(9, -1, AB_FLIPFRAMES, NULL, NULL);

	// Explore
	popup->ItemInsertCommand();
	popup->ItemInsertCommand(6, -1, AB_LAUNCHEXPLORER, NULL, NULL);

	// Explore
	popup->ItemInsertCommand();
	popup->ItemInsertCommand(11, -1, AB_COPYCOLLISIONMASKTOEACHFRAME, NULL, NULL);


	// Show menu
	popup->TrackPopupMenu(TPMX_DO_MESSAGE_LOOP | TPMX_NO_WM_COMMAND | TPMX_NO_CMD_UI, MousePosition.x, MousePosition.y, NULL, NULL, NULL, &ChosenItem);
		
	if (ChosenItem == 1)
		AddFrame();

	else if (ChosenItem == 2)
		RemoveFrame();

	else if (ChosenItem == 3)
	{
		CImportImagesDlg ImportDlg;
		if (ImportDlg.DoModal() == IDOK)
		{			
			for(list<CImageResource>::iterator i = ImportDlg.m_Images.begin(); i!= ImportDlg.m_Images.end(); i++)
			{
				int id = layout->AddImage(i->bitmap.GetWidth(), i->bitmap.GetHeight());

				m_pCurrentAnimation->m_Images.push_back(id);
				m_pCurrentAnimation->m_FrameTimes.push_back(1.0);

				CImageResource* image = application->resources.FindImageResourceFromNumber(id);
				image->bitmap.Copy(i->bitmap);

				image->m_Action = i->m_Action;
				image->m_Hotspot = i->m_Hotspot;
				image->m_Collision = i->m_Collision;
				
			}
			
			UpdateFilmStrip();
		}
	}

	// copy
	else if (ChosenItem == 4)
	{	
		CAnimEdFrame* pFrames = new CAnimEdFrame;
		pFrames->m_anim_ed = this;
		DROPEFFECT de = DROPEFFECT_NONE;
		m_pDDMgr.PrepareDrop(DO_CLIPBOARD, "Construct Frames", pFrames, &de);
	}

	// cut
	else if (ChosenItem == 7)
	{
		CAnimEdFrame* pFrames = new CAnimEdFrame;
		pFrames->m_anim_ed = this;
		DROPEFFECT de = DROPEFFECT_NONE;
		m_pDDMgr.PrepareDrop(DO_CLIPBOARD, "Construct Frames", pFrames, &de);

		RemoveFrame();
	}

	// paste
	else if (ChosenItem == 5)
	{
		if (m_pDDMgr.OkToPaste())
		{
			CAnimEdFrame pFrames;
			pFrames.m_anim_ed = this;
			m_pDDMgr.DoDrop(&pFrames,
							  NULL,
							  "Construct Frames");
		}
	}

	// duplicate
	else if (ChosenItem == 10)
	{	
		CAnimEdFrame* pFrames = new CAnimEdFrame;
		pFrames->m_anim_ed = this;
		DROPEFFECT de = DROPEFFECT_NONE;
		m_pDDMgr.PrepareDrop(DO_CLIPBOARD, "Construct Frames", pFrames, &de);

		if (m_pDDMgr.OkToPaste())
		{
			CAnimEdFrame pFrames;
			pFrames.m_anim_ed = this;
			m_pDDMgr.DoDrop(&pFrames,
							  NULL,
							  "Construct Frames");
		}
	}
	// Copy collision mask to every other frame
	else if (ChosenItem == 11)
	{
		// Get the frame we right clicked on
		POSITION pos = film_strip.GetFirstSelectedItemPosition();
		if(pos)
		{
			int nItem = film_strip.GetNextSelectedItem(pos);
			int handle = m_pCurrentAnimation->m_Images.at(nItem);
		
			int result = MessageBox("Click 'OK' to confirm you want to copy the collision mask of this selected frame to every other frame in the animation package", "Construct", MB_OKCANCEL);

			if(result == IDOK){
				CImageResource* res = application->resources.FindImageResourceFromNumber(handle);
				if(!res)
					MessageBox("Error. Image resource could not be found for this animation frame");
				else
				{
					if(!res->m_Collision.IsValid())
						res->m_Collision = res->bitmap; // copy
					
					application->resources.CopyCollisionMaskToEveryFrameInAnimation(m_pAnimation, res); 

				}
			
				
		}
		}

	}

	// Launch explorer
	else if (ChosenItem == 6)
	{
		CPath Path;
		Path.SetToCurrentDirectory();
		
		CString InfoPath;
		InfoPath.Format("%sImages\\", Path.GetFullPath());

		// make sure directory exists
		::CreateDirectory(InfoPath, NULL);

		// now open file
		InfoPath += "frames.txt";
		CFile File(InfoPath, CFile::modeWrite | CFile::modeCreate);
	

		int index = 0;
		for(vector<int>::iterator i = m_pCurrentAnimation->m_Images.begin(); i!= m_pCurrentAnimation->m_Images.end(); i++)
		{
			CImageResource* img = application->resources.FindImageResourceFromNumber(*i);
			if(img)
			{
				CString nl;
				nl.Format("%c%c", 13,10);
				index ++;
				CString SavePath;
				SavePath.Format("%sImages\\Frame %d.png", Path.GetFullPath(), index);
				CxImage backup = img->bitmap;
				img->Predivide();
				img->bitmap.Save(SavePath,CXIMAGE_FORMAT_PNG);
				img->bitmap = backup;

				if(img->m_Collision.IsValid())
				{
					SavePath.Format("%sImages\\Mask %d.png", Path.GetFullPath(), index);
					img->m_Collision.Save(SavePath,CXIMAGE_FORMAT_PNG);
				}
				else
				{
					SavePath.Format("%sImages\\Mask %d.png", Path.GetFullPath(), index);
					img->bitmap.Save(SavePath,CXIMAGE_FORMAT_PNG);
				}


				CString Info;
				Info.Format("Frame %d%sPivotX%s%d%sPivotY%s%d%s", index, nl,nl, img->m_Hotspot.x, nl,nl, img->m_Hotspot.y, nl);
				for(map<CString, CPoint>::iterator a = img->m_Action.begin(); a!= img->m_Action.end(); a++)
				{
					Info.Format("%s%s%s%d%s%d%s", Info, a->first, nl, a->second.x, nl, a->second.y, nl);
				}
				Info += nl;
				File.Write((const char*)Info, Info.GetLength() * sizeof(char));


			}
		}
		File.Close();

		CString LaunchPath;
		LaunchPath.Format("%sImages\\", Path.GetFullPath());

		ShellExecute(NULL,  "open", LaunchPath, NULL, NULL, SW_SHOW);

		int result = MessageBox("Click 'OK' to reimport the images that have been exported to Explorer.", "Construct", MB_OKCANCEL);

		if(result == IDOK)
		{
			int result2 = MessageBox("Import collision mask?", "Construct", MB_YESNOCANCEL);
			int index = 0;
			for(vector<int>::iterator i = m_pCurrentAnimation->m_Images.begin(); i!= m_pCurrentAnimation->m_Images.end(); i++)
			{
				index ++;
				CImageResource* img = application->resources.FindImageResourceFromNumber(*i);
			
				CString SavePath;
				SavePath.Format("%sImages\\Frame %d.png", Path.GetFullPath(), index);			
				
				img->bitmap.Load(SavePath,CXIMAGE_FORMAT_PNG);
				img->Premultiply();

				if(result2 == IDYES)
				{
				SavePath.Format("%sImages\\Mask %d.png", Path.GetFullPath(), index);			
				img->m_Collision.Load(SavePath,CXIMAGE_FORMAT_PNG);
				}
				if(result2 == IDNO)
				{
					if(img->m_Collision.IsValid())
						img->m_Collision.Destroy();
				}

				application->m_image_to_texture.erase(img->m_FixedID);

				img->small_thumbnail.Destroy();
				img->large_thumbnail.Destroy();
			}

			application->resources.images_changed = true;

			AnimationHasChanged();
			UpdateFilmStrip();
		}
	}

	else if (ChosenItem == 8)
	{
		// mirror
		POSITION position = film_strip.GetFirstSelectedItemPosition();

		if(!m_pCurrentAnimation)
			return;

		vector<int>& images = m_pCurrentAnimation->m_Images;

		while(position)
		{
			int item = film_strip.GetNextSelectedItem(position);

			if (item == -1) break;

			CImageResource* image = application->resources.FindImageResourceFromNumber(images[item]);
			image->Mirror();

			application->resources.images_changed = true;
		}

		AnimationHasChanged();
		UpdateFilmStrip();
	}

	else if (ChosenItem == 9)
	{
		// mirror
		POSITION position = film_strip.GetFirstSelectedItemPosition();

		if(!m_pCurrentAnimation)
			return;

		vector<int>& images = m_pCurrentAnimation->m_Images;

		while(position)
		{
			int item = film_strip.GetNextSelectedItem(position);

			if (item == -1) break;

			CImageResource* image = application->resources.FindImageResourceFromNumber(images[item]);
			image->Flip();

			application->resources.images_changed = true;
		}

		AnimationHasChanged();
		UpdateFilmStrip();
	}
}
void CAnimationEditorDlg::OnTimer(UINT_PTR nIDEvent)
{
	KillTimer(500);

	
	
	


	// Show next bitmap
	if(!m_CurrentAnimation)
	{
		m_Preview.SetBitmap(0);
		return;
	}

	if(m_CurrentAnimation->m_RepeatTo < 1)
		m_CurrentAnimation->m_RepeatTo = 1;
	if(m_CurrentAnimation->m_RepeatTo > m_CurrentAnimation->m_Images.size())
		m_CurrentAnimation->m_RepeatTo = m_CurrentAnimation->m_Images.size();

	if(m_CurrentAnimation->m_Images.size() == 0)
	{
		m_Preview.SetBitmap(0);
		return;
	}

	

	if(m_iPlayForward)
		m_iFrame ++;
	else
		m_iFrame --;

	if (m_iFrame >= m_CurrentAnimation->m_Images.size())
	{		
		if(m_CurrentAnimation->m_bPingPong)
		{
			m_iPlayForward = 1 - m_iPlayForward;
			m_iFrame -=2;
		}
		else
		{
			m_iPlayCount ++;
			m_iFrame = m_CurrentAnimation->m_RepeatTo - 1;
		}
	}
	if(m_iFrame < m_CurrentAnimation->m_RepeatTo-1)
	{
		m_iFrame = m_CurrentAnimation->m_Images.size() - 1;
		m_iPlayForward = 1 - m_iPlayForward;	
		m_iFrame = m_CurrentAnimation->m_RepeatTo-1;
		m_iPlayCount ++;
	}
	
	if(m_iPlayCount < m_CurrentAnimation->m_Repeat || m_CurrentAnimation->m_bForever)
	{
		CImageResource* res = m_pApplication->FindImageResourceFromNumber(m_CurrentAnimation->m_Images[m_iFrame]);
		if(m_Preview.GetBitmap() != res->GetHBitmap(true,true))
			m_Preview.SetBitmap(res->GetHBitmap(true,true));
			
		SetTimer(0, ((int)m_CurrentAnimation->m_FrameTimes[m_iFrame]) * m_CurrentAnimation->m_Speed*20, NULL);
	}
	else
		m_Preview.SetBitmap(NULL);
	CDialog::OnTimer(nIDEvent);
}