Exemplo n.º 1
0
void cScrollBar::LoadInitial()
{  // load static class-wide shared base images into memory; only called once by first scrollbar created
	DirPath dp = ImagePath("Scroll");
	string disabled = string(dp.c_str()) + "LongDisabled.png";
	string off = string(dp.c_str()) + "LongOff.png";
	string on = string(dp.c_str()) + "LongOn.png";
	string bg = string(dp.c_str()) + "LongBackground.png";
	string notches = string(dp.c_str()) + "Notches.png";
	m_ImgBarBG = IMG_Load(bg.c_str());
	SDL_Surface* TmpImg;
	TmpImg = IMG_Load(disabled.c_str());
	m_ImgBarDisabled = SDL_DisplayFormatAlpha(TmpImg);
	SDL_FreeSurface(TmpImg);
	TmpImg = IMG_Load(off.c_str());
	m_ImgBarOff = SDL_DisplayFormatAlpha(TmpImg);
	SDL_FreeSurface(TmpImg);
	TmpImg = IMG_Load(on.c_str());
	m_ImgBarOn = SDL_DisplayFormatAlpha(TmpImg);
	SDL_FreeSurface(TmpImg);
	TmpImg = IMG_Load(notches.c_str());
	m_ImgNotches = SDL_DisplayFormatAlpha(TmpImg);
	SDL_FreeSurface(TmpImg);
	m_NotchOffset = int(((double)m_ImgNotches->h / 2));
	string updisabled = string(dp.c_str()) + "UpDisabled.png";
	string upoff = string(dp.c_str()) + "UpOff.png";
	string upon = string(dp.c_str()) + "UpOn.png";
	string downdisabled = string(dp.c_str()) + "DownDisabled.png";
	string downoff = string(dp.c_str()) + "DownOff.png";
	string downon = string(dp.c_str()) + "DownOn.png";
	TmpImg = IMG_Load(updisabled.c_str());
	m_ImgButtonUpDisabled = SDL_DisplayFormatAlpha(TmpImg);
	SDL_FreeSurface(TmpImg);
	TmpImg = IMG_Load(upoff.c_str());
	m_ImgButtonUpOff = SDL_DisplayFormatAlpha(TmpImg);
	SDL_FreeSurface(TmpImg);
	TmpImg = IMG_Load(upon.c_str());
	m_ImgButtonUpOn = SDL_DisplayFormatAlpha(TmpImg);
	SDL_FreeSurface(TmpImg);
	TmpImg = IMG_Load(downdisabled.c_str());
	m_ImgButtonDownDisabled = SDL_DisplayFormatAlpha(TmpImg);
	SDL_FreeSurface(TmpImg);
	TmpImg = IMG_Load(downoff.c_str());
	m_ImgButtonDownOff = SDL_DisplayFormatAlpha(TmpImg);
	SDL_FreeSurface(TmpImg);
	TmpImg = IMG_Load(downon.c_str());
	m_ImgButtonDownOn = SDL_DisplayFormatAlpha(TmpImg);
	SDL_FreeSurface(TmpImg);
}
Exemplo n.º 2
0
	File(std::string Filename, int Size) :
										   m_Filename(Filename),
										   m_Size(Size)
	{
		// Create 'imgs' directory to store files if doesn't already exists
		CreateImageDirectory();

		std::wstring ImagePath(GetEXEDirectory() + L"\\imgs\\");
		std::string sImagePath(ImagePath.begin(), ImagePath.end());

		// Open file for binary writing
		m_Stream = std::ofstream(sImagePath + m_Filename, std::ios::binary);

		// Display file in listbox lsFiles
		std::wstringstream Text;
		Text << std::wstring(m_Filename.begin(), m_Filename.end()) << L" - (0 / " << m_Size << L") [0% Complete]";

		SendMessage(lsFiles, LB_ADDSTRING, 0, (LPARAM)Text.str().c_str());
	};
Exemplo n.º 3
0
bool CSurface::DrawSurface(int x, int y, SDL_Surface* destination, SDL_Rect* clip, bool resize, bool maintainRatio)
{
	double scaleX = 0;	double scaleY = 0;

	if (m_Surface == 0)
	{
		if (m_ColoredSurface == true)
		{
			g_LogFile.ss() << "ERROR - Colored surface null: '" << m_Filename << "'"; g_LogFile.ssend();
			return false;
		}

		if (m_Temp) SDL_FreeSurface(m_Temp);
		m_Temp = 0;
		if (!loaded)
		{
			if (m_Filename == ButtonPath("").c_str())	// fix disabled buttons
				m_Filename = ImagePath("blank.png").c_str();
			if (!LoadImage(m_Filename))
			{
				g_LogFile.ss() << "ERROR - Loading Image '" << m_Filename << "'"; g_LogFile.ssend();
				return false;
			}
			if (m_Cached)
			{
				loaded = true;
			}
		}
	}

	m_TimeUsed = g_Graphics.GetTicks();

	if (clip && resize)
	{
		if (m_Temp == 0)
		{
			if (maintainRatio == true)
			{
				if (clip->w != m_Surface->w && clip->h != m_Surface->h)
				{
					if (m_Surface->w > m_Surface->h)	// if the width is larger so scale down based on the width but keep aspect ratio
						scaleX = scaleY = ((double)clip->w / (double)m_Surface->w);
					else	// assume the height is larger
						scaleX = scaleY = ((double)clip->h / (double)m_Surface->h);
					m_Temp = zoomSurface(m_Surface, scaleX, scaleY, 1);
				}
			}
			else
			{
				if (clip->w != m_Surface->w || clip->h != m_Surface->h)
				{
					scaleX = ((double)clip->w / (double)m_Surface->w);
					scaleY = ((double)clip->h / (double)m_Surface->h);
					m_Temp = zoomSurface(m_Surface, scaleX, scaleY, 1);
				}
			}
		}
		else
		{
			if (maintainRatio == true)
			{
				if (m_Temp->w != clip->w && m_Temp->h != clip->h)
				{
					if (m_Temp) SDL_FreeSurface(m_Temp);// free old image
					m_Temp = 0;
					if (m_Surface->w > m_Surface->h)	// if the width is larger so scale down based on the width but keep aspect ratio
						scaleX = scaleY = ((double)clip->w / (double)m_Surface->w);
					else	// assume the height is larger
						scaleX = scaleY = ((double)clip->h / (double)m_Surface->h);
					m_Temp = zoomSurface(m_Surface, scaleX, scaleY, 1);
				}
			}
			else
			{
				if (m_Temp->w != clip->w || m_Temp->h != clip->h)
				{
					if (m_Temp)	SDL_FreeSurface(m_Temp);	// free old image
					m_Temp = 0;

					scaleX = ((double)clip->w / (double)m_Surface->w);
					scaleY = ((double)clip->h / (double)m_Surface->h);
					m_Temp = zoomSurface(m_Surface, scaleX, scaleY, 1);
				}
			}
		}
	}

	// create and setup a SDL offset rectangle
	SDL_Rect offset;
	offset.x = x;
	offset.y = y;

	// Draw the source surface onto the destination
	int error = 0;
	if (destination)
	{
		error = m_Temp ?
			SDL_BlitSurface(m_Temp, clip, destination, &offset) :
			SDL_BlitSurface(m_Surface, clip, destination, &offset);
	}
	else	// blit to the screen
	{
		error = m_Temp ?
			SDL_BlitSurface(m_Temp, clip, g_Graphics.GetScreen(), &offset) :
			SDL_BlitSurface(m_Surface, clip, g_Graphics.GetScreen(), &offset);
	}

	if (error == -1)
	{
		g_LogFile.ss() << "Error Blitting surface (" << m_Filename << ") - " << SDL_GetError(); g_LogFile.ssend();
		return false;
	}

	return true;
}
Exemplo n.º 4
0
// `J` Totally new method for image handling for .06.02.00
void cInterfaceWindow::PrepareImage(int id, sGirl* girl, int imagetype, bool rand, int ImageNum, bool gallery, string ImageName)
{
	if (!girl)	return;	// no girl, no images
	if (m_Images[id] &&
		m_Images[id]->m_AnimatedImage &&
		m_Images[id]->m_AnimatedImage->getNumFrames() > 0)
	{
		AG_FreeSurfaces(m_Images[id]->m_AnimatedImage->getAFrames(), m_Images[id]->m_AnimatedImage->getNumFrames());
		m_Images[id]->m_AnimatedImage->m_Gif = false;
		m_Images[id]->m_AnimatedImage = 0;
	}
	string girlName = girl->m_Name;

	int dir = 0; DirPath usedir = "";
	DirPath imagedirCc = DirPath(cfg.folders.characters().c_str()) << girlName;	// usedir = 1
	DirPath imagedirCo = DirPath() << "Resources" << "Characters" << girlName;	// usedir = 2
	DirPath imagedirDc = DirPath(cfg.folders.defaultimageloc().c_str());		// usedir = -1
	DirPath imagedirDo = DirPath() << "Resources" << "DefaultImages";			// usedir = -2
	FileList tiCc(imagedirCc, "*.*");
	FileList tiCo(imagedirCo, "*.*");
	FileList tiDc(imagedirDc, "*.*");
	FileList tiDo(imagedirDo, "*.*");
	int totalimagesCc = tiCc.size();
	int totalimagesCo = tiCo.size();
	int totalimagesDc = tiDc.size();
	int totalimagesDo = tiDo.size();
	if (totalimagesCc + totalimagesCo + totalimagesDc + totalimagesDo < 1)	// no images at all so return a blank image
	{
		m_Images[id]->m_Image = new CSurface(ImagePath("blank.png"));
		m_Images[id]->m_AnimatedImage = 0;
		m_Images[id]->m_Image->m_Message = "No image found.";
		return;
	}

	int tries = 40;
	if (gallery) tries = 0;
	else	// try some corrections
	{
		if (cfg.folders.preferdefault() || totalimagesCc + totalimagesCo < 1)	tries = 10;
		if (imagetype < 0 || imagetype > NUM_IMGTYPES)				imagetype = IMGTYPE_PROFILE;
		if (girl->is_pregnant() && imagetype < IMGTYPE_PREGNANT)	imagetype += PREG_OFFSET;
		if (!girl->is_pregnant() && imagetype == IMGTYPE_PREGNANT)	imagetype = IMGTYPE_PROFILE;
		if (!girl->is_pregnant() && imagetype > IMGTYPE_PREGNANT)	imagetype -= PREG_OFFSET;
	}

	string file = "";
	string filename = "";
	string ext = "";
	
	bool imagechosen = false;
	do
	{
		int tryimagetype = TryImageType(imagetype, tries);

		// choose an image folder
		dir = 0; usedir = "";
		string checkfor = pic_types[tryimagetype] + "*";
		if (tryimagetype == IMGTYPE_PREGNANT) checkfor = "pregnant*.*";

		if (totalimagesCc > 0)
		{
			FileList testall(imagedirCc, checkfor.c_str());
			if (tryimagetype == IMGTYPE_PREGNANT)
			{
				for (u_int i = 0; i < numeric.size(); i++)
				{
					string t = ("preg" + numeric.substr(i, 1) + "*.*");
					testall.add(t.c_str());
				}
			}
			if (testall.size() > 0)
			{
				usedir = imagedirCc;
				dir = 1;
			}
		}
		if (dir == 0 && totalimagesCo > 0)	// if config is not found, check for images in the original folder
		{
			FileList testall(imagedirCo, checkfor.c_str());
			if (tryimagetype == IMGTYPE_PREGNANT)
			{
				for (u_int i = 0; i < numeric.size(); i++)
				{
					string t = ("preg" + numeric.substr(i, 1) + "*.*");
					testall.add(t.c_str());
				}
			}
			if (testall.size() > 0)
			{
				usedir = imagedirCo;
				dir = 2;
			}
		}
		if (dir == 0 && gallery)	// gallery stops here if there are no images
		{
			m_Images[id]->m_Image = new CSurface(ImagePath("blank.png"));
			m_Images[id]->m_AnimatedImage = 0;
			m_Images[id]->m_Image->m_Message = "No images found.";
			break;
		}

		// if neither character folder has what we are looking for try the defaults
		if (totalimagesDc > 0 && dir == 0 && tries < 10)
		{
			FileList testall(imagedirDc, checkfor.c_str());
			if (tryimagetype == IMGTYPE_PREGNANT)
			{
				for (u_int i = 0; i < numeric.size(); i++)
				{
					string t = ("preg" + numeric.substr(i, 1) + "*.*");
					testall.add(t.c_str());
				}
			}
			if (testall.size() > 0)
			{
				usedir = imagedirDc;
				dir = -1;
			}
		}
		if (totalimagesDo > 0 && dir == 0 && tries < 10)
		{
			FileList testall(imagedirDo, checkfor.c_str());
			if (tryimagetype == IMGTYPE_PREGNANT)
			{
				for (u_int i = 0; i < numeric.size(); i++)
				{
					string t = ("preg" + numeric.substr(i, 1) + "*.*");
					testall.add(t.c_str());
				}
			}
			if (testall.size() > 0)
			{
				usedir = imagedirDo;
				dir = -2;
			}
		}
		if (dir == 0)
		{
			m_Images[id]->m_Image = new CSurface(ImagePath("blank.png"));
			m_Images[id]->m_AnimatedImage = 0;
			m_Images[id]->m_Image->m_Message = "No images found.";
			continue;
		}

		FileList testall(usedir, checkfor.c_str());
		if (tryimagetype == IMGTYPE_PREGNANT)
		{
			for (u_int i = 0; i < numeric.size(); i++)
			{
				string t = ("preg" + numeric.substr(i, 1) + "*.*");
				testall.add(t.c_str());
			}
		}
		if (testall.size() <= 0) continue;
		int num = ImageNum;
		if (rand || ImageNum < 0 || ImageNum >= testall.size()) num = g_Dice%testall.size();
		file = testall[num].full();
		filename = testall[num].leaf();
		ext = stringtolowerj(filename.substr(filename.find_last_of('.') + 1, filename.size()));

		if (ext == "ani")
		{
			DirPath anidir = usedir; anidir << "ani";
			string name = filename;
			name.erase(name.size() - 4, 4);
			name += ".jpg";
			FileList testani(anidir, name.c_str());
			if (testani.size() <= 0)
			{
				if (gallery)
				{
					m_Images[id]->m_Image = new CSurface(ImagePath("blank.png"));
					m_Images[id]->m_AnimatedImage = 0;
					m_Images[id]->m_Image->m_Message = "Bad ani file: Missing its matching jpg file: " + file;
					return;
				}
				continue;
			}
			anidir << name;
			cImage* newImage = new cImage();
			newImage->m_Surface = new CSurface();
			newImage->m_Surface->LoadImage(anidir.c_str());
			newImage->m_AniSurface = new cAnimatedSurface();
			int numFrames, speed, aniwidth, aniheight;
			ifstream input;
			input.open(file.c_str());
			if (!input)
			{
				g_LogFile.ss() << "Incorrect data file given for animation - " << file; g_LogFile.ssend();
				if (gallery)
				{
					m_Images[id]->m_Image = new CSurface(ImagePath("blank.png"));
					m_Images[id]->m_AnimatedImage = 0;
					m_Images[id]->m_Image->m_Message = "Bad ani file: Incorrect data file given for animation: " + file;
					return;
				}
			}
			else
			{
				input >> numFrames >> speed >> aniwidth >> aniheight;
				m_Images[id]->m_AnimatedImage = new cAnimatedSurface();
				m_Images[id]->m_AnimatedImage->SetData(0, 0, numFrames, speed, aniwidth, aniheight, newImage->m_Surface);
				imagechosen = true;
				m_Images[id]->m_Image->m_Message = file;
			}
			input.close();
		}
		else if (ext == "gif")
		{
 			const char* n = file.c_str();
			int frames = AG_LoadGIF(n, NULL, 0);
			if (frames)
			{
				cImage* newImage = new cImage();
				newImage->m_Surface = new CSurface();
				newImage->m_Surface->LoadImage(file);
				newImage->m_AniSurface = new cAnimatedSurface();
				AG_Frame* gpAG = new AG_Frame[frames];
				AG_LoadGIF(n, gpAG, frames);
				m_Images[id]->m_Image = newImage->m_Surface;
				m_Images[id]->m_Image->m_Message = file;
				m_Images[id]->m_AnimatedImage = new cAnimatedSurface();
				m_Images[id]->m_AnimatedImage->SetGifData(0, 0, frames, gpAG, newImage->m_Surface);
				imagechosen = true;
			}
			else	// if it does not read as a gif, just load it as a normal image
			{
				m_Images[id]->m_Image = new CSurface(file);
				m_Images[id]->m_AnimatedImage = 0;
				imagechosen = true;
			}
		}
		else
		{
			m_Images[id]->m_Image = new CSurface(file);
			m_Images[id]->m_AnimatedImage = 0;
			imagechosen = true;
		}
	}	while (!imagechosen && --tries > 0);
Exemplo n.º 5
0
void cListBox::CreateListbox(int ID, int x, int y, int width, int height, int BorderSize, bool MultiSelect, bool ShowHeaders, bool HeaderDiv, bool HeaderSort)
{
	SDL_Rect dest_rect;

	m_ShowHeaders = ShowHeaders;
	m_HeaderDividers = HeaderDiv;
	m_HeaderClicksSort = HeaderSort;

	m_ID = ID;

	m_BorderSize = BorderSize;
	SetPosition(x, y, width, height);
	m_Border = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, 0, 0, 0, 0);
	SDL_FillRect(m_Border, 0, SDL_MapRGB(m_Border->format, g_ListBoxBorderR, g_ListBoxBorderG, g_ListBoxBorderB));

	m_Background = SDL_CreateRGBSurface(SDL_SWSURFACE, width - (BorderSize * 2) - 16, height - (BorderSize * 2), 32, 0, 0, 0, 0);
	SDL_FillRect(m_Background, 0, SDL_MapRGB(m_Background->format, g_ListBoxBackgroundR, g_ListBoxBackgroundG, g_ListBoxBackgroundB));

	m_NumDrawnElements = height / LISTBOX_ITEMHEIGHT;
	if (m_ShowHeaders) // Account for headers if shown
		m_NumDrawnElements--;
	m_eWidth = (width - (BorderSize * 2));
	m_eHeight = LISTBOX_ITEMHEIGHT;

	m_RedBackground = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - 2 - 16, m_eHeight - 2, 32, 0, 0, 0, 0);
	SDL_FillRect(m_RedBackground, 0, SDL_MapRGB(m_RedBackground->format, g_ListBoxS1ElementBackgroundR, g_ListBoxS1ElementBackgroundG, g_ListBoxS1ElementBackgroundB));

	m_DarkBlueBackground = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - 2 - 16, m_eHeight - 2, 32, 0, 0, 0, 0);
	SDL_FillRect(m_DarkBlueBackground, 0, SDL_MapRGB(m_DarkBlueBackground->format, g_ListBoxS2ElementBackgroundR, g_ListBoxS2ElementBackgroundG, g_ListBoxS2ElementBackgroundB));

	m_GreenBackground = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - 2 - 16, m_eHeight - 2, 32, 0, 0, 0, 0);
	SDL_FillRect(m_GreenBackground, 0, SDL_MapRGB(m_GreenBackground->format, g_ListBoxS3ElementBackgroundR, g_ListBoxS3ElementBackgroundG, g_ListBoxS3ElementBackgroundB));

	m_YellowBackground = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - 2 - 16, m_eHeight - 2, 32, 0, 0, 0, 0);
	SDL_FillRect(m_YellowBackground, 0, SDL_MapRGB(m_YellowBackground->format, g_ListBoxS4ElementBackgroundR, g_ListBoxS4ElementBackgroundG, g_ListBoxS4ElementBackgroundB));

	m_ElementBackground = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - 2 - 16, m_eHeight - 2, 32, 0, 0, 0, 0);
	SDL_FillRect(m_ElementBackground, 0, SDL_MapRGB(m_ElementBackground->format, g_ListBoxElementBackgroundR, g_ListBoxElementBackgroundG, g_ListBoxElementBackgroundB));

	m_ElementSelectedBackground = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - 2 - 16, m_eHeight - 2, 32, 0, 0, 0, 0);
	SDL_FillRect(m_ElementSelectedBackground, 0, SDL_MapRGB(m_ElementSelectedBackground->format, g_ListBoxSelectedElementR, g_ListBoxSelectedElementG, g_ListBoxSelectedElementB));

	m_SelectedRedBackground = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - 2 - 16, m_eHeight - 2, 32, 0, 0, 0, 0);
	SDL_FillRect(m_SelectedRedBackground, 0, SDL_MapRGB(m_SelectedRedBackground->format, g_ListBoxSelectedS1ElementR, g_ListBoxSelectedS1ElementG, g_ListBoxSelectedS1ElementB));

	m_SelectedDarkBlueBackground = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - 2 - 16, m_eHeight - 2, 32, 0, 0, 0, 0);
	SDL_FillRect(m_SelectedDarkBlueBackground, 0, SDL_MapRGB(m_SelectedDarkBlueBackground->format, g_ListBoxSelectedS2ElementR, g_ListBoxSelectedS2ElementG, g_ListBoxSelectedS2ElementB));

	m_SelectedGreenBackground = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - 2 - 16, m_eHeight - 2, 32, 0, 0, 0, 0);
	SDL_FillRect(m_SelectedGreenBackground, 0, SDL_MapRGB(m_SelectedGreenBackground->format, g_ListBoxSelectedS3ElementR, g_ListBoxSelectedS3ElementG, g_ListBoxSelectedS3ElementB));

	m_SelectedYellowBackground = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - 2 - 16, m_eHeight - 2, 32, 0, 0, 0, 0);
	SDL_FillRect(m_SelectedYellowBackground, 0, SDL_MapRGB(m_SelectedYellowBackground->format, g_ListBoxSelectedS3ElementR, g_ListBoxSelectedS3ElementG, g_ListBoxSelectedS3ElementB));

	m_ElementBorder = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - 16, m_eHeight, 32, 0, 0, 0, 0);
	SDL_FillRect(m_ElementBorder, 0, SDL_MapRGB(m_ElementBorder->format, g_ListBoxElementBorderR, g_ListBoxElementBorderG, g_ListBoxElementBorderB));

	// "beveled" looking border for bottom & right sides of list element
	dest_rect.x = m_BorderSize;
	dest_rect.y = m_BorderSize;
	dest_rect.h = m_eHeight - m_BorderSize;
	dest_rect.w = m_eWidth - m_BorderSize - 16;
	SDL_FillRect(m_ElementBorder, &dest_rect, SDL_MapRGB(m_ElementBorder->format, g_ListBoxElementBorderHR, g_ListBoxElementBorderHG, g_ListBoxElementBorderHB));

	if (ShowHeaders)
	{
		// background for optional column header box
		int scroll_space = (HeaderSort) ? 0 : 16;
		dest_rect.w = m_eWidth - m_BorderSize - scroll_space;
		m_HeaderBackground = SDL_CreateRGBSurface(SDL_SWSURFACE, m_eWidth - scroll_space, m_eHeight, 32, 0, 0, 0, 0);
		SDL_FillRect(m_HeaderBackground, 0, SDL_MapRGB(m_HeaderBackground->format, g_ListBoxHeaderBorderR, g_ListBoxHeaderBorderG, g_ListBoxHeaderBorderB));
		SDL_FillRect(m_HeaderBackground, &dest_rect, SDL_MapRGB(m_HeaderBackground->format, g_ListBoxHeaderBorderHR, g_ListBoxHeaderBorderHG, g_ListBoxHeaderBorderHB));
		dest_rect.h = m_eHeight - (m_BorderSize * 2);
		dest_rect.w = m_eWidth - (m_BorderSize * 2) - scroll_space;
		SDL_FillRect(m_HeaderBackground, &dest_rect, SDL_MapRGB(m_HeaderBackground->format, g_ListBoxHeaderBackgroundR, g_ListBoxHeaderBackgroundG, g_ListBoxHeaderBackgroundB));

		DirPath dp = ImagePath("ListboxSort");
		string Asc = string(dp.c_str()) + "Asc.png";
		string Desc = string(dp.c_str()) + "Desc.png";
		string None = string(dp.c_str()) + "None.png";
		if (m_HeaderSortAsc == 0)	m_HeaderSortAsc = IMG_Load(Asc.c_str());
		if (m_HeaderSortDesc == 0)	m_HeaderSortDesc = IMG_Load(Desc.c_str());
		if (m_HeaderUnSort == 0)	m_HeaderUnSort = IMG_Load(None.c_str());

		// draw the "un-sort" clickable header
		if (HeaderSort)
		{
			m_Divider.x = m_eWidth - 17;
			m_Divider.w = 2;
			SDL_FillRect(
				m_HeaderBackground,
				&m_Divider,
				SDL_MapRGB(
				m_HeaderBackground->format,
				g_ListBoxHeaderBorderHR,
				g_ListBoxHeaderBorderHG,
				g_ListBoxHeaderBorderHB
				)
				);
			m_Divider.x++;
			m_Divider.w = 1;
			m_Divider.h--;
			SDL_FillRect(m_HeaderBackground, &m_Divider, SDL_MapRGB(m_HeaderBackground->format, g_ListBoxHeaderBorderR, g_ListBoxHeaderBorderG, g_ListBoxHeaderBorderB));
			m_Divider.h++;

			dest_rect.x = m_eWidth - 15;
			dest_rect.y = m_BorderSize;
			dest_rect.h = m_eHeight - 2;
			dest_rect.w = 14;
			SDL_BlitSurface(m_HeaderUnSort, 0, m_HeaderBackground, &dest_rect);
		}
	}

	m_Font.LoadFont(cfg.fonts.normal(), 10);
	m_Font.SetText("");
	m_Font.SetColor(g_ListBoxTextR, g_ListBoxTextG, g_ListBoxTextB);

	m_MultiSelect = MultiSelect;

	m_Divider.h = m_eHeight - (m_BorderSize * 2) - 3;
	m_Divider.y = m_BorderSize + 1;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindowEventProducer = createDefaultWindowEventProducer();
    WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();

    TutorialWindowEventProducer->setDisplayCallback(display);
    TutorialWindowEventProducer->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindowEventProducer->addKeyListener(&TheKeyListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(MainWindow);
	
										
    // Make Torus Node (creates Torus in background of scene)
    NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    NodePtr scene = osg::Node::create();
    beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);
        scene->setCore(osg::Group::create());
        scene->addChild(TorusGeometryNode);
    endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);

    //Create the Image
    Path ImagePath("./Data/TutorialImage.jpg");
    ImagePtr TheImage = ImageFileHandler::the().read(ImagePath.string().c_str());

    //Create the texture
    TextureChunkPtr TheTextureChunk = TextureChunk::create();
    beginEditCP(TheTextureChunk);
        TheTextureChunk->setImage(TheImage);

        TheTextureChunk->setMinFilter(GL_NEAREST);
        TheTextureChunk->setMagFilter(GL_NEAREST);

        TheTextureChunk->setWrapS(GL_CLAMP_TO_EDGE);
        TheTextureChunk->setWrapR(GL_CLAMP_TO_EDGE);

        TheTextureChunk->setScale(false);
        TheTextureChunk->setNPOTMatrixScale(true);
        
        TheTextureChunk->setEnvMode(GL_REPLACE); 
    endEditCP(TheTextureChunk);

    //Create a Texture Source
    TextureSourceTextureFilterPtr TutorialTextureSourceTextureFilter = TextureSourceTextureFilter::create();
    beginEditCP(TutorialTextureSourceTextureFilter, TextureSourceTextureFilter::TextureFieldMask);
        TutorialTextureSourceTextureFilter->setTexture(TheTextureChunk);
    endEditCP(TutorialTextureSourceTextureFilter, TextureSourceTextureFilter::TextureFieldMask);

    //Create a Grayscale filter
    std::string GrayScaleFragProg = "uniform sampler2D Slot0Texture; void main() { gl_FragColor = vec4(vec3( dot(vec3(0.3,0.59,0.11), texture2D(Slot0Texture,gl_TexCoord[0].st).rgb)), 1.0); }";

    //Create a shader Filter
    ShaderTextureFilterPtr GrayscaleTextureFilter = ShaderTextureFilter::create();
    GrayscaleTextureFilter->attachSource(TutorialTextureSourceTextureFilter, 0, 0);
    GrayscaleTextureFilter->setFragmentSource(GrayScaleFragProg);

    //Create a Color Mult filter
    std::string ColorMultFragProg = "uniform sampler2D Slot0Texture; void main() { gl_FragColor = vec4(vec3(1.0,0.0,0.0) * texture2D(Slot0Texture,gl_TexCoord[0].st).rgb, 1.0); }";

    //Create a shader Filter
    ShaderTextureFilterPtr ColorMultTextureFilter = ShaderTextureFilter::create();
    ColorMultTextureFilter->attachSource(GrayscaleTextureFilter,0,0);
    ColorMultTextureFilter->setFragmentSource(ColorMultFragProg);

    
    ////Create a Blur filter
    //std::string BlurFragProg = "";
    //BlurFragProg += 
    //"uniform sampler2D Slot0Texture;"
    //"void main()"
    //"{"
    //"    vec2 offsets[9];"
    //"    offsets[0] = vec2(-0.000625,0.00111111111);"
    //"    offsets[1] = vec2(0.0,0.00111111111);"
    //"    offsets[2] = vec2(0.000625,0.00111111111);"
    //"    offsets[3] = vec2(-0.000625,0.0);"
    //"    offsets[4] = vec2(0.0,0.0);"
    //"    offsets[5] = vec2(0.0,0.0);"
    //"    offsets[6] = vec2(-0.000625,-0.00111111111);"
    //"    offsets[7] = vec2(0.0,-0.00111111111);"
    //"    offsets[8] = vec2(0.000625,-0.00111111111);"
    //"    vec4 kernel[9];"
    ////"    kernel[0] = vec4(0.0);"
    ////"    kernel[1] = vec4(0.0);"
    ////"    kernel[2] = vec4(0.0);"
    ////"    kernel[3] = vec4(0.0);"
    ////"    kernel[4] = vec4(1.0);"
    ////"    kernel[5] = vec4(0.0);"
    ////"    kernel[6] = vec4(0.0);"
    ////"    kernel[7] = vec4(0.0);"
    ////"    kernel[8] = vec4(0.0);"
    //"    kernel[0] = vec4(0.0);"
    //"    kernel[1] = vec4(0.15);"
    //"    kernel[2] = vec4(0.0);"
    //"    kernel[3] = vec4(0.15);"
    //"    kernel[4] = vec4(0.4);"
    //"    kernel[5] = vec4(0.15);"
    //"    kernel[6] = vec4(0.0);"
    //"    kernel[7] = vec4(0.15);"
    //"    kernel[8] = vec4(0.0);"
    //"    vec4 sum = vec4(0.0);"
    //"    int i;"
    //"    for(i = 0 ; i < 9 ; i++)"
    //"    {"
    //"        sum += kernel[i] * texture2D(Slot0Texture,gl_TexCoord[0].st + offsets[i]);"
    //"    }"
    //"    gl_FragColor = sum;"
    //"}";

    ////Create a shader Filter
    //ShaderTextureFilterPtr BlurTextureFilter = ShaderTextureFilter::create();
    //BlurTextureFilter->attachSource(ColorMultTextureFilter);
    //BlurTextureFilter->setFragmentSource(BlurFragProg);


	
	// Create the ImageProcessed Foreground Object
    ImageProcessedForegroundPtr TutorialImageProcessedForeground = ImageProcessedForeground::create();

    beginEditCP(TutorialImageProcessedForeground, ImageProcessedForeground::FilterFieldMask | ImageProcessedForeground::OutputSlotFieldMask);
        TutorialImageProcessedForeground->setFilter(ColorMultTextureFilter);
        TutorialImageProcessedForeground->setOutputSlot(0);
    endEditCP(TutorialImageProcessedForeground, ImageProcessedForeground::FilterFieldMask | ImageProcessedForeground::OutputSlotFieldMask);

    mgr->setRoot(scene);

    // Add the ImageProcessed Foreground Object to the Scene
    ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);
        TutorialViewport->getForegrounds().push_back(TutorialImageProcessedForeground);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5);
    TutorialWindowEventProducer->openWindow(WinPos,
            WinSize,
            "02SimpleImagePipeline");

    //Enter main Loop
    TutorialWindowEventProducer->mainLoop();

    osgExit();

    return 0;
}
IconSurface::IconSurface( std::string name )
    : CSurface( ImagePath(name + ".png") )
{
}
ImageSurface::ImageSurface ( std::string name, const char* pt, const char* ext )
    : CSurface( ImagePath((name + pt) + ext).c_str() )
{
}