![]() |
【转帖】howto avoid flickering
howto avoid flickering?
howto avoid flickering? hello i'm using the dwgdirect c++ libraries in a c# application with windows forms (a dxf-viewer with simple interaction). the dxf-drawing is displayed using the wingdi-module which draws to the hdc of my custom windows::forms::control. the onpaint() method tells the device created by the wingdi module to update itself. the result looks good so far. but whenever i interact with the drawing (zoom, pan, show/hide layers, add comments...) it flickers. the redraw-performance while panning is the worst... to force a redraw, i invalidate the control when an interaction occurs. panning invalidates the control on every "onmousemove()"-call. ---------------edit: ok, the problem is solved. i had to override the ondrawbackground() method which is now empty. results look good, no more flickering. ------------------- creating the device( once when loading new file ): code: .... odstring modulename = odstring(l"wingdi.gs"); odgsinitialize(); con->gicontext = odgicontextfordbdatabase::createobject(); con->gicontext->setdatabase(con->database); con->gicontext->enablegsmodel(true); odgsmoduleptr gsmodule = ::odrxdynamiclinker()->loadmodule( modulename, false ); if (con->database.isnull()) { throw gcnew exception("error opening database"); } con->gsdevice = gsmodule->createdevice(); if (con->gsdevice.isnull()) { throw gcnew exception("error creating gdi render device"); } odrxdictionaryptr pproperties = con->gsdevice->properties(); if (pproperties->has(dd_t("doublebufferenabled"))){ pproperties->putat(dd_t("doublebufferenabled"), odrxvariantvalue(true)); } if (pproperties->has(dd_t("clearscreen"))){ pproperties->putat(dd_t("clearscreen"), odrxvariantvalue(false)); } if (pproperties->has(dd_t("enablesoftwarehlr"))){ pproperties->putat(dd_t("enablesoftwarehlr"), odrxvariantvalue(false)); } if (pproperties->has(dd_t("discardbackfaces"))){ pproperties->putat(dd_t("discardbackfaces"), odrxvariantvalue(false)); } odcolorref bg = odrgb(0,0,0); // palette background con->gicontext->setpalettebackground(bg); const odcolorref* palette = odcmacadpalette(bg); con->gsdevice->setlogicalpalette(palette, 256); con->gsdevice = oddbgsmanager::setupactivelayoutviews(con->gsdevice, con->gicontext); drawable = true; zoomextents(); return nullptr; ...onpaint() method in custom control: code: virtual void onpaint(system::windows::forms::painteventargs^ e) override{ control::onpaint(e); // "g" is an instance of system::drawing::graphics intptr hdc = e->graphics->gethdc(); ctx->draw( hdc, this->width, this->height ); }updating the device (call from onpaint() ): code: void draw( intptr hdc, int width, int height ){ try{ if( this->isdrawable() ){ odint32 handlevalue = (odint32)hdc.toint32(); odrxdictionaryptr pproperties = con->gsdevice->properties(); if (pproperties->has(dd_t("windowhdc"))){ pproperties->putat(dd_t("windowhdc"), odrxvariantvalue(handlevalue)); } // code to render the drawing odgsdcrect gsrect(0, width, height, 0); // you'll have to provide the dimensions of the output device con->gsdevice->onsize(gsrect); con->gsdevice->ondisplaychange(16, width, height); odgsviewptr pview = con->gsdevice->viewat(0); pview->setviewportborderproperties(odrgb(0x00, 0x00, 0x00), 0); pview->setviewportbordervisibility(false); pview->setviewport(gsrect); con->gsdevice->update(); } }catch( oderror e ){ odstring err = e.description(); } }do you have any suggestions how to avoid the flickering? i tried to enable doublebuffering in the device-properties but haven't noticed any differences. thanks for hints and ideas. last edited by martin.affolter@ntb.ch; 16th december 2008 at 09:40 amfff">. maybe override the onerasebackground to do nothing. (i didn't see your edit, i know this problem also happens when you use wxwidgets) last edited by billyaraujo@gmail.com; 17th december 2008 at 02:21 amfff">. |
所有的时间均为北京时间。 现在的时间是 07:29 PM. |