Is it possible to shrink the clipping rectangle in Paint method? - delphi

In my custom component Paint method I want to paint just a region not the whole canvas because in the other region are other objects (like a scroll bar) and I don't want to draw over them. Is it possible ? Why on Earth they make the Canvas.ClipRect read only ?

You can use ExcludeClipRect to exclude regions from the clipping region. Pass the canvas Handle as the device context. Call the function once for each scroll bar etc. whose region you wish to exclude.

Related

What does ClipRect do in Delphi

Could you please explain to me what ClipRect is in Delphi?
I read the documentation, and i did not comprehend it well.
What does the following line do?
FillRect(ClipRect);
Assuming you mean TCanvas.ClipRect, the documentation says:
Read-only property that specifies the boundaries of the clipping rectangle.
Use ClipRect to determine where the canvas needs painting. ClipRect limits the drawing region of the canvas so that any drawing that occurs at coordinates outside the ClipRect is clipped and does not appear in the image.
When handling a form's OnPaint event, the canvas's ClipRect property is set to the rectangle that needs to be painted. Portions of the image that do not overlap the ClipRect do not need to be drawn. Thus, OnPaint routines can use the value of ClipRect to optimize painting, speeding the overall performance of the application.
A clipping region ensures that all painting is limited to that region. So if you set a clipping region that only covers parts of the canvas, any painting outside the clipping region will not be performed.
The documentation links to a simple example. This also uses TCanvas.FillRect(), which fills the given rectangle with the current brush (colour or pattern).

Update part of the screen with Direct2D

I have a viewport with some shapes that I draw by using Direct2D. At the moment when I change somehting, for example I set a Rectangle fill from red to green, I first clear the render target and then I draw again all the shapes with the new properties.
Since I know the position and the area of the rectangle I modified, is there a way to clear and re-draw only the area that has been updated insted of re-draw all the thousand shapes I have?
The documentation for:
IDXGISwapChain1::Present1(
UINT SyncInterval,
UINT PresentFlags,
[in] const DXGI_PRESENT_PARAMETERS *pPresentParameters);
states that
An app can use Present1 to optimize presentation by specifying scroll and dirty rectangles.
This information about the modified rectangles is supplied via the *pPresentParameters parameter. For details see:
DXGI_PRESENT_PARAMETERS structure

How to make the PNG's transparent region not be listened by the EventListener when a touch event happened?

I didn't find a variable that could make the PNG picture's transparent region not being touched.
Does DisplayObject have a function or variable that could make that transparent region can't be touched?
Thanks for your answer.
you need to use a mask to disable the transparent touch, please refer to this tutorial:
http://www.coronalabs.com/blog/2012/05/29/how-to-use-bitmap-masks/
I don't remeber any function but you can divide your picture in pieces. Or you can use sprite sheets and select the desired area.

iOs draw an intereactive map

I need to draw an interactive map for an iOs application. For example it can be the map of the US showing the states. It will need to show all the states in different colors ( I'll get this from a delegate colorForStateNo: ) It will need to allow the user to select a state by touching it, when the color will change, and a "stick out" effect should be shown, maybe even a symbol animated to appear over the selected state. Also the color of some states will need to change depending on external events. This color change will mean an animation like a circle starting in the middle of the state and progressing towards the edges changing the color from the current one to the one inside the circle.
Can this be done ,easily in core-graphics? Or is it only possible with Open GL ES? What is the easiest way to do this? I have worked with core graphics and it doesn't seem to handle animation very well, I just redraw the entire screen when something needed to move... Also how could I use an external image to draw the map? Setting up a lot of drawLineToPoint seems like , a lot of work to draw only one state let alone the whole map ...
You could create the map using vector graphics and then have that converted to OpenGL calls.
Displaying SVG in OpenGL without intermediate raster
EDIT: The link applies to C++, but you may be able to find a similar solution.

Painting app with huge canvas

I'm working on yet another drawing app with canvas that is many times bigger than screen.
I need some advice/direction on how to that.
Basically what i want is to scroll around this big canvas, drawing only in visible region.
I was thinking of two approaches:
Have 64x64 (or whatever) "tiles" to draw on, and then on scroll just load new tiles.
Record all user strokes (points) and on scroll calculate which are in specified region, and draw them, using only screen-size canvas.
If this matters, i'm using cocos2d for prototype.
Forget the 2000x200 limitation, I have an open source project that draws 18000 x 18000 NASA images.
I suggest you break this task into two parts. First, scrolling. As was suggested by CodaFi, when you scroll you will provide CATiledLayers. Each of those will be a CGImageRef that you create - a sub image of your really huge canvas. You can then easily support zooming in and out.
The second part is interacting with the user to draw or otherwise effect the canvas. When the user stops scrolling, you then create an opaque UIView subclass, which you add as a subview to your main view, overlaying the view hosting the CATiledLayers. At the moment you need to show this view, you populate it with the proper information so it can draw that portion of your larger canvas properly (say a circle at this point of such and such a color, etc).
You would do your drawing using the drawRect: method of this overlay view. So as the user takes action that changes the view, you do a "setDisplayInRect:" as needed to force iOS to call your drawRect:.
When the user decides to scroll, you need to update your large canvas model with whatever changes the user has made, then remove the opaque overlay, and let the CATiledLayers draw the proper portions of the large image. This transition is probably the most tricky part of the process to avoid visual glitches.
Supposing you have a large array of object definitions used for your canvas. When you need to create a CGImageRef for a tile, you scan through it looking for overlap between the object's frame and the tile's frame, and only then draw those items that are required for that tile.
Many mobile devices don't support textures over 2048x2048. So I would recommend:
make your big surface out of large 2048x2048 tiles
draw only the visible part of the currently visible tile to the screen
you will need to draw up to 4 tiles per frame, in case the user has scrolled to a corner of four tiles, but make sure you don't draw anything extra if there is only one visible tile.
This is probably the most efficient way. 64x64 tiles are really too small, and will be inefficient since there will be a large repeated overhead for the "draw tile" calls.
There is a tiling example in Apples ScrollViewSuite Doesn't have anything to do with the drawing part but it might give you some ideas about how to manage the tile part of things.
You can use CATiledLayer.
See WWDC2010 session 104
But for cocos2d, it might not work.

Resources