wxPerl - custom grid renderer

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
james28909
Knows some wx things
Knows some wx things
Posts: 39
Joined: Mon Jul 01, 2019 8:27 pm

Re: wxPerl - custom grid renderer

Post by james28909 » Sat Jul 27, 2019 2:23 pm

But the redraw looks fine if the window is drawn completely?
yes and no,

yes) if i minimize the window while its running and then bring it back up, then everything gets repainted and the image looks fine but as soon as you scroll it does the same thing.

no) it clobbers any existing information/attributes/text/colors that existed in the cell, which i want to preserve and have the image painted inside the cell as well.
Have you tried clearing the background like i wrote before:
i sure have, within the CustomRenderer, and when try to change/set any brush or colors or anything to $dc (which is Wx::PaintDC as you said) it crashes the program after 3-4 seconds and all that is shown is the window and a grey background without any grids or anything.

EDIT: just had a thought, do you think it could have something to do with pixel data? as in the cell it draws, and the scroll event are two different sizes? like what if the pixel data? was smaller than the actual scrolling size of each scroll? that could cause a smearing effect could it not?

User avatar
doublemax
Moderator
Moderator
Posts: 13985
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxPerl - custom grid renderer

Post by doublemax » Sat Jul 27, 2019 4:17 pm

no) it clobbers any existing information/attributes/text/colors that existed in the cell, which i want to preserve and have the image painted inside the cell as well.
That's a different, less critical issue. That will be solved if you find out how to call a standard cell renderer.
and when try to change/set any brush or colors or anything to $dc (which is Wx::PaintDC as you said) it crashes the program after 3-4 seconds and all that is shown is the window and a grey background without any grids or anything.
This is very strange and unfortunately something i can't help with. Can you compare your code to any (working) custom paint event handler? Can you check the source code for the standard grid cell renderers? ( I actually wanted to do that, but couldn't find it anywhere)
just had a thought, do you think it could have something to do with pixel data? as in the cell it draws, and the scroll event are two different sizes? like what if the pixel data? was smaller than the actual scrolling size of each scroll? that could cause a smearing effect could it not?
No, don't overthink things ;) I'm still sure that the smearing effect is caused by not the whole cell content being drawn.
Use the source, Luke!

james28909
Knows some wx things
Knows some wx things
Posts: 39
Joined: Mon Jul 01, 2019 8:27 pm

Re: wxPerl - custom grid renderer

Post by james28909 » Sat Jul 27, 2019 4:32 pm

well just figured it out haha.

and youre right about the problem being that the cell isnt drawn, which makes me wonder how the image was even showing up tbh... anyway once i did $dc->DrawRectangle($rect->x, $rect->y, width, height); then $dc->DrawBitmap($bmp, $rect->x, $rect->y, 1); then that fixed it. picture is painted and no smearing or artifacts. here is the complete code, thats working.

Code: Select all

package CustomRenderer;

use Wx qw( :everything );
use base 'Wx::PlGridCellRenderer';

sub Draw {
# print @_;
    my ( $self, $grid, $attr, $dc, $rect, $row, $col, $sel ) = ( shift, @_ );
	
	
    my $image = Wx::Image->new("icons/111.png", wxBITMAP_TYPE_PNG);
     $image->Rescale(35,35, 'wxIMAGE_QUALITY_HIGH' );

    my $bmp = Wx::Bitmap->new($image);

    if( $bmp->IsOk() ) {

        $dc->DrawRectangle($rect->x, $rect->y, 200, 40);
        $dc->DrawBitmap( $bmp, $rect->x + 160, $rect->y, 1 );	
    }
	
}
 sub Clone {
    my $self = shift;
     return $self->new;
}
EDIT: but now i have to figure out how to send a string along with the call to setcellrenderer. can i send args along with setcellrenderer?

User avatar
doublemax
Moderator
Moderator
Posts: 13985
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxPerl - custom grid renderer

Post by doublemax » Sat Jul 27, 2019 4:46 pm

EDIT: but now i have to figure out how to send a string along with the call to setcellrenderer. can i send args along with setcellrenderer?
No. A cell renderer would normally get the cell content through the "row" and "cell" parameters from the grid. ( GetCellValue(row, col) )

But i still think you should try to figure out how to call the default renderer.
Use the source, Luke!

james28909
Knows some wx things
Knows some wx things
Posts: 39
Joined: Mon Jul 01, 2019 8:27 pm

Re: wxPerl - custom grid renderer

Post by james28909 » Sat Jul 27, 2019 5:56 pm

i agree, its just the doc for wxperl is very sparse. and translating some things from c++ to perl is slightly harder than trivial, for me atleast. i am sure a perl guru could do it easily, but atleast this way i am learning instead of just copying and pasting ;)

by the time i am done this will be a neat little xmltv/m3u player :) and Wx MediaCtrl works pretty good too. wish i could compile wxwidgets for activestate perl so i could use the libvlc though. thats the whole reason for me wanting to build wxwidgets for perl myself, well that and to update wxwidgets inside of wxperl.

i will look into calling the default renderer, the wxperl_demo has a grid demo, but the way they have the soure is directly inside the gui, and it looks like alot of shortcuts were used, so compile that onto of me not being a perl guru and on top of that i am still learning how wxwidgets works and how the different classes inherit certain functions for base classes or whatever. so yeah it is def a learning experience.

i made a gui a few years back for ps3 NOR/NAND validation. full decryption and used the files built in authentication mechanism. displayed that in a wxtextctrl with red and green if it failed or passed validation. the reason i say that is because that was moderately easy compared to useing wxgrid and renderers and device contexts. lol. and also i am not able to sit down for more than an hour or two at a time to learn so...

but again i want to thank you for the help. i will more than likely be back shortly with a new problem so just a heads up for ya haha

Post Reply