autoredraw exe version

before play a video  the test app cpu occupancy about %5 - 15%;
play a video         the test app cpu occupancy about %40 - 60%;
exit the video       the test app cpu occupancy about %40 - 60%;

maybe it nothing with fltk , it is win32`s BitBlt func or my code  problem.

how to fix it , God save me..





#include <FL/Fl_Box.H>
#include <FL/x.H>
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Double_Window.H>
#include <process.h>

class D_Window : public Fl_Box
{
public:
        int __w,__h;
        D_Window();
        void fl_draw_em(const char * c, int x , int y );
        void copy_offscreen_tr(HBITMAP bitmap);
        void copy_offscreen(HBITMAP bitmap);
        void draw();
        void DrawBG();
        void DrawBgOffScreen();
        void ReDrawBg();
        void DrawText();
        void DrawTextOffScreen();
        void ReDrawText();
};

Fl_Offscreen TextOffScreen = 0;
Fl_Offscreen BgOffScreen = 0;
HDC CDC = 0;

void D_Window::fl_draw_em(const char * c, int x , int y )
{
        Fl_Color tmp = fl_color();
        fl_color(1,1,1);
        fl_draw(c,x-1,y-1);
        fl_draw(c,x+1,y+1);
        fl_draw(c,x+1,y-1);
        fl_draw(c,x-1,y+1);
        fl_color(tmp);
        fl_draw(c,x,y);
}

void D_Window::copy_offscreen_tr(HBITMAP bitmap)
{
        if (!CDC)CDC = CreateCompatibleDC(fl_gc);
        SelectObject(CDC, bitmap);
        TransparentBlt(fl_gc,0,0,w(),h(),CDC,0,0,w(),h(),0);
}
void D_Window::copy_offscreen(HBITMAP bitmap)
{
        if (!CDC)CDC = CreateCompatibleDC(fl_gc);
        SelectObject(CDC, bitmap);
        BitBlt(fl_gc,0,0, w(), h(), CDC,0,0, SRCCOPY);
}
D_Window::D_Window():Fl_Box(0,0,1000,800)
{
}
void D_Window::draw()
{
        if (__w!=w()||__h!=h())
        {
                __w = w();
                __h = h();
                if(TextOffScreen)fl_delete_offscreen(TextOffScreen);
                TextOffScreen = 0;
                if(BgOffScreen)fl_delete_offscreen(BgOffScreen);
                BgOffScreen = 0;
                damage(FL_DAMAGE_ALL);
        }
        if (damage()=='5' || damage() == FL_DAMAGE_ALL)
        {
                DrawTextOffScreen();
        }
        if (damage()=='7' || damage() == FL_DAMAGE_ALL)
        {
                DrawBgOffScreen();
        }
        copy_offscreen(BgOffScreen);
        copy_offscreen_tr(TextOffScreen);
        clear_damage(FL_DAMAGE_ALL);
}

void D_Window::DrawBG()
{
        for(int i = 0 ; i < 25 ; i ++ )
        {
                for(int k = 0 ; k < 50 ; k ++ )
                {
                        fl_color((i*50+k)%256);
                        fl_rectf(i*40,k*16,40,16);
                }
        }
}
void D_Window::DrawBgOffScreen()
{
        if (!BgOffScreen)BgOffScreen = fl_create_offscreen(w(), h());
        fl_begin_offscreen(BgOffScreen);
        {
                DrawBG();
        }
        fl_end_offscreen();
}
void D_Window::ReDrawBg()
{
        damage('7');
}
void D_Window::DrawText()
{
        for(int i = 0 ; i < 25 ; i ++ )
        {
                for(int k = 0 ; k < 50 ; k ++ )
                {
                        fl_color(255-(i*50+k)%256);
                        fl_draw_em("FLTK",i*40+2,k*16+14);

                }
        }
}
void D_Window::DrawTextOffScreen()
{
        if (!TextOffScreen)TextOffScreen = fl_create_offscreen(w(), h());
        fl_begin_offscreen(TextOffScreen);
        {
                DrawText();
        }
        fl_end_offscreen();
}
void D_Window::ReDrawText()
{
        damage('5');
}
Fl_Double_Window * mw;
D_Window * test;

void Redraw(void *)
{
        while(1)
        {
                test->ReDrawBg();
                mw->redraw();
                Fl::awake(mw);
                _sleep(10);
        }
}

int main(int argc, char** argv)
{
        Fl::lock();
        mw = new Fl_Double_Window(0,0,1000,800);
        test = new D_Window();
        mw->end();
        mw->show(argc,argv);
        _beginthread(Redraw,0,0);
        return Fl::run();
}
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to