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  |
 |
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 #2451 is a reply to message #2446] |
Thu, 13 April 2006 08:45   |
 |
forlano
Messages: 1224 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 #2480 is a reply to message #2478] |
Fri, 14 April 2006 00:33   |
 |
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... What Mirek and Co will say?! 
Edit:
P.S. Have you recieved any of Ultimate's upp files like this?!
Open them as text and find out...
[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   |
 |
forlano
Messages: 1224 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... What Mirek and Co will say?! 
Edit:
P.S. Have you recieved any of Ultimate's upp files like this?!
Open them as text and find out... 
|
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 ).
Luigi
|
|
|
|
|
|
|
|
|
|
|
|
| Re: OptionImage ctrl: how to make it better... [message #2488 is a reply to message #2487] |
Fri, 14 April 2006 09:26   |
 |
mirek
Messages: 14291 Registered: November 2005
|
Ultimate Member |
|
|
| mr_ped wrote on Fri, 14 April 2006 03:01 | I did check my test projects, and I did use "Insert any file" too to add files to my package.
Mirek: what's the real difference between those two?
I think (from what I see) they both work in the same way: add the file to the package. The only difference is that the first one makes the path relative, the second one absolute.
But both ways will make any added .cpp file to compile when I hit "Build", so it looks that "any file" belongs to main package anyway.
I think the context menu naming is somewhat confusing in such case (if that's the only difference).
Actually I would prefer single "Insert file" menu in such case, with option "absolute path ON/OFF", which would be set to OFF by default.
Or maybe "Insert any file" should switch the selection from package to "prj-aux" or what's appropriate? And to not add such file to build process (as I believe only package files should be involved in the building process of package).
I'm still a bit confused by packages (I understand them as "libraries" in C terminology), so maybe I don't understand it correctly, but I think TheIDE is right now a bit confusing with those 2x "Insert file". (And the "any file" one was easier to find for me, I never realised there was the package one on the first line (ignored it always) until I read this topic)
|
Sorry about confusion. I guess this is classical case where you have to choose between stronger and easier to use feature set.
It is true that "Insert any file.." for regular package is (should be..) very seldom used, however it can have advantages sometimes (e.g. experimenting with 3rd party code).
Mirek
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Thu May 14 01:40:59 GMT+2 2026
Total time taken to generate the page: 0.00948 seconds
|