Comments (3)
I admit the lib was created with "ease of use" rather then "being as fast as possible" in mind, for purposes of GUI controls in mctrl, where the speed is not that critical. Also, quite often some design choices were dictated by limitations of GDI+ back-end support.
Additionally, the support for old Windows versions (which had to use GDI+) was recently removed from mctrl code base and mctrl now uses Direct2D directly. Therefore my motivation to implement new features in WinDrawLib is quite low.
That said, feel free to make a pull request. Writing the code should not be that difficult and I can point you in right directions if needed.
Generally, I can see the following options:
-
If the scene/background where the text lives changes relatively sporadically, use the canvas caching (assuming you use
wdCreateCanvasWithPaintStruct()
). When reusing the cached canvas, paint only those parts of the scene which do change between the frames. Direct2D implicitly uses double buffering and retains the contents of theID2D1HwndRenderTarget
which is under the hood of the canvas created with the function. -
Or, adding a new
wdCreateBitmapCanvas()
so that you can paint the strings into it and then just copy the pre-painted bitmaps. It would useID2D1Factory::CreateWicBitmapRenderTarget()
with Direct2D backend orgdix_canvas_alloc()
with GDI+ backend under the hood. SeewdCreateCanvasWithHDC()
in src/canvas.c, the new function would be likely quite similar.This approach would have one drawback: Direct2D supports several modes of text aliasing. One which paints directly to the target background and uses that for achieving better aliasing quality; or a universal mode which does not use any target info and which is intended it for painting on any background. This would have to use the latter. I'm not sure how big impact on quality this would bring.
-
Or, adding an ability to store and reuse
IDWriteTextLayout
. Currently,wdDrawString()
in src/string.c creates it, uses it and destroys it. So, some newwdCreateTextLayout()
,wdDrawTextLayout()
andwdDestroyTextLayout()
could be implemented to break it into separate operations so that all the expensive glyph layouting work can be reused if the strings do not change between the frames.Unfortunately, AFAIK, GDI+ does not support anything like that so it would have to be emulated to keep the function parity.
wdCreateTextLayout()
would likely just allocate some helper structure to store the text layout parameters passed to it so thatwdDrawTextLayout()
could retrieve them later via the handle representing the "text layout".(Also see #17. It was meant to do something similar and also much more then that, but it was too ambitious and it would probably never fully support GDI+ backend, that's why mCtrl swtiched to Direct2D directly and I abandoned the pull request. But some simplified version of it, in order to just break the single big operations into separate ones, should not be a problem and quite likely few initial commits of that PR more or less do that.)
from windrawlib.
from windrawlib.
The part I don't understand about choice 2 is how to merge the graphic image created with wdCreateImageFromBuffer and the text overlay image created with the new function wdCreateBitmapCanvas. I would like to overlay the text onto the graphic image and then display the result.
- You create a WIC bitmap. WinDrawLib already knows how to do it.
- In the new
wdCreateBitmapCanvas()
, you pass the WIC bitmap intoID2D1Factory::CreateWicBitmapRenderTarget()
so that the bitmap canvas uses the bitmap as the storage of the created graphics. - Your app clears the canvas with fully transparent color and paints the string into the bitmap canvas.
- Your app transforms the final bitmap into the cached image (
wdCreateCachedImage()
). You keep multiple cached images (e.g. for all digits to paint a game score). - In the real time, you only blit the pre-painted bitmaps (
wdBitBltCachedImage()
) to the right position to the target bitmap.
from windrawlib.
Related Issues (9)
- Cannot build with MinGW-w64 HOT 5
- StrokeStyles: Dots not painted in D2D backend. HOT 3
- StrokeStyles: Antialiasing & GDI+ backend HOT 1
- wdBitBltCachedImage() crashes. HOT 3
- Create canvas with HDC by GetDC and GetWindowDC counld't destroy resources HOT 4
- msvc 2010 cannot be initialized using address of automatic variable 'user_locale' HOT 2
- Can we please have this in one VS2019 solution? HOT 4
- wdDrawString Vertical Center Align (like Button text) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from windrawlib.