Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » OptionImage ctrl: how to make it better...
OptionImage ctrl: how to make it better... [message #2437] Wed, 12 April 2006 17:24 Go to previous message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Ok, I'm posting my a bit improved OptionImage control version and we can disscuss it here...

class OptionImage : public Option {
protected:
	Image imgYes, imgNo, imgMaybe;
public:
	virtual void   Paint(Draw& draw);
	OptionImage& SetImage(const Image& m1, const Image& m2, const Image& m3)
			            { imgYes = m1; imgNo = m2; imgMaybe = m3; Refresh(); return *this; }
	OptionImage& SetImage(const Image& m1, const Image& m2)
			            { imgYes = m1; imgNo = m2; Refresh(); return *this; }
			            
	OptionImage& ThreeState(bool b = true)             { threestate = b; notnull = false; return *this; }

	typedef OptionImage CLASSNAME;
	OptionImage();
	~OptionImage(){;}
};

OptionImage::OptionImage()
{

}


void OptionImage::Paint(Draw& w) {
	Size sz = GetSize();
	if(!IsTransparent())
		w.DrawRect(0, 0, sz.cx, sz.cy, SColorFace);
	Size isz = imgYes.GetSize();  //although maybe it would be good to calc from the biggest...?
	Size tsz = GetSmartTextSize(w, label, font);
	int ty = (sz.cy - tsz.cy) / 2; //text up-down
	int iy = (tsz.cy - isz.cy) / 2 + ty;
	bool ds = !IsShowEnabled();

		Image m = (!notnull || threestate) && IsNull(option) ? ds ? imgMaybe
				                      : IsPush() ? imgYes
							                     : imgMaybe :
			      option == 1 ? ds ? (switchimage ? imgYes : imgYes)
				                   : IsPush() ? (switchimage ? imgYes : imgYes)
							                  : (switchimage ? imgYes : imgYes)
				              : ds ? (switchimage ? imgNo : imgNo)
				                   : IsPush() ? (switchimage ? imgNo : imgNo)
							                  : (switchimage ? imgNo : imgNo);
		w.DrawImage(0, iy, m);
	//	if(!switchimage) //for borders - need to adjust sizes...
	//		w.DrawImage(0, iy, ds ? CtrlImg::optionedged : blackedge ? CtrlImg::blackoptionedge : CtrlImg::optionedge);

	DrawSmartText(w, isz.cx + 4, ty, tsz.cx, label, font, ds ? SGray : SBlack, VisibleAccessKeys() ? accesskey : 0);
	//text length problem - tsz.cx - doesn't work? adjust your size in *.lay... :)
}


Now it works with assigned images from *.iml:
(with autosize from the 1st img - yes...)
	opt3.SetLabel("Avail?");  //todo: doesn't show all text if long... - adjust your size in *.lay... :)
	opt3.ThreeState(true).SetImage( imgYes(), imgNo(), imgMaybe());

P.S. Unzip into ForlanoOption folder (no folders inside!)

[Updated on: Wed, 12 April 2006 20:11]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Different color for three state option button
Next Topic: How to create a non modal dialog
Goto Forum:
  


Current Time: Sat Apr 27 21:11:39 CEST 2024

Total time taken to generate the page: 0.05007 seconds