PDA

View Full Version : [CLOSED] changing already created sprite data from code behind



feanor91
Sep 03, 2013, 10:30 AM
Hello

I ask myself a question since a while. I have solved it, but want to know it there is a better solution.

I my soft, I have to play with sprites to draw arrows (I make a "sort of" visio interface).

To create my sprites, I do something like that:



Dim mySpriteArrow As Sprite = New Sprite 'path sprite

With mySpriteArrow 'define arrow
.SpriteID = "myArrow" + ds.Tables("arrows").Rows(i).Item("ArrowID").ToString 'ID (myArrow1, myArrow2, ..., myArown
.Type = SpriteType.Path
.Path = NewPath
.Stroke = "#3457B6"
.StrokeWidth = 2
'.Fill = "#34ADB6" 'in case inner arrow must be filled
End With

drwVMProcess.Add(mySpriteArrow) 'add sprites to drawer
mySpriteArrow.Show(True) 'show it



All works fine. I have panels at start and en of arrow to simulate some process of course.

But, when I move process, I will have to change the path.

I use


drwVMProcess.GetSprite(ArrowsToDealWith(i))

where
drwVMProcess is my DrawComponent and
ArrowsToDealWith(i) my sprite name, but the only thing I'm able to do with that is to call the Remove method, and create a new sprites with modified path.

It works, but the question is :

is there a way to get all javascript sprite object and change only data needed to redraw it?

Daniil
Sep 03, 2013, 3:04 PM
Hi @feanor91,

It is possible to change some sprite attributes without removing it.
http://examples2.ext.net/#/Draw/Basic/Actions/

Please clarify what exactly do you need to change in a sprite?

feanor91
Sep 03, 2013, 3:25 PM
Hi,

i will check that.

For now, I need to change path (and redraw it), position and size for sprite circles

Daniil
Sep 03, 2013, 4:23 PM
I am not sure what "path" do you mean regarding circles... Could you, please, elaborate?

As for sizing and positioning, I think it is possible to do without removing a sprite.

feanor91
Sep 03, 2013, 4:54 PM
I mean nothing regarding circle. Ihave path sprite on a side and circle sprite on another, I have both type

Daniil
Sep 04, 2013, 6:31 AM
Thank you for clarifying.

It appears to be possible to change a Path as well.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void ChangePath(object sender, DirectEventArgs e)
{
Draw1.GetSprite("Sprite1").SetAttributes(new SpriteAttributes
{
Path = "M200,200 h-50 a50,50 0 1,0 50,-50 z"
},
true);
}
</script>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Viewport runat="server" Layout="FitLayout">
<Items>
<ext:Panel runat="server" Layout="FitLayout">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="Change Path" OnDirectClick="ChangePath" />
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:DrawComponent ID="Draw1" runat="server">
<Items>
<ext:Sprite
SpriteID="Sprite1"
Type="Path"
Path="M 100 100 L 300 100 L 200 300 z"
Fill="green" />
</Items>
</ext:DrawComponent>
</Items>
</ext:Panel>
</Items>
</ext:Viewport>

</form>
</body>
</html>

feanor91
Sep 04, 2013, 8:26 AM
Works like a charm. Thank you