how to snap to grid [message #117725] |
Mon, 16 February 2004 05:39  |
Eclipse User |
|
|
|
Originally posted by: tranfy.hotmail.com
I have drawn a background grid by realize a customer figure named
sectionfigure as following:
protected void paintFigure(Graphics graphics) {
Rectangle rect = getBounds();
for (int r = rect.y + 10; r < rect.height + rect.y; r+=10) {
for (int c = rect.x + 10; c < rect.width + rect.x; c+=10) {
graphics.drawLine(c, r, c, r);
}
}
}
The sectionfigure is a container.Now I want to draw a element in the
container and make the element snap to grid when I drawing it . how I can
snap to grid ?
Thanks a lot!
Waiting for your answer.
|
|
|
|
|
|
Re: how to snap to grid [message #117919 is a reply to message #117749] |
Mon, 16 February 2004 23:22   |
Eclipse User |
|
|
|
Originally posted by: tranfy.hotmail.com
My puzzle is that in my sectionfigure , I realize the background grid by
drawing line and these lines are actual some dots. When I draw a new
element ,I don't know how to get these dots coordinates , so I can not set
new location for the element.
How I can get the dot(background grid) coordinate?
Please give me some advice.
Thanks very much!
Ingo Koch wrote:
> Hi Sunny,
> there a many ways to implement a snap-to-grid.
> One is, you create your own ChangeConstraintCommand.
> The Command receives the desired coordinates,
> transforms them into the snapped coordinates
> and then applies them to the model element.
> An other way is to extend a layoutmanager (Freeform) which
> transforms the coodinates.
> Perhaps in the setConstraint or layout method.
> Regards, Ingo
> "sunny" <tranfy@hotmail.com> wrote in message
> news:c0q6kq$vtu$1@eclipse.org...
> >
> > I have drawn a background grid by realize a customer figure named
> > sectionfigure as following:
> > protected void paintFigure(Graphics graphics) {
> > Rectangle rect = getBounds();
> > for (int r = rect.y + 10; r < rect.height + rect.y; r+=10) {
> > for (int c = rect.x + 10; c < rect.width + rect.x; c+=10) {
> > graphics.drawLine(c, r, c, r);
> > }
> > }
> > }
> >
> > The sectionfigure is a container.Now I want to draw a element in the
> > container and make the element snap to grid when I drawing it . how I can
> > snap to grid ?
> > Thanks a lot!
> > Waiting for your answer.
> >
|
|
|
Re: how to snap to grid [message #117956 is a reply to message #117919] |
Tue, 17 February 2004 04:17   |
Eclipse User |
|
|
|
Originally posted by: nospam.gmx.net
If you insist on implementing your own snap to grid, since
2.1.1 doesn?t support it (but the latest integration builds do),
a little hint:
int newX = GRIDSIZE * (int)Math.round ( (double) oldX / (double)
GRIDSIZE ) + OFFSET;
Also a good point to implement this is in your editpolicy?s
#getChangeConstraintCommand().
Regards, Ingo
"sunny" <tranfy@hotmail.com> wrote in message
news:c0s4th$be1$1@eclipse.org...
>
> My puzzle is that in my sectionfigure , I realize the background grid by
> drawing line and these lines are actual some dots. When I draw a new
> element ,I don't know how to get these dots coordinates , so I can not set
> new location for the element.
> How I can get the dot(background grid) coordinate?
> Please give me some advice.
> Thanks very much!
>
>
>
> Ingo Koch wrote:
>
> > Hi Sunny,
>
> > there a many ways to implement a snap-to-grid.
>
> > One is, you create your own ChangeConstraintCommand.
> > The Command receives the desired coordinates,
> > transforms them into the snapped coordinates
> > and then applies them to the model element.
>
> > An other way is to extend a layoutmanager (Freeform) which
> > transforms the coodinates.
> > Perhaps in the setConstraint or layout method.
>
> > Regards, Ingo
>
>
>
>
>
> > "sunny" <tranfy@hotmail.com> wrote in message
> > news:c0q6kq$vtu$1@eclipse.org...
> > >
> > > I have drawn a background grid by realize a customer figure named
> > > sectionfigure as following:
> > > protected void paintFigure(Graphics graphics) {
> > > Rectangle rect = getBounds();
> > > for (int r = rect.y + 10; r < rect.height + rect.y; r+=10) {
> > > for (int c = rect.x + 10; c < rect.width + rect.x; c+=10) {
> > > graphics.drawLine(c, r, c, r);
> > > }
> > > }
> > > }
> > >
> > > The sectionfigure is a container.Now I want to draw a element in the
> > > container and make the element snap to grid when I drawing it . how I
can
> > > snap to grid ?
> > > Thanks a lot!
> > > Waiting for your answer.
> > >
>
>
|
|
|
Re: how to snap to grid [message #118045 is a reply to message #117907] |
Tue, 17 February 2004 10:38  |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
Because it is only in 3.0.
"sunny" <tranfy@hotmail.com> wrote in message
news:c0s460$aqc$1@eclipse.org...
>
> My gef logic exmaple's version is 2.1.1 and when I run it ,I can not find
> snap-to-grid option in the View menu.
> Why?
>
>
>
>
> Randy Hudson wrote:
>
> > Open the Logic editor.
> > From View menu, enable snap-to-grid.
> > voila.
>
> > See the new class SnapToGrid
>
> > "sunny" <tranfy@hotmail.com> wrote in message
> > news:c0q6kq$vtu$1@eclipse.org...
> > >
> > > I have drawn a background grid by realize a customer figure named
> > > sectionfigure as following:
> > > protected void paintFigure(Graphics graphics) {
> > > Rectangle rect = getBounds();
> > > for (int r = rect.y + 10; r < rect.height + rect.y; r+=10) {
> > > for (int c = rect.x + 10; c < rect.width + rect.x; c+=10) {
> > > graphics.drawLine(c, r, c, r);
> > > }
> > > }
> > > }
> > >
> > > The sectionfigure is a container.Now I want to draw a element in the
> > > container and make the element snap to grid when I drawing it . how I
can
> > > snap to grid ?
> > > Thanks a lot!
> > > Waiting for your answer.
> > >
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03261 seconds