Hi would it be possible to text or label to an Shape object in silverlight like an arc? Currently I created a chart compose of multiple arcs, I need to set a label on top of the arc to identify whose data it is.
You can use a PathListBox if you want to place the text on an arc. See text along curvature path like circular or arc in silverlight
Alternatively, you can position your own TextBlock object. Use the Polar to Rectangular conversion http://www.teacherschoice.com.au/maths_library/coordinates/polar_-_rectangular_conversion.htm
For instance if the center of your circle is 10,20 and the radius is 30 and the angle where you want to place the textblock is 45, then
double DegreeToRadian(double degree) { return Math.PI / 180 * degree; }
x = 30 * Math.Cos(DegreeToRadian(45)) + 10
y = 30 * Math.Sin(DegreeToRadian(45)) + 20
Related
I have 100 .png images loaded into a Godot 3.5.1 array of objects (named splash_planets) as StreamTextures. I need to know how to reference them to allow scaling. I am able to draw them using the following:
for splash_planet in splash_planets:
center = Vector2(splash_planet._x, splash_planet._y)
draw_texture(splash_planet._texture, center)
Now I want to do something like:
draw_texture(splash_planet._texture, center, (scale_x, scale_y))
Thanks in advance for any advice.
First of all, in this line:
draw_texture(splash_planet._texture, center)
You would be drawing the texture with the upper left corner on the coordinates of center. If you want to draw the texture with the center on center, you do this:
var texture := splash_planet._texture
var size := texture.get_size()
draw_texture(texture, center - size * 0.5)
Since you are using draw_texture and you want to scale, you can use draw_set_transform:
draw_set_transform(Vector2.ZERO, 0.0, Vector2(scale_x, scale_y))
As you can see the third parameter is the scale. The first two parameters are translation and rotation. Once you have set the transform you can do the draw call as usual:
draw_set_transform(Vector2.ZERO, 0.0, Vector2(scale_x, scale_y))
var texture := splash_planet._texture
var size := texture.get_size()
draw_texture(texture, center - size * 0.5)
Calling draw_set_transform again (or calling draw_set_transform_matrix) will overwrite the previos transform.
Alternatively you can use draw_texture_rect:
var texture := splash_planet._texture
var size := texture.get_size() * Vector2(scale_x, scale_y)
var rect := Rect2(center - size * 0.5, size)
draw_texture_rect(texture, rect, false)
In this case we compute the rectangle where to draw the texture. We also specify we don't want to tile it (the false as third argument), so Godot will stretch it.
You might also be interested in draw_texture_rect_region, which allows you to draw a rectangular region of the source texture.
I working with highcharts in angularjs and I want to change the background like in the picture. Also, I want to be able to specify dimentions of rectangles
UPDATE
The problem is when I give the parameters to draw my rectangles, it's affecting all the div and what I want is to draw the rectangles on my chart surface only. The problem is because of "this" which I'm using in my code and I want now to replace it with chart.
You can use the renderer to draw arbritary squares on a chart. You can also use the Axis function toPixels to convert values to pixels. I have a function that takes x and y values and draws a square. If you butted those squares together you could have your regions.
var drawSquare = function(x1,x2,y1,y2,color) {
x1 = chart.xAxis[0].toPixels(x1);
x2 = chart.xAxis[0].toPixels(x2);
y1 = chart.yAxis[0].toPixels(y1);
y2 = chart.yAxis[0].toPixels(y2);
var width = x2 - x1;
var height = y1 - y2;
chart.renderer.rect(x1,y2,width, height, 0)
.attr({
fill: color,
zIndex: 0
})
.add();
};
drawSquare(0,40,0,35,'rgba(129,184,222,.5)');
drawSquare(40,100,0,35,'rgba(255,223,134,.5)');
drawSquare(0,40,35,150,'rgba(130,215,169,.5)');
drawSquare(40,100,35,150,'rgba(183,153,206,.5)');
http://jsfiddle.net/Lh74L8vu/1/
I have a simple shape in PPTx
and I saw and got Its position in Openxml
<a:xfrm>
<a:off x="1447800" y="1066800" />
<a:ext cx="3886200" cy="990600" />
</a:xfrm>
I got out this values
but I don't known how to get with, height, and coordinate (left, top) of shape in Open xml to show in wpf with the same with, height and position.
Divide those values by 12700 for point values (what WPF uses). So it would be:
x = 114 (a:off#x = 1447800/12700)
y = 84 (a:off#y = 1066800/12700)
width = 306 (a:ext#cx = 3886200/12700)
height = 78 (a:ext#cy = 990600/12700)
I have an attributed string that I want to draw bottom-aligned into a rectangular path, using Core Text. Is there a way to get CTFrameSetter / CTFrame to do this, or do I need to do it manually? The manual way being:
Figure out the height of the frame using CTFramesetterSuggestFrameSizeWithConstraints
Adjust the height of the path.
You'll have to do it manually.
CGRect boundingBox = CTFontGetBoundingBox(font);
//Get the position on the y axis
float midHeight = self.frame.size.height / 2;
midHeight -= boundingBox.size.height / 2;
CGPathAddRect(path, NULL, CGRectMake(0, midHeight, self.frame.size.width, boundingBox.size.height));
Reference: Vertical align with Core Text?
I have a simple 3D cube that I can rotate using the following code:
void mui3D_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
RotateTransform3D rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0), mui.Model.Bounds.Location);
DoubleAnimation rotateAnim = new DoubleAnimation(0, 130d TimeSpan.FromMilliseconds(3000));
rotateAnim.Completed += new EventHandler(rotateAnim_Completed);
mui.Transform = rotation;
rotation.Rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotateAnim);
}
Each time it executes, this code rotates the cube using an animation around the Y axis from an angle of 0 to 130 degrees.
However I would like to apply the rotation "cumulatively" so that the any previous rotation is taken into account and the cube commences each rotation from the angle it finished the previous rotation.
For example: the animation constructor, instead of requiring a "from" and "to" value for the angle, simply rotates the cube an an additional 130 degrees based on whatever the current rotation angle is.
I could easily use a member variable that contains the current angle, pass it to the animation and then update it when the animation has completed. But I'm wondering if there is a standard approach using WPF to achieve this.
I'm sure there's a method for retrieving the current Euler rotation angle in degrees from the object's transformation matrix. You could then use that as the "from" value and animate to the "to" value.
Failing that, simply create a variable somewhere in your application that remembers the number of degrees the cube as been rotated. Each time the function is run just add the number of degrees you'd like it to rotate and then store the result back in your variable.
some pseudo-code:
angle = 0
function onClick:
new_angle = angle + 30
Animate(angle, new_angle)
angle = new_angle