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 next 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

Re: OptionImage ctrl: how to make it better... [message #2439 is a reply to message #2437] Wed, 12 April 2006 17:51 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Luigi, would you be able now to transform the code above to have possibility:
opt3.Set("Label_text", imgYes(), imgNo(), imgMaybe());

??? Wink
Re: OptionImage ctrl: how to make it better... [message #2445 is a reply to message #2439] Wed, 12 April 2006 23:03 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
fudadmin wrote on Wed, 12 April 2006 17:51

Luigi, would you be able now to transform the code above to have possibility:
opt3.Set("Label_text", imgYes(), imgNo(), imgMaybe());

??? Wink


Aris,

thank you very much for your effort! Just now I've seen the code but I can try only tomorrow. I hope to be able to do so.

Luigi
Re: OptionImage ctrl: how to make it better... [message #2446 is a reply to message #2445] Wed, 12 April 2006 23:11 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
If you download it, it runs "out of the box"...
Re: OptionImage ctrl: how to make it better... [message #2451 is a reply to message #2446] Thu, 13 April 2006 08:45 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
fudadmin wrote on Wed, 12 April 2006 23:11

If you download it, it runs "out of the box"...


Aris,
I tried your code. It works very nice (what do you mean with
"out of the box"?). I've even learned how to put in the designer a new class object (just rename the classobject after CTRL+T). Before to do my 'todo' task I tried to put the wonderful OptionImage in the arrayctrl. I've added the .iml file and the .h file then

1th temptive.
	arr.AddColumn("Avail", "Avail?", 4).Ctrls<OptionImage>();  

nothing appear.

2th temptive.
	arr.AddColumn("Avail", "Avail?", 4).Ctrls(Avail3);   

where, on the model of past example,
void Avail3(One<Ctrl>& ctrl)
{
//	ctrl.Create<Option>().ThreeState();
	ctrl.Create<OptionImage>();
	ctrl.ThreeState(true).SetImage( imgYes(), imgNo(), imgMaybe());
}

but the compiler cryed:
C:\MyApps\vegaMenuStatus\tab1.cpp: In function `void Avail3(One<Ctrl>&)':
C:\MyApps\vegaMenuStatus\tab1.cpp:18: error: 'class One<Ctrl>' has no member named 'ThreeState'


Any idea? I attach the zipped project if could be useful. This part of the code is in the file tab1.cpp. Unzip in vegaMenuStatus with no subfolder.
Thank you,
Luigi

Edit by fudamin:
P.S old zip deleted to save space on the server. New zip below.

[Updated on: Fri, 14 April 2006 07:48] by Moderator

Report message to a moderator

Re: OptionImage ctrl: how to make it better... [message #2462 is a reply to message #2451] Thu, 13 April 2006 16:47 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
void Avail3(One<Ctrl>& ctrl)
{
//	ctrl.Create<Option>().ThreeState();
	ctrl.Create<OptionImage>().ThreeState().SetImage(imgYes(), imgNo(), imgMaybe());
	
}

Smile

Edit:
P.S. "out of the box" means that you don't need any adjustments or changes...

[Updated on: Thu, 13 April 2006 16:48]

Report message to a moderator

Re: OptionImage ctrl: how to make it better... [message #2464 is a reply to message #2462] Thu, 13 April 2006 17:13 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
and for your ArrayCtrl initialization this might be useful:
	arr.SetLineCy(imgYes().GetSize().cy+1);
Re: OptionImage ctrl: how to make it better... [message #2465 is a reply to message #2462] Thu, 13 April 2006 17:43 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
fudadmin wrote on Thu, 13 April 2006 16:47

void Avail3(One<Ctrl>& ctrl)
{
//	ctrl.Create<Option>().ThreeState();
	ctrl.Create<OptionImage>().ThreeState().SetImage(imgYes(), imgNo(), imgMaybe());
	
}

Smile



I remind to have tried even this combination but without success Embarassed . Perhaps there were a mistake in some other place.
Even arr.SetLineCy(imgYes().GetSize().cy+1); is very useful... I was looking for something like it!

How can I know when to use the '.' and connect more methods? So far I'm using the code but without to really understand the syntax. Anyway it works and the understanding can wait. Maybe if I understand the things start to go wrong.

Now I want to realize a small tutorial useful for dinosour as me to fix what I have learned so far.
Luigi
Re: OptionImage ctrl: how to make it better... [message #2466 is a reply to message #2465] Thu, 13 April 2006 18:16 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
The '.' makes you work with instance on the left.

'ctrl.' means you want to do something with arrayctrl (and there's no ThreeState method defined for that class)

'ctrl.Create<OptionImage>().' means you want to call "Create" method of ctrl to create OptionImage class instance with default (void) constructor. And that Create method returns reference to the freshly created control (OptionImage), so the last '.' indicates you want to do something with OptionImage.
Now there's perfectly legal to use "ThreeState" method on that one.

It's like many single lines put into one long.
I think this code would do the same (but I'm writing it just by hand, so maybe there will be some mistake)

    OptionImage &option_instance = ctrl.Create<OptionImage>();
    option_instance.ThreeState();
    option_instance.SetImage(imgYes(), imgNo(), imgMaybe());


i.e. in first line you create your option object instance in memory (and add it to arractrl).
And on next lines you are customizing it's behaviour by calling it's methods.

The long line with many dots is a nice shortcut, which is using the fact that many methods returns the reference to "this" instance, allowing you to continue with another '.'.
Re: OptionImage ctrl: how to make it better... [message #2468 is a reply to message #2466] Thu, 13 April 2006 18:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mr_ped wrote on Thu, 13 April 2006 12:16

The '.' makes you work with instance on the left.

'ctrl.' means you want to do something with arrayctrl (and there's no ThreeState method defined for that class)

'ctrl.Create<OptionImage>().' means you want to call "Create" method of ctrl to create OptionImage class instance with default (void) constructor. And that Create method returns reference to the freshly created control (OptionImage), so the last '.' indicates you want to do something with OptionImage.
Now there's perfectly legal to use "ThreeState" method on that one.

It's like many single lines put into one long.
I think this code would do the same (but I'm writing it just by hand, so maybe there will be some mistake)

    OptionImage &option_instance = ctrl.Create<OptionImage>();
    option_instance.ThreeState();
    option_instance.SetImage(imgYes(), imgNo(), imgMaybe());


i.e. in first line you create your option object instance in memory (and add it to arractrl).
And on next lines you are customizing it's behaviour by calling it's methods.

The long line with many dots is a nice shortcut, which is using the fact that many methods returns the reference to "this" instance, allowing you to continue with another '.'.


And you insist you just barely know C++? Smile

Mirek
Re: OptionImage ctrl: how to make it better... [message #2470 is a reply to message #2465] Thu, 13 April 2006 18:24 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
forlano wrote on Thu, 13 April 2006 16:43


1. How can I know when to use the '.' and connect more methods?

2.So far I'm using the code but without to really understand the syntax. Anyway it works and the understanding can wait. Maybe if I understand the things start to go wrong.

3. Now I want to realize a small tutorial useful for dinosour as me to fix what I have learned so far.
Luigi


1. Look at what is returned from methods:
a) in Assistant - the first column if Ctrl or Ctrl& or Ctrl* or etc.
b) in the library (mostly *.h files) (tip- use alt_J alt_I!)
P.S. In tutorial this should be named
"How to make "sausages" in your code... :)"

2. Proper understanding comes from your mistakes!
If you can drive a car, you don't need to fix it, do you Smile?
You learn only when you need something. Can a child learn how not to fall without falling? Then you remember it better... Smile

3. Very good idea! What I was aiming at... Start from the content?

[Updated on: Thu, 13 April 2006 18:26]

Report message to a moderator

Re: OptionImage ctrl: how to make it better... [message #2471 is a reply to message #2468] Thu, 13 April 2006 18:37 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Mirek, I'm master on assembly level. Wink
So I perfectly understand what instance is, and what is difference between '.' and '->', between stack allocation of local variable and heap allocation by new, and when to use which.

I'm very good on algorithm/problems solving level too.

The C++ is between those two, and my mediocre knowledge is usually enough. In the end the documentation and google will save you, once you know *from* where *to* where you want to go. C++ is just path, and even if I don't choose the most optimal one, it's not the biggest obstacle to reach my goals.
Re: OptionImage ctrl: how to make it better... [message #2473 is a reply to message #2465] Thu, 13 April 2006 19:32 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
forlano wrote on Thu, 13 April 2006 16:43

fudadmin wrote on Thu, 13 April 2006 16:47

void Avail3(One<Ctrl>& ctrl)
{
//	ctrl.Create<Option>().ThreeState();
	ctrl.Create<OptionImage>().ThreeState().SetImage(imgYes(), imgNo(), imgMaybe());
	
}

Smile



I remind to have tried even this combination but without success Embarassed . Perhaps there were a mistake in some other place.
Luigi


1. Perhaps you should try exactly what is here? (it's not in your code...)

2. I'm surprised how from such simple U++ application you were able to make a "spaghetti code"... Smile. First of all, it doesn't run out of the box because I don't use C: and I don't have MyApps... - Why do you use absolute references in *.upp file?
And you don't need a hundred of #include in each file with U++...

http://en.wikipedia.org/wiki/Spaghetti_code
Re: OptionImage ctrl: how to make it better... [message #2478 is a reply to message #2473] Thu, 13 April 2006 23:59 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
fudadmin wrote on Thu, 13 April 2006 19:32

forlano wrote on Thu, 13 April 2006 16:43

fudadmin wrote on Thu, 13 April 2006 16:47

void Avail3(One<Ctrl>& ctrl)
{
//	ctrl.Create<Option>().ThreeState();
	ctrl.Create<OptionImage>().ThreeState().SetImage(imgYes(), imgNo(), imgMaybe());
	
}

Smile



I remind to have tried even this combination but without success Embarassed . Perhaps there were a mistake in some other place.
Luigi


1. Perhaps you should try exactly what is here? (it's not in your code...)

2. I'm surprised how from such simple U++ application you were able to make a "spaghetti code"... Smile. First of all, it doesn't run out of the box because I don't use C: and I don't have MyApps... - Why do you use absolute references in *.upp file?
And you don't need a hundred of #include in each file with U++...

http://en.wikipedia.org/wiki/Spaghetti_code



Thank you to all of you for the precious advices I've receveid. Now it is more clear.

I know perfectly what "spaghetti" and "spaghetti code" means. Nevertheless I do not understand what Aris mean in point 2) and file *.upp and #include.
I know only that now I've a beautiful OptionImage with which to play Very Happy , inside and outside an ArrayCtrl. I'm very satisfied by what I've although I'm aware that there is space for improvement.
Luigi
Re: OptionImage ctrl: how to make it better... [message #2479 is a reply to message #2478] Fri, 14 April 2006 00:18 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Laughing ok, not hundred... but, anyway, I'll try to make it more compact... and maybe I'll succeed with one more nice surprise... (at least for you).
And btw, is OptionImage working with ArrayCtrl?
Re: OptionImage ctrl: how to make it better... [message #2480 is a reply to message #2478] Fri, 14 April 2006 00:33 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
forlano wrote on Thu, 13 April 2006 22:59

I know perfectly what "spaghetti" and "spaghetti code" means.

Nevertheless I do not understand what Aris mean in point 2) and file *.upp and #include.



your *.upp
uses
	CtrlLib;

file
	C:\MyApps\vegaMenuStatus\app.h,
	C:\MyApps\vegaMenuStatus\tab4.cpp,
	C:\MyApps\vegaMenuStatus\tab3.cpp,
	C:\MyApps\vegaMenuStatus\tab2.cpp,
	C:\MyApps\vegaMenuStatus\ForlanoOption.iml,
	C:\MyApps\vegaMenuStatus\ForlanoOption.h,
	C:\MyApps\vegaMenuStatus\tab1.cpp,
	C:\MyApps\vegaMenuStatus\newtournament.lay,
	C:\MyApps\vegaMenuStatus\tabs.h,
	C:\MyApps\vegaMenuStatus\editmask.lay,
	main.cpp;

mainconfig
	"" = "GUI";

these are absolute references, aren't they? And if I use Linux? And IMHO, you are killing the whole idea of packages, forcing me to spend my precious time to rename them, then find all spaghetti includes...
It's M$ and Co approach - to waste others time... Smile What Mirek and Co will say?! Smile
Edit:
P.S. Have you recieved any of Ultimate's upp files like this?!
Open them as text and find out... Smile

[Updated on: Fri, 14 April 2006 00:43]

Report message to a moderator

Re: OptionImage ctrl: how to make it better... [message #2483 is a reply to message #2480] Fri, 14 April 2006 07:09 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
fudadmin wrote on Fri, 14 April 2006 00:33

forlano wrote on Thu, 13 April 2006 22:59

I know perfectly what "spaghetti" and "spaghetti code" means.

Nevertheless I do not understand what Aris mean in point 2) and file *.upp and #include.



your *.upp
uses
	CtrlLib;

file
	C:\MyApps\vegaMenuStatus\app.h,
	C:\MyApps\vegaMenuStatus\tab4.cpp,
	C:\MyApps\vegaMenuStatus\tab3.cpp,
	C:\MyApps\vegaMenuStatus\tab2.cpp,
	C:\MyApps\vegaMenuStatus\ForlanoOption.iml,
	C:\MyApps\vegaMenuStatus\ForlanoOption.h,
	C:\MyApps\vegaMenuStatus\tab1.cpp,
	C:\MyApps\vegaMenuStatus\newtournament.lay,
	C:\MyApps\vegaMenuStatus\tabs.h,
	C:\MyApps\vegaMenuStatus\editmask.lay,
	main.cpp;

mainconfig
	"" = "GUI";

these are absolute references, aren't they? And if I use Linux? And IMHO, you are killing the whole idea of packages, forcing me to spend my precious time to rename them, then find all spaghetti includes...
It's M$ and Co approach - to waste others time... Smile What Mirek and Co will say?! Smile
Edit:
P.S. Have you recieved any of Ultimate's upp files like this?!
Open them as text and find out... Smile


The OptionImage works inside the arrayctrl.
Your *.upp file look like this:
uses
	CtrlLib;

file
	"ForlanoOption.h"
	, main.cpp
	, "ForlanoOption.lay"
	, "ForlanoOption.iml"
;

mainconfig
	"" = "GUI";

That is more clean than mine. However I do not know why my upp file has those absolute paths. When I need a new file I click on "insert any file(s)" and write its name. I'am not aware of this absolute reference... and still I countinue to not understand in what the problem consist (I do not see problem when all work as I want Smile ).

Luigi
Re: OptionImage ctrl: how to make it better... [message #2484 is a reply to message #2483] Fri, 14 April 2006 07:26 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Quote:

When I need a new file I click on "insert any file(s)" and write its name. I'am not aware of this absolute reference... and still I countinue to not understand in what the problem consist (I do not see problem when all work as I want Smile ).

Perhaps I have understood. I should click instead on "insert package directory file(s)". Now the absolute path in *upp disappeared. If this is true, what advantage I achieve in this last method? Which connection has it with the include file?

Luigi
Re: OptionImage ctrl: how to make it better... [message #2485 is a reply to message #2484] Fri, 14 April 2006 07:29 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Ok, your new version is here:

Edit:
P.S. I'll delete the previous file to save space on the server.

[Updated on: Fri, 14 April 2006 07:46]

Report message to a moderator

Re: OptionImage ctrl: how to make it better... [message #2486 is a reply to message #2484] Fri, 14 April 2006 07:44 Go to previous messageGo to previous message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
forlano wrote on Fri, 14 April 2006 06:26

Quote:

When I need a new file I click on "insert any file(s)" and write its name. I'am not aware of this absolute reference... and still I countinue to not understand in what the problem consist (I do not see problem when all work as I want Smile ).

Perhaps I have understood. I should click instead on "insert package directory file(s)". Now the absolute path in *upp disappeared. If this is true, what advantage I achieve in this last method? Which connection has it with the include file?

Luigi

Advantages:
1. Other people do not need to waste time renaming to help you...
2. You can make simple backups or copies (branches) or move the whole dirs with packages...
3. And especially usefull when you work with a team...

P.S. Maybe Mirek can tell more advantages?
Previous Topic: Different color for three state option button
Next Topic: How to create a non modal dialog
Goto Forum:
  


Current Time: Tue Apr 23 08:38:41 CEST 2024

Total time taken to generate the page: 0.02095 seconds