c++ - Override VCL class/component protected method - How to code and use? -


i rewriting old existing code , i'm giving icons overhaul. used have bitmaps assigned tmenuitems i'm changing in favor of imageindex , timagelist colordepth 32bit, containing icons alpha channel. imagelist created , populated icons @ design time. imageindex assigned during program startup , changed if/when appropriate.

i noticed when menuitem disabled (enabled = false), resulting image doesn't great (at all) , read due vcl. mentioned link links delphi code can convert icon greyscale values.

i'm not fluent in delphi nor changing vcl components, subclassing them, inheriting them etc. use available without changing it. i'm starting basic questions:

here's simple attempt inherit timage , override dodraw(), make never disable icon in first place (decipering delphi code greyscale can done in second step)

class mytimagelist : public timagelist     {     public:      __fastcall mytimagelist(classes::tcomponent* aowner)         : timagelist(aowner) {} ;      virtual __fastcall dodraw(int index, tcanvas *canvas, int x, int y, unsigned int style, bool enabled = true)         {         return timagelist::dodraw(index, canvas, x, y, style) ;         }     }; 

fyi: use c++ builder 2009 not compile, error: [bcc32 error] main.h(1018): e2113 virtual function '_fastcall tmainform::mytimagelist::dodraw(int,tcanvas *,int,int,unsigned int,bool)' conflicts base class 'tcustomimagelist'

since i'm insecure inheriting vcl component classes i'm not sure if i'm dealing typo or constructively wrong ? kindly enlighten me.

assuming compiles i'm not sure how proceed further either. because imagelist created @ design time, , used throughout code. change work have work 'mytimagelist'.

so, create mytimagelist during form construction , assign() content of design-time-imagelist, or there more efficient way avoid copying on ?

actually, thinking latter question more, i use internal imagelist of design time imagelist instance.

here c++ translation of delphi code:

class mytimagelist : public timagelist { protected:     virtual void __fastcall dodraw(int index, graphics::tcanvas *canvas, int x, int y, unsigned style, bool enabled = true);  public:     __fastcall mytimagelist(classes::tcomponent* aowner, timagelist *designimagelist); }; 

__fastcall mytimagelist::mytimagelist(classes::tcomponent* aowner, timagelist *designimagelist)     : timagelist(aowner) {     colordepth = designimagelist->colordepth;     handle = designimagelist->handle; // use internally kept list of design time imagelist     shareimages = true; }  unsigned __fastcall getrgbcolor(tcolor value) {     unsigned result = colortorgb(value);     switch (result)     {         case clnone: result = clr_none; break;         case cldefault: result = clr_default; break;     }     return result; }  void __fastcall mytimagelist::dodraw(int index, tcanvas *canvas, int x, int y, unsigned style, bool enabled) {     if ((enabled) || (colordepth != cd32bit))     {         timagelist::dodraw(index, canvas, x, y, style, enabled);     }     else if (handleallocated())     {         imagelistdrawparams options = {0};         options.cbsize = sizeof(options);         options.himl = (himagelist) handle;         options.i = index;         options.hdcdst = canvas->handle;         options.x = x;         options.y = y;         options.cx = 0;         options.cy = 0;         options.xbitmap = 0;         options.ybitmap = 0;         options.rgbbk = getrgbcolor(bkcolor);         options.rgbfg = getrgbcolor(blendcolor);         options.fstyle = style;         options.fstate = ils_saturate; // grayscale 32bit images          imagelist_drawindirect(&options);     } } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -