How do you set the TDirect2DCanvas.Pen.StrokeStyle? - c++builder

I've been trying to modify the StrokeStyle for the TDirect2DCanvas.Pen in C++Builder.
The documentation says this about the property:
Determines the stroke style in which the pen draws lines.
Use StrokeStyle to specify a more complex style in which the lines are drawn. StrokeStyle accepts an interface that provides a set of methods, each returning a certain drawing option.
The documentation gives no examples. When I try to set this property to anything, I get a compile error saying "cannot write a property that has no write specifiers" (it looks like this property is only set up to read the StrokeStyle; even though the documentation seems to indicate otherwise).
My desire here is to get lines to be rendered with rounded ends rather than the flat ends that it seems to default to when using TDirect2DCanvas. Does anybody know how to accomplish this?
I'm using C++Builder 10.2 and the clang compiler. I'm trying to use TDirect2DCanvas rather than the regular TCanvas because it can draw anti-aliased lines.

The documentation is misleading. The TDirect2DPen::StrokeStyle property is indeed read-only, as it represents the current Direct2D ID2D1StrokeStyle object, as created internally by TDirect2DPen. TDirect2DPen does not provide any way to customize any of the stroke settings other than its dashStyle.
The only way to affect the TDirect2DPen::StrokeStyle is to set the TDirect2DPen::Style property. Setting the Style will release the current ID2D1StrokeStyle, and then if the Style is set to a value other than psSolid, psClear, or psInsideFrame then TDirect2DPen will call ID2D1Factory::CreateStrokeStyle() to create a new ID2D1StrokeStyle, specifying the following properties for it:
startCap = D2D1_CAP_STYLE_FLAT
endCap = D2D1_CAP_STYLE_FLAT
dashCap = D2D1_CAP_STYLE_ROUND
lineJoin = D2D1_LINE_JOIN_ROUND
miterLimit = 10
dashStyle = one of the following, depending on the TDirect2DPen.Style:
D2D1_DASH_STYLE_DASH
D2D1_DASH_STYLE_DOT
D2D1_DASH_STYLE_DASH_DOT
D2D1_DASH_STYLE_DASH_DOT_DOT
dashOffset = 0
dashes = nil
dashesCount = 0
This behavior is hard-coded and cannot be changed.
So, if you want more control over the StrokeStyle, you cannot use TDirect2DCanvas at all. You will have to use the Direct2D API directly instead.

Related

How to find out, when and why and how a component's property is changed at runtime?

I have a huge VCL Forms application in delphi and there is an option to display or hide a certain control (MyControl) on each form. Right now the traditional option is enabled, so MyControl should be hidden at runtime.
In Delphi Designer both Controls are visible. Every form is derived from a MyForm-class and in its OnCreate-Procedure the Visible-property of a MyControl (if available) is set to false (according to the traditional option enabled). This does work (as I can see with breaking points and watching expressions). For almost all forms this results in the MyControl not showing.
However for one certain form at some point the MyControl-component itself or any other part of the program sets the MyControls' visibility to true again. How do I find out where this happens?
I am using Delphi 10.1.
my approach:
I've tried to watch the visible-property through the watching-expressions-window using several breaking points. But of course the watching-expression is not available anywhere in the Code (myControl.Visible will only work if the breakingpoint is somewhere myControl is defined). I set a breaking-point anywhere I could evalute myControl.Visible but the magic seems to happen somewhere in between.
So my question: is there some kind of a global variable name, so that I can evalute and watch the visible-property wherever the debugger pauses the program?
a different approach:
I set a data- and an address-breakingpoint but they never fire. Only when I close the program they pause the program a few times.
As advised in the comments, if this is your code you can modify the property to use a Setter and then set a breakpoint on the setter. However if this is not your code and it simply exposes the variable (field) then changing the code to include a setter can be anywhere from triovial to impossible depending on what else needs to be recompiled when you make the change.
If this is your own custom component then you can redeclare an inherited property to use a setter.
If this is not your own custom component - you could make it a custom component and simply change the setter for the property.
You can set a memory breakpoint to alert you to when a memory location changes but your success with this may vary.
I encourage you to experiment with the conditions you can put on breakpoints, get the debugger to work for you.

Can someone explain me TTextureStyle.RenderTarget?

TTexture can have the style [TTextureStyle.RenderTarget]
the doc of delphi says:
Specifies the rendering target for this canvas object. Use the value
of RenderTarget to access the specific properties of the target on
which the canvas is drawn. RenderTarget returns a Direct2D interface
that can be used directly.
This is a little obscure, can someone explain me exactly the purpose of TTextureStyle.RenderTarget and in which condition we need to use it ?
To make the question also useful for everyone, if someone can also explain all the other different values (and their purpose) that TTextureStyle can take :
TTextureStyle = (MipMaps, Dynamic, RenderTarget, Volatile);

Modifying the operating frequency (for 802.11ac) on ns-3

I am attempting to change the operating frequency to 300MHz (to simulate the working of 802.11af) but retain the overall PHY layer configuration of 802.11ac.
I have gone through earlier posts and realized that the SetFrequency() function (in the class YansWifiPhy) can be employed. However, when I implement the following statement ('wifi' is an object of the class WifiHelper)-
NetDeviceContainer staDevices = wifi.Install (phy, mac, wifiStaNodes);
I get an error since the object 'phy' is required to be of YansWifiPhyHelper datatype, not YansWifiPhy. However, I can't seem to change the frequency using the YansWifiPhyHelper class. How do I resolve this problem?
As you can see YansWifiPhy is a child class of WifiPhy. The typeId of WifiPhy has Frequency as an attribute. You can set this attribute using any to of the following way:
You can change the default value of ns3::WifiPhy::Frequency using the Config::SetDefault function. The documentation for the same can be found here.
Secondly you can use the Set function of YansWifiPhyHelper to set any attribute of YansWifiPhy (WifiPhy). You can find an example of this here. The only difference from the link will be that you need to change the attribute name to Frequency and change the value accordingly.
Please, let me know in case of any doubts or any of these don't work for you.

TShape and Integer Value

I'm recently working on an Dart-Counter.
I have a Dartboard presented on a TImage and for every counting position there is a TShape.
Is it possible to assigne a value to a TShape, because the TShape does not like integer?
Thanks.
You could use the Tag property to store your integer value, if nothing else is using that property.
Tag has no predefined meaning. The Tag property can store any additional integer value for the convenience of developers.
Another way would be to derive a sub-class of TShape and add a property to store the information. This would allow you to give the property a more meaningful name, and make the intent clear.
I would comment though that building up a complex visual user interface out of TShape objects is perhaps an inefficient and error prone way to go about your task. Usually for a task like this is would be better to make a custom control that painted itself appropriately, without the use of sub-components.

Syntax Coloring without Presentation Reconciler

I would like to do coloring in Eclipse without using the presentation reconciler. Therefore, first, I need to figure out how to associate a TextPresentation object with either my editor or document, but I am having difficulty finding out how to link it either of those. Normally, the CreatePresentation in the IPResentationReconciler interface would give the style range to the textpresentation, and from there Eclipse would know what to do with that presentation object. Is there some way to use a TextPresentation object without the use of PresentationReconciler? It would be nice if I could do coloring without the use of reconciler. Thank you.
I finally figured out how to achieve the coloring without the use of Reconcilers.
I discovered that first I needed a way to obtain a reference to my SourceViewer object, as I am extending TextEditor. I also discovered that I could implement the TextListener interface and add my own listener to the SourceViewer object. One must be careful, however, as calling the getSourceViewer() method can result in null if not called at the appropriate spot. Originally, I overwrote the init(...) function in my editor class and made the getSourceViewer() call, but it still resulted in null. After doing a bit of research, I discovered that I could properly obtain a reference to the SourceViewer object by overriding the createPartControl method. I first call super.createPartControl(...) and then make a call to getSourceViewer(). After I obtained that reference, I used that with my listener class I created and was able to do the coloring myself with the setTextColor method the SourceViewer object has. Hope this helps others in the same situation.

Resources