I'm drawing a custom chart using Direct2D. The chart has x and y-axis labels painted on side of the chart. When I zoom the chart vertically some data will be painted on top of the x-axis labels and I want to keep the axis labels clean at all times. What is the best way of limiting the painting area to a custom rectangle, not the whole control?
I have a couple ideas on my mind but I'm not sure whether there are better ways to do this:
Method 1)
Go GDI style and paint chart area on one panel and axis labels on another panel. This way when I paint to chart panel I couldn't mess up the axis labels. The problem would be that I would have to make more Direct2D objects (render targets at least for each control (hWnd)) and I'm not sure about the performance implications if I do this.
Method 2)
Copy axis labels to a bitmap every time they are updated and then after chart panel commands draw these bitmaps on top of the control. Is this cheaper than method 1?
Method 3)
Manually check pixel locations on every drawing operation and modify then when necessary. This seems like the worst option.
Edit:
Method 4)
Same as method 1) but paint axis labels using GDI+ and use Direct2D only for the chart.
Method 5)
Using ID2DLayer. I just found this feature from MSDN Documentation. It seems to be what I'm looking for but it came with many warnings about performance implications with frequent use.
Your opinion?
You can use axis aligned clip, which is less hungry.
to push
to pop
Sample from msdn:
pRT->PushAxisAlignedClip(
D2D1::RectF(20, 20, 100, 100),
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
);
pRT->FillRectangle(D2D1::RectF(0, 0, 200, 133), m_pOriginalBitmapBrush);
pRT->PopAxisAlignedClip();
Related
Currently I am using canvas to draw the gold circle, then snip off the areas half way to adjacent stars with globalCompositeOperation : destination-out, then paste the result into the main canvas.
I am contemplating changing to svg for this.
The closest method I have found is clip masks. I would have to create a set of clip-masks for each circle (star), this seems excessive if there were 2000 stars.
Another way would be to create polygons, but the math required to calculate the path may be beyond my capabilities.
So before I go down either of these routes, I would like to know if there is a better way or which of the above methods are recommended.
How do I resize a shape without making a copy and using dilate from point?
How my shape with vectors looks like
How do I limit the axes range for exporting?
How do I define a size, say 3 cm for cropping a portion of the graphics view for export?
Also, is there any software for making simulated graphs without any real data? I'm doing image processing and need to make mock-ups such as temporal segments and histograms.
I guess this question is out of scope of stackoverflow and should be asked in https://help.geogebra.org , but I'll try anyway.
1) You can right-click the graphics view and set the dimensions in there. The export will take the current graphics view. Or you can select part of Graphics using the mouse before export. Or use points Export_1, Export_2 as described here
2) You define cropping of graphics view in one of the ways described above to eg. 6 units, then set the export scale to 0.5cm per unit
3) You can do random functions in GeoGebra directly, eg.
Function[Join[{0,5},Sequence[3*sin(k)+RandomUniform[0, 1],k,0,5,0.1]]]
I succeeded in retrieving the exact tile my player is on, at runtime when walking around the tiledmap. I'd like now to add some alpha marks on the terrain when passing over, and to do that I need to modify the color of some pixels of the tile.
I really don't know how to do it right now.. any hints?
thanks.
You probably want to draw decorations on top of the tiles, rather than modifying the tiles themselves. The tile images are shared across all cells using a tile, so if you modify the tile itself you would see the change everywhere it was used. Further, modifying the texture is a relatively expensive operation that you probably should try to avoid.
To draw on top the tiles, you might draw additional sprites, or use a custom shader.
My graphics are looking blurry unless I add or subtract a half pixel to the Y coordinate.
I know this is a symptom that usually happens when the coordinates are set to sub-pixel values. Which leads me to believe one of my views must be off or something.
But I inspected the window, view controller and subviews, and I don't see any origins or centers with sub-pixel values.
I am stumped, any ideas?
See if somewhere you are using the center property of a view. If you assign that to other subviews, depending on their sizes they may position themselves in half pixel values.
Also, if you are using code to generate the UI I would suggest using https://github.com/domesticcatsoftware/DCIntrospect. This tools allows you in the simulator to look at all the geometry of visible widgets. Half pixel views are highlighted in red vs blue for integer coordinates. It helps a lot.
I'm working on a UI which needs to work in different aspect ratios, 16:9, 16:10, 4:3
The idea is conceptually simple: Everything is centered to the screen in a rough 4:3 area and anything outside this portion of screen has basic artwork, so something like this:
(not drawn to scale)
Where the pink area represents whre all the UI objects are positioned and the blue area is just background and effects.
The trick is in usability, if I pass in coordinates (0,0) in a 4:3 aspect ratio environment (0,0) would be the top left of the screen. However if I'm in a 16:9 environment (0,0) needs to get renormalized based on the new aspect ratio for it to be in the appropriate place. So my question is: How can I achieve this?
edit: for clarification this is basically for a UI system and while I listed the ratios above as 4:3, 16:9, 16:10 it should be able to dynamically adjust values for whatever aspect ratio it is set to.
edit 2: Just to add more details to the situation: When the positions fo rsetting are passed in they are passed in as a % of the screens current widht height, so basically setting position x would be: [pos x as portion of screen]*SCREEN_WIDTH where screen width is the width of the current screen itself.
The obvious answer seems to be an offset. Since 4x3 is 16x9, it appears you want a 16x9 screen to have 2x9 bands to the left and the right. Hence, the X offset should be (2/16) * width.
For 16x10 screens, the factor is slightly more complicated: 4x3 is 13.33x10, so you have edges of width 1.67, and the X offset should be (1.67/16) * width = (5/48)* width.
So ... Can't you just come up with an abstraction layer, that hides the differences? One idea could be to model a "border" around the active area, that gets added. For 4:3 displays, set the border size to 0 to make the active area cover the full screen.