Book a Demo

Author Topic: How to change icon  (Read 6977 times)

xarx

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
How to change icon
« on: June 23, 2009, 11:39:54 pm »
Hello.

Various diagram elements (e.g. a component) have a small icon in the upper right corner. How can I change this image? Must I use a shape script, or is there another (simpler) way (e.g. by importing the new image somewhere)?

Thank you,
Martin.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to change icon
« Reply #1 on: June 24, 2009, 10:31:57 pm »
EA draws these internally so you cannot change them. Nor can you access the internal list from shape scripts. [I've asked for this feature twice but had no traction.]

Yes, you could create a shape script and adorn (or not) the element as you wish. Remember that you will then be responsible for all of the element rendering. If you use the native shape in a script EA may (you have to test this) draw the icon, which would set you back. Check it out though; if EA does not draw the icon you might have your solution.

David
No, you can't have it!

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: How to change icon
« Reply #2 on: June 25, 2009, 08:57:07 am »
Try a shape script like this, it may be what you need:

Code: [Select]
decoration a
{
    orientation="NE";
    setfillcolor(0,255,0);
    rectangle(-10,0,90,120);
}

The co-ordinates of the rectangle command need to be adjusted to completely hide the icon behind it. I just tested this version on a component and the built-in icon is fully hidden. Obviously, you will want to replace the green rectangle with your own icon. Maybe use the image("imagename",0,0,100,100); command.
The Sparx Team
[email protected]

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to change icon
« Reply #3 on: June 25, 2009, 09:11:57 am »
Of course you may need to modify this script if you change the appearance of the element via F4 or such. I don't think you can retrieve the current drawing color in a shape script. [You can retrieve the default pen color, but I do not know if this is sensitive to setting element appearance options.]
No, you can't have it!

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: How to change icon
« Reply #4 on: June 25, 2009, 09:57:20 am »
Quote
I don't think you can retrieve the current drawing color in a shape script.

Yes you can:

Code: [Select]
shape main
{
    setfillcolor(getuserbordercolor());
    setpencolor(getuserfillcolor());
    rectangle(0,0,100,100);
}
« Last Edit: June 25, 2009, 09:58:23 am by KP »
The Sparx Team
[email protected]

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to change icon
« Reply #5 on: June 25, 2009, 08:30:40 pm »
Sorry Neil, I should have been more specific. I do not know if you can retrieve the current color set for a specific instance of an element. That is, if the user had used F4 to set the rendering color for an instance of an element, I don't know if the script could pick that up.
No, you can't have it!

xarx

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: How to change icon
« Reply #6 on: June 26, 2009, 07:48:26 pm »
Thank you KP, that is what I wanted!

Though it doesn't work ideally. E.g. having to hide the default decoration by painting over it  :-? (the background is visibly inhomogenous, on screen). Also, the shapescript draws ellipses and arcs somewhat imprecisely on the screen (even under high magnification; however, they are printed correctly). And there seems to be no posibility to hide the stereotype name when the decoration is applied. Etc.

The following (database sign) decoration I applied on component elements. Note that I had to use coordinate numbers like 2 or -10 in order the decoration looks fine:

Code: [Select]
decoration a
{
   orientation="NE";
   SetOrigin("NE",-35,2);
   setpencolor(getuserfillcolor());
   rectangle(-10,0,80,130);
   setpencolor(getuserbordercolor());
   ellipse(-10,80,80,120);
   setpencolor(getuserfillcolor());
   rectangle(-10,20,80,100);
   setpencolor(getuserbordercolor());
//   Arc(-10,80,80,120,-10,100,80,100);
   MoveTo(-10,20);
   LineTo(-10,100);
   MoveTo(80,20);
   LineTo(80,100);
   ellipse(-10,0,80,40);
//   image("database1",0,0,80,120);
}

Martin.