Author |
Topic |
|
spetric
Croatia
308 Posts |
Posted - Aug 26 2014 : 01:45:50
|
Hi,
I have encountered a problem with SetObjPolyLinePoints that did not exist in older version (3.xx).
In documentation (chm), for declaration SetObjPolylinePoints method is written: procedure SetObjPolylinePoints(hobj:integer; Points:array of TPoint);
The last parameter (PolyCount) is missing. That's not a big issue (just as a remark), but when I've tested my code with XE5 and new ImageEn version, for a simple 2 points object (line), I've got very strange behavior:
1. In OnMouseDown event I'm creating polyline object
_polyCount = 2;
PaintView->SetObjPolylinePoints(_hobj, _polyPoint, _polyCount);
x = PaintView->ObjPolylinePointsCount[_hobj];
Variables x and _polyCount have the same value 2. However, in OnMOuseMove event, I'm "resetting" polyline points (the same object):
PaintView->SetObjPolylinePoints(_hobj, _polyPoint, _polyCount);
x = PaintView->ObjPolylinePointsCount[_hobj];
Now, variables x and _polyCount do not have same value: x is 3 and _polyCount is still 2.
The same thing happens when _polyCount is greater then 2. When resseting object points using SetObjPolylinePoints method, resultant points sount in an object is increased by one.
When SetObjPolylinePoints is used first time, everything is Ok.
TIA, Siniša
|
|
xequte
38615 Posts |
Posted - Aug 27 2014 : 18:41:42
|
Hi Sinisa
I tried to reproduce this with the following code:
procedure TMainForm.ImageEnVect1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Points: array[0..1] of TPoint;
hobj: integer;
begin
Points[0].X := 50;
Points[0].Y := 50;
Points[1].X := 250;
Points[1].Y := 250;
hobj := ImageEnVect1.AddNewObject;
ImageEnVect1.ObjKind[hobj] := iekPOLYLINE;
ImageEnVect1.SetObjPolylinePoints(hobj, Points);
Caption := IntToStr( ImageEnVect1.ObjPolylinePointsCount[hobj] );
end;
procedure TMainForm.ImageEnVect1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Points: array[0..1] of TPoint;
hobj: integer;
begin
Points[0].X := 50;
Points[0].Y := 50;
Points[1].X := 250;
Points[1].Y := 250;
hobj := IEV_PREVIOUS_INSERTED_OBJECT;
ImageEnVect1.SetObjPolylinePoints(hobj, Points);
Caption := IntToStr( ImageEnVect1.ObjPolylinePointsCount[hobj] );
end;
The counts were as expected, so you'll need to give me more code.
Though I can foresee a number of situation where changing properties on MouseDown/Up might conflict with ImageEnVect's own behavior.
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
|
|
spetric
Croatia
308 Posts |
Posted - Aug 28 2014 : 05:29:10
|
Hi Nigel,
The problem occurs in OnMouseMove event.
OnMouseDown (object hobj is of type iekPOLYLINE):
// initialize polyline
_polyInit = true;
// _polyPoint array is an array with 10000 points
_polyCount = 2;
//
_polyPoint[0].x = _mouseData.X_vector_down;
_polyPoint[0].y = _mouseData.Y_vector_down;
_polyPoint[1].x = _mouseData.X_vector_down;
_polyPoint[1].y = _mouseData.Y_vector_down;
// This part is actually workaround (I'm initializing one extra point).
_polyPoint[2].x = _mouseData.X_vector_down;
_polyPoint[2].y = _mouseData.Y_vector_down;
PaintView->SetObjPolylinePoints(_hobj, _polyPoint, _polyCount);
OnMouseMove:
_polyPoint[_polyCount-1].x = _mouseData.X_vector_move_to;
_polyPoint[_polyCount-1].y = _mouseData.Y_vector_move_to;
if (_polyInit)
_polyInit = false;
else
_polyCount++;
// workaround - extra point
_polyPoint[_polyCount].x = _mouseData.X_vector_move_to;
_polyPoint[_polyCount].y = _mouseData.Y_vector_move_to;
PaintView->SetObjPolylinePoints(_hobj, _polyPoint, _polyCount);
//
// Here comes a difference
int iC = PaintView->ObjPolylinePointsCount[_hobj];
// iC <> _polyCount
Actually, I'm adding points to polyline while moving cursor over screen. After mouse button is release, brush stroke is rendered through polyline points.
Also, using shift key (in OnMouseMove), it's possible to translate complete polyline across the screen, and using ctrl key it's possible to "resize" polyline (prior to rendering). So, I'm permanently manipulating with polyline points in OnMouseMove event.
Is there a method to dynamically add points to polyline object?
You've probably noticed that I've added few lines of "workaround" code to override the count difference. |
|
|
xequte
38615 Posts |
Posted - Sep 03 2014 : 19:16:21
|
Hi Siniša
You can add points dynamically using ImageEnVect1.AddPolyLinePoint(hobj: integer; X, Y: integer);
Though you'll need to expose it in ievect.pas
What is the code for _mouseData?
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
|
|
spetric
Croatia
308 Posts |
Posted - Sep 04 2014 : 02:23:27
|
Hi Nigel,
thanks for a tip.
_mouseData is a structure holding various mouse data. I have directly copied the code from my application, sorry for that. _mouseData.X_vector_down is value of mouse position saved in OnMouseDown event:
StandardMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
//...
_mouseData.X_vector_down = X;
_mouseData.Y_vector_down = Y;
//...
}
_mouseData.X_vector_move_to is X mouse position in OnMouseMove event:
StandardMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
//...
_mouseData.X_vector_move_to = X;
_mouseData.Y_vector_move_to = Y;
//...
}
So, you can simply replace _mouseData.X/Y_vector_NNN with variables of your choice. |
|
|
|
Topic |
|
|
|