diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2012-11-22 11:48:47 +0000 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2012-11-22 11:48:47 +0000 |
commit | af45f95f16cee22f8f012f706f4d0a42eaeb68fa (patch) | |
tree | c572c1cc6a7d3bb12874d8f9b9363312b275e328 /src/corelib/render/software/ctrl | |
parent | 9c62dfaf7217557f08a3d33b20bb302874960f87 (diff) | |
download | fpGUI-af45f95f16cee22f8f012f706f4d0a42eaeb68fa.tar.xz |
Fixes line ending issues
Diffstat (limited to 'src/corelib/render/software/ctrl')
-rw-r--r-- | src/corelib/render/software/ctrl/agg_bezier_ctrl.pas | 1774 | ||||
-rw-r--r-- | src/corelib/render/software/ctrl/agg_cbox_ctrl.pas | 860 | ||||
-rw-r--r-- | src/corelib/render/software/ctrl/agg_ctrl.pas | 446 | ||||
-rw-r--r-- | src/corelib/render/software/ctrl/agg_gamma_ctrl.pas | 1762 | ||||
-rw-r--r-- | src/corelib/render/software/ctrl/agg_gamma_spline.pas | 530 | ||||
-rw-r--r-- | src/corelib/render/software/ctrl/agg_polygon_ctrl.pas | 1538 | ||||
-rw-r--r-- | src/corelib/render/software/ctrl/agg_rbox_ctrl.pas | 1242 | ||||
-rw-r--r-- | src/corelib/render/software/ctrl/agg_scale_ctrl.pas | 1494 | ||||
-rw-r--r-- | src/corelib/render/software/ctrl/agg_slider_ctrl.pas | 1390 | ||||
-rw-r--r-- | src/corelib/render/software/ctrl/agg_spline_ctrl.pas | 1632 |
10 files changed, 6334 insertions, 6334 deletions
diff --git a/src/corelib/render/software/ctrl/agg_bezier_ctrl.pas b/src/corelib/render/software/ctrl/agg_bezier_ctrl.pas index 6f158c2b..2b92baa3 100644 --- a/src/corelib/render/software/ctrl/agg_bezier_ctrl.pas +++ b/src/corelib/render/software/ctrl/agg_bezier_ctrl.pas @@ -1,887 +1,887 @@ -//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4 (Public License)
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
-// Pascal Port By: Milan Marusinec alias Milano
-// milan@marusinec.sk
-// http://www.aggpas.org
-// Copyright (c) 2005-2006
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//
-//----------------------------------------------------------------------------
-//
-// classes bezier_ctrl_impl, bezier_ctrl
-//
-// [Pascal Port History] -----------------------------------------------------
-//
-// 23.02.2006-Milano: Unit port establishment
-//
-{ agg_bezier_ctrl.pas }
-unit
- agg_bezier_ctrl ;
-
-INTERFACE
-
-{$I agg_mode.inc }
-
-uses
- agg_basics ,
- agg_ctrl ,
- agg_math ,
- agg_ellipse ,
- agg_trans_affine ,
- agg_color ,
- agg_curves ,
- agg_conv_stroke ,
- agg_conv_curve ,
- agg_polygon_ctrl ;
-
-{ TYPES DEFINITION }
-type
- bezier_ctrl_impl = object(ctrl )
- m_curve : curve4;
- m_ellipse : ellipse;
- m_stroke : conv_stroke;
- m_poly : polygon_ctrl_impl;
- m_idx : unsigned;
-
- constructor Construct;
- destructor Destruct; virtual;
-
- procedure curve_(x1 ,y1 ,x2 ,y2 ,x3 ,y3 ,x4 ,y4 : double );
- function _curve : curve4_ptr;
-
- function _x1 : double;
- function _y1 : double;
- function _x2 : double;
- function _y2 : double;
- function _x3 : double;
- function _y3 : double;
- function _x4 : double;
- function _y4 : double;
-
- procedure x1_(x : double );
- procedure y1_(y : double );
- procedure x2_(x : double );
- procedure y2_(y : double );
- procedure x3_(x : double );
- procedure y3_(y : double );
- procedure x4_(x : double );
- procedure y4_(y : double );
-
- procedure line_width_(w : double );
- function _line_width : double;
-
- procedure point_radius_(r : double );
- function _point_radius : double;
-
- // Event handlers
- function in_rect(x ,y : double ) : boolean; virtual;
-
- function on_mouse_button_down(x ,y : double ) : boolean; virtual;
- function on_mouse_button_up (x ,y : double ) : boolean; virtual;
-
- function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual;
- function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual;
-
- // Vertex source interface
- function num_paths : unsigned; virtual;
- procedure rewind(path_id : unsigned ); virtual;
- function vertex(x ,y : double_ptr ) : unsigned; virtual;
-
- end;
-
- bezier_ctrl = object(bezier_ctrl_impl )
- m_color : aggclr;
-
- constructor Construct;
-
- procedure line_color_(c : aggclr_ptr );
-
- function _color(i : unsigned ) : aggclr_ptr; virtual;
-
- end;
-
- curve3_ctrl_impl = object(ctrl )
- m_curve : curve3;
- m_ellipse : ellipse;
- m_stroke : conv_stroke;
- m_poly : polygon_ctrl_impl;
- m_idx : unsigned;
-
- constructor Construct;
- destructor Destruct; virtual;
-
- procedure curve_(x1 ,y1 ,x2 ,y2 ,x3 ,y3 : double );
- function _curve : curve3_ptr;
-
- function _x1 : double;
- function _y1 : double;
- function _x2 : double;
- function _y2 : double;
- function _x3 : double;
- function _y3 : double;
-
- procedure x1_(x : double );
- procedure y1_(y : double );
- procedure x2_(x : double );
- procedure y2_(y : double );
- procedure x3_(x : double );
- procedure y3_(y : double );
-
- procedure line_width_(w : double );
- function _line_width : double;
-
- procedure point_radius_(r : double );
- function _point_radius : double;
-
- // Event handlers
- function in_rect(x ,y : double ) : boolean; virtual;
-
- function on_mouse_button_down(x ,y : double ) : boolean; virtual;
- function on_mouse_button_up (x ,y : double ) : boolean; virtual;
-
- function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual;
- function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual;
-
- // Vertex source interface
- function num_paths : unsigned; virtual;
- procedure rewind(path_id : unsigned ); virtual;
- function vertex(x ,y : double_ptr ) : unsigned; virtual;
-
- end;
-
- curve3_ctrl = object(curve3_ctrl_impl )
- m_color : aggclr;
-
- constructor Construct;
-
- procedure line_color_(c : aggclr_ptr );
-
- function _color(i : unsigned ) : aggclr_ptr; virtual;
-
- end;
-
-{ GLOBAL PROCEDURES }
-
-
-IMPLEMENTATION
-{ LOCAL VARIABLES & CONSTANTS }
-{ UNIT IMPLEMENTATION }
-{ CONSTRUCT }
-constructor bezier_ctrl_impl.Construct;
-begin
- inherited Construct(0 ,0 ,1 ,1 ,false );
-
- m_curve.Construct;
- m_ellipse.Construct;
- m_stroke.Construct(@m_curve );
- m_poly.Construct (4 ,5.0 );
-
- m_idx:=0;
-
- m_poly.in_polygon_check_(false );
-
- m_poly.xn_ptr(0 )^:=100.0;
- m_poly.yn_ptr(0 )^:= 0.0;
- m_poly.xn_ptr(1 )^:=100.0;
- m_poly.yn_ptr(1 )^:= 50.0;
- m_poly.xn_ptr(2 )^:= 50.0;
- m_poly.yn_ptr(2 )^:=100.0;
- m_poly.xn_ptr(3 )^:= 0.0;
- m_poly.yn_ptr(3 )^:=100.0;
-
-end;
-
-{ DESTRUCT }
-destructor bezier_ctrl_impl.Destruct;
-begin
- m_curve.Destruct;
- m_stroke.Destruct;
- m_poly.Destruct;
-
-end;
-
-{ CURVE_ }
-procedure bezier_ctrl_impl.curve_;
-begin
- m_poly.xn_ptr(0 )^:=x1;
- m_poly.yn_ptr(0 )^:=y1;
- m_poly.xn_ptr(1 )^:=x2;
- m_poly.yn_ptr(1 )^:=y2;
- m_poly.xn_ptr(2 )^:=x3;
- m_poly.yn_ptr(2 )^:=y3;
- m_poly.xn_ptr(3 )^:=x4;
- m_poly.yn_ptr(3 )^:=y4;
-
- _curve;
-
-end;
-
-{ _CURVE }
-function bezier_ctrl_impl._curve;
-begin
- m_curve.init4(
- m_poly._xn(0 ) ,m_poly._yn(0 ) ,
- m_poly._xn(1 ) ,m_poly._yn(1 ) ,
- m_poly._xn(2 ) ,m_poly._yn(2 ) ,
- m_poly._xn(3 ) ,m_poly._yn(3 ) );
-
- result:=@m_curve;
-
-end;
-
-{ _X1 }
-function bezier_ctrl_impl._x1;
-begin
- result:=m_poly._xn(0 );
-
-end;
-
-{ _Y1 }
-function bezier_ctrl_impl._y1;
-begin
- result:=m_poly._yn(0 );
-
-end;
-
-{ _X2 }
-function bezier_ctrl_impl._x2;
-begin
- result:=m_poly._xn(1 );
-
-end;
-
-{ _Y2 }
-function bezier_ctrl_impl._y2;
-begin
- result:=m_poly._yn(1 );
-
-end;
-
-{ _X3 }
-function bezier_ctrl_impl._x3;
-begin
- result:=m_poly._xn(2 );
-
-end;
-
-{ _Y3 }
-function bezier_ctrl_impl._y3;
-begin
- result:=m_poly._yn(2 );
-
-end;
-
-{ _X4 }
-function bezier_ctrl_impl._x4;
-begin
- result:=m_poly._xn(3 );
-
-end;
-
-{ _Y4 }
-function bezier_ctrl_impl._y4;
-begin
- result:=m_poly._yn(3 );
-
-end;
-
-{ X1_ }
-procedure bezier_ctrl_impl.x1_;
-begin
- m_poly.xn_ptr(0 )^:=x;
-
-end;
-
-{ Y1_ }
-procedure bezier_ctrl_impl.y1_;
-begin
- m_poly.yn_ptr(0 )^:=y;
-
-end;
-
-{ X2_ }
-procedure bezier_ctrl_impl.x2_;
-begin
- m_poly.xn_ptr(1 )^:=x;
-
-end;
-
-{ Y2_ }
-procedure bezier_ctrl_impl.y2_;
-begin
- m_poly.yn_ptr(1 )^:=y;
-
-end;
-
-{ X3_ }
-procedure bezier_ctrl_impl.x3_;
-begin
- m_poly.xn_ptr(2 )^:=x;
-
-end;
-
-{ Y3_ }
-procedure bezier_ctrl_impl.y3_;
-begin
- m_poly.yn_ptr(2 )^:=y;
-
-end;
-
-{ X4_ }
-procedure bezier_ctrl_impl.x4_;
-begin
- m_poly.xn_ptr(3 )^:=x;
-
-end;
-
-{ Y4_ }
-procedure bezier_ctrl_impl.y4_;
-begin
- m_poly.yn_ptr(3 )^:=y;
-
-end;
-
-{ LINE_WIDTH_ }
-procedure bezier_ctrl_impl.line_width_;
-begin
- m_stroke.width_(w );
-
-end;
-
-{ _LINE_WIDTH }
-function bezier_ctrl_impl._line_width;
-begin
- result:=m_stroke._width;
-
-end;
-
-{ POINT_RADIUS_ }
-procedure bezier_ctrl_impl.point_radius_;
-begin
- m_poly.point_radius_(r );
-
-end;
-
-{ _POINT_RADIUS }
-function bezier_ctrl_impl._point_radius;
-begin
- result:=m_poly._point_radius;
-
-end;
-
-{ IN_RECT }
-function bezier_ctrl_impl.in_rect;
-begin
- result:=false;
-
-end;
-
-{ ON_MOUSE_BUTTON_DOWN }
-function bezier_ctrl_impl.on_mouse_button_down;
-begin
- inverse_transform_xy(@x ,@y );
-
- result:=m_poly.on_mouse_button_down(x ,y );
-
-end;
-
-{ ON_MOUSE_BUTTON_UP }
-function bezier_ctrl_impl.on_mouse_button_up;
-begin
- result:=m_poly.on_mouse_button_up(x ,y );
-
-end;
-
-{ ON_MOUSE_MOVE }
-function bezier_ctrl_impl.on_mouse_move;
-begin
- inverse_transform_xy(@x ,@y );
-
- result:=m_poly.on_mouse_move(x ,y ,button_flag );
-
-end;
-
-{ ON_ARROW_KEYS }
-function bezier_ctrl_impl.on_arrow_keys;
-begin
- result:=m_poly.on_arrow_keys(left ,right ,down ,up );
-
-end;
-
-{ NUM_PATHS }
-function bezier_ctrl_impl.num_paths;
-begin
- result:=7;
-
-end;
-
-{ REWIND }
-procedure bezier_ctrl_impl.rewind;
-begin
- m_idx:=path_id;
-
- m_curve.approximation_scale_(scale );
-
- case path_id of
- 0 : // Control line 1
- begin
- m_curve.init4(
- m_poly._xn(0 ) ,m_poly._yn(0 ) ,
- (m_poly._xn(0 ) + m_poly._xn(1 ) ) * 0.5 ,
- (m_poly._yn(0 ) + m_poly._yn(1 ) ) * 0.5 ,
- (m_poly._xn(0 ) + m_poly._xn(1 ) ) * 0.5 ,
- (m_poly._yn(0 ) + m_poly._yn(1 ) ) * 0.5 ,
- m_poly._xn(1 ) ,m_poly._yn(1 ) );
-
- m_stroke.rewind(0 );
-
- end;
-
- 1 : // Control line 2
- begin
- m_curve.init4(
- m_poly._xn(2 ) ,m_poly._yn(2 ) ,
- (m_poly._xn(2 ) + m_poly._xn(3 ) ) * 0.5,
- (m_poly._yn(2 ) + m_poly._yn(3 ) ) * 0.5,
- (m_poly._xn(2 ) + m_poly._xn(3 ) ) * 0.5,
- (m_poly._yn(2 ) + m_poly._yn(3 ) ) * 0.5,
- m_poly._xn(3 ) ,m_poly._yn(3 ) );
-
- m_stroke.rewind(0 );
-
- end;
-
- 2 : // Curve itself
- begin
- m_curve.init4(
- m_poly._xn(0 ) ,m_poly._yn(0 ) ,
- m_poly._xn(1 ) ,m_poly._yn(1 ) ,
- m_poly._xn(2 ) ,m_poly._yn(2 ) ,
- m_poly._xn(3 ) ,m_poly._yn(3 ) );
-
- m_stroke.rewind(0 );
-
- end;
-
- 3 : // Point 1
- begin
- m_ellipse.init (m_poly._xn(0 ) ,m_poly._yn(0 ) ,_point_radius ,_point_radius ,20 );
- m_ellipse.rewind(0 );
-
- end;
-
- 4 : // Point 2
- begin
- m_ellipse.init (m_poly._xn(1 ) ,m_poly._yn(1 ) ,_point_radius ,_point_radius ,20 );
- m_ellipse.rewind(0 );
-
- end;
-
- 5 : // Point 3
- begin
- m_ellipse.init (m_poly._xn(2 ) ,m_poly._yn(2 ) ,_point_radius ,_point_radius ,20 );
- m_ellipse.rewind(0 );
-
- end;
-
- 6 : // Point 4
- begin
- m_ellipse.init (m_poly._xn(3 ) ,m_poly._yn(3 ) ,_point_radius ,_point_radius ,20 );
- m_ellipse.rewind(0 );
-
- end;
-
- end;
-
-end;
-
-{ VERTEX }
-function bezier_ctrl_impl.vertex;
-var
- cmd : unsigned;
-
-begin
- cmd:=path_cmd_stop;
-
- case m_idx of
- 0 ,1 ,2 :
- cmd:=m_stroke.vertex(x ,y );
-
- 3 ,4 ,5 ,6 ,7 :
- cmd:=m_ellipse.vertex(x, y);
-
- end;
-
- if not is_stop(cmd ) then
- transform_xy(x ,y );
-
- result:=cmd;
-
-end;
-
-{ CONSTRUCT }
-constructor bezier_ctrl.Construct;
-begin
- inherited Construct;
-
- m_color.ConstrDbl(0.0 ,0.0 ,0.0 );
-
-end;
-
-{ LINE_COLOR_ }
-procedure bezier_ctrl.line_color_;
-begin
- m_color:=c^;
-
-end;
-
-{ _COLOR }
-function bezier_ctrl._color;
-begin
- result:=@m_color;
-
-end;
-
-{ CONSTRUCT }
-constructor curve3_ctrl_impl.Construct;
-begin
- inherited Construct(0 ,0 ,1 ,1 ,false );
-
- m_curve.Construct;
- m_ellipse.Construct;
- m_stroke.Construct(@m_curve );
- m_poly.Construct (3 ,5.0 );
-
- m_idx:=0;
-
- m_poly.in_polygon_check_(false );
-
- m_poly.xn_ptr(0 )^:=100.0;
- m_poly.yn_ptr(0 )^:= 0.0;
- m_poly.xn_ptr(1 )^:=100.0;
- m_poly.yn_ptr(1 )^:= 50.0;
- m_poly.xn_ptr(2 )^:= 50.0;
- m_poly.yn_ptr(2 )^:=100.0;
-
-end;
-
-{ DESTRUCT }
-destructor curve3_ctrl_impl.Destruct;
-begin
- m_curve.Destruct;
- m_stroke.Destruct;
- m_poly.Destruct;
-
-end;
-
-{ CURVE_ }
-procedure curve3_ctrl_impl.curve_;
-begin
- m_poly.xn_ptr(0 )^:=x1;
- m_poly.yn_ptr(0 )^:=y1;
- m_poly.xn_ptr(1 )^:=x2;
- m_poly.yn_ptr(1 )^:=y2;
- m_poly.xn_ptr(2 )^:=x3;
- m_poly.yn_ptr(2 )^:=y3;
-
- _curve;
-
-end;
-
-{ _CURVE }
-function curve3_ctrl_impl._curve;
-begin
- m_curve.init3(
- m_poly._xn(0 ) ,m_poly._yn(0 ) ,
- m_poly._xn(1 ) ,m_poly._yn(1 ) ,
- m_poly._xn(2 ) ,m_poly._yn(2 ) );
-
- result:=@m_curve;
-
-end;
-
-{ _X1 }
-function curve3_ctrl_impl._x1;
-begin
- result:=m_poly._xn(0 );
-
-end;
-
-{ _Y1 }
-function curve3_ctrl_impl._y1;
-begin
- result:=m_poly._yn(0 );
-
-end;
-
-{ _X2 }
-function curve3_ctrl_impl._x2;
-begin
- result:=m_poly._xn(1 );
-
-end;
-
-{ _Y2 }
-function curve3_ctrl_impl._y2;
-begin
- result:=m_poly._yn(1 );
-
-end;
-
-{ _X3 }
-function curve3_ctrl_impl._x3;
-begin
- result:=m_poly._xn(2 );
-
-end;
-
-{ _Y3 }
-function curve3_ctrl_impl._y3;
-begin
- result:=m_poly._yn(2 );
-
-end;
-
-{ X1_ }
-procedure curve3_ctrl_impl.x1_;
-begin
- m_poly.xn_ptr(0 )^:=x;
-
-end;
-
-{ Y1_ }
-procedure curve3_ctrl_impl.y1_;
-begin
- m_poly.yn_ptr(0 )^:=y;
-
-end;
-
-{ X2_ }
-procedure curve3_ctrl_impl.x2_;
-begin
- m_poly.xn_ptr(1 )^:=x;
-
-end;
-
-{ Y2_ }
-procedure curve3_ctrl_impl.y2_;
-begin
- m_poly.yn_ptr(1 )^:=y;
-
-end;
-
-{ X3_ }
-procedure curve3_ctrl_impl.x3_;
-begin
- m_poly.xn_ptr(2 )^:=x;
-
-end;
-
-{ Y3_ }
-procedure curve3_ctrl_impl.y3_;
-begin
- m_poly.yn_ptr(2 )^:=y;
-
-end;
-
-{ LINE_WIDTH_ }
-procedure curve3_ctrl_impl.line_width_;
-begin
- m_stroke.width_(w );
-
-end;
-
-{ _LINE_WIDTH }
-function curve3_ctrl_impl._line_width;
-begin
- result:=m_stroke._width;
-
-end;
-
-{ POINT_RADIUS_ }
-procedure curve3_ctrl_impl.point_radius_;
-begin
- m_poly.point_radius_(r );
-
-end;
-
-{ _POINT_RADIUS }
-function curve3_ctrl_impl._point_radius;
-begin
- result:=m_poly._point_radius;
-
-end;
-
-{ IN_RECT }
-function curve3_ctrl_impl.in_rect;
-begin
- result:=false;
-
-end;
-
-{ ON_MOUSE_BUTTON_DOWN }
-function curve3_ctrl_impl.on_mouse_button_down;
-begin
- inverse_transform_xy(@x ,@y );
-
- result:=m_poly.on_mouse_button_down(x ,y );
-
-end;
-
-{ ON_MOUSE_BUTTON_UP }
-function curve3_ctrl_impl.on_mouse_button_up;
-begin
- result:=m_poly.on_mouse_button_up(x ,y );
-
-end;
-
-{ ON_MOUSE_MOVE }
-function curve3_ctrl_impl.on_mouse_move;
-begin
- inverse_transform_xy(@x ,@y );
-
- result:=m_poly.on_mouse_move(x ,y ,button_flag );
-
-end;
-
-{ ON_ARROW_KEYS }
-function curve3_ctrl_impl.on_arrow_keys;
-begin
- result:=m_poly.on_arrow_keys(left ,right ,down ,up );
-
-end;
-
-{ NUM_PATHS }
-function curve3_ctrl_impl.num_paths;
-begin
- result:=6;
-
-end;
-
-{ REWIND }
-procedure curve3_ctrl_impl.rewind;
-begin
- m_idx:=path_id;
-
- case path_id of
- 0 : // Control line
- begin
- m_curve.init3(
- m_poly._xn(0 ) ,m_poly._yn(0 ) ,
- (m_poly._xn(0 ) + m_poly._xn(1 ) ) * 0.5,
- (m_poly._yn(0 ) + m_poly._yn(1 ) ) * 0.5,
- m_poly._xn(1 ) ,m_poly._yn(1 ) );
-
- m_stroke.rewind(0 );
-
- end;
-
- 1 : // Control line 2
- begin
- m_curve.init3(
- m_poly._xn(1 ) ,m_poly._yn(1 ) ,
- (m_poly._xn(1 ) + m_poly._xn(2 ) ) * 0.5,
- (m_poly._yn(1 ) + m_poly._yn(2 ) ) * 0.5,
- m_poly._xn(2 ) ,m_poly._yn(2 ) );
-
- m_stroke.rewind(0 );
-
- end;
-
- 2 : // Curve itself
- begin
- m_curve.init3(
- m_poly._xn(0 ) ,m_poly._yn(0 ) ,
- m_poly._xn(1 ) ,m_poly._yn(1 ) ,
- m_poly._xn(2 ) ,m_poly._yn(2 ) );
-
- m_stroke.rewind(0 );
-
- end;
-
- 3 : // Point 1
- begin
- m_ellipse.init (m_poly._xn(0 ) ,m_poly._yn(0 ) ,_point_radius ,_point_radius ,20 );
- m_ellipse.rewind(0 );
-
- end;
-
- 4 : // Point 2
- begin
- m_ellipse.init (m_poly._xn(1 ) ,m_poly._yn(1 ) ,_point_radius ,_point_radius ,20 );
- m_ellipse.rewind(0 );
-
- end;
-
- 5 : // Point 3
- begin
- m_ellipse.init (m_poly._xn(2 ) ,m_poly._yn(2 ) ,_point_radius ,_point_radius ,20 );
- m_ellipse.rewind(0 );
-
- end;
-
- end;
-
-end;
-
-{ VERTEX }
-function curve3_ctrl_impl.vertex;
-var
- cmd : unsigned;
-
-begin
- cmd:=path_cmd_stop;
-
- case m_idx of
- 0 ,1 ,2 :
- cmd:=m_stroke.vertex(x ,y );
-
- 3 ,4 ,5 ,6 :
- cmd:=m_ellipse.vertex(x ,y );
-
- end;
-
- if not is_stop(cmd ) then
- transform_xy(x ,y );
-
- result:=cmd;
-
-end;
-
-{ CONSTRUCT }
-constructor curve3_ctrl.Construct;
-begin
- inherited Construct;
-
- m_color.ConstrDbl(0.0 ,0.0 ,0.0 );
-
-end;
-
-{ LINE_COLOR_ }
-procedure curve3_ctrl.line_color_;
-begin
- m_color:=c^;
-
-end;
-
-{ _COLOR }
-function curve3_ctrl._color;
-begin
- result:=@m_color;
-
-end;
-
-END.
-
+//---------------------------------------------------------------------------- +// Anti-Grain Geometry - Version 2.4 (Public License) +// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) +// +// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) +// Pascal Port By: Milan Marusinec alias Milano +// milan@marusinec.sk +// http://www.aggpas.org +// Copyright (c) 2005-2006 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +//---------------------------------------------------------------------------- +// Contact: mcseem@antigrain.com +// mcseemagg@yahoo.com +// http://www.antigrain.com +// +//---------------------------------------------------------------------------- +// +// classes bezier_ctrl_impl, bezier_ctrl +// +// [Pascal Port History] ----------------------------------------------------- +// +// 23.02.2006-Milano: Unit port establishment +// +{ agg_bezier_ctrl.pas } +unit + agg_bezier_ctrl ; + +INTERFACE + +{$I agg_mode.inc } + +uses + agg_basics , + agg_ctrl , + agg_math , + agg_ellipse , + agg_trans_affine , + agg_color , + agg_curves , + agg_conv_stroke , + agg_conv_curve , + agg_polygon_ctrl ; + +{ TYPES DEFINITION } +type + bezier_ctrl_impl = object(ctrl ) + m_curve : curve4; + m_ellipse : ellipse; + m_stroke : conv_stroke; + m_poly : polygon_ctrl_impl; + m_idx : unsigned; + + constructor Construct; + destructor Destruct; virtual; + + procedure curve_(x1 ,y1 ,x2 ,y2 ,x3 ,y3 ,x4 ,y4 : double ); + function _curve : curve4_ptr; + + function _x1 : double; + function _y1 : double; + function _x2 : double; + function _y2 : double; + function _x3 : double; + function _y3 : double; + function _x4 : double; + function _y4 : double; + + procedure x1_(x : double ); + procedure y1_(y : double ); + procedure x2_(x : double ); + procedure y2_(y : double ); + procedure x3_(x : double ); + procedure y3_(y : double ); + procedure x4_(x : double ); + procedure y4_(y : double ); + + procedure line_width_(w : double ); + function _line_width : double; + + procedure point_radius_(r : double ); + function _point_radius : double; + + // Event handlers + function in_rect(x ,y : double ) : boolean; virtual; + + function on_mouse_button_down(x ,y : double ) : boolean; virtual; + function on_mouse_button_up (x ,y : double ) : boolean; virtual; + + function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual; + function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual; + + // Vertex source interface + function num_paths : unsigned; virtual; + procedure rewind(path_id : unsigned ); virtual; + function vertex(x ,y : double_ptr ) : unsigned; virtual; + + end; + + bezier_ctrl = object(bezier_ctrl_impl ) + m_color : aggclr; + + constructor Construct; + + procedure line_color_(c : aggclr_ptr ); + + function _color(i : unsigned ) : aggclr_ptr; virtual; + + end; + + curve3_ctrl_impl = object(ctrl ) + m_curve : curve3; + m_ellipse : ellipse; + m_stroke : conv_stroke; + m_poly : polygon_ctrl_impl; + m_idx : unsigned; + + constructor Construct; + destructor Destruct; virtual; + + procedure curve_(x1 ,y1 ,x2 ,y2 ,x3 ,y3 : double ); + function _curve : curve3_ptr; + + function _x1 : double; + function _y1 : double; + function _x2 : double; + function _y2 : double; + function _x3 : double; + function _y3 : double; + + procedure x1_(x : double ); + procedure y1_(y : double ); + procedure x2_(x : double ); + procedure y2_(y : double ); + procedure x3_(x : double ); + procedure y3_(y : double ); + + procedure line_width_(w : double ); + function _line_width : double; + + procedure point_radius_(r : double ); + function _point_radius : double; + + // Event handlers + function in_rect(x ,y : double ) : boolean; virtual; + + function on_mouse_button_down(x ,y : double ) : boolean; virtual; + function on_mouse_button_up (x ,y : double ) : boolean; virtual; + + function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual; + function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual; + + // Vertex source interface + function num_paths : unsigned; virtual; + procedure rewind(path_id : unsigned ); virtual; + function vertex(x ,y : double_ptr ) : unsigned; virtual; + + end; + + curve3_ctrl = object(curve3_ctrl_impl ) + m_color : aggclr; + + constructor Construct; + + procedure line_color_(c : aggclr_ptr ); + + function _color(i : unsigned ) : aggclr_ptr; virtual; + + end; + +{ GLOBAL PROCEDURES } + + +IMPLEMENTATION +{ LOCAL VARIABLES & CONSTANTS } +{ UNIT IMPLEMENTATION } +{ CONSTRUCT } +constructor bezier_ctrl_impl.Construct; +begin + inherited Construct(0 ,0 ,1 ,1 ,false ); + + m_curve.Construct; + m_ellipse.Construct; + m_stroke.Construct(@m_curve ); + m_poly.Construct (4 ,5.0 ); + + m_idx:=0; + + m_poly.in_polygon_check_(false ); + + m_poly.xn_ptr(0 )^:=100.0; + m_poly.yn_ptr(0 )^:= 0.0; + m_poly.xn_ptr(1 )^:=100.0; + m_poly.yn_ptr(1 )^:= 50.0; + m_poly.xn_ptr(2 )^:= 50.0; + m_poly.yn_ptr(2 )^:=100.0; + m_poly.xn_ptr(3 )^:= 0.0; + m_poly.yn_ptr(3 )^:=100.0; + +end; + +{ DESTRUCT } +destructor bezier_ctrl_impl.Destruct; +begin + m_curve.Destruct; + m_stroke.Destruct; + m_poly.Destruct; + +end; + +{ CURVE_ } +procedure bezier_ctrl_impl.curve_; +begin + m_poly.xn_ptr(0 )^:=x1; + m_poly.yn_ptr(0 )^:=y1; + m_poly.xn_ptr(1 )^:=x2; + m_poly.yn_ptr(1 )^:=y2; + m_poly.xn_ptr(2 )^:=x3; + m_poly.yn_ptr(2 )^:=y3; + m_poly.xn_ptr(3 )^:=x4; + m_poly.yn_ptr(3 )^:=y4; + + _curve; + +end; + +{ _CURVE } +function bezier_ctrl_impl._curve; +begin + m_curve.init4( + m_poly._xn(0 ) ,m_poly._yn(0 ) , + m_poly._xn(1 ) ,m_poly._yn(1 ) , + m_poly._xn(2 ) ,m_poly._yn(2 ) , + m_poly._xn(3 ) ,m_poly._yn(3 ) ); + + result:=@m_curve; + +end; + +{ _X1 } +function bezier_ctrl_impl._x1; +begin + result:=m_poly._xn(0 ); + +end; + +{ _Y1 } +function bezier_ctrl_impl._y1; +begin + result:=m_poly._yn(0 ); + +end; + +{ _X2 } +function bezier_ctrl_impl._x2; +begin + result:=m_poly._xn(1 ); + +end; + +{ _Y2 } +function bezier_ctrl_impl._y2; +begin + result:=m_poly._yn(1 ); + +end; + +{ _X3 } +function bezier_ctrl_impl._x3; +begin + result:=m_poly._xn(2 ); + +end; + +{ _Y3 } +function bezier_ctrl_impl._y3; +begin + result:=m_poly._yn(2 ); + +end; + +{ _X4 } +function bezier_ctrl_impl._x4; +begin + result:=m_poly._xn(3 ); + +end; + +{ _Y4 } +function bezier_ctrl_impl._y4; +begin + result:=m_poly._yn(3 ); + +end; + +{ X1_ } +procedure bezier_ctrl_impl.x1_; +begin + m_poly.xn_ptr(0 )^:=x; + +end; + +{ Y1_ } +procedure bezier_ctrl_impl.y1_; +begin + m_poly.yn_ptr(0 )^:=y; + +end; + +{ X2_ } +procedure bezier_ctrl_impl.x2_; +begin + m_poly.xn_ptr(1 )^:=x; + +end; + +{ Y2_ } +procedure bezier_ctrl_impl.y2_; +begin + m_poly.yn_ptr(1 )^:=y; + +end; + +{ X3_ } +procedure bezier_ctrl_impl.x3_; +begin + m_poly.xn_ptr(2 )^:=x; + +end; + +{ Y3_ } +procedure bezier_ctrl_impl.y3_; +begin + m_poly.yn_ptr(2 )^:=y; + +end; + +{ X4_ } +procedure bezier_ctrl_impl.x4_; +begin + m_poly.xn_ptr(3 )^:=x; + +end; + +{ Y4_ } +procedure bezier_ctrl_impl.y4_; +begin + m_poly.yn_ptr(3 )^:=y; + +end; + +{ LINE_WIDTH_ } +procedure bezier_ctrl_impl.line_width_; +begin + m_stroke.width_(w ); + +end; + +{ _LINE_WIDTH } +function bezier_ctrl_impl._line_width; +begin + result:=m_stroke._width; + +end; + +{ POINT_RADIUS_ } +procedure bezier_ctrl_impl.point_radius_; +begin + m_poly.point_radius_(r ); + +end; + +{ _POINT_RADIUS } +function bezier_ctrl_impl._point_radius; +begin + result:=m_poly._point_radius; + +end; + +{ IN_RECT } +function bezier_ctrl_impl.in_rect; +begin + result:=false; + +end; + +{ ON_MOUSE_BUTTON_DOWN } +function bezier_ctrl_impl.on_mouse_button_down; +begin + inverse_transform_xy(@x ,@y ); + + result:=m_poly.on_mouse_button_down(x ,y ); + +end; + +{ ON_MOUSE_BUTTON_UP } +function bezier_ctrl_impl.on_mouse_button_up; +begin + result:=m_poly.on_mouse_button_up(x ,y ); + +end; + +{ ON_MOUSE_MOVE } +function bezier_ctrl_impl.on_mouse_move; +begin + inverse_transform_xy(@x ,@y ); + + result:=m_poly.on_mouse_move(x ,y ,button_flag ); + +end; + +{ ON_ARROW_KEYS } +function bezier_ctrl_impl.on_arrow_keys; +begin + result:=m_poly.on_arrow_keys(left ,right ,down ,up ); + +end; + +{ NUM_PATHS } +function bezier_ctrl_impl.num_paths; +begin + result:=7; + +end; + +{ REWIND } +procedure bezier_ctrl_impl.rewind; +begin + m_idx:=path_id; + + m_curve.approximation_scale_(scale ); + + case path_id of + 0 : // Control line 1 + begin + m_curve.init4( + m_poly._xn(0 ) ,m_poly._yn(0 ) , + (m_poly._xn(0 ) + m_poly._xn(1 ) ) * 0.5 , + (m_poly._yn(0 ) + m_poly._yn(1 ) ) * 0.5 , + (m_poly._xn(0 ) + m_poly._xn(1 ) ) * 0.5 , + (m_poly._yn(0 ) + m_poly._yn(1 ) ) * 0.5 , + m_poly._xn(1 ) ,m_poly._yn(1 ) ); + + m_stroke.rewind(0 ); + + end; + + 1 : // Control line 2 + begin + m_curve.init4( + m_poly._xn(2 ) ,m_poly._yn(2 ) , + (m_poly._xn(2 ) + m_poly._xn(3 ) ) * 0.5, + (m_poly._yn(2 ) + m_poly._yn(3 ) ) * 0.5, + (m_poly._xn(2 ) + m_poly._xn(3 ) ) * 0.5, + (m_poly._yn(2 ) + m_poly._yn(3 ) ) * 0.5, + m_poly._xn(3 ) ,m_poly._yn(3 ) ); + + m_stroke.rewind(0 ); + + end; + + 2 : // Curve itself + begin + m_curve.init4( + m_poly._xn(0 ) ,m_poly._yn(0 ) , + m_poly._xn(1 ) ,m_poly._yn(1 ) , + m_poly._xn(2 ) ,m_poly._yn(2 ) , + m_poly._xn(3 ) ,m_poly._yn(3 ) ); + + m_stroke.rewind(0 ); + + end; + + 3 : // Point 1 + begin + m_ellipse.init (m_poly._xn(0 ) ,m_poly._yn(0 ) ,_point_radius ,_point_radius ,20 ); + m_ellipse.rewind(0 ); + + end; + + 4 : // Point 2 + begin + m_ellipse.init (m_poly._xn(1 ) ,m_poly._yn(1 ) ,_point_radius ,_point_radius ,20 ); + m_ellipse.rewind(0 ); + + end; + + 5 : // Point 3 + begin + m_ellipse.init (m_poly._xn(2 ) ,m_poly._yn(2 ) ,_point_radius ,_point_radius ,20 ); + m_ellipse.rewind(0 ); + + end; + + 6 : // Point 4 + begin + m_ellipse.init (m_poly._xn(3 ) ,m_poly._yn(3 ) ,_point_radius ,_point_radius ,20 ); + m_ellipse.rewind(0 ); + + end; + + end; + +end; + +{ VERTEX } +function bezier_ctrl_impl.vertex; +var + cmd : unsigned; + +begin + cmd:=path_cmd_stop; + + case m_idx of + 0 ,1 ,2 : + cmd:=m_stroke.vertex(x ,y ); + + 3 ,4 ,5 ,6 ,7 : + cmd:=m_ellipse.vertex(x, y); + + end; + + if not is_stop(cmd ) then + transform_xy(x ,y ); + + result:=cmd; + +end; + +{ CONSTRUCT } +constructor bezier_ctrl.Construct; +begin + inherited Construct; + + m_color.ConstrDbl(0.0 ,0.0 ,0.0 ); + +end; + +{ LINE_COLOR_ } +procedure bezier_ctrl.line_color_; +begin + m_color:=c^; + +end; + +{ _COLOR } +function bezier_ctrl._color; +begin + result:=@m_color; + +end; + +{ CONSTRUCT } +constructor curve3_ctrl_impl.Construct; +begin + inherited Construct(0 ,0 ,1 ,1 ,false ); + + m_curve.Construct; + m_ellipse.Construct; + m_stroke.Construct(@m_curve ); + m_poly.Construct (3 ,5.0 ); + + m_idx:=0; + + m_poly.in_polygon_check_(false ); + + m_poly.xn_ptr(0 )^:=100.0; + m_poly.yn_ptr(0 )^:= 0.0; + m_poly.xn_ptr(1 )^:=100.0; + m_poly.yn_ptr(1 )^:= 50.0; + m_poly.xn_ptr(2 )^:= 50.0; + m_poly.yn_ptr(2 )^:=100.0; + +end; + +{ DESTRUCT } +destructor curve3_ctrl_impl.Destruct; +begin + m_curve.Destruct; + m_stroke.Destruct; + m_poly.Destruct; + +end; + +{ CURVE_ } +procedure curve3_ctrl_impl.curve_; +begin + m_poly.xn_ptr(0 )^:=x1; + m_poly.yn_ptr(0 )^:=y1; + m_poly.xn_ptr(1 )^:=x2; + m_poly.yn_ptr(1 )^:=y2; + m_poly.xn_ptr(2 )^:=x3; + m_poly.yn_ptr(2 )^:=y3; + + _curve; + +end; + +{ _CURVE } +function curve3_ctrl_impl._curve; +begin + m_curve.init3( + m_poly._xn(0 ) ,m_poly._yn(0 ) , + m_poly._xn(1 ) ,m_poly._yn(1 ) , + m_poly._xn(2 ) ,m_poly._yn(2 ) ); + + result:=@m_curve; + +end; + +{ _X1 } +function curve3_ctrl_impl._x1; +begin + result:=m_poly._xn(0 ); + +end; + +{ _Y1 } +function curve3_ctrl_impl._y1; +begin + result:=m_poly._yn(0 ); + +end; + +{ _X2 } +function curve3_ctrl_impl._x2; +begin + result:=m_poly._xn(1 ); + +end; + +{ _Y2 } +function curve3_ctrl_impl._y2; +begin + result:=m_poly._yn(1 ); + +end; + +{ _X3 } +function curve3_ctrl_impl._x3; +begin + result:=m_poly._xn(2 ); + +end; + +{ _Y3 } +function curve3_ctrl_impl._y3; +begin + result:=m_poly._yn(2 ); + +end; + +{ X1_ } +procedure curve3_ctrl_impl.x1_; +begin + m_poly.xn_ptr(0 )^:=x; + +end; + +{ Y1_ } +procedure curve3_ctrl_impl.y1_; +begin + m_poly.yn_ptr(0 )^:=y; + +end; + +{ X2_ } +procedure curve3_ctrl_impl.x2_; +begin + m_poly.xn_ptr(1 )^:=x; + +end; + +{ Y2_ } +procedure curve3_ctrl_impl.y2_; +begin + m_poly.yn_ptr(1 )^:=y; + +end; + +{ X3_ } +procedure curve3_ctrl_impl.x3_; +begin + m_poly.xn_ptr(2 )^:=x; + +end; + +{ Y3_ } +procedure curve3_ctrl_impl.y3_; +begin + m_poly.yn_ptr(2 )^:=y; + +end; + +{ LINE_WIDTH_ } +procedure curve3_ctrl_impl.line_width_; +begin + m_stroke.width_(w ); + +end; + +{ _LINE_WIDTH } +function curve3_ctrl_impl._line_width; +begin + result:=m_stroke._width; + +end; + +{ POINT_RADIUS_ } +procedure curve3_ctrl_impl.point_radius_; +begin + m_poly.point_radius_(r ); + +end; + +{ _POINT_RADIUS } +function curve3_ctrl_impl._point_radius; +begin + result:=m_poly._point_radius; + +end; + +{ IN_RECT } +function curve3_ctrl_impl.in_rect; +begin + result:=false; + +end; + +{ ON_MOUSE_BUTTON_DOWN } +function curve3_ctrl_impl.on_mouse_button_down; +begin + inverse_transform_xy(@x ,@y ); + + result:=m_poly.on_mouse_button_down(x ,y ); + +end; + +{ ON_MOUSE_BUTTON_UP } +function curve3_ctrl_impl.on_mouse_button_up; +begin + result:=m_poly.on_mouse_button_up(x ,y ); + +end; + +{ ON_MOUSE_MOVE } +function curve3_ctrl_impl.on_mouse_move; +begin + inverse_transform_xy(@x ,@y ); + + result:=m_poly.on_mouse_move(x ,y ,button_flag ); + +end; + +{ ON_ARROW_KEYS } +function curve3_ctrl_impl.on_arrow_keys; +begin + result:=m_poly.on_arrow_keys(left ,right ,down ,up ); + +end; + +{ NUM_PATHS } +function curve3_ctrl_impl.num_paths; +begin + result:=6; + +end; + +{ REWIND } +procedure curve3_ctrl_impl.rewind; +begin + m_idx:=path_id; + + case path_id of + 0 : // Control line + begin + m_curve.init3( + m_poly._xn(0 ) ,m_poly._yn(0 ) , + (m_poly._xn(0 ) + m_poly._xn(1 ) ) * 0.5, + (m_poly._yn(0 ) + m_poly._yn(1 ) ) * 0.5, + m_poly._xn(1 ) ,m_poly._yn(1 ) ); + + m_stroke.rewind(0 ); + + end; + + 1 : // Control line 2 + begin + m_curve.init3( + m_poly._xn(1 ) ,m_poly._yn(1 ) , + (m_poly._xn(1 ) + m_poly._xn(2 ) ) * 0.5, + (m_poly._yn(1 ) + m_poly._yn(2 ) ) * 0.5, + m_poly._xn(2 ) ,m_poly._yn(2 ) ); + + m_stroke.rewind(0 ); + + end; + + 2 : // Curve itself + begin + m_curve.init3( + m_poly._xn(0 ) ,m_poly._yn(0 ) , + m_poly._xn(1 ) ,m_poly._yn(1 ) , + m_poly._xn(2 ) ,m_poly._yn(2 ) ); + + m_stroke.rewind(0 ); + + end; + + 3 : // Point 1 + begin + m_ellipse.init (m_poly._xn(0 ) ,m_poly._yn(0 ) ,_point_radius ,_point_radius ,20 ); + m_ellipse.rewind(0 ); + + end; + + 4 : // Point 2 + begin + m_ellipse.init (m_poly._xn(1 ) ,m_poly._yn(1 ) ,_point_radius ,_point_radius ,20 ); + m_ellipse.rewind(0 ); + + end; + + 5 : // Point 3 + begin + m_ellipse.init (m_poly._xn(2 ) ,m_poly._yn(2 ) ,_point_radius ,_point_radius ,20 ); + m_ellipse.rewind(0 ); + + end; + + end; + +end; + +{ VERTEX } +function curve3_ctrl_impl.vertex; +var + cmd : unsigned; + +begin + cmd:=path_cmd_stop; + + case m_idx of + 0 ,1 ,2 : + cmd:=m_stroke.vertex(x ,y ); + + 3 ,4 ,5 ,6 : + cmd:=m_ellipse.vertex(x ,y ); + + end; + + if not is_stop(cmd ) then + transform_xy(x ,y ); + + result:=cmd; + +end; + +{ CONSTRUCT } +constructor curve3_ctrl.Construct; +begin + inherited Construct; + + m_color.ConstrDbl(0.0 ,0.0 ,0.0 ); + +end; + +{ LINE_COLOR_ } +procedure curve3_ctrl.line_color_; +begin + m_color:=c^; + +end; + +{ _COLOR } +function curve3_ctrl._color; +begin + result:=@m_color; + +end; + +END. + diff --git a/src/corelib/render/software/ctrl/agg_cbox_ctrl.pas b/src/corelib/render/software/ctrl/agg_cbox_ctrl.pas index f8245efa..545de382 100644 --- a/src/corelib/render/software/ctrl/agg_cbox_ctrl.pas +++ b/src/corelib/render/software/ctrl/agg_cbox_ctrl.pas @@ -1,430 +1,430 @@ -//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4 (Public License)
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
-// Pascal Port By: Milan Marusinec alias Milano
-// milan@marusinec.sk
-// http://www.aggpas.org
-// Copyright (c) 2005-2006
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//
-// [Pascal Port History] -----------------------------------------------------
-//
-// 15.01.2006-Milano: Unit port establishment
-//
-{ agg_cbox_ctrl.pas }
-unit
- agg_cbox_ctrl ;
-
-INTERFACE
-
-{$I agg_mode.inc }
-
-uses
- SysUtils ,
- agg_basics ,
- agg_ctrl ,
- agg_conv_stroke ,
- agg_gsv_text ,
- agg_color ,
- agg_math_stroke ;
-
-{ TYPES DEFINITION }
-type
- cbox_ctrl_impl = object(ctrl )
- m_text_thickness ,
- m_text_height ,
- m_text_width : double;
-
- m_label : array[0..127 ] of char;
- m_status : boolean;
-
- m_vx ,
- m_vy : array[0..31 ] of double;
-
- m_text : gsv_text;
- m_text_poly : conv_stroke;
-
- m_idx ,
- m_vertex : unsigned;
-
- constructor Construct(x ,y : double; l : PChar; flip_y : boolean = false );
- destructor Destruct; virtual;
-
- procedure text_thickness_(t : double );
- procedure text_size_ (h : double; w : double = 0 );
-
- function _label : PChar;
- procedure label_(l : PChar );
-
- function _status : boolean;
- procedure status_(st : boolean );
-
- function in_rect(x ,y : double ) : boolean; virtual;
-
- function on_mouse_button_down(x ,y : double ) : boolean; virtual;
- function on_mouse_button_up (x ,y : double ) : boolean; virtual;
-
- function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual;
- function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual;
-
- // Vertex source interface
- function num_paths : unsigned; virtual;
- procedure rewind(path_id : unsigned ); virtual;
- function vertex(x ,y : double_ptr ) : unsigned; virtual;
-
- end;
-
- cbox_ctrl_ptr = ^cbox_ctrl;
- cbox_ctrl = object(cbox_ctrl_impl )
- m_text_color ,
- m_inactive_color ,
- m_active_color : aggclr;
-
- m_colors : array[0..2 ] of aggclr_ptr;
-
- constructor Construct(x ,y : double; l : PChar; flip_y : boolean = false );
-
- procedure text_color_ (c : aggclr_ptr );
- procedure inactive_color_(c : aggclr_ptr );
- procedure active_color_ (c : aggclr_ptr );
-
- function _color(i : unsigned ) : aggclr_ptr; virtual;
-
- end;
-
-{ GLOBAL PROCEDURES }
-
-
-IMPLEMENTATION
-{ LOCAL VARIABLES & CONSTANTS }
-{ UNIT IMPLEMENTATION }
-{ CONSTRUCT }
-constructor cbox_ctrl_impl.Construct;
-begin
- inherited Construct(x ,y ,x + 9.0 * 1.5 ,y + 9.0 * 1.5 ,flip_y );
-
- m_text.Construct;
- m_text_poly.Construct(@m_text );
-
- m_text_thickness:=1.5;
- m_text_height :=9.0;
- m_text_width :=0.0;
-
- m_status:=false;
-
- label_(l );
-
-end;
-
-{ DESTRUCT }
-destructor cbox_ctrl_impl.Destruct;
-begin
- m_text_poly.Destruct;
- m_text.Destruct;
-
-end;
-
-{ TEXT_THICKNESS_ }
-procedure cbox_ctrl_impl.text_thickness_;
-begin
- m_text_thickness:=t;
-
-end;
-
-{ TEXT_SIZE_ }
-procedure cbox_ctrl_impl.text_size_;
-begin
- m_text_width :=w;
- m_text_height:=h;
-
-end;
-
-{ _LABEL }
-function cbox_ctrl_impl._label;
-begin
- result:=@m_label[0 ];
-
-end;
-
-{ LABEL_ }
-procedure cbox_ctrl_impl.label_;
-var
- len : unsigned;
-
-begin
- len:=StrLen(l );
-
- if len > 127 then
- len:=127;
-
- move(l^ ,m_label[0 ] ,len );
-
- m_label[len ]:=#0;
-
-end;
-
-{ _STATUS }
-function cbox_ctrl_impl._status;
-begin
- result:=m_status;
-
-end;
-
-{ STATUS_ }
-procedure cbox_ctrl_impl.status_;
-begin
- m_status:=st;
-
-end;
-
-{ IN_RECT }
-function cbox_ctrl_impl.in_rect;
-begin
- inverse_transform_xy(@x ,@y );
-
- result:=
- (x >= m_x1 ) and
- (y >= m_y1 ) and
- (x <= m_x2 ) and
- (y <= m_y2 );
-
-end;
-
-{ ON_MOUSE_BUTTON_DOWN }
-function cbox_ctrl_impl.on_mouse_button_down;
-begin
- inverse_transform_xy(@x ,@y );
-
- if (x >= m_x1 ) and
- (y >= m_y1 ) and
- (x <= m_x2 ) and
- (y <= m_y2 ) then
- begin
- m_status:=not m_status;
-
- result:=true;
-
- end
- else
- result:=false;
-
-end;
-
-{ ON_MOUSE_BUTTON_UP }
-function cbox_ctrl_impl.on_mouse_button_up;
-begin
- result:=false;
-
-end;
-
-{ ON_MOUSE_MOVE }
-function cbox_ctrl_impl.on_mouse_move;
-begin
- result:=false;
-
-end;
-
-{ ON_ARROW_KEYS }
-function cbox_ctrl_impl.on_arrow_keys;
-begin
- result:=false;
-
-end;
-
-{ NUM_PATHS }
-function cbox_ctrl_impl.num_paths;
-begin
- result:=3;
-
-end;
-
-{ REWIND }
-procedure cbox_ctrl_impl.rewind;
-var
- d2 ,t : double;
-
-begin
- m_idx:=path_id;
-
- case path_id of
- 0 : // Border
- begin
- m_vertex:=0;
-
- m_vx[0 ]:=m_x1;
- m_vy[0 ]:=m_y1;
- m_vx[1 ]:=m_x2;
- m_vy[1 ]:=m_y1;
- m_vx[2 ]:=m_x2;
- m_vy[2 ]:=m_y2;
- m_vx[3 ]:=m_x1;
- m_vy[3 ]:=m_y2;
- m_vx[4 ]:=m_x1 + m_text_thickness;
- m_vy[4 ]:=m_y1 + m_text_thickness;
- m_vx[5 ]:=m_x1 + m_text_thickness;
- m_vy[5 ]:=m_y2 - m_text_thickness;
- m_vx[6 ]:=m_x2 - m_text_thickness;
- m_vy[6 ]:=m_y2 - m_text_thickness;
- m_vx[7 ]:=m_x2 - m_text_thickness;
- m_vy[7 ]:=m_y1 + m_text_thickness;
-
- end;
-
- 1 : // Text
- begin
- m_text.text_ (@m_label[0 ] );
- m_text.start_point_(m_x1 + m_text_height * 2.0 ,m_y1 + m_text_height / 5.0 );
- m_text.size_ (m_text_height ,m_text_width );
-
- m_text_poly.width_ (m_text_thickness );
- m_text_poly.line_join_(round_join );
- m_text_poly.line_cap_ (round_cap );
-
- m_text_poly.rewind(0 );
-
- end;
-
- 2 : // Active item
- begin
- m_vertex:=0;
-
- d2:=(m_y2 - m_y1 ) / 2.0;
- t :=m_text_thickness * 1.5;
-
- m_vx[0 ]:=m_x1 + m_text_thickness;
- m_vy[0 ]:=m_y1 + m_text_thickness;
- m_vx[1 ]:=m_x1 + d2;
- m_vy[1 ]:=m_y1 + d2 - t;
- m_vx[2 ]:=m_x2 - m_text_thickness;
- m_vy[2 ]:=m_y1 + m_text_thickness;
- m_vx[3 ]:=m_x1 + d2 + t;
- m_vy[3 ]:=m_y1 + d2;
- m_vx[4 ]:=m_x2 - m_text_thickness;
- m_vy[4 ]:=m_y2 - m_text_thickness;
- m_vx[5 ]:=m_x1 + d2;
- m_vy[5 ]:=m_y1 + d2 + t;
- m_vx[6 ]:=m_x1 + m_text_thickness;
- m_vy[6 ]:=m_y2 - m_text_thickness;
- m_vx[7 ]:=m_x1 + d2 - t;
- m_vy[7 ]:=m_y1 + d2;
-
- end;
-
- end;
-
-end;
-
-{ VERTEX }
-function cbox_ctrl_impl.vertex;
-var
- cmd : unsigned;
-
-begin
- cmd:=path_cmd_line_to;
-
- case m_idx of
- 0 :
- begin
- if (m_vertex = 0 ) or
- (m_vertex = 4 ) then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 8then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 1 :
- cmd:=m_text_poly.vertex(x ,y );
-
- 2 :
- if m_status then
- begin
- if m_vertex = 0 then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 8 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end
- else
- cmd:=path_cmd_stop;
-
- else
- cmd:=path_cmd_stop;
-
- end;
-
- if not is_stop(cmd ) then
- transform_xy(x ,y );
-
- result:=cmd;
-
-end;
-
-{ CONSTRUCT }
-constructor cbox_ctrl.Construct;
-begin
- inherited Construct(x ,y ,l ,flip_y );
-
- m_text_color.ConstrDbl (0.0 ,0.0 ,0.0 );
- m_inactive_color.ConstrDbl(0.0 ,0.0 ,0.0 );
- m_active_color.ConstrDbl (0.4 ,0.0 ,0.0 );
-
- m_colors[0 ]:=@m_inactive_color;
- m_colors[1 ]:=@m_text_color;
- m_colors[2 ]:=@m_active_color;
-
-end;
-
-{ TEXT_COLOR_ }
-procedure cbox_ctrl.text_color_;
-begin
- m_text_color:=c^;
-
-end;
-
-{ INACTIVE_COLOR_ }
-procedure cbox_ctrl.inactive_color_;
-begin
- m_inactive_color:=c^;
-
-end;
-
-{ ACTIVE_COLOR_ }
-procedure cbox_ctrl.active_color_;
-begin
- m_active_color:=c^;
-
-end;
-
-{ _COLOR }
-function cbox_ctrl._color;
-begin
- result:=m_colors[i ];
-
-end;
-
-END.
-
+//---------------------------------------------------------------------------- +// Anti-Grain Geometry - Version 2.4 (Public License) +// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) +// +// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) +// Pascal Port By: Milan Marusinec alias Milano +// milan@marusinec.sk +// http://www.aggpas.org +// Copyright (c) 2005-2006 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +//---------------------------------------------------------------------------- +// Contact: mcseem@antigrain.com +// mcseemagg@yahoo.com +// http://www.antigrain.com +// +// [Pascal Port History] ----------------------------------------------------- +// +// 15.01.2006-Milano: Unit port establishment +// +{ agg_cbox_ctrl.pas } +unit + agg_cbox_ctrl ; + +INTERFACE + +{$I agg_mode.inc } + +uses + SysUtils , + agg_basics , + agg_ctrl , + agg_conv_stroke , + agg_gsv_text , + agg_color , + agg_math_stroke ; + +{ TYPES DEFINITION } +type + cbox_ctrl_impl = object(ctrl ) + m_text_thickness , + m_text_height , + m_text_width : double; + + m_label : array[0..127 ] of char; + m_status : boolean; + + m_vx , + m_vy : array[0..31 ] of double; + + m_text : gsv_text; + m_text_poly : conv_stroke; + + m_idx , + m_vertex : unsigned; + + constructor Construct(x ,y : double; l : PChar; flip_y : boolean = false ); + destructor Destruct; virtual; + + procedure text_thickness_(t : double ); + procedure text_size_ (h : double; w : double = 0 ); + + function _label : PChar; + procedure label_(l : PChar ); + + function _status : boolean; + procedure status_(st : boolean ); + + function in_rect(x ,y : double ) : boolean; virtual; + + function on_mouse_button_down(x ,y : double ) : boolean; virtual; + function on_mouse_button_up (x ,y : double ) : boolean; virtual; + + function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual; + function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual; + + // Vertex source interface + function num_paths : unsigned; virtual; + procedure rewind(path_id : unsigned ); virtual; + function vertex(x ,y : double_ptr ) : unsigned; virtual; + + end; + + cbox_ctrl_ptr = ^cbox_ctrl; + cbox_ctrl = object(cbox_ctrl_impl ) + m_text_color , + m_inactive_color , + m_active_color : aggclr; + + m_colors : array[0..2 ] of aggclr_ptr; + + constructor Construct(x ,y : double; l : PChar; flip_y : boolean = false ); + + procedure text_color_ (c : aggclr_ptr ); + procedure inactive_color_(c : aggclr_ptr ); + procedure active_color_ (c : aggclr_ptr ); + + function _color(i : unsigned ) : aggclr_ptr; virtual; + + end; + +{ GLOBAL PROCEDURES } + + +IMPLEMENTATION +{ LOCAL VARIABLES & CONSTANTS } +{ UNIT IMPLEMENTATION } +{ CONSTRUCT } +constructor cbox_ctrl_impl.Construct; +begin + inherited Construct(x ,y ,x + 9.0 * 1.5 ,y + 9.0 * 1.5 ,flip_y ); + + m_text.Construct; + m_text_poly.Construct(@m_text ); + + m_text_thickness:=1.5; + m_text_height :=9.0; + m_text_width :=0.0; + + m_status:=false; + + label_(l ); + +end; + +{ DESTRUCT } +destructor cbox_ctrl_impl.Destruct; +begin + m_text_poly.Destruct; + m_text.Destruct; + +end; + +{ TEXT_THICKNESS_ } +procedure cbox_ctrl_impl.text_thickness_; +begin + m_text_thickness:=t; + +end; + +{ TEXT_SIZE_ } +procedure cbox_ctrl_impl.text_size_; +begin + m_text_width :=w; + m_text_height:=h; + +end; + +{ _LABEL } +function cbox_ctrl_impl._label; +begin + result:=@m_label[0 ]; + +end; + +{ LABEL_ } +procedure cbox_ctrl_impl.label_; +var + len : unsigned; + +begin + len:=StrLen(l ); + + if len > 127 then + len:=127; + + move(l^ ,m_label[0 ] ,len ); + + m_label[len ]:=#0; + +end; + +{ _STATUS } +function cbox_ctrl_impl._status; +begin + result:=m_status; + +end; + +{ STATUS_ } +procedure cbox_ctrl_impl.status_; +begin + m_status:=st; + +end; + +{ IN_RECT } +function cbox_ctrl_impl.in_rect; +begin + inverse_transform_xy(@x ,@y ); + + result:= + (x >= m_x1 ) and + (y >= m_y1 ) and + (x <= m_x2 ) and + (y <= m_y2 ); + +end; + +{ ON_MOUSE_BUTTON_DOWN } +function cbox_ctrl_impl.on_mouse_button_down; +begin + inverse_transform_xy(@x ,@y ); + + if (x >= m_x1 ) and + (y >= m_y1 ) and + (x <= m_x2 ) and + (y <= m_y2 ) then + begin + m_status:=not m_status; + + result:=true; + + end + else + result:=false; + +end; + +{ ON_MOUSE_BUTTON_UP } +function cbox_ctrl_impl.on_mouse_button_up; +begin + result:=false; + +end; + +{ ON_MOUSE_MOVE } +function cbox_ctrl_impl.on_mouse_move; +begin + result:=false; + +end; + +{ ON_ARROW_KEYS } +function cbox_ctrl_impl.on_arrow_keys; +begin + result:=false; + +end; + +{ NUM_PATHS } +function cbox_ctrl_impl.num_paths; +begin + result:=3; + +end; + +{ REWIND } +procedure cbox_ctrl_impl.rewind; +var + d2 ,t : double; + +begin + m_idx:=path_id; + + case path_id of + 0 : // Border + begin + m_vertex:=0; + + m_vx[0 ]:=m_x1; + m_vy[0 ]:=m_y1; + m_vx[1 ]:=m_x2; + m_vy[1 ]:=m_y1; + m_vx[2 ]:=m_x2; + m_vy[2 ]:=m_y2; + m_vx[3 ]:=m_x1; + m_vy[3 ]:=m_y2; + m_vx[4 ]:=m_x1 + m_text_thickness; + m_vy[4 ]:=m_y1 + m_text_thickness; + m_vx[5 ]:=m_x1 + m_text_thickness; + m_vy[5 ]:=m_y2 - m_text_thickness; + m_vx[6 ]:=m_x2 - m_text_thickness; + m_vy[6 ]:=m_y2 - m_text_thickness; + m_vx[7 ]:=m_x2 - m_text_thickness; + m_vy[7 ]:=m_y1 + m_text_thickness; + + end; + + 1 : // Text + begin + m_text.text_ (@m_label[0 ] ); + m_text.start_point_(m_x1 + m_text_height * 2.0 ,m_y1 + m_text_height / 5.0 ); + m_text.size_ (m_text_height ,m_text_width ); + + m_text_poly.width_ (m_text_thickness ); + m_text_poly.line_join_(round_join ); + m_text_poly.line_cap_ (round_cap ); + + m_text_poly.rewind(0 ); + + end; + + 2 : // Active item + begin + m_vertex:=0; + + d2:=(m_y2 - m_y1 ) / 2.0; + t :=m_text_thickness * 1.5; + + m_vx[0 ]:=m_x1 + m_text_thickness; + m_vy[0 ]:=m_y1 + m_text_thickness; + m_vx[1 ]:=m_x1 + d2; + m_vy[1 ]:=m_y1 + d2 - t; + m_vx[2 ]:=m_x2 - m_text_thickness; + m_vy[2 ]:=m_y1 + m_text_thickness; + m_vx[3 ]:=m_x1 + d2 + t; + m_vy[3 ]:=m_y1 + d2; + m_vx[4 ]:=m_x2 - m_text_thickness; + m_vy[4 ]:=m_y2 - m_text_thickness; + m_vx[5 ]:=m_x1 + d2; + m_vy[5 ]:=m_y1 + d2 + t; + m_vx[6 ]:=m_x1 + m_text_thickness; + m_vy[6 ]:=m_y2 - m_text_thickness; + m_vx[7 ]:=m_x1 + d2 - t; + m_vy[7 ]:=m_y1 + d2; + + end; + + end; + +end; + +{ VERTEX } +function cbox_ctrl_impl.vertex; +var + cmd : unsigned; + +begin + cmd:=path_cmd_line_to; + + case m_idx of + 0 : + begin + if (m_vertex = 0 ) or + (m_vertex = 4 ) then + cmd:=path_cmd_move_to; + + if m_vertex >= 8then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 1 : + cmd:=m_text_poly.vertex(x ,y ); + + 2 : + if m_status then + begin + if m_vertex = 0 then + cmd:=path_cmd_move_to; + + if m_vertex >= 8 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end + else + cmd:=path_cmd_stop; + + else + cmd:=path_cmd_stop; + + end; + + if not is_stop(cmd ) then + transform_xy(x ,y ); + + result:=cmd; + +end; + +{ CONSTRUCT } +constructor cbox_ctrl.Construct; +begin + inherited Construct(x ,y ,l ,flip_y ); + + m_text_color.ConstrDbl (0.0 ,0.0 ,0.0 ); + m_inactive_color.ConstrDbl(0.0 ,0.0 ,0.0 ); + m_active_color.ConstrDbl (0.4 ,0.0 ,0.0 ); + + m_colors[0 ]:=@m_inactive_color; + m_colors[1 ]:=@m_text_color; + m_colors[2 ]:=@m_active_color; + +end; + +{ TEXT_COLOR_ } +procedure cbox_ctrl.text_color_; +begin + m_text_color:=c^; + +end; + +{ INACTIVE_COLOR_ } +procedure cbox_ctrl.inactive_color_; +begin + m_inactive_color:=c^; + +end; + +{ ACTIVE_COLOR_ } +procedure cbox_ctrl.active_color_; +begin + m_active_color:=c^; + +end; + +{ _COLOR } +function cbox_ctrl._color; +begin + result:=m_colors[i ]; + +end; + +END. + diff --git a/src/corelib/render/software/ctrl/agg_ctrl.pas b/src/corelib/render/software/ctrl/agg_ctrl.pas index 0c8d198e..81372532 100644 --- a/src/corelib/render/software/ctrl/agg_ctrl.pas +++ b/src/corelib/render/software/ctrl/agg_ctrl.pas @@ -1,223 +1,223 @@ -//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4 (Public License)
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
-// Pascal Port By: Milan Marusinec alias Milano
-// milan@marusinec.sk
-// http://www.aggpas.org
-// Copyright (c) 2005-2006
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//
-//----------------------------------------------------------------------------
-//
-// Function render_ctrl
-//
-// [Pascal Port History] -----------------------------------------------------
-//
-// 13.12.2005-Milano: Unit port establishment
-//
-{ agg_ctrl.pas }
-unit
- agg_ctrl ;
-
-INTERFACE
-
-{$I agg_mode.inc }
-
-uses
- agg_basics ,
- agg_trans_affine ,
- agg_rasterizer_scanline_aa ,
- agg_scanline ,
- agg_renderer_scanline ,
- agg_render_scanlines ,
- agg_vertex_source ,
- agg_color ;
-
-{ TYPES DEFINITION }
-type
- ctrl_ptr = ^ctrl;
- ctrl = object(vertex_source )
- m_x1 ,
- m_y1 ,
- m_x2 ,
- m_y2 : double;
-
- m_flip_y : boolean;
-
- m_mtx : trans_affine_ptr;
-
- constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean );
- destructor Destruct; virtual;
-
- function in_rect(x ,y : double ) : boolean; virtual;
-
- function on_mouse_button_down(x ,y : double ) : boolean; virtual;
- function on_mouse_button_up (x ,y : double ) : boolean; virtual;
-
- function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual;
- function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual;
-
- procedure transform(mtx : trans_affine_ptr );
- procedure no_transform;
-
- procedure transform_xy(x ,y : double_ptr );
-
- procedure inverse_transform_xy(x ,y : double_ptr );
-
- function scale : double;
-
- function _color(i : unsigned ) : aggclr_ptr; virtual;
-
- end;
-
-{ GLOBAL PROCEDURES }
- procedure render_ctrl(ras : rasterizer_scanline_ptr; sl : scanline_ptr; r : renderer_scanline_ptr; c : ctrl_ptr );
-
-
-IMPLEMENTATION
-{ LOCAL VARIABLES & CONSTANTS }
-{ UNIT IMPLEMENTATION }
-{ CONSTRUCT }
-constructor ctrl.Construct;
-begin
- inherited Construct;
-
- m_x1:=x1;
- m_y1:=y1;
- m_x2:=x2;
- m_y2:=y2;
-
- m_flip_y:=flip_y;
-
- m_mtx:=NIL;
-
-end;
-
-{ DESTRUCT }
-destructor ctrl.Destruct;
-begin
- inherited Destruct;
-
-end;
-
-{ IN_RECT }
-function ctrl.in_rect;
-begin
- result:=false;
-
-end;
-
-{ ON_MOUSE_BUTTON_DOWN }
-function ctrl.on_mouse_button_down;
-begin
- result:=false;
-
-end;
-
-{ ON_MOUSE_BUTTON_UP }
-function ctrl.on_mouse_button_up;
-begin
- result:=false;
-
-end;
-
-{ ON_MOUSE_MOVE }
-function ctrl.on_mouse_move;
-begin
- result:=false;
-
-end;
-
-{ ON_ARROW_KEYS }
-function ctrl.on_arrow_keys;
-begin
- result:=false;
-
-end;
-
-{ TRANSFORM }
-procedure ctrl.transform;
-begin
- m_mtx:=mtx;
-
-end;
-
-{ NO_TRANSFORM }
-procedure ctrl.no_transform;
-begin
- m_mtx:=NIL;
-
-end;
-
-{ TRANSFORM_XY }
-procedure ctrl.transform_xy;
-begin
- if m_flip_y then
- y^:=m_y1 + m_y2 - y^;
-
- if m_mtx <> NIL then
- m_mtx.transform(m_mtx ,x ,y );
-
-end;
-
-{ INVERSE_TRANSFORM_XY }
-procedure ctrl.inverse_transform_xy;
-begin
- if m_mtx <> NIL then
- m_mtx.inverse_transform(m_mtx ,x ,y );
-
- if m_flip_y then
- y^:=m_y1 + m_y2 - y^;
-
-end;
-
-{ SCALE }
-function ctrl.scale;
-begin
- if m_mtx <> NIL then
- result:=m_mtx.scale
- else
- result:=1.0;
-
-end;
-
-{ _COLOR }
-function ctrl._color;
-begin
- result:=NIL;
-
-end;
-
-{ RENDER_CTRL }
-procedure render_ctrl;
-var
- i : unsigned;
-
-begin
- if c.num_paths > 0 then
- for i:=0 to c.num_paths - 1 do
- begin
- ras.reset;
- ras.add_path(c ,i );
-
- r.color_(c._color(i ) );
-
- render_scanlines(ras ,sl ,r );
-
- end;
-
-end;
-
-END.
-
+//---------------------------------------------------------------------------- +// Anti-Grain Geometry - Version 2.4 (Public License) +// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) +// +// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) +// Pascal Port By: Milan Marusinec alias Milano +// milan@marusinec.sk +// http://www.aggpas.org +// Copyright (c) 2005-2006 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +//---------------------------------------------------------------------------- +// Contact: mcseem@antigrain.com +// mcseemagg@yahoo.com +// http://www.antigrain.com +// +//---------------------------------------------------------------------------- +// +// Function render_ctrl +// +// [Pascal Port History] ----------------------------------------------------- +// +// 13.12.2005-Milano: Unit port establishment +// +{ agg_ctrl.pas } +unit + agg_ctrl ; + +INTERFACE + +{$I agg_mode.inc } + +uses + agg_basics , + agg_trans_affine , + agg_rasterizer_scanline_aa , + agg_scanline , + agg_renderer_scanline , + agg_render_scanlines , + agg_vertex_source , + agg_color ; + +{ TYPES DEFINITION } +type + ctrl_ptr = ^ctrl; + ctrl = object(vertex_source ) + m_x1 , + m_y1 , + m_x2 , + m_y2 : double; + + m_flip_y : boolean; + + m_mtx : trans_affine_ptr; + + constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean ); + destructor Destruct; virtual; + + function in_rect(x ,y : double ) : boolean; virtual; + + function on_mouse_button_down(x ,y : double ) : boolean; virtual; + function on_mouse_button_up (x ,y : double ) : boolean; virtual; + + function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual; + function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual; + + procedure transform(mtx : trans_affine_ptr ); + procedure no_transform; + + procedure transform_xy(x ,y : double_ptr ); + + procedure inverse_transform_xy(x ,y : double_ptr ); + + function scale : double; + + function _color(i : unsigned ) : aggclr_ptr; virtual; + + end; + +{ GLOBAL PROCEDURES } + procedure render_ctrl(ras : rasterizer_scanline_ptr; sl : scanline_ptr; r : renderer_scanline_ptr; c : ctrl_ptr ); + + +IMPLEMENTATION +{ LOCAL VARIABLES & CONSTANTS } +{ UNIT IMPLEMENTATION } +{ CONSTRUCT } +constructor ctrl.Construct; +begin + inherited Construct; + + m_x1:=x1; + m_y1:=y1; + m_x2:=x2; + m_y2:=y2; + + m_flip_y:=flip_y; + + m_mtx:=NIL; + +end; + +{ DESTRUCT } +destructor ctrl.Destruct; +begin + inherited Destruct; + +end; + +{ IN_RECT } +function ctrl.in_rect; +begin + result:=false; + +end; + +{ ON_MOUSE_BUTTON_DOWN } +function ctrl.on_mouse_button_down; +begin + result:=false; + +end; + +{ ON_MOUSE_BUTTON_UP } +function ctrl.on_mouse_button_up; +begin + result:=false; + +end; + +{ ON_MOUSE_MOVE } +function ctrl.on_mouse_move; +begin + result:=false; + +end; + +{ ON_ARROW_KEYS } +function ctrl.on_arrow_keys; +begin + result:=false; + +end; + +{ TRANSFORM } +procedure ctrl.transform; +begin + m_mtx:=mtx; + +end; + +{ NO_TRANSFORM } +procedure ctrl.no_transform; +begin + m_mtx:=NIL; + +end; + +{ TRANSFORM_XY } +procedure ctrl.transform_xy; +begin + if m_flip_y then + y^:=m_y1 + m_y2 - y^; + + if m_mtx <> NIL then + m_mtx.transform(m_mtx ,x ,y ); + +end; + +{ INVERSE_TRANSFORM_XY } +procedure ctrl.inverse_transform_xy; +begin + if m_mtx <> NIL then + m_mtx.inverse_transform(m_mtx ,x ,y ); + + if m_flip_y then + y^:=m_y1 + m_y2 - y^; + +end; + +{ SCALE } +function ctrl.scale; +begin + if m_mtx <> NIL then + result:=m_mtx.scale + else + result:=1.0; + +end; + +{ _COLOR } +function ctrl._color; +begin + result:=NIL; + +end; + +{ RENDER_CTRL } +procedure render_ctrl; +var + i : unsigned; + +begin + if c.num_paths > 0 then + for i:=0 to c.num_paths - 1 do + begin + ras.reset; + ras.add_path(c ,i ); + + r.color_(c._color(i ) ); + + render_scanlines(ras ,sl ,r ); + + end; + +end; + +END. + diff --git a/src/corelib/render/software/ctrl/agg_gamma_ctrl.pas b/src/corelib/render/software/ctrl/agg_gamma_ctrl.pas index da79fdcf..1fc6e698 100644 --- a/src/corelib/render/software/ctrl/agg_gamma_ctrl.pas +++ b/src/corelib/render/software/ctrl/agg_gamma_ctrl.pas @@ -1,881 +1,881 @@ -//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4 (Public License)
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
-// Pascal Port By: Milan Marusinec alias Milano
-// milan@marusinec.sk
-// http://www.aggpas.org
-// Copyright (c) 2005-2006
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//
-// [Pascal Port History] -----------------------------------------------------
-//
-// 30.01.2006-Milano: Unit port establishment
-//
-{ agg_gamma_ctrl.pas }
-unit
- agg_gamma_ctrl ;
-
-INTERFACE
-
-{$I agg_mode.inc }
-
-uses
- SysUtils ,
- agg_basics ,
- agg_gamma_spline ,
- agg_ellipse ,
- agg_conv_stroke ,
- agg_gsv_text ,
- agg_trans_affine ,
- agg_color ,
- agg_ctrl ,
- agg_math ,
- agg_math_stroke ;
-
-{ TYPES DEFINITION }
-type
- gamma_ctrl_impl = object(ctrl )
- m_gamma_spline : gamma_spline;
-
- m_border_width ,
- m_border_extra ,
- m_curve_width ,
- m_grid_width ,
- m_text_thickness ,
- m_point_size ,
- m_text_height ,
- m_text_width ,
-
- m_xc1 ,
- m_yc1 ,
- m_xc2 ,
- m_yc2 ,
- m_xs1 ,
- m_ys1 ,
- m_xs2 ,
- m_ys2 ,
- m_xt1 ,
- m_yt1 ,
- m_xt2 ,
- m_yt2 : double;
-
- m_curve_poly : conv_stroke;
- m_ellipse : ellipse;
- m_text : gsv_text;
- m_text_poly : conv_stroke;
-
- m_idx ,
- m_vertex : unsigned;
-
- m_vx ,
- m_vy : array[0..31 ] of double;
-
- m_xp1 ,
- m_yp1 ,
- m_xp2 ,
- m_yp2 : double;
-
- m_p1_active : boolean;
- m_mouse_point : unsigned;
-
- m_pdx ,
- m_pdy : double;
-
- constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false );
- destructor Destruct; virtual;
-
- // Set other parameters
- procedure border_width_ (t : double; extra : double = 0.0 );
- procedure curve_width_ (t : double );
- procedure grid_width_ (t : double );
- procedure text_thickness_(t : double );
- procedure text_size_ (h : double; w : double = 0.0 );
- procedure point_size_ (s : double );
-
- // Event handlers. Just call them if the respective events
- // in your system occure. The functions return true if redrawing
- // is required.
- function in_rect(x ,y : double ) : boolean; virtual;
-
- function on_mouse_button_down(x ,y : double ) : boolean; virtual;
- function on_mouse_button_up (x ,y : double ) : boolean; virtual;
-
- function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual;
- function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual;
-
- procedure change_active_point;
-
- // A copy of gamma_spline interface
- procedure values(kx1 ,ky1 ,kx2 ,ky2 : double ); overload;
- procedure values(kx1 ,ky1 ,kx2 ,ky2 : double_ptr ); overload;
-
- function gamma : char_ptr;
- function _y(x : double ) : double;
-
- function func_operator_gamma(x : double ) : double; virtual;
-
- // Vertex soutce interface
- function num_paths : unsigned; virtual;
- procedure rewind(path_id : unsigned ); virtual;
- function vertex(x ,y : double_ptr ) : unsigned; virtual;
-
- // Private
- procedure calc_spline_box;
- procedure calc_points;
- procedure calc_values;
-
- end;
-
- gamma_ctrl = object(gamma_ctrl_impl )
- m_background_color ,
- m_border_color ,
- m_curve_color ,
- m_grid_color ,
- m_inactive_pnt_color ,
- m_active_pnt_color ,
- m_text_color : aggclr;
-
- m_colors : array[0..6 ] of aggclr_ptr;
-
- constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false );
-
- procedure background_color_ (c : aggclr_ptr );
- procedure border_color_ (c : aggclr_ptr );
- procedure curve_color_ (c : aggclr_ptr );
- procedure grid_color_ (c : aggclr_ptr );
- procedure inactive_pnt_color_(c : aggclr_ptr );
- procedure active_pnt_color_ (c : aggclr_ptr );
- procedure text_color_ (c : aggclr_ptr );
-
- function _color(i : unsigned ) : aggclr_ptr; virtual;
-
- end;
-
-{ GLOBAL PROCEDURES }
-
-
-IMPLEMENTATION
-{ LOCAL VARIABLES & CONSTANTS }
-{ UNIT IMPLEMENTATION }
-{ CONSTRUCT }
-constructor gamma_ctrl_impl.Construct;
-begin
- inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y );
-
- m_border_width :=2.0;
- m_border_extra :=0.0;
- m_curve_width :=2.0;
- m_grid_width :=0.2;
- m_text_thickness:=1.5;
- m_point_size :=5.0;
- m_text_height :=9.0;
- m_text_width :=0.0;
-
- m_xc1:=x1;
- m_yc1:=y1;
- m_xc2:=x2;
- m_yc2:=y2 - m_text_height * 2.0;
- m_xt1:=x1;
- m_yt1:=y2 - m_text_height * 2.0;
- m_xt2:=x2;
- m_yt2:=y2;
-
- m_gamma_spline.Construct;
- m_ellipse.Construct;
- m_curve_poly.Construct(@m_gamma_spline );
- m_text.Construct;
- m_text_poly.Construct (@m_text );
-
- m_idx :=0;
- m_vertex:=0;
-
- m_p1_active :=true;
- m_mouse_point:=0;
-
- m_pdx:=0.0;
- m_pdy:=0.0;
-
- calc_spline_box;
-
-end;
-
-{ DESTRUCT }
-destructor gamma_ctrl_impl.Destruct;
-begin
- m_gamma_spline.Destruct;
- m_curve_poly.Destruct;
- m_text.Destruct;
- m_text_poly.Destruct;
-
-end;
-
-{ BORDER_WIDTH_ }
-procedure gamma_ctrl_impl.border_width_;
-begin
- m_border_width:=t;
- m_border_extra:=extra;
-
- calc_spline_box;
-
-end;
-
-{ CURVE_WIDTH_ }
-procedure gamma_ctrl_impl.curve_width_;
-begin
- m_curve_width:=t;
-
-end;
-
-{ GRID_WIDTH_ }
-procedure gamma_ctrl_impl.grid_width_;
-begin
- m_grid_width:=t;
-
-end;
-
-{ TEXT_THICKNESS_ }
-procedure gamma_ctrl_impl.text_thickness_;
-begin
- m_text_thickness:=t;
-
-end;
-
-{ TEXT_SIZE_ }
-procedure gamma_ctrl_impl.text_size_;
-begin
- m_text_width :=w;
- m_text_height:=h;
-
- m_yc2:=m_y2 - m_text_height * 2.0;
- m_yt1:=m_y2 - m_text_height * 2.0;
-
- calc_spline_box;
-
-end;
-
-{ POINT_SIZE_ }
-procedure gamma_ctrl_impl.point_size_;
-begin
- m_point_size:=s;
-
-end;
-
-{ IN_RECT }
-function gamma_ctrl_impl.in_rect;
-begin
- inverse_transform_xy(@x ,@y );
-
- result:=
- (x >= m_x1 ) and
- (x <= m_x2 ) and
- (y >= m_y1 ) and
- (y <= m_y2 );
-
-end;
-
-{ ON_MOUSE_BUTTON_DOWN }
-function gamma_ctrl_impl.on_mouse_button_down;
-begin
- inverse_transform_xy(@x ,@y );
- calc_points;
-
- if calc_distance(x ,y ,m_xp1 ,m_yp1 ) <= m_point_size + 1 then
- begin
- m_mouse_point:=1;
-
- m_pdx:=m_xp1 - x;
- m_pdy:=m_yp1 - y;
-
- m_p1_active:=true;
-
- result:=true;
-
- exit;
-
- end;
-
- if calc_distance(x ,y ,m_xp2 ,m_yp2 ) <= m_point_size + 1 then
- begin
- m_mouse_point:=2;
-
- m_pdx:=m_xp2 - x;
- m_pdy:=m_yp2 - y;
-
- m_p1_active:=false;
-
- result:=true;
-
- exit;
-
- end;
-
- result:=false;
-
-end;
-
-{ ON_MOUSE_BUTTON_UP }
-function gamma_ctrl_impl.on_mouse_button_up;
-begin
- if m_mouse_point <> 0 then
- begin
- m_mouse_point:=0;
-
- result:=true;
-
- end
- else
- result:=false;
-
-end;
-
-{ ON_MOUSE_MOVE }
-function gamma_ctrl_impl.on_mouse_move;
-begin
- inverse_transform_xy(@x ,@y );
-
- if not button_flag then
- result:=on_mouse_button_up(x ,y )
- else
- begin
- if m_mouse_point = 1 then
- begin
- m_xp1:=x + m_pdx;
- m_yp1:=y + m_pdy;
-
- calc_values;
-
- result:=true;
-
- exit;
-
- end;
-
- if m_mouse_point = 2 then
- begin
- m_xp2:=x + m_pdx;
- m_yp2:=y + m_pdy;
-
- calc_values;
-
- result:=true;
-
- exit;
-
- end;
-
- result:=false;
-
- end;
-
-end;
-
-{ ON_ARROW_KEYS }
-function gamma_ctrl_impl.on_arrow_keys;
-var
- kx1 ,ky1 ,kx2 ,ky2 : double;
-
- ret : boolean;
-
-begin
- ret:=false;
-
- m_gamma_spline.values(@kx1 ,@ky1 ,@kx2 ,@ky2 );
-
- if m_p1_active then
- begin
- if left then
- begin
- kx1:=kx1 - 0.005;
- ret:=true;
-
- end;
-
- if right then
- begin
- kx1:=kx1 + 0.005;
- ret:=true;
-
- end;
-
- if down then
- begin
- ky1:=ky1 - 0.005;
- ret:=true;
-
- end;
-
- if up then
- begin
- ky1:=ky1 + 0.005;
- ret:=true;
-
- end;
-
- end
- else
- begin
- if left then
- begin
- kx2:=kx2 + 0.005;
- ret:=true;
-
- end;
-
- if right then
- begin
- kx2:=kx2 - 0.005;
- ret:=true;
-
- end;
-
- if down then
- begin
- ky2:=ky2 + 0.005;
- ret:=true;
-
- end;
-
- if up then
- begin
- ky2:=ky2 - 0.005;
- ret:= true;
-
- end;
-
- end;
-
- if ret then
- m_gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 );
-
- result:=ret;
-
-end;
-
-{ CHANGE_ACTIVE_POINT }
-procedure gamma_ctrl_impl.change_active_point;
-begin
- if m_p1_active then
- m_p1_active:=false
- else
- m_p1_active:=true;
-
-end;
-
-{ VALUES }
-procedure gamma_ctrl_impl.values(kx1 ,ky1 ,kx2 ,ky2 : double );
-begin
- m_gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 );
-
-end;
-
-{ VALUES }
-procedure gamma_ctrl_impl.values(kx1 ,ky1 ,kx2 ,ky2 : double_ptr );
-begin
- m_gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 );
-
-end;
-
-{ GAMMA }
-function gamma_ctrl_impl.gamma;
-begin
- result:=m_gamma_spline.gamma;
-
-end;
-
-{ _Y }
-function gamma_ctrl_impl._y;
-begin
- result:=m_gamma_spline._y(x );
-
-end;
-
-{ FUNC_OPERATOR_GAMMA }
-function gamma_ctrl_impl.func_operator_gamma;
-begin
- result:=m_gamma_spline._y(x );
-
-end;
-
-{ NUM_PATHS }
-function gamma_ctrl_impl.num_paths;
-begin
- result:=7;
-
-end;
-
-{ REWIND }
-procedure gamma_ctrl_impl.rewind;
-var
- kx1 ,ky1 ,kx2 ,ky2 : double;
-
- tbuf : array[0..31 ] of char;
-
-begin
- m_idx:=path_id;
-
- case path_id of
- 0 : // Background
- begin
- m_vertex:=0;
-
- m_vx[0 ]:=m_x1 - m_border_extra;
- m_vy[0 ]:=m_y1 - m_border_extra;
- m_vx[1 ]:=m_x2 + m_border_extra;
- m_vy[1 ]:=m_y1 - m_border_extra;
- m_vx[2 ]:=m_x2 + m_border_extra;
- m_vy[2 ]:=m_y2 + m_border_extra;
- m_vx[3 ]:=m_x1 - m_border_extra;
- m_vy[3 ]:=m_y2 + m_border_extra;
-
- end;
-
- 1 : // Border
- begin
- m_vertex:=0;
-
- m_vx[0 ]:=m_x1;
- m_vy[0 ]:=m_y1;
- m_vx[1 ]:=m_x2;
- m_vy[1 ]:=m_y1;
- m_vx[2 ]:=m_x2;
- m_vy[2 ]:=m_y2;
- m_vx[3 ]:=m_x1;
- m_vy[3 ]:=m_y2;
- m_vx[4 ]:=m_x1 + m_border_width;
- m_vy[4 ]:=m_y1 + m_border_width;
- m_vx[5 ]:=m_x1 + m_border_width;
- m_vy[5 ]:=m_y2 - m_border_width;
- m_vx[6 ]:=m_x2 - m_border_width;
- m_vy[6 ]:=m_y2 - m_border_width;
- m_vx[7 ]:=m_x2 - m_border_width;
- m_vy[7 ]:=m_y1 + m_border_width;
- m_vx[8 ]:=m_xc1 + m_border_width;
- m_vy[8 ]:=m_yc2 - m_border_width * 0.5;
- m_vx[9 ]:=m_xc2 - m_border_width;
- m_vy[9 ]:=m_yc2 - m_border_width * 0.5;
- m_vx[10 ]:=m_xc2 - m_border_width;
- m_vy[10 ]:=m_yc2 + m_border_width * 0.5;
- m_vx[11 ]:=m_xc1 + m_border_width;
- m_vy[11 ]:=m_yc2 + m_border_width * 0.5;
-
- end;
-
- 2 : // Curve
- begin
- m_gamma_spline.box(m_xs1 ,m_ys1 ,m_xs2 ,m_ys2 );
-
- m_curve_poly.width_(m_curve_width );
- m_curve_poly.rewind(0 );
-
- end;
-
- 3 : // Grid
- begin
- m_vertex:=0;
-
- m_vx[0 ]:=m_xs1;
- m_vy[0 ]:=(m_ys1 + m_ys2) * 0.5 - m_grid_width * 0.5;
- m_vx[1 ]:=m_xs2;
- m_vy[1 ]:=(m_ys1 + m_ys2) * 0.5 - m_grid_width * 0.5;
- m_vx[2 ]:=m_xs2;
- m_vy[2 ]:=(m_ys1 + m_ys2) * 0.5 + m_grid_width * 0.5;
- m_vx[3 ]:=m_xs1;
- m_vy[3 ]:=(m_ys1 + m_ys2) * 0.5 + m_grid_width * 0.5;
- m_vx[4 ]:=(m_xs1 + m_xs2) * 0.5 - m_grid_width * 0.5;
- m_vy[4 ]:=m_ys1;
- m_vx[5 ]:=(m_xs1 + m_xs2) * 0.5 - m_grid_width * 0.5;
- m_vy[5 ]:=m_ys2;
- m_vx[6 ]:=(m_xs1 + m_xs2) * 0.5 + m_grid_width * 0.5;
- m_vy[6 ]:=m_ys2;
- m_vx[7 ]:=(m_xs1 + m_xs2) * 0.5 + m_grid_width * 0.5;
- m_vy[7 ]:=m_ys1;
-
- calc_points;
-
- m_vx[8 ]:=m_xs1;
- m_vy[8 ]:=m_yp1 - m_grid_width * 0.5;
- m_vx[9 ]:=m_xp1 - m_grid_width * 0.5;
- m_vy[9 ]:=m_yp1 - m_grid_width * 0.5;
- m_vx[10 ]:=m_xp1 - m_grid_width * 0.5;
- m_vy[10 ]:=m_ys1;
- m_vx[11 ]:=m_xp1 + m_grid_width * 0.5;
- m_vy[11 ]:=m_ys1;
- m_vx[12 ]:=m_xp1 + m_grid_width * 0.5;
- m_vy[12 ]:=m_yp1 + m_grid_width * 0.5;
- m_vx[13 ]:=m_xs1;
- m_vy[13 ]:=m_yp1 + m_grid_width * 0.5;
- m_vx[14 ]:=m_xs2;
- m_vy[14 ]:=m_yp2 + m_grid_width * 0.5;
- m_vx[15 ]:=m_xp2 + m_grid_width * 0.5;
- m_vy[15 ]:=m_yp2 + m_grid_width * 0.5;
- m_vx[16 ]:=m_xp2 + m_grid_width * 0.5;
- m_vy[16 ]:=m_ys2;
- m_vx[17 ]:=m_xp2 - m_grid_width * 0.5;
- m_vy[17 ]:=m_ys2;
- m_vx[18 ]:=m_xp2 - m_grid_width * 0.5;
- m_vy[18 ]:=m_yp2 - m_grid_width * 0.5;
- m_vx[19 ]:=m_xs2;
- m_vy[19 ]:=m_yp2 - m_grid_width * 0.5;
-
- end;
-
- 4 : // Point1
- begin
- calc_points;
-
- if m_p1_active then
- m_ellipse.init(m_xp2 ,m_yp2 ,m_point_size ,m_point_size ,32 )
- else
- m_ellipse.init(m_xp1 ,m_yp1 ,m_point_size ,m_point_size ,32 );
-
- end;
-
- 5 : // Point2
- begin
- calc_points;
-
- if m_p1_active then
- m_ellipse.init(m_xp1 ,m_yp1 ,m_point_size ,m_point_size ,32 )
- else
- m_ellipse.init(m_xp2 ,m_yp2 ,m_point_size ,m_point_size ,32 );
-
- end;
-
- 6 : // Text
- begin
- m_gamma_spline.values(@kx1 ,@ky1 ,@kx2 ,@ky2 );
-
- sprintf(@tbuf[0] , '%.3f '#0 ,kx1 );
- sprintf(@tbuf[StrLen(@tbuf[0 ] ) ] ,'%.3f '#0 ,ky1 );
- sprintf(@tbuf[StrLen(@tbuf[0 ] ) ] ,'%.3f '#0 ,kx2 );
- sprintf(@tbuf[StrLen(@tbuf[0 ] ) ] ,'%.3f'#0 ,ky2 );
-
- m_text.text_(@tbuf[0 ] );
- m_text.size_(m_text_height ,m_text_width );
-
- m_text.start_point_(m_xt1 + m_border_width * 2.0 ,(m_yt1 + m_yt2 ) * 0.5 - m_text_height * 0.5 );
- m_text_poly.width_(m_text_thickness );
-
- m_text_poly.line_join_(round_join );
- m_text_poly.line_cap_ (round_cap );
-
- m_text_poly.rewind(0);
-
- end;
-
- end;
-
-end;
-
-{ VERTEX }
-function gamma_ctrl_impl.vertex;
-var
- cmd : unsigned;
-
-begin
- cmd:=path_cmd_line_to;
-
- case m_idx of
- 0 :
- begin
- if m_vertex = 0 then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 4 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 1 :
- begin
- if (m_vertex = 0 ) or
- (m_vertex = 4 ) or
- (m_vertex = 8 ) then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 12 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 2 :
- cmd:=m_curve_poly.vertex(x ,y );
-
- 3 :
- begin
- if (m_vertex = 0 ) or
- (m_vertex = 4 ) or
- (m_vertex = 8 ) or
- (m_vertex = 14 ) then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 20 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 4 ,5 :
- cmd:=m_ellipse.vertex(x ,y );
-
- 6 :
- cmd:=m_text_poly.vertex(x ,y );
-
- else
- cmd:=path_cmd_stop;
-
- end;
-
- if not is_stop(cmd ) then
- transform_xy(x ,y );
-
- result:=cmd;
-
-end;
-
-{ CALC_SPLINE_BOX }
-procedure gamma_ctrl_impl.calc_spline_box;
-begin
- m_xs1:=m_xc1 + m_border_width;
- m_ys1:=m_yc1 + m_border_width;
- m_xs2:=m_xc2 - m_border_width;
- m_ys2:=m_yc2 - m_border_width * 0.5;
-
-end;
-
-{ CALC_POINTS }
-procedure gamma_ctrl_impl.calc_points;
-var
- kx1 ,ky1 ,kx2 ,ky2 : double;
-
-begin
- m_gamma_spline.values(@kx1 ,@ky1 ,@kx2 ,@ky2 );
-
- m_xp1:=m_xs1 + (m_xs2 - m_xs1 ) * kx1 * 0.25;
- m_yp1:=m_ys1 + (m_ys2 - m_ys1 ) * ky1 * 0.25;
- m_xp2:=m_xs2 - (m_xs2 - m_xs1 ) * kx2 * 0.25;
- m_yp2:=m_ys2 - (m_ys2 - m_ys1 ) * ky2 * 0.25;
-
-end;
-
-{ CALC_VALUES }
-procedure gamma_ctrl_impl.calc_values;
-var
- kx1 ,ky1 ,kx2 ,ky2 : double;
-
-begin
- kx1:=(m_xp1 - m_xs1 ) * 4.0 / (m_xs2 - m_xs1 );
- ky1:=(m_yp1 - m_ys1 ) * 4.0 / (m_ys2 - m_ys1 );
- kx2:=(m_xs2 - m_xp2 ) * 4.0 / (m_xs2 - m_xs1 );
- ky2:=(m_ys2 - m_yp2 ) * 4.0 / (m_ys2 - m_ys1 );
-
- m_gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 );
-
-end;
-
-{ CONSTRUCT }
-constructor gamma_ctrl.Construct;
-begin
- inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y );
-
- m_background_color.ConstrDbl (1.0 ,1.0 ,0.9 );
- m_border_color.ConstrDbl (0.0 ,0.0 ,0.0 );
- m_curve_color.ConstrDbl (0.0 ,0.0 ,0.0 );
- m_grid_color.ConstrDbl (0.2 ,0.2 ,0.0 );
- m_inactive_pnt_color.ConstrDbl(0.0 ,0.0 ,0.0 );
- m_active_pnt_color.ConstrDbl (1.0 ,0.0 ,0.0 );
- m_text_color.ConstrDbl (0.0 ,0.0 ,0.0 );
-
- m_colors[0 ]:=@m_background_color;
- m_colors[1 ]:=@m_border_color;
- m_colors[2 ]:=@m_curve_color;
- m_colors[3 ]:=@m_grid_color;
- m_colors[4 ]:=@m_inactive_pnt_color;
- m_colors[5 ]:=@m_active_pnt_color;
- m_colors[6 ]:=@m_text_color;
-
-end;
-
-{ BACKGROUND_COLOR_ }
-procedure gamma_ctrl.background_color_;
-begin
- m_background_color:=c^;
-
-end;
-
-{ BORDER_COLOR_ }
-procedure gamma_ctrl.border_color_;
-begin
- m_border_color:=c^;
-
-end;
-
-{ CURVE_COLOR_ }
-procedure gamma_ctrl.curve_color_;
-begin
- m_curve_color:=c^;
-
-end;
-
-{ GRID_COLOR_ }
-procedure gamma_ctrl.grid_color_;
-begin
- m_grid_color:=c^;
-
-end;
-
-{ INACTIVE_PNT_COLOR_ }
-procedure gamma_ctrl.inactive_pnt_color_;
-begin
- m_inactive_pnt_color:=c^;
-
-end;
-
-{ ACTIVE_PNT_COLOR_ }
-procedure gamma_ctrl.active_pnt_color_;
-begin
- m_active_pnt_color:=c^;
-
-end;
-
-{ TEXT_COLOR_ }
-procedure gamma_ctrl.text_color_;
-begin
- m_text_color:=c^;
-
-end;
-
-{ _COLOR }
-function gamma_ctrl._color;
-begin
- result:=m_colors[i ];
-
-end;
-
-END.
-
+//---------------------------------------------------------------------------- +// Anti-Grain Geometry - Version 2.4 (Public License) +// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) +// +// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) +// Pascal Port By: Milan Marusinec alias Milano +// milan@marusinec.sk +// http://www.aggpas.org +// Copyright (c) 2005-2006 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +//---------------------------------------------------------------------------- +// Contact: mcseem@antigrain.com +// mcseemagg@yahoo.com +// http://www.antigrain.com +// +// [Pascal Port History] ----------------------------------------------------- +// +// 30.01.2006-Milano: Unit port establishment +// +{ agg_gamma_ctrl.pas } +unit + agg_gamma_ctrl ; + +INTERFACE + +{$I agg_mode.inc } + +uses + SysUtils , + agg_basics , + agg_gamma_spline , + agg_ellipse , + agg_conv_stroke , + agg_gsv_text , + agg_trans_affine , + agg_color , + agg_ctrl , + agg_math , + agg_math_stroke ; + +{ TYPES DEFINITION } +type + gamma_ctrl_impl = object(ctrl ) + m_gamma_spline : gamma_spline; + + m_border_width , + m_border_extra , + m_curve_width , + m_grid_width , + m_text_thickness , + m_point_size , + m_text_height , + m_text_width , + + m_xc1 , + m_yc1 , + m_xc2 , + m_yc2 , + m_xs1 , + m_ys1 , + m_xs2 , + m_ys2 , + m_xt1 , + m_yt1 , + m_xt2 , + m_yt2 : double; + + m_curve_poly : conv_stroke; + m_ellipse : ellipse; + m_text : gsv_text; + m_text_poly : conv_stroke; + + m_idx , + m_vertex : unsigned; + + m_vx , + m_vy : array[0..31 ] of double; + + m_xp1 , + m_yp1 , + m_xp2 , + m_yp2 : double; + + m_p1_active : boolean; + m_mouse_point : unsigned; + + m_pdx , + m_pdy : double; + + constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false ); + destructor Destruct; virtual; + + // Set other parameters + procedure border_width_ (t : double; extra : double = 0.0 ); + procedure curve_width_ (t : double ); + procedure grid_width_ (t : double ); + procedure text_thickness_(t : double ); + procedure text_size_ (h : double; w : double = 0.0 ); + procedure point_size_ (s : double ); + + // Event handlers. Just call them if the respective events + // in your system occure. The functions return true if redrawing + // is required. + function in_rect(x ,y : double ) : boolean; virtual; + + function on_mouse_button_down(x ,y : double ) : boolean; virtual; + function on_mouse_button_up (x ,y : double ) : boolean; virtual; + + function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual; + function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual; + + procedure change_active_point; + + // A copy of gamma_spline interface + procedure values(kx1 ,ky1 ,kx2 ,ky2 : double ); overload; + procedure values(kx1 ,ky1 ,kx2 ,ky2 : double_ptr ); overload; + + function gamma : char_ptr; + function _y(x : double ) : double; + + function func_operator_gamma(x : double ) : double; virtual; + + // Vertex soutce interface + function num_paths : unsigned; virtual; + procedure rewind(path_id : unsigned ); virtual; + function vertex(x ,y : double_ptr ) : unsigned; virtual; + + // Private + procedure calc_spline_box; + procedure calc_points; + procedure calc_values; + + end; + + gamma_ctrl = object(gamma_ctrl_impl ) + m_background_color , + m_border_color , + m_curve_color , + m_grid_color , + m_inactive_pnt_color , + m_active_pnt_color , + m_text_color : aggclr; + + m_colors : array[0..6 ] of aggclr_ptr; + + constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false ); + + procedure background_color_ (c : aggclr_ptr ); + procedure border_color_ (c : aggclr_ptr ); + procedure curve_color_ (c : aggclr_ptr ); + procedure grid_color_ (c : aggclr_ptr ); + procedure inactive_pnt_color_(c : aggclr_ptr ); + procedure active_pnt_color_ (c : aggclr_ptr ); + procedure text_color_ (c : aggclr_ptr ); + + function _color(i : unsigned ) : aggclr_ptr; virtual; + + end; + +{ GLOBAL PROCEDURES } + + +IMPLEMENTATION +{ LOCAL VARIABLES & CONSTANTS } +{ UNIT IMPLEMENTATION } +{ CONSTRUCT } +constructor gamma_ctrl_impl.Construct; +begin + inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y ); + + m_border_width :=2.0; + m_border_extra :=0.0; + m_curve_width :=2.0; + m_grid_width :=0.2; + m_text_thickness:=1.5; + m_point_size :=5.0; + m_text_height :=9.0; + m_text_width :=0.0; + + m_xc1:=x1; + m_yc1:=y1; + m_xc2:=x2; + m_yc2:=y2 - m_text_height * 2.0; + m_xt1:=x1; + m_yt1:=y2 - m_text_height * 2.0; + m_xt2:=x2; + m_yt2:=y2; + + m_gamma_spline.Construct; + m_ellipse.Construct; + m_curve_poly.Construct(@m_gamma_spline ); + m_text.Construct; + m_text_poly.Construct (@m_text ); + + m_idx :=0; + m_vertex:=0; + + m_p1_active :=true; + m_mouse_point:=0; + + m_pdx:=0.0; + m_pdy:=0.0; + + calc_spline_box; + +end; + +{ DESTRUCT } +destructor gamma_ctrl_impl.Destruct; +begin + m_gamma_spline.Destruct; + m_curve_poly.Destruct; + m_text.Destruct; + m_text_poly.Destruct; + +end; + +{ BORDER_WIDTH_ } +procedure gamma_ctrl_impl.border_width_; +begin + m_border_width:=t; + m_border_extra:=extra; + + calc_spline_box; + +end; + +{ CURVE_WIDTH_ } +procedure gamma_ctrl_impl.curve_width_; +begin + m_curve_width:=t; + +end; + +{ GRID_WIDTH_ } +procedure gamma_ctrl_impl.grid_width_; +begin + m_grid_width:=t; + +end; + +{ TEXT_THICKNESS_ } +procedure gamma_ctrl_impl.text_thickness_; +begin + m_text_thickness:=t; + +end; + +{ TEXT_SIZE_ } +procedure gamma_ctrl_impl.text_size_; +begin + m_text_width :=w; + m_text_height:=h; + + m_yc2:=m_y2 - m_text_height * 2.0; + m_yt1:=m_y2 - m_text_height * 2.0; + + calc_spline_box; + +end; + +{ POINT_SIZE_ } +procedure gamma_ctrl_impl.point_size_; +begin + m_point_size:=s; + +end; + +{ IN_RECT } +function gamma_ctrl_impl.in_rect; +begin + inverse_transform_xy(@x ,@y ); + + result:= + (x >= m_x1 ) and + (x <= m_x2 ) and + (y >= m_y1 ) and + (y <= m_y2 ); + +end; + +{ ON_MOUSE_BUTTON_DOWN } +function gamma_ctrl_impl.on_mouse_button_down; +begin + inverse_transform_xy(@x ,@y ); + calc_points; + + if calc_distance(x ,y ,m_xp1 ,m_yp1 ) <= m_point_size + 1 then + begin + m_mouse_point:=1; + + m_pdx:=m_xp1 - x; + m_pdy:=m_yp1 - y; + + m_p1_active:=true; + + result:=true; + + exit; + + end; + + if calc_distance(x ,y ,m_xp2 ,m_yp2 ) <= m_point_size + 1 then + begin + m_mouse_point:=2; + + m_pdx:=m_xp2 - x; + m_pdy:=m_yp2 - y; + + m_p1_active:=false; + + result:=true; + + exit; + + end; + + result:=false; + +end; + +{ ON_MOUSE_BUTTON_UP } +function gamma_ctrl_impl.on_mouse_button_up; +begin + if m_mouse_point <> 0 then + begin + m_mouse_point:=0; + + result:=true; + + end + else + result:=false; + +end; + +{ ON_MOUSE_MOVE } +function gamma_ctrl_impl.on_mouse_move; +begin + inverse_transform_xy(@x ,@y ); + + if not button_flag then + result:=on_mouse_button_up(x ,y ) + else + begin + if m_mouse_point = 1 then + begin + m_xp1:=x + m_pdx; + m_yp1:=y + m_pdy; + + calc_values; + + result:=true; + + exit; + + end; + + if m_mouse_point = 2 then + begin + m_xp2:=x + m_pdx; + m_yp2:=y + m_pdy; + + calc_values; + + result:=true; + + exit; + + end; + + result:=false; + + end; + +end; + +{ ON_ARROW_KEYS } +function gamma_ctrl_impl.on_arrow_keys; +var + kx1 ,ky1 ,kx2 ,ky2 : double; + + ret : boolean; + +begin + ret:=false; + + m_gamma_spline.values(@kx1 ,@ky1 ,@kx2 ,@ky2 ); + + if m_p1_active then + begin + if left then + begin + kx1:=kx1 - 0.005; + ret:=true; + + end; + + if right then + begin + kx1:=kx1 + 0.005; + ret:=true; + + end; + + if down then + begin + ky1:=ky1 - 0.005; + ret:=true; + + end; + + if up then + begin + ky1:=ky1 + 0.005; + ret:=true; + + end; + + end + else + begin + if left then + begin + kx2:=kx2 + 0.005; + ret:=true; + + end; + + if right then + begin + kx2:=kx2 - 0.005; + ret:=true; + + end; + + if down then + begin + ky2:=ky2 + 0.005; + ret:=true; + + end; + + if up then + begin + ky2:=ky2 - 0.005; + ret:= true; + + end; + + end; + + if ret then + m_gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 ); + + result:=ret; + +end; + +{ CHANGE_ACTIVE_POINT } +procedure gamma_ctrl_impl.change_active_point; +begin + if m_p1_active then + m_p1_active:=false + else + m_p1_active:=true; + +end; + +{ VALUES } +procedure gamma_ctrl_impl.values(kx1 ,ky1 ,kx2 ,ky2 : double ); +begin + m_gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 ); + +end; + +{ VALUES } +procedure gamma_ctrl_impl.values(kx1 ,ky1 ,kx2 ,ky2 : double_ptr ); +begin + m_gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 ); + +end; + +{ GAMMA } +function gamma_ctrl_impl.gamma; +begin + result:=m_gamma_spline.gamma; + +end; + +{ _Y } +function gamma_ctrl_impl._y; +begin + result:=m_gamma_spline._y(x ); + +end; + +{ FUNC_OPERATOR_GAMMA } +function gamma_ctrl_impl.func_operator_gamma; +begin + result:=m_gamma_spline._y(x ); + +end; + +{ NUM_PATHS } +function gamma_ctrl_impl.num_paths; +begin + result:=7; + +end; + +{ REWIND } +procedure gamma_ctrl_impl.rewind; +var + kx1 ,ky1 ,kx2 ,ky2 : double; + + tbuf : array[0..31 ] of char; + +begin + m_idx:=path_id; + + case path_id of + 0 : // Background + begin + m_vertex:=0; + + m_vx[0 ]:=m_x1 - m_border_extra; + m_vy[0 ]:=m_y1 - m_border_extra; + m_vx[1 ]:=m_x2 + m_border_extra; + m_vy[1 ]:=m_y1 - m_border_extra; + m_vx[2 ]:=m_x2 + m_border_extra; + m_vy[2 ]:=m_y2 + m_border_extra; + m_vx[3 ]:=m_x1 - m_border_extra; + m_vy[3 ]:=m_y2 + m_border_extra; + + end; + + 1 : // Border + begin + m_vertex:=0; + + m_vx[0 ]:=m_x1; + m_vy[0 ]:=m_y1; + m_vx[1 ]:=m_x2; + m_vy[1 ]:=m_y1; + m_vx[2 ]:=m_x2; + m_vy[2 ]:=m_y2; + m_vx[3 ]:=m_x1; + m_vy[3 ]:=m_y2; + m_vx[4 ]:=m_x1 + m_border_width; + m_vy[4 ]:=m_y1 + m_border_width; + m_vx[5 ]:=m_x1 + m_border_width; + m_vy[5 ]:=m_y2 - m_border_width; + m_vx[6 ]:=m_x2 - m_border_width; + m_vy[6 ]:=m_y2 - m_border_width; + m_vx[7 ]:=m_x2 - m_border_width; + m_vy[7 ]:=m_y1 + m_border_width; + m_vx[8 ]:=m_xc1 + m_border_width; + m_vy[8 ]:=m_yc2 - m_border_width * 0.5; + m_vx[9 ]:=m_xc2 - m_border_width; + m_vy[9 ]:=m_yc2 - m_border_width * 0.5; + m_vx[10 ]:=m_xc2 - m_border_width; + m_vy[10 ]:=m_yc2 + m_border_width * 0.5; + m_vx[11 ]:=m_xc1 + m_border_width; + m_vy[11 ]:=m_yc2 + m_border_width * 0.5; + + end; + + 2 : // Curve + begin + m_gamma_spline.box(m_xs1 ,m_ys1 ,m_xs2 ,m_ys2 ); + + m_curve_poly.width_(m_curve_width ); + m_curve_poly.rewind(0 ); + + end; + + 3 : // Grid + begin + m_vertex:=0; + + m_vx[0 ]:=m_xs1; + m_vy[0 ]:=(m_ys1 + m_ys2) * 0.5 - m_grid_width * 0.5; + m_vx[1 ]:=m_xs2; + m_vy[1 ]:=(m_ys1 + m_ys2) * 0.5 - m_grid_width * 0.5; + m_vx[2 ]:=m_xs2; + m_vy[2 ]:=(m_ys1 + m_ys2) * 0.5 + m_grid_width * 0.5; + m_vx[3 ]:=m_xs1; + m_vy[3 ]:=(m_ys1 + m_ys2) * 0.5 + m_grid_width * 0.5; + m_vx[4 ]:=(m_xs1 + m_xs2) * 0.5 - m_grid_width * 0.5; + m_vy[4 ]:=m_ys1; + m_vx[5 ]:=(m_xs1 + m_xs2) * 0.5 - m_grid_width * 0.5; + m_vy[5 ]:=m_ys2; + m_vx[6 ]:=(m_xs1 + m_xs2) * 0.5 + m_grid_width * 0.5; + m_vy[6 ]:=m_ys2; + m_vx[7 ]:=(m_xs1 + m_xs2) * 0.5 + m_grid_width * 0.5; + m_vy[7 ]:=m_ys1; + + calc_points; + + m_vx[8 ]:=m_xs1; + m_vy[8 ]:=m_yp1 - m_grid_width * 0.5; + m_vx[9 ]:=m_xp1 - m_grid_width * 0.5; + m_vy[9 ]:=m_yp1 - m_grid_width * 0.5; + m_vx[10 ]:=m_xp1 - m_grid_width * 0.5; + m_vy[10 ]:=m_ys1; + m_vx[11 ]:=m_xp1 + m_grid_width * 0.5; + m_vy[11 ]:=m_ys1; + m_vx[12 ]:=m_xp1 + m_grid_width * 0.5; + m_vy[12 ]:=m_yp1 + m_grid_width * 0.5; + m_vx[13 ]:=m_xs1; + m_vy[13 ]:=m_yp1 + m_grid_width * 0.5; + m_vx[14 ]:=m_xs2; + m_vy[14 ]:=m_yp2 + m_grid_width * 0.5; + m_vx[15 ]:=m_xp2 + m_grid_width * 0.5; + m_vy[15 ]:=m_yp2 + m_grid_width * 0.5; + m_vx[16 ]:=m_xp2 + m_grid_width * 0.5; + m_vy[16 ]:=m_ys2; + m_vx[17 ]:=m_xp2 - m_grid_width * 0.5; + m_vy[17 ]:=m_ys2; + m_vx[18 ]:=m_xp2 - m_grid_width * 0.5; + m_vy[18 ]:=m_yp2 - m_grid_width * 0.5; + m_vx[19 ]:=m_xs2; + m_vy[19 ]:=m_yp2 - m_grid_width * 0.5; + + end; + + 4 : // Point1 + begin + calc_points; + + if m_p1_active then + m_ellipse.init(m_xp2 ,m_yp2 ,m_point_size ,m_point_size ,32 ) + else + m_ellipse.init(m_xp1 ,m_yp1 ,m_point_size ,m_point_size ,32 ); + + end; + + 5 : // Point2 + begin + calc_points; + + if m_p1_active then + m_ellipse.init(m_xp1 ,m_yp1 ,m_point_size ,m_point_size ,32 ) + else + m_ellipse.init(m_xp2 ,m_yp2 ,m_point_size ,m_point_size ,32 ); + + end; + + 6 : // Text + begin + m_gamma_spline.values(@kx1 ,@ky1 ,@kx2 ,@ky2 ); + + sprintf(@tbuf[0] , '%.3f '#0 ,kx1 ); + sprintf(@tbuf[StrLen(@tbuf[0 ] ) ] ,'%.3f '#0 ,ky1 ); + sprintf(@tbuf[StrLen(@tbuf[0 ] ) ] ,'%.3f '#0 ,kx2 ); + sprintf(@tbuf[StrLen(@tbuf[0 ] ) ] ,'%.3f'#0 ,ky2 ); + + m_text.text_(@tbuf[0 ] ); + m_text.size_(m_text_height ,m_text_width ); + + m_text.start_point_(m_xt1 + m_border_width * 2.0 ,(m_yt1 + m_yt2 ) * 0.5 - m_text_height * 0.5 ); + m_text_poly.width_(m_text_thickness ); + + m_text_poly.line_join_(round_join ); + m_text_poly.line_cap_ (round_cap ); + + m_text_poly.rewind(0); + + end; + + end; + +end; + +{ VERTEX } +function gamma_ctrl_impl.vertex; +var + cmd : unsigned; + +begin + cmd:=path_cmd_line_to; + + case m_idx of + 0 : + begin + if m_vertex = 0 then + cmd:=path_cmd_move_to; + + if m_vertex >= 4 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 1 : + begin + if (m_vertex = 0 ) or + (m_vertex = 4 ) or + (m_vertex = 8 ) then + cmd:=path_cmd_move_to; + + if m_vertex >= 12 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 2 : + cmd:=m_curve_poly.vertex(x ,y ); + + 3 : + begin + if (m_vertex = 0 ) or + (m_vertex = 4 ) or + (m_vertex = 8 ) or + (m_vertex = 14 ) then + cmd:=path_cmd_move_to; + + if m_vertex >= 20 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 4 ,5 : + cmd:=m_ellipse.vertex(x ,y ); + + 6 : + cmd:=m_text_poly.vertex(x ,y ); + + else + cmd:=path_cmd_stop; + + end; + + if not is_stop(cmd ) then + transform_xy(x ,y ); + + result:=cmd; + +end; + +{ CALC_SPLINE_BOX } +procedure gamma_ctrl_impl.calc_spline_box; +begin + m_xs1:=m_xc1 + m_border_width; + m_ys1:=m_yc1 + m_border_width; + m_xs2:=m_xc2 - m_border_width; + m_ys2:=m_yc2 - m_border_width * 0.5; + +end; + +{ CALC_POINTS } +procedure gamma_ctrl_impl.calc_points; +var + kx1 ,ky1 ,kx2 ,ky2 : double; + +begin + m_gamma_spline.values(@kx1 ,@ky1 ,@kx2 ,@ky2 ); + + m_xp1:=m_xs1 + (m_xs2 - m_xs1 ) * kx1 * 0.25; + m_yp1:=m_ys1 + (m_ys2 - m_ys1 ) * ky1 * 0.25; + m_xp2:=m_xs2 - (m_xs2 - m_xs1 ) * kx2 * 0.25; + m_yp2:=m_ys2 - (m_ys2 - m_ys1 ) * ky2 * 0.25; + +end; + +{ CALC_VALUES } +procedure gamma_ctrl_impl.calc_values; +var + kx1 ,ky1 ,kx2 ,ky2 : double; + +begin + kx1:=(m_xp1 - m_xs1 ) * 4.0 / (m_xs2 - m_xs1 ); + ky1:=(m_yp1 - m_ys1 ) * 4.0 / (m_ys2 - m_ys1 ); + kx2:=(m_xs2 - m_xp2 ) * 4.0 / (m_xs2 - m_xs1 ); + ky2:=(m_ys2 - m_yp2 ) * 4.0 / (m_ys2 - m_ys1 ); + + m_gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 ); + +end; + +{ CONSTRUCT } +constructor gamma_ctrl.Construct; +begin + inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y ); + + m_background_color.ConstrDbl (1.0 ,1.0 ,0.9 ); + m_border_color.ConstrDbl (0.0 ,0.0 ,0.0 ); + m_curve_color.ConstrDbl (0.0 ,0.0 ,0.0 ); + m_grid_color.ConstrDbl (0.2 ,0.2 ,0.0 ); + m_inactive_pnt_color.ConstrDbl(0.0 ,0.0 ,0.0 ); + m_active_pnt_color.ConstrDbl (1.0 ,0.0 ,0.0 ); + m_text_color.ConstrDbl (0.0 ,0.0 ,0.0 ); + + m_colors[0 ]:=@m_background_color; + m_colors[1 ]:=@m_border_color; + m_colors[2 ]:=@m_curve_color; + m_colors[3 ]:=@m_grid_color; + m_colors[4 ]:=@m_inactive_pnt_color; + m_colors[5 ]:=@m_active_pnt_color; + m_colors[6 ]:=@m_text_color; + +end; + +{ BACKGROUND_COLOR_ } +procedure gamma_ctrl.background_color_; +begin + m_background_color:=c^; + +end; + +{ BORDER_COLOR_ } +procedure gamma_ctrl.border_color_; +begin + m_border_color:=c^; + +end; + +{ CURVE_COLOR_ } +procedure gamma_ctrl.curve_color_; +begin + m_curve_color:=c^; + +end; + +{ GRID_COLOR_ } +procedure gamma_ctrl.grid_color_; +begin + m_grid_color:=c^; + +end; + +{ INACTIVE_PNT_COLOR_ } +procedure gamma_ctrl.inactive_pnt_color_; +begin + m_inactive_pnt_color:=c^; + +end; + +{ ACTIVE_PNT_COLOR_ } +procedure gamma_ctrl.active_pnt_color_; +begin + m_active_pnt_color:=c^; + +end; + +{ TEXT_COLOR_ } +procedure gamma_ctrl.text_color_; +begin + m_text_color:=c^; + +end; + +{ _COLOR } +function gamma_ctrl._color; +begin + result:=m_colors[i ]; + +end; + +END. + diff --git a/src/corelib/render/software/ctrl/agg_gamma_spline.pas b/src/corelib/render/software/ctrl/agg_gamma_spline.pas index 7be50692..e061955c 100644 --- a/src/corelib/render/software/ctrl/agg_gamma_spline.pas +++ b/src/corelib/render/software/ctrl/agg_gamma_spline.pas @@ -1,265 +1,265 @@ -//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4 (Public License)
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
-// Pascal Port By: Milan Marusinec alias Milano
-// milan@marusinec.sk
-// http://www.aggpas.org
-// Copyright (c) 2005-2006
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//
-// [Pascal Port History] -----------------------------------------------------
-//
-// 30.01.2006-Milano: Unit port establishment
-//
-{ agg_gamma_spline.pas }
-unit
- agg_gamma_spline ;
-
-INTERFACE
-
-{$I agg_mode.inc }
-
-uses
- agg_basics ,
- agg_bspline ,
- agg_vertex_source ;
-
-{ TYPES DEFINITION }
-type
-// Class-helper for calculation gamma-correction arrays. A gamma-correction
-// array is an array of 256 unsigned chars that determine the actual values
-// of Anti-Aliasing for each pixel coverage value from 0 to 255. If all the
-// values in the array are equal to its index, i.e. 0,1,2,3,... there's
-// no gamma-correction. Class agg::polyfill allows you to use custom
-// gamma-correction arrays. You can calculate it using any approach, and
-// class gamma_spline allows you to calculate almost any reasonable shape
-// of the gamma-curve with using only 4 values - kx1, ky1, kx2, ky2.
-//
-// kx2
-// +----------------------------------+
-// | | | . |
-// | | | . | ky2
-// | | . ------|
-// | | . |
-// | | . |
-// |----------------.|----------------|
-// | . | |
-// | . | |
-// |-------. | |
-// ky1 | . | | |
-// | . | | |
-// +----------------------------------+
-// kx1
-//
-// Each value can be in range [0...2]. Value 1.0 means one quarter of the
-// bounding rectangle. Function values() calculates the curve by these
-// 4 values. After calling it one can get the gamma-array with call gamma().
-// Class also supports the vertex source interface, i.e rewind() and
-// vertex(). It's made for convinience and used in class gamma_ctrl.
-// Before calling rewind/vertex one must set the bounding box
-// box() using pixel coordinates.
- gamma_spline = object(vertex_source )
- m_gamma : array[0..255 ] of char;
-
- m_x ,
- m_y : array[0..3 ] of double;
- m_x1 ,
- m_y1 ,
- m_x2 ,
- m_y2 ,
-
- m_cur_x : double;
- m_spline : bspline;
-
- constructor Construct;
- destructor Destruct; virtual;
-
- procedure values(kx1 ,ky1 ,kx2 ,ky2 : double ); overload;
- procedure values(kx1 ,ky1 ,kx2 ,ky2 : double_ptr ); overload;
-
- function gamma : char_ptr;
- function _y (x : double ) : double;
- procedure box(x1 ,y1 ,x2 ,y2 : double );
-
- procedure rewind(path_id : unsigned ); virtual;
- function vertex(x ,y : double_ptr ) : unsigned; virtual;
-
- end;
-
-{ GLOBAL PROCEDURES }
-
-
-IMPLEMENTATION
-{ LOCAL VARIABLES & CONSTANTS }
-{ UNIT IMPLEMENTATION }
-{ CONSTRUCT }
-constructor gamma_spline.Construct;
-begin
- m_spline.Construct;
-
- m_x1:=0;
- m_y1:=0;
- m_x2:=10;
- m_y2:=10;
-
- m_cur_x:=0.0;
-
- values(1.0 ,1.0 ,1.0 ,1.0 );
-
-end;
-
-{ DESTRUCT }
-destructor gamma_spline.Destruct;
-begin
- m_spline.Destruct;
-
-end;
-
-{ VALUES }
-procedure gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 : double );
-var
- i : int;
-
-begin
- if kx1 < 0.001 then
- kx1:=0.001;
-
- if kx1 > 1.999 then
- kx1:=1.999;
-
- if ky1 < 0.001 then
- ky1:=0.001;
-
- if ky1 > 1.999 then
- ky1:=1.999;
-
- if kx2 < 0.001 then
- kx2:=0.001;
-
- if kx2 > 1.999 then
- kx2:=1.999;
-
- if ky2 < 0.001 then
- ky2:=0.001;
-
- if ky2 > 1.999 then
- ky2:=1.999;
-
- m_x[0 ]:=0.0;
- m_y[0 ]:=0.0;
- m_x[1 ]:=kx1 * 0.25;
- m_y[1 ]:=ky1 * 0.25;
- m_x[2 ]:=1.0 - kx2 * 0.25;
- m_y[2 ]:=1.0 - ky2 * 0.25;
- m_x[3 ]:=1.0;
- m_y[3 ]:=1.0;
-
- m_spline.init(4 ,@m_x ,@m_y );
-
- for i:=0 to 255 do
- m_gamma[i ]:=char(trunc(_y(i / 255.0 ) * 255.0 ) );
-
-end;
-
-{ VALUES }
-procedure gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 : double_ptr );
-begin
- kx1^:=m_x[1 ] * 4.0;
- ky1^:=m_y[1 ] * 4.0;
- kx2^:=(1.0 - m_x[2 ] ) * 4.0;
- ky2^:=(1.0 - m_y[2 ] ) * 4.0;
-
-end;
-
-{ GAMMA }
-function gamma_spline.gamma;
-begin
- result:=@m_gamma[0 ];
-
-end;
-
-{ _Y }
-function gamma_spline._y;
-var
- val : double;
-
-begin
- if x < 0.0 then
- x:=0.0;
-
- if x > 1.0 then
- x:=1.0;
-
- val:=m_spline.get(x );
-
- if val < 0.0 then
- val:=0.0;
-
- if val > 1.0 then
- val:=1.0;
-
- result:=val;
-
-end;
-
-{ BOX }
-procedure gamma_spline.box;
-begin
- m_x1:=x1;
- m_y1:=y1;
- m_x2:=x2;
- m_y2:=y2;
-
-end;
-
-{ REWIND }
-procedure gamma_spline.rewind;
-begin
- m_cur_x:=0.0;
-
-end;
-
-{ VERTEX }
-function gamma_spline.vertex;
-begin
- if m_cur_x = 0.0 then
- begin
- x^:=m_x1;
- y^:=m_y1;
-
- m_cur_x:=m_cur_x + (1.0 / (m_x2 - m_x1 ) );
- result :=path_cmd_move_to;
-
- exit;
-
- end;
-
- if m_cur_x > 1.0 then
- begin
- result:=path_cmd_stop;
-
- exit;
-
- end;
-
- x^:=m_x1 + m_cur_x * (m_x2 - m_x1 );
- y^:=m_y1 + _y(m_cur_x ) * (m_y2 - m_y1 );
-
- m_cur_x:=m_cur_x + (1.0 / (m_x2 - m_x1 ) );
- result :=path_cmd_line_to;
-
-end;
-
-END.
-
+//---------------------------------------------------------------------------- +// Anti-Grain Geometry - Version 2.4 (Public License) +// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) +// +// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) +// Pascal Port By: Milan Marusinec alias Milano +// milan@marusinec.sk +// http://www.aggpas.org +// Copyright (c) 2005-2006 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +//---------------------------------------------------------------------------- +// Contact: mcseem@antigrain.com +// mcseemagg@yahoo.com +// http://www.antigrain.com +// +// [Pascal Port History] ----------------------------------------------------- +// +// 30.01.2006-Milano: Unit port establishment +// +{ agg_gamma_spline.pas } +unit + agg_gamma_spline ; + +INTERFACE + +{$I agg_mode.inc } + +uses + agg_basics , + agg_bspline , + agg_vertex_source ; + +{ TYPES DEFINITION } +type +// Class-helper for calculation gamma-correction arrays. A gamma-correction +// array is an array of 256 unsigned chars that determine the actual values +// of Anti-Aliasing for each pixel coverage value from 0 to 255. If all the +// values in the array are equal to its index, i.e. 0,1,2,3,... there's +// no gamma-correction. Class agg::polyfill allows you to use custom +// gamma-correction arrays. You can calculate it using any approach, and +// class gamma_spline allows you to calculate almost any reasonable shape +// of the gamma-curve with using only 4 values - kx1, ky1, kx2, ky2. +// +// kx2 +// +----------------------------------+ +// | | | . | +// | | | . | ky2 +// | | . ------| +// | | . | +// | | . | +// |----------------.|----------------| +// | . | | +// | . | | +// |-------. | | +// ky1 | . | | | +// | . | | | +// +----------------------------------+ +// kx1 +// +// Each value can be in range [0...2]. Value 1.0 means one quarter of the +// bounding rectangle. Function values() calculates the curve by these +// 4 values. After calling it one can get the gamma-array with call gamma(). +// Class also supports the vertex source interface, i.e rewind() and +// vertex(). It's made for convinience and used in class gamma_ctrl. +// Before calling rewind/vertex one must set the bounding box +// box() using pixel coordinates. + gamma_spline = object(vertex_source ) + m_gamma : array[0..255 ] of char; + + m_x , + m_y : array[0..3 ] of double; + m_x1 , + m_y1 , + m_x2 , + m_y2 , + + m_cur_x : double; + m_spline : bspline; + + constructor Construct; + destructor Destruct; virtual; + + procedure values(kx1 ,ky1 ,kx2 ,ky2 : double ); overload; + procedure values(kx1 ,ky1 ,kx2 ,ky2 : double_ptr ); overload; + + function gamma : char_ptr; + function _y (x : double ) : double; + procedure box(x1 ,y1 ,x2 ,y2 : double ); + + procedure rewind(path_id : unsigned ); virtual; + function vertex(x ,y : double_ptr ) : unsigned; virtual; + + end; + +{ GLOBAL PROCEDURES } + + +IMPLEMENTATION +{ LOCAL VARIABLES & CONSTANTS } +{ UNIT IMPLEMENTATION } +{ CONSTRUCT } +constructor gamma_spline.Construct; +begin + m_spline.Construct; + + m_x1:=0; + m_y1:=0; + m_x2:=10; + m_y2:=10; + + m_cur_x:=0.0; + + values(1.0 ,1.0 ,1.0 ,1.0 ); + +end; + +{ DESTRUCT } +destructor gamma_spline.Destruct; +begin + m_spline.Destruct; + +end; + +{ VALUES } +procedure gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 : double ); +var + i : int; + +begin + if kx1 < 0.001 then + kx1:=0.001; + + if kx1 > 1.999 then + kx1:=1.999; + + if ky1 < 0.001 then + ky1:=0.001; + + if ky1 > 1.999 then + ky1:=1.999; + + if kx2 < 0.001 then + kx2:=0.001; + + if kx2 > 1.999 then + kx2:=1.999; + + if ky2 < 0.001 then + ky2:=0.001; + + if ky2 > 1.999 then + ky2:=1.999; + + m_x[0 ]:=0.0; + m_y[0 ]:=0.0; + m_x[1 ]:=kx1 * 0.25; + m_y[1 ]:=ky1 * 0.25; + m_x[2 ]:=1.0 - kx2 * 0.25; + m_y[2 ]:=1.0 - ky2 * 0.25; + m_x[3 ]:=1.0; + m_y[3 ]:=1.0; + + m_spline.init(4 ,@m_x ,@m_y ); + + for i:=0 to 255 do + m_gamma[i ]:=char(trunc(_y(i / 255.0 ) * 255.0 ) ); + +end; + +{ VALUES } +procedure gamma_spline.values(kx1 ,ky1 ,kx2 ,ky2 : double_ptr ); +begin + kx1^:=m_x[1 ] * 4.0; + ky1^:=m_y[1 ] * 4.0; + kx2^:=(1.0 - m_x[2 ] ) * 4.0; + ky2^:=(1.0 - m_y[2 ] ) * 4.0; + +end; + +{ GAMMA } +function gamma_spline.gamma; +begin + result:=@m_gamma[0 ]; + +end; + +{ _Y } +function gamma_spline._y; +var + val : double; + +begin + if x < 0.0 then + x:=0.0; + + if x > 1.0 then + x:=1.0; + + val:=m_spline.get(x ); + + if val < 0.0 then + val:=0.0; + + if val > 1.0 then + val:=1.0; + + result:=val; + +end; + +{ BOX } +procedure gamma_spline.box; +begin + m_x1:=x1; + m_y1:=y1; + m_x2:=x2; + m_y2:=y2; + +end; + +{ REWIND } +procedure gamma_spline.rewind; +begin + m_cur_x:=0.0; + +end; + +{ VERTEX } +function gamma_spline.vertex; +begin + if m_cur_x = 0.0 then + begin + x^:=m_x1; + y^:=m_y1; + + m_cur_x:=m_cur_x + (1.0 / (m_x2 - m_x1 ) ); + result :=path_cmd_move_to; + + exit; + + end; + + if m_cur_x > 1.0 then + begin + result:=path_cmd_stop; + + exit; + + end; + + x^:=m_x1 + m_cur_x * (m_x2 - m_x1 ); + y^:=m_y1 + _y(m_cur_x ) * (m_y2 - m_y1 ); + + m_cur_x:=m_cur_x + (1.0 / (m_x2 - m_x1 ) ); + result :=path_cmd_line_to; + +end; + +END. + diff --git a/src/corelib/render/software/ctrl/agg_polygon_ctrl.pas b/src/corelib/render/software/ctrl/agg_polygon_ctrl.pas index 881c9d60..2aa16ed7 100644 --- a/src/corelib/render/software/ctrl/agg_polygon_ctrl.pas +++ b/src/corelib/render/software/ctrl/agg_polygon_ctrl.pas @@ -1,769 +1,769 @@ -//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4 (Public License)
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
-// Pascal Port By: Milan Marusinec alias Milano
-// milan@marusinec.sk
-// http://www.aggpas.org
-// Copyright (c) 2005-2006
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//
-// [Pascal Port History] -----------------------------------------------------
-//
-// 23.06.2006-Milano: ptrcomp adjustments
-// 23.02.2006-Milano: Unit port establishment
-//
-{ agg_polygon_ctrl.pas }
-unit
- agg_polygon_ctrl ;
-
-INTERFACE
-
-{$I agg_mode.inc }
-
-uses
- Math ,
- agg_basics ,
- agg_conv_stroke ,
- agg_ellipse ,
- agg_color ,
- agg_ctrl ,
- agg_vertex_source ;
-
-{ TYPES DEFINITION }
-type
- simple_polygon_vertex_source = object(vertex_source )
- m_polygon : double_ptr;
- m_num_points ,
- m_vertex : unsigned;
- m_roundoff ,
- m_close : boolean;
-
- constructor Construct(polygon : double_ptr; np : unsigned; roundoff : boolean = false; close : boolean = true );
-
- procedure close_(f : boolean );
- function _close : boolean;
-
- procedure rewind(path_id : unsigned ); virtual;
- function vertex(x ,y : double_ptr ) : unsigned; virtual;
-
- end;
-
- polygon_ctrl_impl = object(ctrl )
- m_polygon : double_ptr;
- m_num_points : unsigned;
-
- m_node ,
- m_edge : int;
-
- m_vs : simple_polygon_vertex_source;
- m_stroke : conv_stroke;
-
- m_ellipse : ellipse;
- m_point_radius : double;
- m_status : unsigned;
-
- m_dx ,
- m_dy : double;
-
- m_in_polygon_check : boolean;
-
- constructor Construct(np : unsigned; point_radius : double = 5 );
- destructor Destruct; virtual;
-
- function _num_points : unsigned;
-
- function _xn(n : unsigned ) : double;
- function _yn(n : unsigned ) : double;
-
- function xn_ptr(n : unsigned ) : double_ptr;
- function yn_ptr(n : unsigned ) : double_ptr;
-
- function _polygon : double_ptr;
-
- procedure line_width_(w : double );
- function _line_width : double;
-
- procedure point_radius_(r : double );
- function _point_radius : double;
-
- procedure in_polygon_check_(f : boolean );
- function _in_polygon_check : boolean;
-
- procedure close_(f : boolean );
- function _close : boolean;
-
- // Vertex source interface
- function num_paths : unsigned; virtual;
- procedure rewind(path_id : unsigned ); virtual;
- function vertex(x ,y : double_ptr ) : unsigned; virtual;
-
- // Event handlers
- function in_rect(x ,y : double ) : boolean; virtual;
-
- function on_mouse_button_down(x ,y : double ) : boolean; virtual;
- function on_mouse_button_up (x ,y : double ) : boolean; virtual;
-
- function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual;
- function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual;
-
- // Private
- function check_edge (i : unsigned; x ,y : double ) : boolean;
- function point_in_polygon(x ,y : double ) : boolean;
-
- end;
-
- polygon_ctrl = object(polygon_ctrl_impl )
- m_color : aggclr;
-
- constructor Construct(np : unsigned; point_radius : double = 5 );
-
- procedure line_color_(c : aggclr_ptr );
-
- function _color(i : unsigned ) : aggclr_ptr; virtual;
-
- end;
-
-{ GLOBAL PROCEDURES }
-
-
-IMPLEMENTATION
-{ LOCAL VARIABLES & CONSTANTS }
-{ UNIT IMPLEMENTATION }
-{ CONSTRUCT }
-constructor simple_polygon_vertex_source.Construct;
-begin
- m_polygon :=polygon;
- m_num_points:=np;
- m_vertex :=0;
- m_roundoff :=roundoff;
- m_close :=close;
-
-end;
-
-{ CLOSE_ }
-procedure simple_polygon_vertex_source.close_;
-begin
- m_close:=f;
-
-end;
-
-{ _CLOSE }
-function simple_polygon_vertex_source._close;
-begin
- result:=m_close;
-
-end;
-
-{ REWIND }
-procedure simple_polygon_vertex_source.rewind;
-begin
- m_vertex:=0;
-
-end;
-
-{ VERTEX }
-function simple_polygon_vertex_source.vertex;
-begin
- if m_vertex > m_num_points then
- begin
- result:=path_cmd_stop;
-
- exit;
-
- end;
-
- if m_vertex = m_num_points then
- begin
- inc(m_vertex );
-
- if m_close then
- result:=path_cmd_end_poly or path_flags_close
- else
- result:=path_cmd_end_poly or 0;
-
- exit;
-
- end;
-
- x^:=double_ptr(ptrcomp(m_polygon ) + (m_vertex * 2 ) * sizeof(double ) )^;
- y^:=double_ptr(ptrcomp(m_polygon ) + (m_vertex * 2 + 1 ) * sizeof(double ) )^;
-
- if m_roundoff then
- begin
- x^:=Floor(x^ ) + 0.5;
- y^:=Floor(y^ ) + 0.5;
-
- end;
-
- inc(m_vertex );
-
- if m_vertex = 1 then
- result:=path_cmd_move_to
- else
- result:=path_cmd_line_to;
-
-end;
-
-{ CONSTRUCT }
-constructor polygon_ctrl_impl.Construct;
-begin
- inherited Construct(0 ,0 ,1 ,1 ,false );
-
- agg_getmem(pointer(m_polygon ) ,np * 2 * sizeof(double ) );
-
- m_num_points:=np;
-
- m_node:=-1;
- m_edge:=-1;
-
- m_vs.Construct (m_polygon ,m_num_points ,false );
- m_stroke.Construct(@m_vs );
- m_ellipse.Construct;
-
- m_point_radius:=point_radius;
-
- m_status:=0;
-
- m_dx:=0.0;
- m_dy:=0.0;
-
- m_in_polygon_check:=false;
-
- m_stroke.width_(1.0 );
-
-end;
-
-{ DESTRUCT }
-destructor polygon_ctrl_impl.Destruct;
-begin
- agg_freemem(pointer(m_polygon ) ,m_num_points * 2 * sizeof(double ) );
-
- m_stroke.Destruct;
-
-end;
-
-{ _NUM_POINTS }
-function polygon_ctrl_impl._num_points;
-begin
- result:=m_num_points;
-
-end;
-
-{ _XN }
-function polygon_ctrl_impl._xn;
-begin
- result:=double_ptr(ptrcomp(m_polygon ) + (n * 2 ) * sizeof(double ) )^;
-
-end;
-
-{ _YN }
-function polygon_ctrl_impl._yn;
-begin
- result:=double_ptr(ptrcomp(m_polygon ) + (n * 2 + 1 ) * sizeof(double ) )^;
-
-end;
-
-{ XN_PTR }
-function polygon_ctrl_impl.xn_ptr;
-begin
- result:=double_ptr(ptrcomp(m_polygon ) + (n * 2 ) * sizeof(double ) );
-
-end;
-
-{ YN_PTR }
-function polygon_ctrl_impl.yn_ptr;
-begin
- result:=double_ptr(ptrcomp(m_polygon ) + (n * 2 + 1 ) * sizeof(double ) );
-
-end;
-
-{ _POLYGON }
-function polygon_ctrl_impl._polygon;
-begin
- result:=m_polygon;
-
-end;
-
-{ LINE_WIDTH_ }
-procedure polygon_ctrl_impl.line_width_;
-begin
- m_stroke.width_(w );
-
-end;
-
-{ _LINE_WIDTH }
-function polygon_ctrl_impl._line_width;
-begin
- result:=m_stroke._width;
-
-end;
-
-{ POINT_RADIUS_ }
-procedure polygon_ctrl_impl.point_radius_;
-begin
- m_point_radius:=r;
-
-end;
-
-{ _POINT_RADIUS }
-function polygon_ctrl_impl._point_radius;
-begin
- result:=m_point_radius;
-
-end;
-
-{ IN_POLYGON_CHECK_ }
-procedure polygon_ctrl_impl.in_polygon_check_;
-begin
- m_in_polygon_check:=f;
-
-end;
-
-{ _IN_POLYGON_CHECK }
-function polygon_ctrl_impl._in_polygon_check;
-begin
- result:=m_in_polygon_check;
-
-end;
-
-{ CLOSE_ }
-procedure polygon_ctrl_impl.close_;
-begin
- m_vs.close_(f );
-
-end;
-
-{ _CLOSE }
-function polygon_ctrl_impl._close;
-begin
- result:=m_vs._close;
-
-end;
-
-{ NUM_PATHS }
-function polygon_ctrl_impl.num_paths;
-begin
- result:=1;
-
-end;
-
-{ REWIND }
-procedure polygon_ctrl_impl.rewind;
-begin
- m_status:=0;
-
- m_stroke.rewind(0 );
-
-end;
-
-{ VERTEX }
-function polygon_ctrl_impl.vertex;
-var
- cmd : unsigned;
- r : double;
-
-begin
- cmd:=path_cmd_stop;
- r :=m_point_radius;
-
- if m_status = 0 then
- begin
- cmd:=m_stroke.vertex(x ,y );
-
- if not is_stop(cmd ) then
- begin
- transform_xy(x ,y );
-
- result:=cmd;
-
- exit;
-
- end;
-
- if (m_node >= 0 ) and
- (m_node = m_status ) then
- r:=r * 1.2;
-
- m_ellipse.init(_xn(m_status ) ,_yn(m_status ) ,r ,r ,32 );
-
- inc(m_status );
-
- end;
-
- cmd:=m_ellipse.vertex(x ,y );
-
- if not is_stop(cmd ) then
- begin
- transform_xy(x ,y );
-
- result:=cmd;
-
- exit;
-
- end;
-
- if m_status >= m_num_points then
- begin
- result:=path_cmd_stop;
-
- exit;
-
- end;
-
- if (m_node >= 0 ) and
- (m_node = m_status ) then
- r:=r * 1.2;
-
- m_ellipse.init(_xn(m_status ) ,_yn(m_status ) ,r ,r ,32 );
-
- inc(m_status );
-
- cmd:=m_ellipse.vertex(x ,y );
-
- if not is_stop(cmd ) then
- transform_xy(x ,y );
-
- result:=cmd;
-
-end;
-
-{ IN_RECT }
-function polygon_ctrl_impl.in_rect;
-begin
- result:=false;
-
-end;
-
-{ ON_MOUSE_BUTTON_DOWN }
-function polygon_ctrl_impl.on_mouse_button_down;
-var
- i : unsigned;
- ret : boolean;
-
-begin
- ret:=false;
-
- m_node:=-1;
- m_edge:=-1;
-
- inverse_transform_xy(@x ,@y );
-
- for i:=0 to m_num_points - 1 do
- if Sqrt((x - _xn(i ) ) * (x - _xn(i ) ) + (y - _yn(i ) ) * (y - _yn(i ) ) ) < m_point_radius then
- begin
- m_dx :=x - _xn(i );
- m_dy :=y - _yn(i );
- m_node:=i;
- ret :=true;
-
- break;
-
- end;
-
- if not ret then
- for i:=0 to m_num_points - 1 do
- if check_edge(i ,x ,y ) then
- begin
- m_dx :=x;
- m_dy :=y;
- m_edge:=i;
- ret :=true;
-
- break;
-
- end;
-
- if not ret then
- if point_in_polygon(x ,y ) then
- begin
- m_dx :=x;
- m_dy :=y;
- m_node:=m_num_points;
- ret :=true;
-
- end;
-
- result:=ret;
-
-end;
-
-{ ON_MOUSE_BUTTON_UP }
-function polygon_ctrl_impl.on_mouse_button_up;
-var
- ret : boolean;
-
-begin
- ret :=(m_node >= 0 ) or (m_edge >= 0 );
- m_node:=-1;
- m_edge:=-1;
- result:=ret;
-
-end;
-
-{ ON_MOUSE_MOVE }
-function polygon_ctrl_impl.on_mouse_move;
-var
- ret : boolean;
-
- i ,n1 ,n2 : unsigned;
-
- dx ,dy : double;
-
-begin
- ret:=false;
-
- inverse_transform_xy(@x ,@y );
-
- if m_node = m_num_points then
- begin
- dx:=x - m_dx;
- dy:=y - m_dy;
-
- for i:=0 to m_num_points - 1 do
- begin
- xn_ptr(i )^:=_xn(i ) + dx;
- yn_ptr(i )^:=_yn(i ) + dy;
-
- end;
-
- m_dx:=x;
- m_dy:=y;
- ret :=true;
-
- end
- else
- if m_edge >= 0 then
- begin
- n1:=m_edge;
- n2:=(n1 + m_num_points - 1 ) mod m_num_points;
- dx:=x - m_dx;
- dy:=y - m_dy;
-
- xn_ptr(n1 )^:=_xn(n1 ) + dx;
- yn_ptr(n1 )^:=_yn(n1 ) + dy;
- xn_ptr(n2 )^:=_xn(n2 ) + dx;
- yn_ptr(n2 )^:=_yn(n2 ) + dy;
-
- m_dx:=x;
- m_dy:=y;
- ret :=true;
-
- end
- else
- if m_node >= 0 then
- begin
- xn_ptr(m_node )^:=x - m_dx;
- yn_ptr(m_node )^:=y - m_dy;
-
- ret:=true;
-
- end;
-
- result:=ret;
-
-end;
-
-{ ON_ARROW_KEYS }
-function polygon_ctrl_impl.on_arrow_keys;
-begin
- result:=false;
-
-end;
-
-{ CHECK_EDGE }
-function polygon_ctrl_impl.check_edge;
-var
- ret : boolean;
-
- n1 ,n2 : unsigned;
-
- x1 ,y1 ,x2 ,y2 ,dx ,dy ,x3 ,y3 ,x4 ,y4 ,den ,u1 ,xi ,yi : double;
-
-begin
- ret:=false;
-
- n1:=i;
- n2:=(i + m_num_points - 1 ) mod m_num_points;
- x1:=_xn(n1 );
- y1:=_yn(n1 );
- x2:=_xn(n2 );
- y2:=_yn(n2 );
-
- dx:=x2 - x1;
- dy:=y2 - y1;
-
- if Sqrt(dx * dx + dy * dy ) > 0.0000001 then
- begin
- x3:=x;
- y3:=y;
- x4:=x3 - dy;
- y4:=y3 + dx;
-
- den:=(y4 - y3 ) * (x2 - x1 ) - (x4 - x3 ) * (y2 - y1 );
- u1 :=((x4 - x3 ) * (y1 - y3 ) - (y4 - y3 ) * (x1 - x3 ) ) / den;
-
- xi:=x1 + u1 * (x2 - x1 );
- yi:=y1 + u1 * (y2 - y1 );
-
- dx:=xi - x;
- dy:=yi - y;
-
- if (u1 > 0.0 ) and
- (u1 < 1.0 ) and
- (Sqrt(dx * dx + dy * dy ) <= m_point_radius ) then
- ret:=true;
-
- end;
-
- result:=ret;
-
-end;
-
-{ POINT_IN_POLYGON }
-//======= Crossings Multiply algorithm of InsideTest ========================
-//
-// By Eric Haines, 3D/Eye Inc, erich@eye.com
-//
-// This version is usually somewhat faster than the original published in
-// Graphics Gems IV; by turning the division for testing the X axis crossing
-// into a tricky multiplication test this part of the test became faster,
-// which had the additional effect of making the test for "both to left or
-// both to right" a bit slower for triangles than simply computing the
-// intersection each time. The main increase is in triangle testing speed,
-// which was about 15% faster; all other polygon complexities were pretty much
-// the same as before. On machines where division is very expensive (not the
-// case on the HP 9000 series on which I tested) this test should be much
-// faster overall than the old code. Your mileage may (in fact, will) vary,
-// depending on the machine and the test data, but in general I believe this
-// code is both shorter and faster. This test was inspired by unpublished
-// Graphics Gems submitted by Joseph Samosky and Mark Haigh-Hutchinson.
-// Related work by Samosky is in:
-//
-// Samosky, Joseph, "SectionView: A system for interactively specifying and
-// visualizing sections through three-dimensional medical image data",
-// M.S. Thesis, Department of Electrical Engineering and Computer Science,
-// Massachusetts Institute of Technology, 1993.
-//
-// Shoot a test ray along +X axis. The strategy is to compare vertex Y values
-// to the testing point's Y and quickly discard edges which are entirely to one
-// side of the test ray. Note that CONVEX and WINDING code can be added as
-// for the CrossingsTest() code; it is left out here for clarity.
-//
-// Input 2D polygon _pgon_ with _numverts_ number of vertices and test point
-// _point_, returns 1 if inside, 0 if outside.
-function polygon_ctrl_impl.point_in_polygon;
-var
- j ,k : unsigned;
-
- yflag0 ,yflag1 ,inside_flag : int;
-
- vtx0 ,vty0 ,vtx1 ,vty1 : double;
-
-begin
- if m_num_points < 3 then
- begin
- result:=false;
-
- exit;
-
- end;
-
- if not m_in_polygon_check then
- begin
- result:=false;
-
- exit;
-
- end;
-
- vtx0:=_xn(m_num_points - 1 );
- vty0:=_yn(m_num_points - 1 );
-
-// get test bit for above/below X axis
- yflag0:=int(vty0 >= y);
-
- vtx1:=_xn(0 );
- vty1:=_yn(0 );
-
- inside_flag:=0;
-
- for j:=1 to m_num_points do
- begin
- yflag1:=int(vty1 >= y );
-
- // Check if endpoints straddle (are on opposite sides) of X axis
- // (i.e. the Y's differ); if so, +X ray could intersect this edge.
- // The old test also checked whether the endpoints are both to the
- // right or to the left of the test point. However, given the faster
- // intersection point computation used below, this test was found to
- // be a break-even proposition for most polygons and a loser for
- // triangles (where 50% or more of the edges which survive this test
- // will cross quadrants and so have to have the X intersection computed
- // anyway). I credit Joseph Samosky with inspiring me to try dropping
- // the "both left or both right" part of my code.
- if yflag0 <> yflag1 then
- // Check intersection of pgon segment with +X ray.
- // Note if >= point's X; if so, the ray hits it.
- // The division operation is avoided for the ">=" test by checking
- // the sign of the first vertex wrto the test point; idea inspired
- // by Joseph Samosky's and Mark Haigh-Hutchinson's different
- // polygon inclusion tests.
- if int((vty1 - y ) * (vtx0 - vtx1 ) >=
- (vtx1 - x ) * (vty0 - vty1 ) ) = yflag1 then
- inside_flag:=inside_flag xor 1;
-
- // Move to the next pair of vertices, retaining info as possible.
- yflag0:=yflag1;
- vtx0 :=vtx1;
- vty0 :=vty1;
-
- if j >= m_num_points then
- k:=j - m_num_points
- else
- k:=j;
-
- vtx1:=_xn(k );
- vty1:=_yn(k );
-
- end;
-
- result:=inside_flag <> 0;
-
-end;
-
-{ CONSTRUCT }
-constructor polygon_ctrl.Construct;
-begin
- inherited Construct(np ,point_radius );
-
- m_color.ConstrDbl(0.0 ,0.0 ,0.0 );
-
-end;
-
-{ LINE_COLOR_ }
-procedure polygon_ctrl.line_color_;
-begin
- m_color:=c^;
-
-end;
-
-{ _COLOR }
-function polygon_ctrl._color;
-begin
- result:=@m_color;
-
-end;
-
-END.
-
+//---------------------------------------------------------------------------- +// Anti-Grain Geometry - Version 2.4 (Public License) +// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) +// +// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) +// Pascal Port By: Milan Marusinec alias Milano +// milan@marusinec.sk +// http://www.aggpas.org +// Copyright (c) 2005-2006 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +//---------------------------------------------------------------------------- +// Contact: mcseem@antigrain.com +// mcseemagg@yahoo.com +// http://www.antigrain.com +// +// [Pascal Port History] ----------------------------------------------------- +// +// 23.06.2006-Milano: ptrcomp adjustments +// 23.02.2006-Milano: Unit port establishment +// +{ agg_polygon_ctrl.pas } +unit + agg_polygon_ctrl ; + +INTERFACE + +{$I agg_mode.inc } + +uses + Math , + agg_basics , + agg_conv_stroke , + agg_ellipse , + agg_color , + agg_ctrl , + agg_vertex_source ; + +{ TYPES DEFINITION } +type + simple_polygon_vertex_source = object(vertex_source ) + m_polygon : double_ptr; + m_num_points , + m_vertex : unsigned; + m_roundoff , + m_close : boolean; + + constructor Construct(polygon : double_ptr; np : unsigned; roundoff : boolean = false; close : boolean = true ); + + procedure close_(f : boolean ); + function _close : boolean; + + procedure rewind(path_id : unsigned ); virtual; + function vertex(x ,y : double_ptr ) : unsigned; virtual; + + end; + + polygon_ctrl_impl = object(ctrl ) + m_polygon : double_ptr; + m_num_points : unsigned; + + m_node , + m_edge : int; + + m_vs : simple_polygon_vertex_source; + m_stroke : conv_stroke; + + m_ellipse : ellipse; + m_point_radius : double; + m_status : unsigned; + + m_dx , + m_dy : double; + + m_in_polygon_check : boolean; + + constructor Construct(np : unsigned; point_radius : double = 5 ); + destructor Destruct; virtual; + + function _num_points : unsigned; + + function _xn(n : unsigned ) : double; + function _yn(n : unsigned ) : double; + + function xn_ptr(n : unsigned ) : double_ptr; + function yn_ptr(n : unsigned ) : double_ptr; + + function _polygon : double_ptr; + + procedure line_width_(w : double ); + function _line_width : double; + + procedure point_radius_(r : double ); + function _point_radius : double; + + procedure in_polygon_check_(f : boolean ); + function _in_polygon_check : boolean; + + procedure close_(f : boolean ); + function _close : boolean; + + // Vertex source interface + function num_paths : unsigned; virtual; + procedure rewind(path_id : unsigned ); virtual; + function vertex(x ,y : double_ptr ) : unsigned; virtual; + + // Event handlers + function in_rect(x ,y : double ) : boolean; virtual; + + function on_mouse_button_down(x ,y : double ) : boolean; virtual; + function on_mouse_button_up (x ,y : double ) : boolean; virtual; + + function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual; + function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual; + + // Private + function check_edge (i : unsigned; x ,y : double ) : boolean; + function point_in_polygon(x ,y : double ) : boolean; + + end; + + polygon_ctrl = object(polygon_ctrl_impl ) + m_color : aggclr; + + constructor Construct(np : unsigned; point_radius : double = 5 ); + + procedure line_color_(c : aggclr_ptr ); + + function _color(i : unsigned ) : aggclr_ptr; virtual; + + end; + +{ GLOBAL PROCEDURES } + + +IMPLEMENTATION +{ LOCAL VARIABLES & CONSTANTS } +{ UNIT IMPLEMENTATION } +{ CONSTRUCT } +constructor simple_polygon_vertex_source.Construct; +begin + m_polygon :=polygon; + m_num_points:=np; + m_vertex :=0; + m_roundoff :=roundoff; + m_close :=close; + +end; + +{ CLOSE_ } +procedure simple_polygon_vertex_source.close_; +begin + m_close:=f; + +end; + +{ _CLOSE } +function simple_polygon_vertex_source._close; +begin + result:=m_close; + +end; + +{ REWIND } +procedure simple_polygon_vertex_source.rewind; +begin + m_vertex:=0; + +end; + +{ VERTEX } +function simple_polygon_vertex_source.vertex; +begin + if m_vertex > m_num_points then + begin + result:=path_cmd_stop; + + exit; + + end; + + if m_vertex = m_num_points then + begin + inc(m_vertex ); + + if m_close then + result:=path_cmd_end_poly or path_flags_close + else + result:=path_cmd_end_poly or 0; + + exit; + + end; + + x^:=double_ptr(ptrcomp(m_polygon ) + (m_vertex * 2 ) * sizeof(double ) )^; + y^:=double_ptr(ptrcomp(m_polygon ) + (m_vertex * 2 + 1 ) * sizeof(double ) )^; + + if m_roundoff then + begin + x^:=Floor(x^ ) + 0.5; + y^:=Floor(y^ ) + 0.5; + + end; + + inc(m_vertex ); + + if m_vertex = 1 then + result:=path_cmd_move_to + else + result:=path_cmd_line_to; + +end; + +{ CONSTRUCT } +constructor polygon_ctrl_impl.Construct; +begin + inherited Construct(0 ,0 ,1 ,1 ,false ); + + agg_getmem(pointer(m_polygon ) ,np * 2 * sizeof(double ) ); + + m_num_points:=np; + + m_node:=-1; + m_edge:=-1; + + m_vs.Construct (m_polygon ,m_num_points ,false ); + m_stroke.Construct(@m_vs ); + m_ellipse.Construct; + + m_point_radius:=point_radius; + + m_status:=0; + + m_dx:=0.0; + m_dy:=0.0; + + m_in_polygon_check:=false; + + m_stroke.width_(1.0 ); + +end; + +{ DESTRUCT } +destructor polygon_ctrl_impl.Destruct; +begin + agg_freemem(pointer(m_polygon ) ,m_num_points * 2 * sizeof(double ) ); + + m_stroke.Destruct; + +end; + +{ _NUM_POINTS } +function polygon_ctrl_impl._num_points; +begin + result:=m_num_points; + +end; + +{ _XN } +function polygon_ctrl_impl._xn; +begin + result:=double_ptr(ptrcomp(m_polygon ) + (n * 2 ) * sizeof(double ) )^; + +end; + +{ _YN } +function polygon_ctrl_impl._yn; +begin + result:=double_ptr(ptrcomp(m_polygon ) + (n * 2 + 1 ) * sizeof(double ) )^; + +end; + +{ XN_PTR } +function polygon_ctrl_impl.xn_ptr; +begin + result:=double_ptr(ptrcomp(m_polygon ) + (n * 2 ) * sizeof(double ) ); + +end; + +{ YN_PTR } +function polygon_ctrl_impl.yn_ptr; +begin + result:=double_ptr(ptrcomp(m_polygon ) + (n * 2 + 1 ) * sizeof(double ) ); + +end; + +{ _POLYGON } +function polygon_ctrl_impl._polygon; +begin + result:=m_polygon; + +end; + +{ LINE_WIDTH_ } +procedure polygon_ctrl_impl.line_width_; +begin + m_stroke.width_(w ); + +end; + +{ _LINE_WIDTH } +function polygon_ctrl_impl._line_width; +begin + result:=m_stroke._width; + +end; + +{ POINT_RADIUS_ } +procedure polygon_ctrl_impl.point_radius_; +begin + m_point_radius:=r; + +end; + +{ _POINT_RADIUS } +function polygon_ctrl_impl._point_radius; +begin + result:=m_point_radius; + +end; + +{ IN_POLYGON_CHECK_ } +procedure polygon_ctrl_impl.in_polygon_check_; +begin + m_in_polygon_check:=f; + +end; + +{ _IN_POLYGON_CHECK } +function polygon_ctrl_impl._in_polygon_check; +begin + result:=m_in_polygon_check; + +end; + +{ CLOSE_ } +procedure polygon_ctrl_impl.close_; +begin + m_vs.close_(f ); + +end; + +{ _CLOSE } +function polygon_ctrl_impl._close; +begin + result:=m_vs._close; + +end; + +{ NUM_PATHS } +function polygon_ctrl_impl.num_paths; +begin + result:=1; + +end; + +{ REWIND } +procedure polygon_ctrl_impl.rewind; +begin + m_status:=0; + + m_stroke.rewind(0 ); + +end; + +{ VERTEX } +function polygon_ctrl_impl.vertex; +var + cmd : unsigned; + r : double; + +begin + cmd:=path_cmd_stop; + r :=m_point_radius; + + if m_status = 0 then + begin + cmd:=m_stroke.vertex(x ,y ); + + if not is_stop(cmd ) then + begin + transform_xy(x ,y ); + + result:=cmd; + + exit; + + end; + + if (m_node >= 0 ) and + (m_node = m_status ) then + r:=r * 1.2; + + m_ellipse.init(_xn(m_status ) ,_yn(m_status ) ,r ,r ,32 ); + + inc(m_status ); + + end; + + cmd:=m_ellipse.vertex(x ,y ); + + if not is_stop(cmd ) then + begin + transform_xy(x ,y ); + + result:=cmd; + + exit; + + end; + + if m_status >= m_num_points then + begin + result:=path_cmd_stop; + + exit; + + end; + + if (m_node >= 0 ) and + (m_node = m_status ) then + r:=r * 1.2; + + m_ellipse.init(_xn(m_status ) ,_yn(m_status ) ,r ,r ,32 ); + + inc(m_status ); + + cmd:=m_ellipse.vertex(x ,y ); + + if not is_stop(cmd ) then + transform_xy(x ,y ); + + result:=cmd; + +end; + +{ IN_RECT } +function polygon_ctrl_impl.in_rect; +begin + result:=false; + +end; + +{ ON_MOUSE_BUTTON_DOWN } +function polygon_ctrl_impl.on_mouse_button_down; +var + i : unsigned; + ret : boolean; + +begin + ret:=false; + + m_node:=-1; + m_edge:=-1; + + inverse_transform_xy(@x ,@y ); + + for i:=0 to m_num_points - 1 do + if Sqrt((x - _xn(i ) ) * (x - _xn(i ) ) + (y - _yn(i ) ) * (y - _yn(i ) ) ) < m_point_radius then + begin + m_dx :=x - _xn(i ); + m_dy :=y - _yn(i ); + m_node:=i; + ret :=true; + + break; + + end; + + if not ret then + for i:=0 to m_num_points - 1 do + if check_edge(i ,x ,y ) then + begin + m_dx :=x; + m_dy :=y; + m_edge:=i; + ret :=true; + + break; + + end; + + if not ret then + if point_in_polygon(x ,y ) then + begin + m_dx :=x; + m_dy :=y; + m_node:=m_num_points; + ret :=true; + + end; + + result:=ret; + +end; + +{ ON_MOUSE_BUTTON_UP } +function polygon_ctrl_impl.on_mouse_button_up; +var + ret : boolean; + +begin + ret :=(m_node >= 0 ) or (m_edge >= 0 ); + m_node:=-1; + m_edge:=-1; + result:=ret; + +end; + +{ ON_MOUSE_MOVE } +function polygon_ctrl_impl.on_mouse_move; +var + ret : boolean; + + i ,n1 ,n2 : unsigned; + + dx ,dy : double; + +begin + ret:=false; + + inverse_transform_xy(@x ,@y ); + + if m_node = m_num_points then + begin + dx:=x - m_dx; + dy:=y - m_dy; + + for i:=0 to m_num_points - 1 do + begin + xn_ptr(i )^:=_xn(i ) + dx; + yn_ptr(i )^:=_yn(i ) + dy; + + end; + + m_dx:=x; + m_dy:=y; + ret :=true; + + end + else + if m_edge >= 0 then + begin + n1:=m_edge; + n2:=(n1 + m_num_points - 1 ) mod m_num_points; + dx:=x - m_dx; + dy:=y - m_dy; + + xn_ptr(n1 )^:=_xn(n1 ) + dx; + yn_ptr(n1 )^:=_yn(n1 ) + dy; + xn_ptr(n2 )^:=_xn(n2 ) + dx; + yn_ptr(n2 )^:=_yn(n2 ) + dy; + + m_dx:=x; + m_dy:=y; + ret :=true; + + end + else + if m_node >= 0 then + begin + xn_ptr(m_node )^:=x - m_dx; + yn_ptr(m_node )^:=y - m_dy; + + ret:=true; + + end; + + result:=ret; + +end; + +{ ON_ARROW_KEYS } +function polygon_ctrl_impl.on_arrow_keys; +begin + result:=false; + +end; + +{ CHECK_EDGE } +function polygon_ctrl_impl.check_edge; +var + ret : boolean; + + n1 ,n2 : unsigned; + + x1 ,y1 ,x2 ,y2 ,dx ,dy ,x3 ,y3 ,x4 ,y4 ,den ,u1 ,xi ,yi : double; + +begin + ret:=false; + + n1:=i; + n2:=(i + m_num_points - 1 ) mod m_num_points; + x1:=_xn(n1 ); + y1:=_yn(n1 ); + x2:=_xn(n2 ); + y2:=_yn(n2 ); + + dx:=x2 - x1; + dy:=y2 - y1; + + if Sqrt(dx * dx + dy * dy ) > 0.0000001 then + begin + x3:=x; + y3:=y; + x4:=x3 - dy; + y4:=y3 + dx; + + den:=(y4 - y3 ) * (x2 - x1 ) - (x4 - x3 ) * (y2 - y1 ); + u1 :=((x4 - x3 ) * (y1 - y3 ) - (y4 - y3 ) * (x1 - x3 ) ) / den; + + xi:=x1 + u1 * (x2 - x1 ); + yi:=y1 + u1 * (y2 - y1 ); + + dx:=xi - x; + dy:=yi - y; + + if (u1 > 0.0 ) and + (u1 < 1.0 ) and + (Sqrt(dx * dx + dy * dy ) <= m_point_radius ) then + ret:=true; + + end; + + result:=ret; + +end; + +{ POINT_IN_POLYGON } +//======= Crossings Multiply algorithm of InsideTest ======================== +// +// By Eric Haines, 3D/Eye Inc, erich@eye.com +// +// This version is usually somewhat faster than the original published in +// Graphics Gems IV; by turning the division for testing the X axis crossing +// into a tricky multiplication test this part of the test became faster, +// which had the additional effect of making the test for "both to left or +// both to right" a bit slower for triangles than simply computing the +// intersection each time. The main increase is in triangle testing speed, +// which was about 15% faster; all other polygon complexities were pretty much +// the same as before. On machines where division is very expensive (not the +// case on the HP 9000 series on which I tested) this test should be much +// faster overall than the old code. Your mileage may (in fact, will) vary, +// depending on the machine and the test data, but in general I believe this +// code is both shorter and faster. This test was inspired by unpublished +// Graphics Gems submitted by Joseph Samosky and Mark Haigh-Hutchinson. +// Related work by Samosky is in: +// +// Samosky, Joseph, "SectionView: A system for interactively specifying and +// visualizing sections through three-dimensional medical image data", +// M.S. Thesis, Department of Electrical Engineering and Computer Science, +// Massachusetts Institute of Technology, 1993. +// +// Shoot a test ray along +X axis. The strategy is to compare vertex Y values +// to the testing point's Y and quickly discard edges which are entirely to one +// side of the test ray. Note that CONVEX and WINDING code can be added as +// for the CrossingsTest() code; it is left out here for clarity. +// +// Input 2D polygon _pgon_ with _numverts_ number of vertices and test point +// _point_, returns 1 if inside, 0 if outside. +function polygon_ctrl_impl.point_in_polygon; +var + j ,k : unsigned; + + yflag0 ,yflag1 ,inside_flag : int; + + vtx0 ,vty0 ,vtx1 ,vty1 : double; + +begin + if m_num_points < 3 then + begin + result:=false; + + exit; + + end; + + if not m_in_polygon_check then + begin + result:=false; + + exit; + + end; + + vtx0:=_xn(m_num_points - 1 ); + vty0:=_yn(m_num_points - 1 ); + +// get test bit for above/below X axis + yflag0:=int(vty0 >= y); + + vtx1:=_xn(0 ); + vty1:=_yn(0 ); + + inside_flag:=0; + + for j:=1 to m_num_points do + begin + yflag1:=int(vty1 >= y ); + + // Check if endpoints straddle (are on opposite sides) of X axis + // (i.e. the Y's differ); if so, +X ray could intersect this edge. + // The old test also checked whether the endpoints are both to the + // right or to the left of the test point. However, given the faster + // intersection point computation used below, this test was found to + // be a break-even proposition for most polygons and a loser for + // triangles (where 50% or more of the edges which survive this test + // will cross quadrants and so have to have the X intersection computed + // anyway). I credit Joseph Samosky with inspiring me to try dropping + // the "both left or both right" part of my code. + if yflag0 <> yflag1 then + // Check intersection of pgon segment with +X ray. + // Note if >= point's X; if so, the ray hits it. + // The division operation is avoided for the ">=" test by checking + // the sign of the first vertex wrto the test point; idea inspired + // by Joseph Samosky's and Mark Haigh-Hutchinson's different + // polygon inclusion tests. + if int((vty1 - y ) * (vtx0 - vtx1 ) >= + (vtx1 - x ) * (vty0 - vty1 ) ) = yflag1 then + inside_flag:=inside_flag xor 1; + + // Move to the next pair of vertices, retaining info as possible. + yflag0:=yflag1; + vtx0 :=vtx1; + vty0 :=vty1; + + if j >= m_num_points then + k:=j - m_num_points + else + k:=j; + + vtx1:=_xn(k ); + vty1:=_yn(k ); + + end; + + result:=inside_flag <> 0; + +end; + +{ CONSTRUCT } +constructor polygon_ctrl.Construct; +begin + inherited Construct(np ,point_radius ); + + m_color.ConstrDbl(0.0 ,0.0 ,0.0 ); + +end; + +{ LINE_COLOR_ } +procedure polygon_ctrl.line_color_; +begin + m_color:=c^; + +end; + +{ _COLOR } +function polygon_ctrl._color; +begin + result:=@m_color; + +end; + +END. + diff --git a/src/corelib/render/software/ctrl/agg_rbox_ctrl.pas b/src/corelib/render/software/ctrl/agg_rbox_ctrl.pas index 4b445138..08fd3e63 100644 --- a/src/corelib/render/software/ctrl/agg_rbox_ctrl.pas +++ b/src/corelib/render/software/ctrl/agg_rbox_ctrl.pas @@ -1,621 +1,621 @@ -//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4 (Public License)
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
-// Pascal Port By: Milan Marusinec alias Milano
-// milan@marusinec.sk
-// http://www.aggpas.org
-// Copyright (c) 2005-2006
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//
-// [Pascal Port History] -----------------------------------------------------
-//
-// 19.01.2006-Milano: Unit port establishment
-//
-{ agg_rbox_ctrl.pas }
-unit
- agg_rbox_ctrl ;
-
-INTERFACE
-
-{$I agg_mode.inc }
-
-uses
- SysUtils ,
- agg_basics ,
- agg_ctrl ,
- agg_conv_stroke ,
- agg_gsv_text ,
- agg_color ,
- agg_ellipse ,
- agg_math ,
- agg_math_stroke ;
-
-{ TYPES DEFINITION }
-type
- rbox_ctrl_impl = object(ctrl )
- m_border_width ,
- m_border_extra ,
- m_text_thickness ,
- m_text_height ,
- m_text_width : double;
-
- m_items : array[0..31 ] of char_ptr;
- m_sizes : array[0..31 ] of int8u;
-
- m_num_items : unsigned;
- m_cur_item : int;
-
- m_xs1 ,
- m_ys1 ,
- m_xs2 ,
- m_ys2 ,
- m_dy : double;
-
- m_vx ,
- m_vy : array[0..31 ] of double;
-
- m_draw_item : unsigned;
-
- m_ellipse : ellipse;
- m_ellipse_poly : conv_stroke;
- m_text : gsv_text;
- m_text_poly : conv_stroke;
-
- m_idx ,
- m_vertex : unsigned;
-
- constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y_ : boolean = false );
- destructor Destruct; virtual;
-
- procedure border_width_ (t : double; extra : double = 0.0 );
- procedure text_thickness_(t : double );
- procedure text_size_ (h : double; w : double = 0.0 );
-
- procedure add_item (text : PChar );
- function _cur_item : int;
- procedure cur_item_(i : int );
-
- function in_rect(x ,y : double ) : boolean; virtual;
-
- function on_mouse_button_down(x ,y : double ) : boolean; virtual;
- function on_mouse_button_up (x ,y : double ) : boolean; virtual;
-
- function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual;
- function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual;
-
- // Vertex source interface
- function num_paths : unsigned; virtual;
- procedure rewind(path_id : unsigned ); virtual;
- function vertex(x ,y : double_ptr ) : unsigned; virtual;
-
- procedure calc_rbox;
-
- end;
-
- rbox_ctrl_ptr = ^rbox_ctrl;
- rbox_ctrl = object(rbox_ctrl_impl )
- m_background_color ,
- m_border_color ,
- m_text_color ,
- m_inactive_color ,
- m_active_color : aggclr;
-
- m_colors : array[0..4 ] of aggclr_ptr;
-
- constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y_ : boolean = false );
-
- procedure background_color_(c : aggclr_ptr );
- procedure border_color_ (c : aggclr_ptr );
- procedure text_color_ (c : aggclr_ptr );
- procedure inactive_color_ (c : aggclr_ptr );
- procedure active_color_ (c : aggclr_ptr );
-
- function _color(i : unsigned ) : aggclr_ptr; virtual;
-
- end;
-
-{ GLOBAL PROCEDURES }
-
-
-IMPLEMENTATION
-{ LOCAL VARIABLES & CONSTANTS }
-{ UNIT IMPLEMENTATION }
-{ CONSTRUCT }
-constructor rbox_ctrl_impl.Construct;
-begin
- inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y_ );
-
- m_ellipse.Construct;
- m_text.Construct;
-
- m_ellipse_poly.Construct(@m_ellipse );
- m_text_poly.Construct (@m_text );
-
- m_border_width :=1.0;
- m_border_extra :=0.0;
- m_text_thickness:=1.5;
- m_text_height :=9.0;
- m_text_width :=0.0;
-
- m_num_items:=0;
- m_cur_item :=-1;
-
- m_idx :=0;
- m_vertex:=0;
-
- calc_rbox;
-
-end;
-
-{ DESTRUCT }
-destructor rbox_ctrl_impl.Destruct;
-begin
- m_ellipse_poly.Destruct;
- m_text_poly.Destruct;
-
- m_text.Destruct;
-
- while m_num_items > 0 do
- begin
- agg_freemem(p32(m_items[m_num_items - 1 ] ).ptr ,m_sizes[m_num_items - 1 ] );
-
- dec(m_num_items );
-
- end;
-
-end;
-
-{ BORDER_WIDTH_ }
-procedure rbox_ctrl_impl.border_width_;
-begin
- m_border_width:=t;
- m_border_extra:=extra;
-
- calc_rbox;
-
-end;
-
-{ TEXT_THICKNESS_ }
-procedure rbox_ctrl_impl.text_thickness_;
-begin
- m_text_thickness:=t;
-
-end;
-
-{ TEXT_SIZE_ }
-procedure rbox_ctrl_impl.text_size_;
-begin
- m_text_width :=w;
- m_text_height:=h;
-
-end;
-
-{ ADD_ITEM }
-procedure rbox_ctrl_impl.add_item;
-begin
- if m_num_items < 32 then
- begin
- if StrLen(text ) > 255 then
- m_sizes[m_num_items ]:=255
- else
- m_sizes[m_num_items ]:=StrLen(text ) + 1;
-
- agg_getmem(p32(m_items[m_num_items ] ).ptr ,m_sizes[m_num_items ] );
-
- fillchar(p32(m_items[m_num_items ] ).ptr^ ,m_sizes[m_num_items ] ,0 );
- move (text^ ,p32(m_items[m_num_items ] ).ptr^ ,m_sizes[m_num_items ] - 1 );
-
- inc(m_num_items );
-
- end;
-
-end;
-
-{ _CUR_ITEM }
-function rbox_ctrl_impl._cur_item;
-begin
- result:=m_cur_item;
-
-end;
-
-{ CUR_ITEM_ }
-procedure rbox_ctrl_impl.cur_item_;
-begin
- m_cur_item:=i;
-
-end;
-
-{ IN_RECT }
-function rbox_ctrl_impl.in_rect;
-begin
- inverse_transform_xy(@x ,@y );
-
- result:=
- (x >= m_x1 ) and
- (x <= m_x2 ) and
- (y >= m_y1 ) and
- (y <= m_y2 );
-
-end;
-
-{ ON_MOUSE_BUTTON_DOWN }
-function rbox_ctrl_impl.on_mouse_button_down;
-var
- i : unsigned;
-
- xp ,yp : double;
-
-begin
- inverse_transform_xy(@x ,@y );
-
- for i:=0 to m_num_items - 1 do
- begin
- xp:=m_xs1 + m_dy / 1.3;
- yp:=m_ys1 + m_dy * i + m_dy / 1.3;
-
- if calc_distance(x ,y ,xp ,yp ) <= m_text_height / 1.5 then
- begin
- m_cur_item:=i;
-
- result:=true;
-
- exit;
-
- end;
-
- end;
-
- result:=false;
-
-end;
-
-{ ON_MOUSE_BUTTON_UP }
-function rbox_ctrl_impl.on_mouse_button_up;
-begin
- result:=false;
-
-end;
-
-{ ON_MOUSE_MOVE }
-function rbox_ctrl_impl.on_mouse_move;
-begin
- result:=false;
-
-end;
-
-{ ON_ARROW_KEYS }
-function rbox_ctrl_impl.on_arrow_keys;
-begin
- if m_cur_item >= 0 then
- begin
- if up or right then
- begin
- inc(m_cur_item );
-
- if m_cur_item >= m_num_items then
- m_cur_item:=0;
-
- result:=true;
-
- exit;
-
- end;
-
- if down or left then
- begin
- dec(m_cur_item );
-
- if m_cur_item < 0 then
- m_cur_item:=m_num_items - 1;
-
- result:=true;
-
- exit;
-
- end;
-
- end;
-
- result:=false;
-
-end;
-
-{ NUM_PATHS }
-function rbox_ctrl_impl.num_paths;
-begin
- result:=5;
-
-end;
-
-{ REWIND }
-procedure rbox_ctrl_impl.rewind;
-begin
- m_idx:=path_id;
- m_dy :=m_text_height * 2.0;
-
- m_draw_item:=0;
-
- case path_id of
- 0 : // Background
- begin
- m_vertex:=0;
-
- m_vx[0 ]:=m_x1 - m_border_extra;
- m_vy[0 ]:=m_y1 - m_border_extra;
- m_vx[1 ]:=m_x2 + m_border_extra;
- m_vy[1 ]:=m_y1 - m_border_extra;
- m_vx[2 ]:=m_x2 + m_border_extra;
- m_vy[2 ]:=m_y2 + m_border_extra;
- m_vx[3 ]:=m_x1 - m_border_extra;
- m_vy[3 ]:=m_y2 + m_border_extra;
-
- end;
-
- 1 : // Border
- begin
- m_vertex:=0;
-
- m_vx[0 ]:=m_x1;
- m_vy[0 ]:=m_y1;
- m_vx[1 ]:=m_x2;
- m_vy[1 ]:=m_y1;
- m_vx[2 ]:=m_x2;
- m_vy[2 ]:=m_y2;
- m_vx[3 ]:=m_x1;
- m_vy[3 ]:=m_y2;
- m_vx[4 ]:=m_x1 + m_border_width;
- m_vy[4 ]:=m_y1 + m_border_width;
- m_vx[5 ]:=m_x1 + m_border_width;
- m_vy[5 ]:=m_y2 - m_border_width;
- m_vx[6 ]:=m_x2 - m_border_width;
- m_vy[6 ]:=m_y2 - m_border_width;
- m_vx[7 ]:=m_x2 - m_border_width;
- m_vy[7 ]:=m_y1 + m_border_width;
-
- end;
-
- 2 : // Text
- begin
- m_text.text_ (pointer(m_items[0 ] ) );
- m_text.start_point_(m_xs1 + m_dy * 1.5 ,m_ys1 + m_dy / 2.0 );
- m_text.size_ (m_text_height ,m_text_width );
-
- m_text_poly.width_ (m_text_thickness);
- m_text_poly.line_join_(round_join );
- m_text_poly.line_cap_ (round_cap );
-
- m_text_poly.rewind(0 );
-
- end;
-
- 3 : // Inactive items
- begin
- m_ellipse.init(
- m_xs1 + m_dy / 1.3 ,
- m_ys1 + m_dy / 1.3 ,
- m_text_height / 1.5 ,
- m_text_height / 1.5 ,32 );
-
- m_ellipse_poly.width_(m_text_thickness );
- m_ellipse_poly.rewind(0 );
-
- end;
-
- 4 : // Active Item
- if m_cur_item >= 0 then
- begin
- m_ellipse.init(
- m_xs1 + m_dy / 1.3 ,
- m_ys1 + m_dy * m_cur_item + m_dy / 1.3 ,
- m_text_height / 2.0 ,
- m_text_height / 2.0 ,32 );
-
- m_ellipse.rewind(0 );
-
- end;
-
- end;
-
-end;
-
-{ VERTEX }
-function rbox_ctrl_impl.vertex;
-var
- cmd : unsigned;
-
-label
- _Esc ;
-
-begin
- cmd:=path_cmd_line_to;
-
- case m_idx of
- 0 :
- begin
- if m_vertex = 0 then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 4 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 1 :
- begin
- if (m_vertex = 0 ) or
- (m_vertex = 4 ) then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 8 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 2 :
- begin
- cmd:=m_text_poly.vertex(x ,y );
-
- if is_stop(cmd ) then
- begin
- inc(m_draw_item );
-
- if m_draw_item >= m_num_items then
- goto _Esc
- else
- begin
- m_text.text_ (pointer(m_items[m_draw_item ] ) );
- m_text.start_point_(
- m_xs1 + m_dy * 1.5 ,
- m_ys1 + m_dy * (m_draw_item + 1 ) - m_dy / 2.0 );
-
- m_text_poly.rewind(0 );
-
- cmd:=m_text_poly.vertex(x ,y );
-
- end;
-
- end;
-
- end;
-
- 3 :
- begin
- cmd:=m_ellipse_poly.vertex(x ,y );
-
- if is_stop(cmd ) then
- begin
- inc(m_draw_item );
-
- if m_draw_item >= m_num_items then
- goto _Esc
- else
- begin
- m_ellipse.init(
- m_xs1 + m_dy / 1.3 ,
- m_ys1 + m_dy * m_draw_item + m_dy / 1.3 ,
- m_text_height / 1.5 ,
- m_text_height / 1.5 ,32 );
-
- m_ellipse_poly.rewind(0 );
-
- cmd:=m_ellipse_poly.vertex(x ,y );
-
- end;
-
- end;
-
- end;
-
- 4 :
- if m_cur_item >= 0 then
- cmd:=m_ellipse.vertex(x ,y )
- else
- cmd:=path_cmd_stop;
-
- else
- cmd:=path_cmd_stop;
-
- end;
-
-_Esc:
- if not is_stop(cmd ) then
- transform_xy(x ,y );
-
- result:=cmd;
-
-end;
-
-{ CALC_RBOX }
-procedure rbox_ctrl_impl.calc_rbox;
-begin
- m_xs1:=m_x1 + m_border_width;
- m_ys1:=m_y1 + m_border_width;
- m_xs2:=m_x2 - m_border_width;
- m_ys2:=m_y2 - m_border_width;
-
-end;
-
-{ CONSTRUCT }
-constructor rbox_ctrl.Construct;
-begin
- inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y_ );
-
- m_background_color.ConstrDbl(1.0 ,1.0 ,0.9 );
- m_border_color.ConstrDbl (0.0 ,0.0 ,0.0 );
- m_text_color.ConstrDbl (0.0 ,0.0 ,0.0 );
- m_inactive_color.ConstrDbl (0.0 ,0.0 ,0.0 );
- m_active_color.ConstrDbl (0.4 ,0.0 ,0.0 );
-
- m_colors[0 ]:=@m_background_color;
- m_colors[1 ]:=@m_border_color;
- m_colors[2 ]:=@m_text_color;
- m_colors[3 ]:=@m_inactive_color;
- m_colors[4 ]:=@m_active_color;
-
-end;
-
-{ BACKGROUND_COLOR_ }
-procedure rbox_ctrl.background_color_;
-begin
- m_background_color:=c^;
-
-end;
-
-{ BORDER_COLOR_ }
-procedure rbox_ctrl.border_color_;
-begin
- m_border_color:=c^;
-
-end;
-
-{ TEXT_COLOR_ }
-procedure rbox_ctrl.text_color_;
-begin
- m_text_color:=c^;
-
-end;
-
-{ INACTIVE_COLOR_ }
-procedure rbox_ctrl.inactive_color_;
-begin
- m_inactive_color:=c^;
-
-end;
-
-{ ACTIVE_COLOR_ }
-procedure rbox_ctrl.active_color_;
-begin
- m_active_color:=c^;
-
-end;
-
-{ _COLOR }
-function rbox_ctrl._color;
-begin
- result:=m_colors[i ];
-
-end;
-
-END.
-
+//---------------------------------------------------------------------------- +// Anti-Grain Geometry - Version 2.4 (Public License) +// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) +// +// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) +// Pascal Port By: Milan Marusinec alias Milano +// milan@marusinec.sk +// http://www.aggpas.org +// Copyright (c) 2005-2006 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +//---------------------------------------------------------------------------- +// Contact: mcseem@antigrain.com +// mcseemagg@yahoo.com +// http://www.antigrain.com +// +// [Pascal Port History] ----------------------------------------------------- +// +// 19.01.2006-Milano: Unit port establishment +// +{ agg_rbox_ctrl.pas } +unit + agg_rbox_ctrl ; + +INTERFACE + +{$I agg_mode.inc } + +uses + SysUtils , + agg_basics , + agg_ctrl , + agg_conv_stroke , + agg_gsv_text , + agg_color , + agg_ellipse , + agg_math , + agg_math_stroke ; + +{ TYPES DEFINITION } +type + rbox_ctrl_impl = object(ctrl ) + m_border_width , + m_border_extra , + m_text_thickness , + m_text_height , + m_text_width : double; + + m_items : array[0..31 ] of char_ptr; + m_sizes : array[0..31 ] of int8u; + + m_num_items : unsigned; + m_cur_item : int; + + m_xs1 , + m_ys1 , + m_xs2 , + m_ys2 , + m_dy : double; + + m_vx , + m_vy : array[0..31 ] of double; + + m_draw_item : unsigned; + + m_ellipse : ellipse; + m_ellipse_poly : conv_stroke; + m_text : gsv_text; + m_text_poly : conv_stroke; + + m_idx , + m_vertex : unsigned; + + constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y_ : boolean = false ); + destructor Destruct; virtual; + + procedure border_width_ (t : double; extra : double = 0.0 ); + procedure text_thickness_(t : double ); + procedure text_size_ (h : double; w : double = 0.0 ); + + procedure add_item (text : PChar ); + function _cur_item : int; + procedure cur_item_(i : int ); + + function in_rect(x ,y : double ) : boolean; virtual; + + function on_mouse_button_down(x ,y : double ) : boolean; virtual; + function on_mouse_button_up (x ,y : double ) : boolean; virtual; + + function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual; + function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual; + + // Vertex source interface + function num_paths : unsigned; virtual; + procedure rewind(path_id : unsigned ); virtual; + function vertex(x ,y : double_ptr ) : unsigned; virtual; + + procedure calc_rbox; + + end; + + rbox_ctrl_ptr = ^rbox_ctrl; + rbox_ctrl = object(rbox_ctrl_impl ) + m_background_color , + m_border_color , + m_text_color , + m_inactive_color , + m_active_color : aggclr; + + m_colors : array[0..4 ] of aggclr_ptr; + + constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y_ : boolean = false ); + + procedure background_color_(c : aggclr_ptr ); + procedure border_color_ (c : aggclr_ptr ); + procedure text_color_ (c : aggclr_ptr ); + procedure inactive_color_ (c : aggclr_ptr ); + procedure active_color_ (c : aggclr_ptr ); + + function _color(i : unsigned ) : aggclr_ptr; virtual; + + end; + +{ GLOBAL PROCEDURES } + + +IMPLEMENTATION +{ LOCAL VARIABLES & CONSTANTS } +{ UNIT IMPLEMENTATION } +{ CONSTRUCT } +constructor rbox_ctrl_impl.Construct; +begin + inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y_ ); + + m_ellipse.Construct; + m_text.Construct; + + m_ellipse_poly.Construct(@m_ellipse ); + m_text_poly.Construct (@m_text ); + + m_border_width :=1.0; + m_border_extra :=0.0; + m_text_thickness:=1.5; + m_text_height :=9.0; + m_text_width :=0.0; + + m_num_items:=0; + m_cur_item :=-1; + + m_idx :=0; + m_vertex:=0; + + calc_rbox; + +end; + +{ DESTRUCT } +destructor rbox_ctrl_impl.Destruct; +begin + m_ellipse_poly.Destruct; + m_text_poly.Destruct; + + m_text.Destruct; + + while m_num_items > 0 do + begin + agg_freemem(p32(m_items[m_num_items - 1 ] ).ptr ,m_sizes[m_num_items - 1 ] ); + + dec(m_num_items ); + + end; + +end; + +{ BORDER_WIDTH_ } +procedure rbox_ctrl_impl.border_width_; +begin + m_border_width:=t; + m_border_extra:=extra; + + calc_rbox; + +end; + +{ TEXT_THICKNESS_ } +procedure rbox_ctrl_impl.text_thickness_; +begin + m_text_thickness:=t; + +end; + +{ TEXT_SIZE_ } +procedure rbox_ctrl_impl.text_size_; +begin + m_text_width :=w; + m_text_height:=h; + +end; + +{ ADD_ITEM } +procedure rbox_ctrl_impl.add_item; +begin + if m_num_items < 32 then + begin + if StrLen(text ) > 255 then + m_sizes[m_num_items ]:=255 + else + m_sizes[m_num_items ]:=StrLen(text ) + 1; + + agg_getmem(p32(m_items[m_num_items ] ).ptr ,m_sizes[m_num_items ] ); + + fillchar(p32(m_items[m_num_items ] ).ptr^ ,m_sizes[m_num_items ] ,0 ); + move (text^ ,p32(m_items[m_num_items ] ).ptr^ ,m_sizes[m_num_items ] - 1 ); + + inc(m_num_items ); + + end; + +end; + +{ _CUR_ITEM } +function rbox_ctrl_impl._cur_item; +begin + result:=m_cur_item; + +end; + +{ CUR_ITEM_ } +procedure rbox_ctrl_impl.cur_item_; +begin + m_cur_item:=i; + +end; + +{ IN_RECT } +function rbox_ctrl_impl.in_rect; +begin + inverse_transform_xy(@x ,@y ); + + result:= + (x >= m_x1 ) and + (x <= m_x2 ) and + (y >= m_y1 ) and + (y <= m_y2 ); + +end; + +{ ON_MOUSE_BUTTON_DOWN } +function rbox_ctrl_impl.on_mouse_button_down; +var + i : unsigned; + + xp ,yp : double; + +begin + inverse_transform_xy(@x ,@y ); + + for i:=0 to m_num_items - 1 do + begin + xp:=m_xs1 + m_dy / 1.3; + yp:=m_ys1 + m_dy * i + m_dy / 1.3; + + if calc_distance(x ,y ,xp ,yp ) <= m_text_height / 1.5 then + begin + m_cur_item:=i; + + result:=true; + + exit; + + end; + + end; + + result:=false; + +end; + +{ ON_MOUSE_BUTTON_UP } +function rbox_ctrl_impl.on_mouse_button_up; +begin + result:=false; + +end; + +{ ON_MOUSE_MOVE } +function rbox_ctrl_impl.on_mouse_move; +begin + result:=false; + +end; + +{ ON_ARROW_KEYS } +function rbox_ctrl_impl.on_arrow_keys; +begin + if m_cur_item >= 0 then + begin + if up or right then + begin + inc(m_cur_item ); + + if m_cur_item >= m_num_items then + m_cur_item:=0; + + result:=true; + + exit; + + end; + + if down or left then + begin + dec(m_cur_item ); + + if m_cur_item < 0 then + m_cur_item:=m_num_items - 1; + + result:=true; + + exit; + + end; + + end; + + result:=false; + +end; + +{ NUM_PATHS } +function rbox_ctrl_impl.num_paths; +begin + result:=5; + +end; + +{ REWIND } +procedure rbox_ctrl_impl.rewind; +begin + m_idx:=path_id; + m_dy :=m_text_height * 2.0; + + m_draw_item:=0; + + case path_id of + 0 : // Background + begin + m_vertex:=0; + + m_vx[0 ]:=m_x1 - m_border_extra; + m_vy[0 ]:=m_y1 - m_border_extra; + m_vx[1 ]:=m_x2 + m_border_extra; + m_vy[1 ]:=m_y1 - m_border_extra; + m_vx[2 ]:=m_x2 + m_border_extra; + m_vy[2 ]:=m_y2 + m_border_extra; + m_vx[3 ]:=m_x1 - m_border_extra; + m_vy[3 ]:=m_y2 + m_border_extra; + + end; + + 1 : // Border + begin + m_vertex:=0; + + m_vx[0 ]:=m_x1; + m_vy[0 ]:=m_y1; + m_vx[1 ]:=m_x2; + m_vy[1 ]:=m_y1; + m_vx[2 ]:=m_x2; + m_vy[2 ]:=m_y2; + m_vx[3 ]:=m_x1; + m_vy[3 ]:=m_y2; + m_vx[4 ]:=m_x1 + m_border_width; + m_vy[4 ]:=m_y1 + m_border_width; + m_vx[5 ]:=m_x1 + m_border_width; + m_vy[5 ]:=m_y2 - m_border_width; + m_vx[6 ]:=m_x2 - m_border_width; + m_vy[6 ]:=m_y2 - m_border_width; + m_vx[7 ]:=m_x2 - m_border_width; + m_vy[7 ]:=m_y1 + m_border_width; + + end; + + 2 : // Text + begin + m_text.text_ (pointer(m_items[0 ] ) ); + m_text.start_point_(m_xs1 + m_dy * 1.5 ,m_ys1 + m_dy / 2.0 ); + m_text.size_ (m_text_height ,m_text_width ); + + m_text_poly.width_ (m_text_thickness); + m_text_poly.line_join_(round_join ); + m_text_poly.line_cap_ (round_cap ); + + m_text_poly.rewind(0 ); + + end; + + 3 : // Inactive items + begin + m_ellipse.init( + m_xs1 + m_dy / 1.3 , + m_ys1 + m_dy / 1.3 , + m_text_height / 1.5 , + m_text_height / 1.5 ,32 ); + + m_ellipse_poly.width_(m_text_thickness ); + m_ellipse_poly.rewind(0 ); + + end; + + 4 : // Active Item + if m_cur_item >= 0 then + begin + m_ellipse.init( + m_xs1 + m_dy / 1.3 , + m_ys1 + m_dy * m_cur_item + m_dy / 1.3 , + m_text_height / 2.0 , + m_text_height / 2.0 ,32 ); + + m_ellipse.rewind(0 ); + + end; + + end; + +end; + +{ VERTEX } +function rbox_ctrl_impl.vertex; +var + cmd : unsigned; + +label + _Esc ; + +begin + cmd:=path_cmd_line_to; + + case m_idx of + 0 : + begin + if m_vertex = 0 then + cmd:=path_cmd_move_to; + + if m_vertex >= 4 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 1 : + begin + if (m_vertex = 0 ) or + (m_vertex = 4 ) then + cmd:=path_cmd_move_to; + + if m_vertex >= 8 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 2 : + begin + cmd:=m_text_poly.vertex(x ,y ); + + if is_stop(cmd ) then + begin + inc(m_draw_item ); + + if m_draw_item >= m_num_items then + goto _Esc + else + begin + m_text.text_ (pointer(m_items[m_draw_item ] ) ); + m_text.start_point_( + m_xs1 + m_dy * 1.5 , + m_ys1 + m_dy * (m_draw_item + 1 ) - m_dy / 2.0 ); + + m_text_poly.rewind(0 ); + + cmd:=m_text_poly.vertex(x ,y ); + + end; + + end; + + end; + + 3 : + begin + cmd:=m_ellipse_poly.vertex(x ,y ); + + if is_stop(cmd ) then + begin + inc(m_draw_item ); + + if m_draw_item >= m_num_items then + goto _Esc + else + begin + m_ellipse.init( + m_xs1 + m_dy / 1.3 , + m_ys1 + m_dy * m_draw_item + m_dy / 1.3 , + m_text_height / 1.5 , + m_text_height / 1.5 ,32 ); + + m_ellipse_poly.rewind(0 ); + + cmd:=m_ellipse_poly.vertex(x ,y ); + + end; + + end; + + end; + + 4 : + if m_cur_item >= 0 then + cmd:=m_ellipse.vertex(x ,y ) + else + cmd:=path_cmd_stop; + + else + cmd:=path_cmd_stop; + + end; + +_Esc: + if not is_stop(cmd ) then + transform_xy(x ,y ); + + result:=cmd; + +end; + +{ CALC_RBOX } +procedure rbox_ctrl_impl.calc_rbox; +begin + m_xs1:=m_x1 + m_border_width; + m_ys1:=m_y1 + m_border_width; + m_xs2:=m_x2 - m_border_width; + m_ys2:=m_y2 - m_border_width; + +end; + +{ CONSTRUCT } +constructor rbox_ctrl.Construct; +begin + inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y_ ); + + m_background_color.ConstrDbl(1.0 ,1.0 ,0.9 ); + m_border_color.ConstrDbl (0.0 ,0.0 ,0.0 ); + m_text_color.ConstrDbl (0.0 ,0.0 ,0.0 ); + m_inactive_color.ConstrDbl (0.0 ,0.0 ,0.0 ); + m_active_color.ConstrDbl (0.4 ,0.0 ,0.0 ); + + m_colors[0 ]:=@m_background_color; + m_colors[1 ]:=@m_border_color; + m_colors[2 ]:=@m_text_color; + m_colors[3 ]:=@m_inactive_color; + m_colors[4 ]:=@m_active_color; + +end; + +{ BACKGROUND_COLOR_ } +procedure rbox_ctrl.background_color_; +begin + m_background_color:=c^; + +end; + +{ BORDER_COLOR_ } +procedure rbox_ctrl.border_color_; +begin + m_border_color:=c^; + +end; + +{ TEXT_COLOR_ } +procedure rbox_ctrl.text_color_; +begin + m_text_color:=c^; + +end; + +{ INACTIVE_COLOR_ } +procedure rbox_ctrl.inactive_color_; +begin + m_inactive_color:=c^; + +end; + +{ ACTIVE_COLOR_ } +procedure rbox_ctrl.active_color_; +begin + m_active_color:=c^; + +end; + +{ _COLOR } +function rbox_ctrl._color; +begin + result:=m_colors[i ]; + +end; + +END. + diff --git a/src/corelib/render/software/ctrl/agg_scale_ctrl.pas b/src/corelib/render/software/ctrl/agg_scale_ctrl.pas index afbfc1c0..e062f56e 100644 --- a/src/corelib/render/software/ctrl/agg_scale_ctrl.pas +++ b/src/corelib/render/software/ctrl/agg_scale_ctrl.pas @@ -1,747 +1,747 @@ -//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4 (Public License)
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
-// Pascal Port By: Milan Marusinec alias Milano
-// milan@marusinec.sk
-// http://www.aggpas.org
-// Copyright (c) 2005-2006
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//
-// [Pascal Port History] -----------------------------------------------------
-//
-// 29.01.2006-Milano: Unit port establishment
-//
-{ agg_scale_ctrl.pas }
-unit
- agg_scale_ctrl ;
-
-INTERFACE
-
-{$I agg_mode.inc }
-
-uses
- agg_basics ,
- agg_ctrl ,
- agg_color ,
- agg_ellipse ,
- agg_math ,
- agg_trans_affine ;
-
-{ TYPES DEFINITION }
-type
- move_e = (move_nothing ,move_value1 ,move_value2 ,move_slider );
-
- scale_ctrl_impl = object(ctrl )
- m_border_thickness ,
- m_border_extra ,
-
- m_value1 ,
- m_value2 ,
- m_min_d ,
-
- m_xs1 ,
- m_ys1 ,
- m_xs2 ,
- m_ys2 ,
- m_pdx ,
- m_pdy : double;
-
- m_move_what : move_e;
- m_vx ,
- m_vy : array[0..31 ] of double;
-
- m_ellipse : ellipse;
-
- m_idx ,
- m_vertex : unsigned;
-
- constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false );
- destructor Destruct; virtual;
-
- procedure border_thickness_(t : double; extra : double = 0.0 );
-
- procedure resize(x1 ,y1 ,x2 ,y2 : double );
-
- function _min_delta : double;
- procedure min_delta_(d : double );
-
- function _value1 : double;
- procedure value1_(value : double );
-
- function _value2 : double;
- procedure value2_(value : double );
-
- procedure move(d : double );
-
- function in_rect(x ,y : double ) : boolean; virtual;
-
- function on_mouse_button_down(x ,y : double ) : boolean; virtual;
- function on_mouse_button_up (x ,y : double ) : boolean; virtual;
-
- function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual;
- function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual;
-
- // Vertex source interface
- function num_paths : unsigned; virtual;
- procedure rewind(path_id : unsigned ); virtual;
- function vertex(x ,y : double_ptr ) : unsigned; virtual;
-
- // Private
- procedure calc_box;
-
- end;
-
- scale_ctrl = object(scale_ctrl_impl )
- m_background_color ,
- m_border_color ,
- m_pointers_color ,
- m_slider_color : aggclr;
-
- m_colors : array[0..5 ] of aggclr_ptr;
-
- constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false );
-
- procedure background_color_(c : aggclr_ptr );
- procedure border_color_ (c : aggclr_ptr );
- procedure pointers_color_ (c : aggclr_ptr );
- procedure slider_color_ (c : aggclr_ptr );
-
- function _color(i : unsigned ) : aggclr_ptr; virtual;
-
- end;
-
-{ GLOBAL PROCEDURES }
-
-
-IMPLEMENTATION
-{ LOCAL VARIABLES & CONSTANTS }
-{ UNIT IMPLEMENTATION }
-{ CONSTRUCT }
-constructor scale_ctrl_impl.Construct;
-begin
- inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y );
-
- m_border_thickness:=1.0;
-
- if Abs(x2 - x1 ) > Abs(y2 - y1 ) then
- m_border_extra:=(y2 - y1 ) / 2
- else
- m_border_extra:=(x2 - x1 ) / 2;
-
- m_pdx:=0.0;
- m_pdy:=0.0;
-
- m_move_what:=move_nothing;
-
- m_value1:=0.3;
- m_value2:=0.7;
- m_min_d :=0.01;
-
- m_ellipse.Construct;
-
- calc_box;
-
-end;
-
-{ DESTRUCT }
-destructor scale_ctrl_impl.destruct;
-begin
-end;
-
-{ BORDER_THICKNESS_ }
-procedure scale_ctrl_impl.border_thickness_;
-begin
- m_border_thickness:=t;
- m_border_extra :=extra;
-
- calc_box;
-
-end;
-
-{ RESIZE }
-procedure scale_ctrl_impl.resize;
-begin
- m_x1:=x1;
- m_y1:=y1;
- m_x2:=x2;
- m_y2:=y2;
-
- calc_box;
-
- if Abs(x2 - x1 ) > Abs(y2 - y1 ) then
- m_border_extra:=(y2 - y1 ) / 2
- else
- m_border_extra:=(x2 - x1 ) / 2;
-
-end;
-
-{ _MIN_DELTA }
-function scale_ctrl_impl._min_delta;
-begin
- result:=m_min_d;
-
-end;
-
-{ MIN_DELTA_ }
-procedure scale_ctrl_impl.min_delta_;
-begin
- m_min_d:=d;
-
-end;
-
-{ _VALUE1 }
-function scale_ctrl_impl._value1;
-begin
- result:=m_value1;
-
-end;
-
-{ VALUE1_ }
-procedure scale_ctrl_impl.value1_;
-begin
- if value < 0.0 then
- value:=0.0;
-
- if value > 1.0 then
- value:=1.0;
-
- if m_value2 - value < m_min_d then
- value:=m_value2 - m_min_d;
-
- m_value1:=value;
-
-end;
-
-{ _VALUE2 }
-function scale_ctrl_impl._value2;
-begin
- result:=m_value2;
-
-end;
-
-{ VALUE2_ }
-procedure scale_ctrl_impl.value2_;
-begin
- if value < 0.0 then
- value:=0.0;
-
- if value > 1.0 then
- value:=1.0;
-
- if m_value1 + value < m_min_d then
- value:=m_value1 + m_min_d;
-
- m_value2:=value;
-
-end;
-
-{ MOVE }
-procedure scale_ctrl_impl.move;
-begin
- m_value1:=m_value1 + d;
- m_value2:=m_value2 + d;
-
- if m_value1 < 0.0 then
- begin
- m_value2:=m_value2 - m_value1;
- m_value1:=0.0;
-
- end;
-
- if m_value2 > 1.0 then
- begin
- m_value1:=m_value1 - m_value2 - 1.0;
- m_value2:=1.0;
-
- end;
-
-end;
-
-{ IN_RECT }
-function scale_ctrl_impl.in_rect;
-begin
- inverse_transform_xy(@x ,@y );
-
- result:=
- (x >= m_x1 ) and
- (x <= m_x2 ) and
- (y >= m_y1 ) and
- (y <= m_y2 );
-
-end;
-
-{ ON_MOUSE_BUTTON_DOWN }
-function scale_ctrl_impl.on_mouse_button_down;
-var
- xp1 ,xp2 ,ys1 ,ys2 ,xp ,yp : double;
-
-begin
- inverse_transform_xy(@x ,@y );
-
- if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then
- begin
- xp1:=m_xs1 + (m_xs2 - m_xs1 ) * m_value1;
- xp2:=m_xs1 + (m_xs2 - m_xs1 ) * m_value2;
- ys1:=m_y1 - m_border_extra / 2.0;
- ys2:=m_y2 + m_border_extra / 2.0;
- yp :=(m_ys1 + m_ys2 ) / 2.0;
-
- if (x > xp1 ) and
- (y > ys1 ) and
- (x < xp2 ) and
- (y < ys2 ) then
- begin
- m_pdx:=xp1 - x;
-
- m_move_what:=move_slider;
-
- result:=true;
-
- exit;
-
- end;
-
- //if(x < xp1 && calc_distance(x, y, xp1, yp) <= m_y2 - m_y1)
- if calc_distance(x ,y ,xp1 ,yp ) <= m_y2 - m_y1 then
- begin
- m_pdx:=xp1 - x;
-
- m_move_what:=move_value1;
-
- result:=true;
-
- exit;
-
- end;
-
- //if(x > xp2 && calc_distance(x, y, xp2, yp) <= m_y2 - m_y1)
- if calc_distance(x ,y ,xp2 ,yp ) <= m_y2 - m_y1 then
- begin
- m_pdx:=xp2 - x;
-
- m_move_what:=move_value2;
-
- result:=true;
-
- end;
-
- end
- else
- begin
- xp1:=m_x1 - m_border_extra / 2.0;
- xp2:=m_x2 + m_border_extra / 2.0;
- ys1:=m_ys1 + (m_ys2 - m_ys1 ) * m_value1;
- ys2:=m_ys1 + (m_ys2 - m_ys1 ) * m_value2;
- xp :=(m_xs1 + m_xs2 ) / 2.0;
-
- if (x > xp1 ) and
- (y > ys1 ) and
- (x < xp2 ) and
- (y < ys2 ) then
- begin
- m_pdy:=ys1 - y;
-
- m_move_what:=move_slider;
-
- result:=true;
-
- exit;
-
- end;
-
- //if(y < ys1 && calc_distance(x, y, xp, ys1) <= m_x2 - m_x1)
- if calc_distance(x ,y ,xp ,ys1 ) <= m_x2 - m_x1 then
- begin
- m_pdy:=ys1 - y;
-
- m_move_what:=move_value1;
-
- result:=true;
-
- exit;
-
- end;
-
- //if(y > ys2 && calc_distance(x, y, xp, ys2) <= m_x2 - m_x1)
- if calc_distance(x, y, xp, ys2) <= m_x2 - m_x1 then
- begin
- m_pdy:=ys2 - y;
-
- m_move_what:=move_value2;
-
- result:=true;
-
- exit;
-
- end;
-
- end;
-
- result:=false;
-
-end;
-
-{ ON_MOUSE_BUTTON_UP }
-function scale_ctrl_impl.on_mouse_button_up;
-begin
- m_move_what:=move_nothing;
-
- result:=false;
-
-end;
-
-{ ON_MOUSE_MOVE }
-function scale_ctrl_impl.on_mouse_move;
-var
- xp ,yp ,dv : double;
-
-begin
- inverse_transform_xy(@x ,@y );
-
- if not button_flag then
- result:=on_mouse_button_up(x ,y )
- else
- begin
- xp:=x + m_pdx;
- yp:=y + m_pdy;
-
- case m_move_what of
- move_value1 :
- begin
- if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then
- m_value1:=(xp - m_xs1 ) / (m_xs2 - m_xs1 )
- else
- m_value1:=(yp - m_ys1 ) / (m_ys2 - m_ys1 );
-
- if m_value1 < 0.0 then
- m_value1:=0.0;
-
- if m_value1 > m_value2 - m_min_d then
- m_value1:=m_value2 - m_min_d;
-
- result:=true;
-
- end;
-
- move_value2 :
- begin
- if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then
- m_value2:=(xp - m_xs1 ) / (m_xs2 - m_xs1 )
- else
- m_value2:=(yp - m_ys1 ) / (m_ys2 - m_ys1 );
-
- if m_value2 > 1.0 then
- m_value2:=1.0;
-
- if m_value2 < m_value1 + m_min_d then
- m_value2:=m_value1 + m_min_d;
-
- result:=true;
-
- end;
-
- move_slider :
- begin
- dv:=m_value2 - m_value1;
-
- if Abs(m_x2 - m_x1 ) > abs(m_y2 - m_y1 ) then
- m_value1:=(xp - m_xs1 ) / (m_xs2 - m_xs1 )
- else
- m_value1:=(yp - m_ys1 ) / (m_ys2 - m_ys1 );
-
- m_value2:=m_value1 + dv;
-
- if m_value1 < 0.0 then
- begin
- dv:=m_value2 - m_value1;
-
- m_value1:=0.0;
- m_value2:=m_value1 + dv;
-
- end;
-
- if m_value2 > 1.0 then
- begin
- dv:=m_value2 - m_value1;
-
- m_value2:=1.0;
- m_value1:=m_value2 - dv;
-
- end;
-
- result:=true;
-
- end;
-
- else
- result:=false;
-
- end;
-
- end;
-
-end;
-
-{ ON_ARROW_KEYS }
-function scale_ctrl_impl.on_arrow_keys;
-begin
- result:=false
-
-end;
-
-{ NUM_PATHS }
-function scale_ctrl_impl.num_paths;
-begin
- result:=5;
-
-end;
-
-{ REWIND }
-procedure scale_ctrl_impl.rewind;
-begin
- m_idx:=path_id;
-
- case path_id of
- 0: // Background
- begin
- m_vertex:=0;
-
- m_vx[0 ]:=m_x1 - m_border_extra;
- m_vy[0 ]:=m_y1 - m_border_extra;
- m_vx[1 ]:=m_x2 + m_border_extra;
- m_vy[1 ]:=m_y1 - m_border_extra;
- m_vx[2 ]:=m_x2 + m_border_extra;
- m_vy[2 ]:=m_y2 + m_border_extra;
- m_vx[3 ]:=m_x1 - m_border_extra;
- m_vy[3 ]:=m_y2 + m_border_extra;
-
- end;
-
- 1: // Border
- begin
- m_vertex:=0;
-
- m_vx[0 ]:=m_x1;
- m_vy[0 ]:=m_y1;
- m_vx[1 ]:=m_x2;
- m_vy[1 ]:=m_y1;
- m_vx[2 ]:=m_x2;
- m_vy[2 ]:=m_y2;
- m_vx[3 ]:=m_x1;
- m_vy[3 ]:=m_y2;
- m_vx[4 ]:=m_x1 + m_border_thickness;
- m_vy[4 ]:=m_y1 + m_border_thickness;
- m_vx[5 ]:=m_x1 + m_border_thickness;
- m_vy[5 ]:=m_y2 - m_border_thickness;
- m_vx[6 ]:=m_x2 - m_border_thickness;
- m_vy[6 ]:=m_y2 - m_border_thickness;
- m_vx[7 ]:=m_x2 - m_border_thickness;
- m_vy[7 ]:=m_y1 + m_border_thickness;
-
- end;
-
- 2: // pointer1
- begin
- if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then
- m_ellipse.init(
- m_xs1 + (m_xs2 - m_xs1 ) * m_value1 ,
- (m_ys1 + m_ys2 ) / 2.0 ,
- m_y2 - m_y1 ,
- m_y2 - m_y1 ,32 )
- else
- m_ellipse.init(
- (m_xs1 + m_xs2 ) / 2.0,
- m_ys1 + (m_ys2 - m_ys1 ) * m_value1 ,
- m_x2 - m_x1 ,
- m_x2 - m_x1 ,32 );
-
- m_ellipse.rewind(0 );
-
- end;
-
- 3: // pointer2
- begin
- if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then
- m_ellipse.init(
- m_xs1 + (m_xs2 - m_xs1 ) * m_value2 ,
- (m_ys1 + m_ys2 ) / 2.0 ,
- m_y2 - m_y1 ,
- m_y2 - m_y1 ,32 )
- else
- m_ellipse.init(
- (m_xs1 + m_xs2 ) / 2.0 ,
- m_ys1 + (m_ys2 - m_ys1 ) * m_value2 ,
- m_x2 - m_x1 ,
- m_x2 - m_x1 ,32 );
-
- m_ellipse.rewind(0);
-
- end;
-
- 4: // slider
- begin
- m_vertex:=0;
-
- if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then
- begin
- m_vx[0 ]:=m_xs1 + (m_xs2 - m_xs1 ) * m_value1;
- m_vy[0 ]:=m_y1 - m_border_extra / 2.0;
- m_vx[1 ]:=m_xs1 + (m_xs2 - m_xs1 ) * m_value2;
- m_vy[1 ]:=m_vy[0 ];
- m_vx[2 ]:=m_vx[1 ];
- m_vy[2 ]:=m_y2 + m_border_extra / 2.0;
- m_vx[3 ]:=m_vx[0 ];
- m_vy[3 ]:=m_vy[2 ];
-
- end
- else
- begin
- m_vx[0 ]:=m_x1 - m_border_extra / 2.0;
- m_vy[0 ]:=m_ys1 + (m_ys2 - m_ys1 ) * m_value1;
- m_vx[1 ]:=m_vx[0 ];
- m_vy[1 ]:=m_ys1 + (m_ys2 - m_ys1 ) * m_value2;
- m_vx[2 ]:=m_x2 + m_border_extra / 2.0;
- m_vy[2 ]:=m_vy[1 ];
- m_vx[3 ]:=m_vx[2 ];
- m_vy[3 ]:=m_vy[0 ];
-
- end;
-
- end;
-
- end;
-
-end;
-
-{ VERTEX }
-function scale_ctrl_impl.vertex;
-var
- cmd : unsigned;
-
-begin
- cmd:=path_cmd_line_to;
-
- case m_idx of
- 0 ,4 :
- begin
- if m_vertex = 0 then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 4 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 1 :
- begin
- if (m_vertex = 0 ) or
- (m_vertex = 4 ) then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 8 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 2 ,3 :
- cmd:=m_ellipse.vertex(x ,y );
-
- else
- cmd:=path_cmd_stop;
-
- end;
-
- if not is_stop(cmd ) then
- transform_xy(x ,y );
-
- result:=cmd;
-
-end;
-
-{ CALC_BOX }
-procedure scale_ctrl_impl.calc_box;
-begin
- m_xs1:=m_x1 + m_border_thickness;
- m_ys1:=m_y1 + m_border_thickness;
- m_xs2:=m_x2 - m_border_thickness;
- m_ys2:=m_y2 - m_border_thickness;
-
-end;
-
-{ CONSTRUCT }
-constructor scale_ctrl.Construct;
-begin
- inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y );
-
- m_background_color.ConstrDbl(1.0 ,0.9 ,0.8 );
- m_border_color.ConstrDbl (0.0 ,0.0 ,0.0 );
- m_pointers_color.ConstrDbl (0.8 ,0.0 ,0.0 ,0.8 );
- m_slider_color.ConstrDbl (0.2 ,0.1 ,0.0 ,0.6 );
-
- m_colors[0 ]:=@m_background_color;
- m_colors[1 ]:=@m_border_color;
- m_colors[2 ]:=@m_pointers_color;
- m_colors[3 ]:=@m_pointers_color;
- m_colors[4 ]:=@m_slider_color;
-
-end;
-
-{ BACKGROUND_COLOR_ }
-procedure scale_ctrl.background_color_;
-begin
- m_background_color:=c^;
-
-end;
-
-{ BORDER_COLOR_ }
-procedure scale_ctrl.border_color_;
-begin
- m_border_color:=c^;
-
-end;
-
-{ POINTERS_COLOR_ }
-procedure scale_ctrl.pointers_color_;
-begin
- m_pointers_color:=c^;
-
-end;
-
-{ SLIDER_COLOR_ }
-procedure scale_ctrl.slider_color_;
-begin
- m_slider_color:=c^;
-
-end;
-
-{ _COLOR }
-function scale_ctrl._color;
-begin
- result:=m_colors[i ];
-
-end;
-
-
-END.
-
+//---------------------------------------------------------------------------- +// Anti-Grain Geometry - Version 2.4 (Public License) +// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) +// +// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) +// Pascal Port By: Milan Marusinec alias Milano +// milan@marusinec.sk +// http://www.aggpas.org +// Copyright (c) 2005-2006 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +//---------------------------------------------------------------------------- +// Contact: mcseem@antigrain.com +// mcseemagg@yahoo.com +// http://www.antigrain.com +// +// [Pascal Port History] ----------------------------------------------------- +// +// 29.01.2006-Milano: Unit port establishment +// +{ agg_scale_ctrl.pas } +unit + agg_scale_ctrl ; + +INTERFACE + +{$I agg_mode.inc } + +uses + agg_basics , + agg_ctrl , + agg_color , + agg_ellipse , + agg_math , + agg_trans_affine ; + +{ TYPES DEFINITION } +type + move_e = (move_nothing ,move_value1 ,move_value2 ,move_slider ); + + scale_ctrl_impl = object(ctrl ) + m_border_thickness , + m_border_extra , + + m_value1 , + m_value2 , + m_min_d , + + m_xs1 , + m_ys1 , + m_xs2 , + m_ys2 , + m_pdx , + m_pdy : double; + + m_move_what : move_e; + m_vx , + m_vy : array[0..31 ] of double; + + m_ellipse : ellipse; + + m_idx , + m_vertex : unsigned; + + constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false ); + destructor Destruct; virtual; + + procedure border_thickness_(t : double; extra : double = 0.0 ); + + procedure resize(x1 ,y1 ,x2 ,y2 : double ); + + function _min_delta : double; + procedure min_delta_(d : double ); + + function _value1 : double; + procedure value1_(value : double ); + + function _value2 : double; + procedure value2_(value : double ); + + procedure move(d : double ); + + function in_rect(x ,y : double ) : boolean; virtual; + + function on_mouse_button_down(x ,y : double ) : boolean; virtual; + function on_mouse_button_up (x ,y : double ) : boolean; virtual; + + function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual; + function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual; + + // Vertex source interface + function num_paths : unsigned; virtual; + procedure rewind(path_id : unsigned ); virtual; + function vertex(x ,y : double_ptr ) : unsigned; virtual; + + // Private + procedure calc_box; + + end; + + scale_ctrl = object(scale_ctrl_impl ) + m_background_color , + m_border_color , + m_pointers_color , + m_slider_color : aggclr; + + m_colors : array[0..5 ] of aggclr_ptr; + + constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false ); + + procedure background_color_(c : aggclr_ptr ); + procedure border_color_ (c : aggclr_ptr ); + procedure pointers_color_ (c : aggclr_ptr ); + procedure slider_color_ (c : aggclr_ptr ); + + function _color(i : unsigned ) : aggclr_ptr; virtual; + + end; + +{ GLOBAL PROCEDURES } + + +IMPLEMENTATION +{ LOCAL VARIABLES & CONSTANTS } +{ UNIT IMPLEMENTATION } +{ CONSTRUCT } +constructor scale_ctrl_impl.Construct; +begin + inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y ); + + m_border_thickness:=1.0; + + if Abs(x2 - x1 ) > Abs(y2 - y1 ) then + m_border_extra:=(y2 - y1 ) / 2 + else + m_border_extra:=(x2 - x1 ) / 2; + + m_pdx:=0.0; + m_pdy:=0.0; + + m_move_what:=move_nothing; + + m_value1:=0.3; + m_value2:=0.7; + m_min_d :=0.01; + + m_ellipse.Construct; + + calc_box; + +end; + +{ DESTRUCT } +destructor scale_ctrl_impl.destruct; +begin +end; + +{ BORDER_THICKNESS_ } +procedure scale_ctrl_impl.border_thickness_; +begin + m_border_thickness:=t; + m_border_extra :=extra; + + calc_box; + +end; + +{ RESIZE } +procedure scale_ctrl_impl.resize; +begin + m_x1:=x1; + m_y1:=y1; + m_x2:=x2; + m_y2:=y2; + + calc_box; + + if Abs(x2 - x1 ) > Abs(y2 - y1 ) then + m_border_extra:=(y2 - y1 ) / 2 + else + m_border_extra:=(x2 - x1 ) / 2; + +end; + +{ _MIN_DELTA } +function scale_ctrl_impl._min_delta; +begin + result:=m_min_d; + +end; + +{ MIN_DELTA_ } +procedure scale_ctrl_impl.min_delta_; +begin + m_min_d:=d; + +end; + +{ _VALUE1 } +function scale_ctrl_impl._value1; +begin + result:=m_value1; + +end; + +{ VALUE1_ } +procedure scale_ctrl_impl.value1_; +begin + if value < 0.0 then + value:=0.0; + + if value > 1.0 then + value:=1.0; + + if m_value2 - value < m_min_d then + value:=m_value2 - m_min_d; + + m_value1:=value; + +end; + +{ _VALUE2 } +function scale_ctrl_impl._value2; +begin + result:=m_value2; + +end; + +{ VALUE2_ } +procedure scale_ctrl_impl.value2_; +begin + if value < 0.0 then + value:=0.0; + + if value > 1.0 then + value:=1.0; + + if m_value1 + value < m_min_d then + value:=m_value1 + m_min_d; + + m_value2:=value; + +end; + +{ MOVE } +procedure scale_ctrl_impl.move; +begin + m_value1:=m_value1 + d; + m_value2:=m_value2 + d; + + if m_value1 < 0.0 then + begin + m_value2:=m_value2 - m_value1; + m_value1:=0.0; + + end; + + if m_value2 > 1.0 then + begin + m_value1:=m_value1 - m_value2 - 1.0; + m_value2:=1.0; + + end; + +end; + +{ IN_RECT } +function scale_ctrl_impl.in_rect; +begin + inverse_transform_xy(@x ,@y ); + + result:= + (x >= m_x1 ) and + (x <= m_x2 ) and + (y >= m_y1 ) and + (y <= m_y2 ); + +end; + +{ ON_MOUSE_BUTTON_DOWN } +function scale_ctrl_impl.on_mouse_button_down; +var + xp1 ,xp2 ,ys1 ,ys2 ,xp ,yp : double; + +begin + inverse_transform_xy(@x ,@y ); + + if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then + begin + xp1:=m_xs1 + (m_xs2 - m_xs1 ) * m_value1; + xp2:=m_xs1 + (m_xs2 - m_xs1 ) * m_value2; + ys1:=m_y1 - m_border_extra / 2.0; + ys2:=m_y2 + m_border_extra / 2.0; + yp :=(m_ys1 + m_ys2 ) / 2.0; + + if (x > xp1 ) and + (y > ys1 ) and + (x < xp2 ) and + (y < ys2 ) then + begin + m_pdx:=xp1 - x; + + m_move_what:=move_slider; + + result:=true; + + exit; + + end; + + //if(x < xp1 && calc_distance(x, y, xp1, yp) <= m_y2 - m_y1) + if calc_distance(x ,y ,xp1 ,yp ) <= m_y2 - m_y1 then + begin + m_pdx:=xp1 - x; + + m_move_what:=move_value1; + + result:=true; + + exit; + + end; + + //if(x > xp2 && calc_distance(x, y, xp2, yp) <= m_y2 - m_y1) + if calc_distance(x ,y ,xp2 ,yp ) <= m_y2 - m_y1 then + begin + m_pdx:=xp2 - x; + + m_move_what:=move_value2; + + result:=true; + + end; + + end + else + begin + xp1:=m_x1 - m_border_extra / 2.0; + xp2:=m_x2 + m_border_extra / 2.0; + ys1:=m_ys1 + (m_ys2 - m_ys1 ) * m_value1; + ys2:=m_ys1 + (m_ys2 - m_ys1 ) * m_value2; + xp :=(m_xs1 + m_xs2 ) / 2.0; + + if (x > xp1 ) and + (y > ys1 ) and + (x < xp2 ) and + (y < ys2 ) then + begin + m_pdy:=ys1 - y; + + m_move_what:=move_slider; + + result:=true; + + exit; + + end; + + //if(y < ys1 && calc_distance(x, y, xp, ys1) <= m_x2 - m_x1) + if calc_distance(x ,y ,xp ,ys1 ) <= m_x2 - m_x1 then + begin + m_pdy:=ys1 - y; + + m_move_what:=move_value1; + + result:=true; + + exit; + + end; + + //if(y > ys2 && calc_distance(x, y, xp, ys2) <= m_x2 - m_x1) + if calc_distance(x, y, xp, ys2) <= m_x2 - m_x1 then + begin + m_pdy:=ys2 - y; + + m_move_what:=move_value2; + + result:=true; + + exit; + + end; + + end; + + result:=false; + +end; + +{ ON_MOUSE_BUTTON_UP } +function scale_ctrl_impl.on_mouse_button_up; +begin + m_move_what:=move_nothing; + + result:=false; + +end; + +{ ON_MOUSE_MOVE } +function scale_ctrl_impl.on_mouse_move; +var + xp ,yp ,dv : double; + +begin + inverse_transform_xy(@x ,@y ); + + if not button_flag then + result:=on_mouse_button_up(x ,y ) + else + begin + xp:=x + m_pdx; + yp:=y + m_pdy; + + case m_move_what of + move_value1 : + begin + if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then + m_value1:=(xp - m_xs1 ) / (m_xs2 - m_xs1 ) + else + m_value1:=(yp - m_ys1 ) / (m_ys2 - m_ys1 ); + + if m_value1 < 0.0 then + m_value1:=0.0; + + if m_value1 > m_value2 - m_min_d then + m_value1:=m_value2 - m_min_d; + + result:=true; + + end; + + move_value2 : + begin + if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then + m_value2:=(xp - m_xs1 ) / (m_xs2 - m_xs1 ) + else + m_value2:=(yp - m_ys1 ) / (m_ys2 - m_ys1 ); + + if m_value2 > 1.0 then + m_value2:=1.0; + + if m_value2 < m_value1 + m_min_d then + m_value2:=m_value1 + m_min_d; + + result:=true; + + end; + + move_slider : + begin + dv:=m_value2 - m_value1; + + if Abs(m_x2 - m_x1 ) > abs(m_y2 - m_y1 ) then + m_value1:=(xp - m_xs1 ) / (m_xs2 - m_xs1 ) + else + m_value1:=(yp - m_ys1 ) / (m_ys2 - m_ys1 ); + + m_value2:=m_value1 + dv; + + if m_value1 < 0.0 then + begin + dv:=m_value2 - m_value1; + + m_value1:=0.0; + m_value2:=m_value1 + dv; + + end; + + if m_value2 > 1.0 then + begin + dv:=m_value2 - m_value1; + + m_value2:=1.0; + m_value1:=m_value2 - dv; + + end; + + result:=true; + + end; + + else + result:=false; + + end; + + end; + +end; + +{ ON_ARROW_KEYS } +function scale_ctrl_impl.on_arrow_keys; +begin + result:=false + +end; + +{ NUM_PATHS } +function scale_ctrl_impl.num_paths; +begin + result:=5; + +end; + +{ REWIND } +procedure scale_ctrl_impl.rewind; +begin + m_idx:=path_id; + + case path_id of + 0: // Background + begin + m_vertex:=0; + + m_vx[0 ]:=m_x1 - m_border_extra; + m_vy[0 ]:=m_y1 - m_border_extra; + m_vx[1 ]:=m_x2 + m_border_extra; + m_vy[1 ]:=m_y1 - m_border_extra; + m_vx[2 ]:=m_x2 + m_border_extra; + m_vy[2 ]:=m_y2 + m_border_extra; + m_vx[3 ]:=m_x1 - m_border_extra; + m_vy[3 ]:=m_y2 + m_border_extra; + + end; + + 1: // Border + begin + m_vertex:=0; + + m_vx[0 ]:=m_x1; + m_vy[0 ]:=m_y1; + m_vx[1 ]:=m_x2; + m_vy[1 ]:=m_y1; + m_vx[2 ]:=m_x2; + m_vy[2 ]:=m_y2; + m_vx[3 ]:=m_x1; + m_vy[3 ]:=m_y2; + m_vx[4 ]:=m_x1 + m_border_thickness; + m_vy[4 ]:=m_y1 + m_border_thickness; + m_vx[5 ]:=m_x1 + m_border_thickness; + m_vy[5 ]:=m_y2 - m_border_thickness; + m_vx[6 ]:=m_x2 - m_border_thickness; + m_vy[6 ]:=m_y2 - m_border_thickness; + m_vx[7 ]:=m_x2 - m_border_thickness; + m_vy[7 ]:=m_y1 + m_border_thickness; + + end; + + 2: // pointer1 + begin + if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then + m_ellipse.init( + m_xs1 + (m_xs2 - m_xs1 ) * m_value1 , + (m_ys1 + m_ys2 ) / 2.0 , + m_y2 - m_y1 , + m_y2 - m_y1 ,32 ) + else + m_ellipse.init( + (m_xs1 + m_xs2 ) / 2.0, + m_ys1 + (m_ys2 - m_ys1 ) * m_value1 , + m_x2 - m_x1 , + m_x2 - m_x1 ,32 ); + + m_ellipse.rewind(0 ); + + end; + + 3: // pointer2 + begin + if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then + m_ellipse.init( + m_xs1 + (m_xs2 - m_xs1 ) * m_value2 , + (m_ys1 + m_ys2 ) / 2.0 , + m_y2 - m_y1 , + m_y2 - m_y1 ,32 ) + else + m_ellipse.init( + (m_xs1 + m_xs2 ) / 2.0 , + m_ys1 + (m_ys2 - m_ys1 ) * m_value2 , + m_x2 - m_x1 , + m_x2 - m_x1 ,32 ); + + m_ellipse.rewind(0); + + end; + + 4: // slider + begin + m_vertex:=0; + + if Abs(m_x2 - m_x1 ) > Abs(m_y2 - m_y1 ) then + begin + m_vx[0 ]:=m_xs1 + (m_xs2 - m_xs1 ) * m_value1; + m_vy[0 ]:=m_y1 - m_border_extra / 2.0; + m_vx[1 ]:=m_xs1 + (m_xs2 - m_xs1 ) * m_value2; + m_vy[1 ]:=m_vy[0 ]; + m_vx[2 ]:=m_vx[1 ]; + m_vy[2 ]:=m_y2 + m_border_extra / 2.0; + m_vx[3 ]:=m_vx[0 ]; + m_vy[3 ]:=m_vy[2 ]; + + end + else + begin + m_vx[0 ]:=m_x1 - m_border_extra / 2.0; + m_vy[0 ]:=m_ys1 + (m_ys2 - m_ys1 ) * m_value1; + m_vx[1 ]:=m_vx[0 ]; + m_vy[1 ]:=m_ys1 + (m_ys2 - m_ys1 ) * m_value2; + m_vx[2 ]:=m_x2 + m_border_extra / 2.0; + m_vy[2 ]:=m_vy[1 ]; + m_vx[3 ]:=m_vx[2 ]; + m_vy[3 ]:=m_vy[0 ]; + + end; + + end; + + end; + +end; + +{ VERTEX } +function scale_ctrl_impl.vertex; +var + cmd : unsigned; + +begin + cmd:=path_cmd_line_to; + + case m_idx of + 0 ,4 : + begin + if m_vertex = 0 then + cmd:=path_cmd_move_to; + + if m_vertex >= 4 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 1 : + begin + if (m_vertex = 0 ) or + (m_vertex = 4 ) then + cmd:=path_cmd_move_to; + + if m_vertex >= 8 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 2 ,3 : + cmd:=m_ellipse.vertex(x ,y ); + + else + cmd:=path_cmd_stop; + + end; + + if not is_stop(cmd ) then + transform_xy(x ,y ); + + result:=cmd; + +end; + +{ CALC_BOX } +procedure scale_ctrl_impl.calc_box; +begin + m_xs1:=m_x1 + m_border_thickness; + m_ys1:=m_y1 + m_border_thickness; + m_xs2:=m_x2 - m_border_thickness; + m_ys2:=m_y2 - m_border_thickness; + +end; + +{ CONSTRUCT } +constructor scale_ctrl.Construct; +begin + inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y ); + + m_background_color.ConstrDbl(1.0 ,0.9 ,0.8 ); + m_border_color.ConstrDbl (0.0 ,0.0 ,0.0 ); + m_pointers_color.ConstrDbl (0.8 ,0.0 ,0.0 ,0.8 ); + m_slider_color.ConstrDbl (0.2 ,0.1 ,0.0 ,0.6 ); + + m_colors[0 ]:=@m_background_color; + m_colors[1 ]:=@m_border_color; + m_colors[2 ]:=@m_pointers_color; + m_colors[3 ]:=@m_pointers_color; + m_colors[4 ]:=@m_slider_color; + +end; + +{ BACKGROUND_COLOR_ } +procedure scale_ctrl.background_color_; +begin + m_background_color:=c^; + +end; + +{ BORDER_COLOR_ } +procedure scale_ctrl.border_color_; +begin + m_border_color:=c^; + +end; + +{ POINTERS_COLOR_ } +procedure scale_ctrl.pointers_color_; +begin + m_pointers_color:=c^; + +end; + +{ SLIDER_COLOR_ } +procedure scale_ctrl.slider_color_; +begin + m_slider_color:=c^; + +end; + +{ _COLOR } +function scale_ctrl._color; +begin + result:=m_colors[i ]; + +end; + + +END. + diff --git a/src/corelib/render/software/ctrl/agg_slider_ctrl.pas b/src/corelib/render/software/ctrl/agg_slider_ctrl.pas index 6bd35880..6c89c955 100644 --- a/src/corelib/render/software/ctrl/agg_slider_ctrl.pas +++ b/src/corelib/render/software/ctrl/agg_slider_ctrl.pas @@ -1,695 +1,695 @@ -//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4 (Public License)
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
-// Pascal Port By: Milan Marusinec alias Milano
-// milan@marusinec.sk
-// http://www.aggpas.org
-// Copyright (c) 2005-2006
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//
-//----------------------------------------------------------------------------
-//
-// classes slider_ctrl_impl, slider_ctrl
-//
-// [Pascal Port History] -----------------------------------------------------
-//
-// 21.12.2005-Milano: Complete unit port
-// 18.12.2005-Milano: Unit port establishment
-//
-{ agg_slider_ctrl.pas }
-unit
- agg_slider_ctrl ;
-
-INTERFACE
-
-{$I agg_mode.inc }
-
-uses
- SysUtils ,
- agg_basics ,
- agg_ctrl ,
- agg_color ,
- agg_ellipse ,
- agg_path_storage ,
- agg_conv_stroke ,
- agg_gsv_text ,
- agg_math ,
- agg_math_stroke ;
-
-{ TYPES DEFINITION }
-type
- slider_ctrl_impl = object(ctrl )
- m_border_width ,
- m_border_extra ,
- m_text_thickness ,
- m_value ,
- m_preview_value ,
-
- m_min ,
- m_max : double;
-
- m_num_steps : unsigned;
- m_descending : boolean;
-
- m_label : array[0..63 ] of byte;
-
- m_xs1 ,
- m_ys1 ,
- m_xs2 ,
- m_ys2 ,
- m_pdx : double;
-
- m_mouse_move : boolean;
-
- m_vx ,
- m_vy : array[0..31 ] of double;
-
- m_ellipse : ellipse;
-
- m_idx ,
- m_vertex : unsigned;
-
- m_text : gsv_text;
- m_text_poly : conv_stroke;
- m_storage : path_storage;
-
- constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false );
- destructor Destruct; virtual;
-
- procedure border_width_(t : double; extra : double = 0.0 );
-
- procedure range_ (min ,max : double );
- procedure num_steps_ (num : unsigned );
- procedure label_ (fmt : PChar );
- procedure text_thickness_(t : double );
-
- function _descending : boolean;
- procedure descending_(v : boolean );
-
- function _value : double;
- procedure value_(v : double );
-
- function in_rect(x ,y : double ) : boolean; virtual;
-
- function on_mouse_button_down(x ,y : double ) : boolean; virtual;
- function on_mouse_button_up (x ,y : double ) : boolean; virtual;
-
- function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual;
- function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual;
-
- // Vertex source interface
- function num_paths : unsigned; virtual;
- procedure rewind(path_id : unsigned ); virtual;
- function vertex(x ,y : double_ptr ) : unsigned; virtual;
-
- // Private
- procedure calc_box;
- function normalize_value(preview_value_flag : boolean ) : boolean;
-
- end;
-
- slider_ctrl_ptr = ^slider_ctrl;
- slider_ctrl = object(slider_ctrl_impl )
- m_background_color ,
- m_triangle_color ,
- m_text_color ,
- m_pointer_preview_color ,
- m_pointer_color : aggclr;
-
- m_colors : array[0..5 ] of aggclr_ptr;
-
- constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false );
-
- procedure background_color_(c : aggclr_ptr );
- procedure pointer_color_ (c : aggclr_ptr );
-
- function _color(i : unsigned ) : aggclr_ptr; virtual;
-
- end;
-
-{ GLOBAL PROCEDURES }
-
-
-IMPLEMENTATION
-{ LOCAL VARIABLES & CONSTANTS }
-{ UNIT IMPLEMENTATION }
-{ CONSTRUCT }
-constructor slider_ctrl_impl.Construct;
-begin
- inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y );
-
- m_ellipse.Construct;
- m_text.Construct;
- m_text_poly.Construct(@m_text );
- m_storage.Construct;
-
- m_border_width :=1.0;
- m_border_extra :=(y2 - y1 ) / 2;
- m_text_thickness:=1.0;
- m_pdx :=0.0;
- m_mouse_move :=false;
- m_value :=0.5;
- m_preview_value :=0.5;
- m_min :=0.0;
- m_max :=1.0;
- m_num_steps :=0;
- m_descending :=false;
-
- m_label[0 ]:=0;
-
- calc_box;
-
-end;
-
-{ DESTRUCT }
-destructor slider_ctrl_impl.Destruct;
-begin
- m_storage.Destruct;
- m_text_poly.Destruct;
- m_text.Destruct;
-
-end;
-
-{ BORDER_WIDTH_ }
-procedure slider_ctrl_impl.border_width_;
-begin
- m_border_width:=t;
- m_border_extra:=extra;
-
- calc_box;
-
-end;
-
-{ RANGE_ }
-procedure slider_ctrl_impl.range_;
-begin
- m_min:=min;
- m_max:=max;
-
-end;
-
-{ NUM_STEPS_ }
-procedure slider_ctrl_impl.num_steps_;
-begin
- m_num_steps:=num;
-
-end;
-
-{ LABEL_ }
-procedure slider_ctrl_impl.label_;
-var
- len : unsigned;
-
-begin
- m_label[0 ]:=0;
-
- if fmt <> NIL then
- begin
- len:=StrLen(fmt );
-
- if len > 63 then
- len:=63;
-
- move(fmt^ ,m_label[0 ] ,len );
-
- m_label[len ]:=0;
-
- end;
-
-end;
-
-{ TEXT_THICKNESS_ }
-procedure slider_ctrl_impl.text_thickness_;
-begin
- m_text_thickness:=t;
-
-end;
-
-{ _DESCENDING }
-function slider_ctrl_impl._descending;
-begin
- result:=m_descending;
-
-end;
-
-{ DESCENDING_ }
-procedure slider_ctrl_impl.descending_;
-begin
- m_descending:=v;
-
-end;
-
-{ _VALUE }
-function slider_ctrl_impl._value;
-begin
- result:=m_value * (m_max - m_min ) + m_min;
-
-end;
-
-{ VALUE_ }
-procedure slider_ctrl_impl.value_;
-begin
- m_preview_value:=(v - m_min ) / (m_max - m_min );
-
- if m_preview_value > 1.0 then
- m_preview_value:=1.0;
-
- if m_preview_value < 0.0 then
- m_preview_value:=0.0;
-
- normalize_value(true );
-
-end;
-
-{ IN_RECT }
-function slider_ctrl_impl.in_rect;
-begin
- inverse_transform_xy(@x ,@y );
-
- result:=
- (x >= m_x1 ) and
- (x <= m_x2 ) and
- (y >= m_y1 ) and
- (y <= m_y2 );
-
-end;
-
-{ ON_MOUSE_BUTTON_DOWN }
-function slider_ctrl_impl.on_mouse_button_down;
-var
- xp ,yp : double;
-
-begin
- inverse_transform_xy(@x ,@y );
-
- xp:=m_xs1 + (m_xs2 - m_xs1 ) * m_value;
- yp:=(m_ys1 + m_ys2 ) / 2.0;
-
- if calc_distance(x ,y ,xp ,yp ) <= m_y2 - m_y1 then
- begin
- m_pdx:=xp - x;
-
- m_mouse_move:= true;
-
- result:=true;
-
- end
- else
- result:=false;
-
-end;
-
-{ ON_MOUSE_BUTTON_UP }
-function slider_ctrl_impl.on_mouse_button_up;
-begin
- m_mouse_move:=false;
-
- normalize_value(true );
-
- result:=true;
-
-end;
-
-{ ON_MOUSE_MOVE }
-function slider_ctrl_impl.on_mouse_move;
-var
- xp : double;
-
-begin
- inverse_transform_xy(@x ,@y );
-
- if not button_flag then
- begin
- on_mouse_button_up(x ,y );
-
- result:=false;
-
- exit;
-
- end;
-
- if m_mouse_move then
- begin
- xp:=x + m_pdx;
-
- m_preview_value:=(xp - m_xs1 ) / (m_xs2 - m_xs1 );
-
- if m_preview_value < 0.0 then
- m_preview_value:=0.0;
-
- if m_preview_value > 1.0 then
- m_preview_value:=1.0;
-
- result:=true;
-
- end
- else
- result:=false;
-
-end;
-
-{ ON_ARROW_KEYS }
-function slider_ctrl_impl.on_arrow_keys;
-var
- d : double;
-
-begin
- d:=0.005;
-
- if m_num_steps <> 0 then
- d:=1.0 / m_num_steps;
-
- if right or
- up then
- begin
- m_preview_value:=m_preview_value + d;
-
- if m_preview_value > 1.0 then
- m_preview_value:=1.0;
-
- normalize_value(true );
-
- result:=true;
-
- exit;
-
- end;
-
- if left or
- down then
- begin
- m_preview_value:=m_preview_value - d;
-
- if m_preview_value < 0.0 then
- m_preview_value:=0.0;
-
- normalize_value(true );
-
- result:=true;
-
- end
- else
- result:=false;
-
-end;
-
-{ NUM_PATHS }
-function slider_ctrl_impl.num_paths;
-begin
- result:=6;
-
-end;
-
-{ REWIND }
-procedure slider_ctrl_impl.rewind;
-var
- i : unsigned;
-
- d ,x : double;
-
- buf : array[0..255 ] of byte;
-
-label
- _0 ;
-
-begin
- m_idx:=path_id;
-
- case path_id of
- 0 : // Background
- begin
- _0 :
- m_vertex:=0;
-
- m_vx[0 ]:=m_x1 - m_border_extra;
- m_vy[0 ]:=m_y1 - m_border_extra;
- m_vx[1 ]:=m_x2 + m_border_extra;
- m_vy[1 ]:=m_y1 - m_border_extra;
- m_vx[2 ]:=m_x2 + m_border_extra;
- m_vy[2 ]:=m_y2 + m_border_extra;
- m_vx[3 ]:=m_x1 - m_border_extra;
- m_vy[3 ]:=m_y2 + m_border_extra;
-
- end;
-
- 1 : // Triangle
- begin
- m_vertex:=0;
-
- if m_descending then
- begin
- m_vx[0 ]:=m_x1;
- m_vy[0 ]:=m_y1;
- m_vx[1 ]:=m_x2;
- m_vy[1 ]:=m_y1;
- m_vx[2 ]:=m_x1;
- m_vy[2 ]:=m_y2;
- m_vx[3 ]:=m_x1;
- m_vy[3 ]:=m_y1;
-
- end
- else
- begin
- m_vx[0 ]:=m_x1;
- m_vy[0 ]:=m_y1;
- m_vx[1 ]:=m_x2;
- m_vy[1 ]:=m_y1;
- m_vx[2 ]:=m_x2;
- m_vy[2 ]:=m_y2;
- m_vx[3 ]:=m_x1;
- m_vy[3 ]:=m_y1;
-
- end;
-
- end;
-
- 2 :
- begin
- m_text.text_(@m_label[0 ] );
-
- if m_label[0 ] <> 0 then
- begin
- sprintf(@buf[0 ] ,@m_label[0 ] ,_value );
-
- m_text.text_(@buf[0 ] );
-
- end;
-
- m_text.start_point_(m_x1 ,m_y1 );
- m_text.size_ ((m_y2 - m_y1 ) * 1.2 ,m_y2 - m_y1 );
-
- m_text_poly.width_ (m_text_thickness );
- m_text_poly.line_join_(round_join );
- m_text_poly.line_cap_ (round_cap );
-
- m_text_poly.rewind(0 );
-
- end;
-
- 3 : // pointer preview
- m_ellipse.init(
- m_xs1 + (m_xs2 - m_xs1 ) * m_preview_value ,
- (m_ys1 + m_ys2 ) / 2.0 ,
- m_y2 - m_y1 ,
- m_y2 - m_y1 ,
- 32 );
-
- 4 : // pointer
- begin
- normalize_value(false );
-
- m_ellipse.init(
- m_xs1 + (m_xs2 - m_xs1 ) * m_value ,
- (m_ys1 + m_ys2 ) / 2.0 ,
- m_y2 - m_y1 ,
- m_y2 - m_y1 ,
- 32 );
-
- m_ellipse.rewind(0 );
-
- end;
-
- 5 :
- begin
- m_storage.remove_all;
-
- if m_num_steps <> 0 then
- begin
- d:=(m_xs2 - m_xs1 ) / m_num_steps;
-
- if d > 0.004 then
- d:=0.004;
-
- for i:=0 to m_num_steps do
- begin
- x:=m_xs1 + (m_xs2 - m_xs1 ) * i / m_num_steps;
-
- m_storage.move_to(x ,m_y1 );
-
- m_storage.line_to(x - d * (m_x2 - m_x1 ) ,m_y1 - m_border_extra );
- m_storage.line_to(x + d * (m_x2 - m_x1 ) ,m_y1 - m_border_extra );
-
- end;
-
- end;
-
- end;
-
- else
- goto _0;
-
- end;
-
-end;
-
-{ VERTEX }
-function slider_ctrl_impl.vertex;
-var
- cmd : unsigned;
-
-begin
- cmd:=path_cmd_line_to;
-
- case m_idx of
- 0 :
- begin
- if m_vertex = 0 then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 4 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 1 :
- begin
- if m_vertex = 0 then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 4 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 2 :
- cmd:=m_text_poly.vertex(x ,y );
-
- 3 ,4 :
- cmd:=m_ellipse.vertex(x ,y );
-
- 5 :
- cmd:=m_storage.vertex(x ,y );
-
- else
- cmd:=path_cmd_stop;
-
- end;
-
- if not is_stop(cmd ) then
- transform_xy(x ,y );
-
- result:=cmd;
-
-end;
-
-{ CALC_BOX }
-procedure slider_ctrl_impl.calc_box;
-begin
- m_xs1:=m_x1 + m_border_width;
- m_ys1:=m_y1 + m_border_width;
- m_xs2:=m_x2 - m_border_width;
- m_ys2:=m_y2 - m_border_width;
-
-end;
-
-{ NORMALIZE_VALUE }
-function slider_ctrl_impl.normalize_value;
-var
- ret : boolean;
- step : int;
-
-begin
- ret:=true;
-
- if m_num_steps <> 0 then
- begin
- step:=trunc(m_preview_value * m_num_steps + 0.5 );
- ret :=m_value <> (step / m_num_steps );
-
- m_value:=step / m_num_steps;
-
- end
- else
- m_value:=m_preview_value;
-
- if preview_value_flag then
- m_preview_value:=m_value;
-
- result:=ret;
-
-end;
-
-{ CONSTRUCT }
-constructor slider_ctrl.Construct;
-begin
- inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y );
-
- m_background_color.ConstrDbl (1.0 ,0.9 ,0.8 );
- m_triangle_color.ConstrDbl (0.7 ,0.6 ,0.6 );
- m_text_color.ConstrDbl (0.0 ,0.0 ,0.0 );
- m_pointer_preview_color.ConstrDbl(0.6 ,0.4 ,0.4 ,0.4 );
- m_pointer_color.ConstrDbl (0.8 ,0.0 ,0.0 ,0.6 );
-
- m_colors[0 ]:=@m_background_color;
- m_colors[1 ]:=@m_triangle_color;
- m_colors[2 ]:=@m_text_color;
- m_colors[3 ]:=@m_pointer_preview_color;
- m_colors[4 ]:=@m_pointer_color;
- m_colors[5 ]:=@m_text_color;
-
-end;
-
-{ BACKGROUND_COLOR_ }
-procedure slider_ctrl.background_color_;
-begin
- m_background_color:=c^;
-
-end;
-
-{ POINTER_COLOR_ }
-procedure slider_ctrl.pointer_color_;
-begin
- m_pointer_color:=c^;
-
-end;
-
-{ _COLOR }
-function slider_ctrl._color;
-begin
- result:=m_colors[i ];
-
-end;
-
-END.
-
+//---------------------------------------------------------------------------- +// Anti-Grain Geometry - Version 2.4 (Public License) +// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) +// +// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) +// Pascal Port By: Milan Marusinec alias Milano +// milan@marusinec.sk +// http://www.aggpas.org +// Copyright (c) 2005-2006 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +//---------------------------------------------------------------------------- +// Contact: mcseem@antigrain.com +// mcseemagg@yahoo.com +// http://www.antigrain.com +// +//---------------------------------------------------------------------------- +// +// classes slider_ctrl_impl, slider_ctrl +// +// [Pascal Port History] ----------------------------------------------------- +// +// 21.12.2005-Milano: Complete unit port +// 18.12.2005-Milano: Unit port establishment +// +{ agg_slider_ctrl.pas } +unit + agg_slider_ctrl ; + +INTERFACE + +{$I agg_mode.inc } + +uses + SysUtils , + agg_basics , + agg_ctrl , + agg_color , + agg_ellipse , + agg_path_storage , + agg_conv_stroke , + agg_gsv_text , + agg_math , + agg_math_stroke ; + +{ TYPES DEFINITION } +type + slider_ctrl_impl = object(ctrl ) + m_border_width , + m_border_extra , + m_text_thickness , + m_value , + m_preview_value , + + m_min , + m_max : double; + + m_num_steps : unsigned; + m_descending : boolean; + + m_label : array[0..63 ] of byte; + + m_xs1 , + m_ys1 , + m_xs2 , + m_ys2 , + m_pdx : double; + + m_mouse_move : boolean; + + m_vx , + m_vy : array[0..31 ] of double; + + m_ellipse : ellipse; + + m_idx , + m_vertex : unsigned; + + m_text : gsv_text; + m_text_poly : conv_stroke; + m_storage : path_storage; + + constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false ); + destructor Destruct; virtual; + + procedure border_width_(t : double; extra : double = 0.0 ); + + procedure range_ (min ,max : double ); + procedure num_steps_ (num : unsigned ); + procedure label_ (fmt : PChar ); + procedure text_thickness_(t : double ); + + function _descending : boolean; + procedure descending_(v : boolean ); + + function _value : double; + procedure value_(v : double ); + + function in_rect(x ,y : double ) : boolean; virtual; + + function on_mouse_button_down(x ,y : double ) : boolean; virtual; + function on_mouse_button_up (x ,y : double ) : boolean; virtual; + + function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual; + function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual; + + // Vertex source interface + function num_paths : unsigned; virtual; + procedure rewind(path_id : unsigned ); virtual; + function vertex(x ,y : double_ptr ) : unsigned; virtual; + + // Private + procedure calc_box; + function normalize_value(preview_value_flag : boolean ) : boolean; + + end; + + slider_ctrl_ptr = ^slider_ctrl; + slider_ctrl = object(slider_ctrl_impl ) + m_background_color , + m_triangle_color , + m_text_color , + m_pointer_preview_color , + m_pointer_color : aggclr; + + m_colors : array[0..5 ] of aggclr_ptr; + + constructor Construct(x1 ,y1 ,x2 ,y2 : double; flip_y : boolean = false ); + + procedure background_color_(c : aggclr_ptr ); + procedure pointer_color_ (c : aggclr_ptr ); + + function _color(i : unsigned ) : aggclr_ptr; virtual; + + end; + +{ GLOBAL PROCEDURES } + + +IMPLEMENTATION +{ LOCAL VARIABLES & CONSTANTS } +{ UNIT IMPLEMENTATION } +{ CONSTRUCT } +constructor slider_ctrl_impl.Construct; +begin + inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y ); + + m_ellipse.Construct; + m_text.Construct; + m_text_poly.Construct(@m_text ); + m_storage.Construct; + + m_border_width :=1.0; + m_border_extra :=(y2 - y1 ) / 2; + m_text_thickness:=1.0; + m_pdx :=0.0; + m_mouse_move :=false; + m_value :=0.5; + m_preview_value :=0.5; + m_min :=0.0; + m_max :=1.0; + m_num_steps :=0; + m_descending :=false; + + m_label[0 ]:=0; + + calc_box; + +end; + +{ DESTRUCT } +destructor slider_ctrl_impl.Destruct; +begin + m_storage.Destruct; + m_text_poly.Destruct; + m_text.Destruct; + +end; + +{ BORDER_WIDTH_ } +procedure slider_ctrl_impl.border_width_; +begin + m_border_width:=t; + m_border_extra:=extra; + + calc_box; + +end; + +{ RANGE_ } +procedure slider_ctrl_impl.range_; +begin + m_min:=min; + m_max:=max; + +end; + +{ NUM_STEPS_ } +procedure slider_ctrl_impl.num_steps_; +begin + m_num_steps:=num; + +end; + +{ LABEL_ } +procedure slider_ctrl_impl.label_; +var + len : unsigned; + +begin + m_label[0 ]:=0; + + if fmt <> NIL then + begin + len:=StrLen(fmt ); + + if len > 63 then + len:=63; + + move(fmt^ ,m_label[0 ] ,len ); + + m_label[len ]:=0; + + end; + +end; + +{ TEXT_THICKNESS_ } +procedure slider_ctrl_impl.text_thickness_; +begin + m_text_thickness:=t; + +end; + +{ _DESCENDING } +function slider_ctrl_impl._descending; +begin + result:=m_descending; + +end; + +{ DESCENDING_ } +procedure slider_ctrl_impl.descending_; +begin + m_descending:=v; + +end; + +{ _VALUE } +function slider_ctrl_impl._value; +begin + result:=m_value * (m_max - m_min ) + m_min; + +end; + +{ VALUE_ } +procedure slider_ctrl_impl.value_; +begin + m_preview_value:=(v - m_min ) / (m_max - m_min ); + + if m_preview_value > 1.0 then + m_preview_value:=1.0; + + if m_preview_value < 0.0 then + m_preview_value:=0.0; + + normalize_value(true ); + +end; + +{ IN_RECT } +function slider_ctrl_impl.in_rect; +begin + inverse_transform_xy(@x ,@y ); + + result:= + (x >= m_x1 ) and + (x <= m_x2 ) and + (y >= m_y1 ) and + (y <= m_y2 ); + +end; + +{ ON_MOUSE_BUTTON_DOWN } +function slider_ctrl_impl.on_mouse_button_down; +var + xp ,yp : double; + +begin + inverse_transform_xy(@x ,@y ); + + xp:=m_xs1 + (m_xs2 - m_xs1 ) * m_value; + yp:=(m_ys1 + m_ys2 ) / 2.0; + + if calc_distance(x ,y ,xp ,yp ) <= m_y2 - m_y1 then + begin + m_pdx:=xp - x; + + m_mouse_move:= true; + + result:=true; + + end + else + result:=false; + +end; + +{ ON_MOUSE_BUTTON_UP } +function slider_ctrl_impl.on_mouse_button_up; +begin + m_mouse_move:=false; + + normalize_value(true ); + + result:=true; + +end; + +{ ON_MOUSE_MOVE } +function slider_ctrl_impl.on_mouse_move; +var + xp : double; + +begin + inverse_transform_xy(@x ,@y ); + + if not button_flag then + begin + on_mouse_button_up(x ,y ); + + result:=false; + + exit; + + end; + + if m_mouse_move then + begin + xp:=x + m_pdx; + + m_preview_value:=(xp - m_xs1 ) / (m_xs2 - m_xs1 ); + + if m_preview_value < 0.0 then + m_preview_value:=0.0; + + if m_preview_value > 1.0 then + m_preview_value:=1.0; + + result:=true; + + end + else + result:=false; + +end; + +{ ON_ARROW_KEYS } +function slider_ctrl_impl.on_arrow_keys; +var + d : double; + +begin + d:=0.005; + + if m_num_steps <> 0 then + d:=1.0 / m_num_steps; + + if right or + up then + begin + m_preview_value:=m_preview_value + d; + + if m_preview_value > 1.0 then + m_preview_value:=1.0; + + normalize_value(true ); + + result:=true; + + exit; + + end; + + if left or + down then + begin + m_preview_value:=m_preview_value - d; + + if m_preview_value < 0.0 then + m_preview_value:=0.0; + + normalize_value(true ); + + result:=true; + + end + else + result:=false; + +end; + +{ NUM_PATHS } +function slider_ctrl_impl.num_paths; +begin + result:=6; + +end; + +{ REWIND } +procedure slider_ctrl_impl.rewind; +var + i : unsigned; + + d ,x : double; + + buf : array[0..255 ] of byte; + +label + _0 ; + +begin + m_idx:=path_id; + + case path_id of + 0 : // Background + begin + _0 : + m_vertex:=0; + + m_vx[0 ]:=m_x1 - m_border_extra; + m_vy[0 ]:=m_y1 - m_border_extra; + m_vx[1 ]:=m_x2 + m_border_extra; + m_vy[1 ]:=m_y1 - m_border_extra; + m_vx[2 ]:=m_x2 + m_border_extra; + m_vy[2 ]:=m_y2 + m_border_extra; + m_vx[3 ]:=m_x1 - m_border_extra; + m_vy[3 ]:=m_y2 + m_border_extra; + + end; + + 1 : // Triangle + begin + m_vertex:=0; + + if m_descending then + begin + m_vx[0 ]:=m_x1; + m_vy[0 ]:=m_y1; + m_vx[1 ]:=m_x2; + m_vy[1 ]:=m_y1; + m_vx[2 ]:=m_x1; + m_vy[2 ]:=m_y2; + m_vx[3 ]:=m_x1; + m_vy[3 ]:=m_y1; + + end + else + begin + m_vx[0 ]:=m_x1; + m_vy[0 ]:=m_y1; + m_vx[1 ]:=m_x2; + m_vy[1 ]:=m_y1; + m_vx[2 ]:=m_x2; + m_vy[2 ]:=m_y2; + m_vx[3 ]:=m_x1; + m_vy[3 ]:=m_y1; + + end; + + end; + + 2 : + begin + m_text.text_(@m_label[0 ] ); + + if m_label[0 ] <> 0 then + begin + sprintf(@buf[0 ] ,@m_label[0 ] ,_value ); + + m_text.text_(@buf[0 ] ); + + end; + + m_text.start_point_(m_x1 ,m_y1 ); + m_text.size_ ((m_y2 - m_y1 ) * 1.2 ,m_y2 - m_y1 ); + + m_text_poly.width_ (m_text_thickness ); + m_text_poly.line_join_(round_join ); + m_text_poly.line_cap_ (round_cap ); + + m_text_poly.rewind(0 ); + + end; + + 3 : // pointer preview + m_ellipse.init( + m_xs1 + (m_xs2 - m_xs1 ) * m_preview_value , + (m_ys1 + m_ys2 ) / 2.0 , + m_y2 - m_y1 , + m_y2 - m_y1 , + 32 ); + + 4 : // pointer + begin + normalize_value(false ); + + m_ellipse.init( + m_xs1 + (m_xs2 - m_xs1 ) * m_value , + (m_ys1 + m_ys2 ) / 2.0 , + m_y2 - m_y1 , + m_y2 - m_y1 , + 32 ); + + m_ellipse.rewind(0 ); + + end; + + 5 : + begin + m_storage.remove_all; + + if m_num_steps <> 0 then + begin + d:=(m_xs2 - m_xs1 ) / m_num_steps; + + if d > 0.004 then + d:=0.004; + + for i:=0 to m_num_steps do + begin + x:=m_xs1 + (m_xs2 - m_xs1 ) * i / m_num_steps; + + m_storage.move_to(x ,m_y1 ); + + m_storage.line_to(x - d * (m_x2 - m_x1 ) ,m_y1 - m_border_extra ); + m_storage.line_to(x + d * (m_x2 - m_x1 ) ,m_y1 - m_border_extra ); + + end; + + end; + + end; + + else + goto _0; + + end; + +end; + +{ VERTEX } +function slider_ctrl_impl.vertex; +var + cmd : unsigned; + +begin + cmd:=path_cmd_line_to; + + case m_idx of + 0 : + begin + if m_vertex = 0 then + cmd:=path_cmd_move_to; + + if m_vertex >= 4 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 1 : + begin + if m_vertex = 0 then + cmd:=path_cmd_move_to; + + if m_vertex >= 4 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 2 : + cmd:=m_text_poly.vertex(x ,y ); + + 3 ,4 : + cmd:=m_ellipse.vertex(x ,y ); + + 5 : + cmd:=m_storage.vertex(x ,y ); + + else + cmd:=path_cmd_stop; + + end; + + if not is_stop(cmd ) then + transform_xy(x ,y ); + + result:=cmd; + +end; + +{ CALC_BOX } +procedure slider_ctrl_impl.calc_box; +begin + m_xs1:=m_x1 + m_border_width; + m_ys1:=m_y1 + m_border_width; + m_xs2:=m_x2 - m_border_width; + m_ys2:=m_y2 - m_border_width; + +end; + +{ NORMALIZE_VALUE } +function slider_ctrl_impl.normalize_value; +var + ret : boolean; + step : int; + +begin + ret:=true; + + if m_num_steps <> 0 then + begin + step:=trunc(m_preview_value * m_num_steps + 0.5 ); + ret :=m_value <> (step / m_num_steps ); + + m_value:=step / m_num_steps; + + end + else + m_value:=m_preview_value; + + if preview_value_flag then + m_preview_value:=m_value; + + result:=ret; + +end; + +{ CONSTRUCT } +constructor slider_ctrl.Construct; +begin + inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y ); + + m_background_color.ConstrDbl (1.0 ,0.9 ,0.8 ); + m_triangle_color.ConstrDbl (0.7 ,0.6 ,0.6 ); + m_text_color.ConstrDbl (0.0 ,0.0 ,0.0 ); + m_pointer_preview_color.ConstrDbl(0.6 ,0.4 ,0.4 ,0.4 ); + m_pointer_color.ConstrDbl (0.8 ,0.0 ,0.0 ,0.6 ); + + m_colors[0 ]:=@m_background_color; + m_colors[1 ]:=@m_triangle_color; + m_colors[2 ]:=@m_text_color; + m_colors[3 ]:=@m_pointer_preview_color; + m_colors[4 ]:=@m_pointer_color; + m_colors[5 ]:=@m_text_color; + +end; + +{ BACKGROUND_COLOR_ } +procedure slider_ctrl.background_color_; +begin + m_background_color:=c^; + +end; + +{ POINTER_COLOR_ } +procedure slider_ctrl.pointer_color_; +begin + m_pointer_color:=c^; + +end; + +{ _COLOR } +function slider_ctrl._color; +begin + result:=m_colors[i ]; + +end; + +END. + diff --git a/src/corelib/render/software/ctrl/agg_spline_ctrl.pas b/src/corelib/render/software/ctrl/agg_spline_ctrl.pas index 255bdb27..71e05a1a 100644 --- a/src/corelib/render/software/ctrl/agg_spline_ctrl.pas +++ b/src/corelib/render/software/ctrl/agg_spline_ctrl.pas @@ -1,816 +1,816 @@ -//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4 (Public License)
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
-// Pascal Port By: Milan Marusinec alias Milano
-// milan@marusinec.sk
-// http://www.aggpas.org
-// Copyright (c) 2005-2006
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//
-//----------------------------------------------------------------------------
-//
-// classes spline_ctrl_impl, spline_ctrl
-//
-// Class that can be used to create an interactive control to set up
-// gamma arrays.
-//
-// [Pascal Port History] -----------------------------------------------------
-//
-// 23.02.2006-Milano: Unit port establishment
-//
-{ agg_spline_ctrl.pas }
-unit
- agg_spline_ctrl ;
-
-INTERFACE
-
-{$I agg_mode.inc }
-
-uses
- agg_basics ,
- agg_ellipse ,
- agg_bspline ,
- agg_conv_stroke ,
- agg_path_storage ,
- agg_trans_affine ,
- agg_color ,
- agg_ctrl ,
- agg_math ;
-
-{ TYPES DEFINITION }
-type
- spline_ctrl_impl = object(ctrl )
- m_num_pnt : unsigned;
-
- m_xp ,
- m_yp : array[0..31 ] of double;
-
- m_spline : bspline;
-
- m_spline_values : array[0..255 ] of double;
- m_spline_values8 : array[0..255 ] of int8u;
- m_border_width ,
- m_border_extra ,
- m_curve_width ,
- m_point_size ,
-
- m_xs1 ,
- m_ys1 ,
- m_xs2 ,
- m_ys2 : double;
-
- m_curve_pnt : path_storage;
- m_curve_poly : conv_stroke;
- m_ellipse : ellipse;
-
- m_idx ,
- m_vertex : unsigned;
-
- m_vx ,
- m_vy : array[0..31 ] of double;
-
- m_active_pnt ,
- m_move_pnt : int;
-
- m_pdx ,
- m_pdy : double;
-
- constructor Construct(x1 ,y1 ,x2 ,y2 : double; num_pnt : unsigned; flip_y : boolean = false );
- destructor Destruct; virtual;
-
- // Set other parameters
- procedure border_width_(t : double; extra : double = 0.0 );
- procedure curve_width_ (t : double );
- procedure point_size_ (s : double );
-
- // Event handlers. Just call them if the respective events
- // in your system occure. The functions return true if redrawing
- // is required.
- function in_rect(x ,y : double ) : boolean; virtual;
-
- function on_mouse_button_down(x ,y : double ) : boolean; virtual;
- function on_mouse_button_up (x ,y : double ) : boolean; virtual;
-
- function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual;
- function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual;
-
- // Spline
- procedure active_point_(i : int );
-
- function _spline : double_ptr;
- function _spline8 : int8u_ptr;
-
- function _value(x : double ) : double;
- procedure value_(idx : unsigned; y : double );
- procedure point_(idx : unsigned; x ,y : double );
-
- procedure x_(idx : unsigned; x : double );
- procedure y_(idx : unsigned; y : double );
- function _x(idx : unsigned ) : double;
- function _y(idx : unsigned ) : double;
-
- procedure update_spline;
-
- // Vertex soutce interface
- function num_paths : unsigned; virtual;
- procedure rewind(path_id : unsigned ); virtual;
- function vertex(x ,y : double_ptr ) : unsigned; virtual;
-
- // Private
- procedure calc_spline_box;
- procedure calc_curve;
- function calc_xp(idx : unsigned ) : double;
- function calc_yp(idx : unsigned ) : double;
- procedure set_xp (idx : unsigned; val : double );
- procedure set_yp (idx : unsigned; val : double );
-
- end;
-
- spline_ctrl = object(spline_ctrl_impl )
- m_background_color ,
- m_border_color ,
- m_curve_color ,
- m_inactive_pnt_color ,
- m_active_pnt_color : aggclr;
-
- m_colors : array[0..4 ] of aggclr_ptr;
-
- constructor Construct(x1 ,y1 ,x2 ,y2 : double; num_pnt : unsigned; flip_y : boolean = false );
-
- procedure background_color_ (c : aggclr_ptr );
- procedure border_color_ (c : aggclr_ptr );
- procedure curve_color_ (c : aggclr_ptr );
- procedure inactive_pnt_color_(c : aggclr_ptr );
- procedure active_pnt_color_ (c : aggclr_ptr );
-
- function _color(i : unsigned ) : aggclr_ptr; virtual;
-
- end;
-
-{ GLOBAL PROCEDURES }
-
-
-IMPLEMENTATION
-{ LOCAL VARIABLES & CONSTANTS }
-{ UNIT IMPLEMENTATION }
-{ CONSTRUCT }
-constructor spline_ctrl_impl.Construct;
-var
- i : unsigned;
-
-begin
- inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y );
-
- m_num_pnt:=num_pnt;
-
- m_border_width:=1.0;
- m_border_extra:=0.0;
- m_curve_width :=1.0;
- m_point_size :=3.0;
-
- m_spline.Construct;
- m_curve_pnt.Construct;
- m_curve_poly.Construct(@m_curve_pnt );
- m_ellipse.Construct;
-
- m_idx :=0;
- m_vertex :=0;
- m_active_pnt:=-1;
- m_move_pnt :=-1;
-
- m_pdx:=0.0;
- m_pdy:=0.0;
-
- if m_num_pnt < 4 then
- m_num_pnt:=4;
-
- if m_num_pnt > 32 then
- m_num_pnt:=32;
-
- for i:=0 to m_num_pnt - 1 do
- begin
- m_xp[i ]:=i / (m_num_pnt - 1 );
- m_yp[i ]:=0.5;
-
- end;
-
- calc_spline_box;
- update_spline;
-
-end;
-
-{ DESTRUCT }
-destructor spline_ctrl_impl.Destruct;
-begin
- m_spline.Destruct;
- m_curve_pnt.Destruct;
- m_curve_poly.Destruct;
-
-end;
-
-{ BORDER_WIDTH_ }
-procedure spline_ctrl_impl.border_width_;
-begin
- m_border_width:=t;
- m_border_extra:=extra;
-
- calc_spline_box;
-
-end;
-
-{ CURVE_WIDTH_ }
-procedure spline_ctrl_impl.curve_width_;
-begin
- m_curve_width:=t;
-
-end;
-
-{ POINT_SIZE_ }
-procedure spline_ctrl_impl.point_size_;
-begin
- m_point_size:=s;
-
-end;
-
-{ IN_RECT }
-function spline_ctrl_impl.in_rect;
-begin
- inverse_transform_xy(@x ,@y );
-
- result:=
- (x >= m_x1 ) and
- (x <= m_x2 ) and
- (y >= m_y1 ) and
- (y <= m_y2 );
-
-end;
-
-{ ON_MOUSE_BUTTON_DOWN }
-function spline_ctrl_impl.on_mouse_button_down;
-var
- i : unsigned;
-
- xp ,yp : double;
-
-begin
- inverse_transform_xy(@x ,@y );
-
- for i:=0 to m_num_pnt - 1 do
- begin
- xp:=calc_xp(i );
- yp:=calc_yp(i );
-
- if calc_distance(x ,y ,xp ,yp ) <= m_point_size + 1 then
- begin
- m_pdx:=xp - x;
- m_pdy:=yp - y;
-
- m_active_pnt:=i;
- m_move_pnt :=i;
-
- result:=true;
-
- exit;
-
- end;
-
- end;
-
- result:=false;
-
-end;
-
-{ ON_MOUSE_BUTTON_UP }
-function spline_ctrl_impl.on_mouse_button_up;
-begin
- if m_move_pnt >= 0 then
- begin
- m_move_pnt:=-1;
-
- result:=true;
-
- end
- else
- result:=false;
-
-end;
-
-{ ON_MOUSE_MOVE }
-function spline_ctrl_impl.on_mouse_move;
-var
- xp ,yp : double;
-
-begin
- inverse_transform_xy(@x ,@y );
-
- if not button_flag then
- begin
- result:=on_mouse_button_up(x ,y );
-
- exit;
-
- end;
-
- if m_move_pnt >= 0 then
- begin
- xp:=x + m_pdx;
- yp:=y + m_pdy;
-
- set_xp(m_move_pnt ,(xp - m_xs1 ) / (m_xs2 - m_xs1 ) );
- set_yp(m_move_pnt ,(yp - m_ys1 ) / (m_ys2 - m_ys1 ) );
-
- update_spline;
-
- result:=true;
-
- end
- else
- result:=false;
-
-end;
-
-{ ON_ARROW_KEYS }
-function spline_ctrl_impl.on_arrow_keys;
-var
- kx ,ky : double;
-
- ret : boolean;
-
-begin
- kx :=0.0;
- ky :=0.0;
- ret:=false;
-
- if m_active_pnt >= 0 then
- begin
- kx:=m_xp[m_active_pnt ];
- ky:=m_yp[m_active_pnt ];
-
- if left then
- begin
- kx :=kx - 0.001;
- ret:=true;
-
- end;
-
- if right then
- begin
- kx :=kx + 0.001;
- ret:=true;
-
- end;
-
- if down then
- begin
- ky :=ky - 0.001;
- ret:=true;
-
- end;
-
- if up then
- begin
- ky :=ky + 0.001;
- ret:=true;
-
- end;
-
- end;
-
- if ret then
- begin
- set_xp(m_active_pnt ,kx );
- set_yp(m_active_pnt ,ky );
-
- update_spline;
-
- end;
-
- result:=ret;
-
-end;
-
-{ ACTIVE_POINT_ }
-procedure spline_ctrl_impl.active_point_;
-begin
- m_active_pnt:=i;
-
-end;
-
-{ _SPLINE }
-function spline_ctrl_impl._spline;
-begin
- result:=@m_spline_values;
-
-end;
-
-{ _SPLINE8 }
-function spline_ctrl_impl._spline8;
-begin
- result:=@m_spline_values8;
-
-end;
-
-{ _VALUE }
-function spline_ctrl_impl._value;
-begin
- x:=m_spline.get(x );
-
- if x < 0.0 then
- x:=0.0;
-
- if x > 1.0 then
- x:=1.0;
-
- result:=x;
-
-end;
-
-{ VALUE_ }
-procedure spline_ctrl_impl.value_;
-begin
- if idx < m_num_pnt then
- set_yp(idx ,y );
-
-end;
-
-{ POINT_ }
-procedure spline_ctrl_impl.point_;
-begin
- if idx < m_num_pnt then
- begin
- set_xp(idx ,x );
- set_yp(idx ,y );
-
- end;
-
-end;
-
-{ X_ }
-procedure spline_ctrl_impl.x_;
-begin
- m_xp[idx ]:=x;
-
-end;
-
-{ Y_ }
-procedure spline_ctrl_impl.y_;
-begin
- m_yp[idx ]:=y;
-
-end;
-
-{ _X }
-function spline_ctrl_impl._x;
-begin
- result:=m_xp[idx ];
-
-end;
-
-{ _Y }
-function spline_ctrl_impl._y;
-begin
- result:=m_yp[idx ];
-
-end;
-
-{ UPDATE_SPLINE }
-procedure spline_ctrl_impl.update_spline;
-var
- i : int;
-
-begin
- m_spline.init(m_num_pnt ,@m_xp ,@m_yp );
-
- for i:=0 to 255 do
- begin
- m_spline_values[i ]:=m_spline.get(i / 255.0 );
-
- if m_spline_values[i ] < 0.0 then
- m_spline_values[i ]:=0.0;
-
- if m_spline_values[i ] > 1.0 then
- m_spline_values[i ]:=1.0;
-
- m_spline_values8[i ]:=int8u(trunc(m_spline_values[i ] * 255.0 ) );
-
- end;
-
-end;
-
-{ NUM_PATHS }
-function spline_ctrl_impl.num_paths;
-begin
- result:=5;
-
-end;
-
-{ REWIND }
-procedure spline_ctrl_impl.rewind;
-var
- i : unsigned;
-
-begin
- m_idx:=path_id;
-
- case path_id of
- 0 : // Background
- begin
- m_vertex:=0;
-
- m_vx[0 ]:=m_x1 - m_border_extra;
- m_vy[0 ]:=m_y1 - m_border_extra;
- m_vx[1 ]:=m_x2 + m_border_extra;
- m_vy[1 ]:=m_y1 - m_border_extra;
- m_vx[2 ]:=m_x2 + m_border_extra;
- m_vy[2 ]:=m_y2 + m_border_extra;
- m_vx[3 ]:=m_x1 - m_border_extra;
- m_vy[3 ]:=m_y2 + m_border_extra;
-
- end;
-
- 1 : // Border
- begin
- m_vertex:=0;
-
- m_vx[0 ]:=m_x1;
- m_vy[0 ]:=m_y1;
- m_vx[1 ]:=m_x2;
- m_vy[1 ]:=m_y1;
- m_vx[2 ]:=m_x2;
- m_vy[2 ]:=m_y2;
- m_vx[3 ]:=m_x1;
- m_vy[3 ]:=m_y2;
- m_vx[4 ]:=m_x1 + m_border_width;
- m_vy[4 ]:=m_y1 + m_border_width;
- m_vx[5 ]:=m_x1 + m_border_width;
- m_vy[5 ]:=m_y2 - m_border_width;
- m_vx[6 ]:=m_x2 - m_border_width;
- m_vy[6 ]:=m_y2 - m_border_width;
- m_vx[7 ]:=m_x2 - m_border_width;
- m_vy[7 ]:=m_y1 + m_border_width;
-
- end;
-
- 2 : // Curve
- begin
- calc_curve;
-
- m_curve_poly.width_(m_curve_width );
- m_curve_poly.rewind(0 );
-
- end;
-
- 3 : // Inactive points
- begin
- m_curve_pnt.remove_all;
-
- for i:=0 to m_num_pnt - 1 do
- if i <> m_active_pnt then
- begin
- m_ellipse.init(
- calc_xp(i ) ,calc_yp(i ) ,
- m_point_size ,m_point_size ,32 );
-
- m_curve_pnt.add_path(@m_ellipse ,0 ,false );
-
- end;
-
- m_curve_poly.rewind(0 );
-
- end;
-
- 4 : // Active point
- begin
- m_curve_pnt.remove_all;
-
- if m_active_pnt >= 0 then
- begin
- m_ellipse.init(
- calc_xp(m_active_pnt ) ,calc_yp(m_active_pnt ) ,
- m_point_size ,m_point_size ,32 );
-
- m_curve_pnt.add_path(@m_ellipse );
-
- end;
-
- m_curve_poly.rewind(0 );
-
- end;
-
- end;
-
-end;
-
-{ VERTEX }
-function spline_ctrl_impl.vertex;
-var
- cmd : unsigned;
-
-begin
- cmd:=path_cmd_line_to;
-
- case m_idx of
- 0 :
- begin
- if m_vertex = 0 then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 4 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 1 :
- begin
- if (m_vertex = 0 ) or
- (m_vertex = 4 ) then
- cmd:=path_cmd_move_to;
-
- if m_vertex >= 8 then
- cmd:=path_cmd_stop;
-
- x^:=m_vx[m_vertex ];
- y^:=m_vy[m_vertex ];
-
- inc(m_vertex );
-
- end;
-
- 2 :
- cmd:=m_curve_poly.vertex(x ,y );
-
- 3 ,4 :
- cmd:=m_curve_pnt.vertex(x ,y );
-
- else
- cmd:=path_cmd_stop;
-
- end;
-
- if not is_stop(cmd ) then
- transform_xy(x ,y );
-
- result:=cmd;
-
-end;
-
-{ CALC_SPLINE_BOX }
-procedure spline_ctrl_impl.calc_spline_box;
-begin
- m_xs1:=m_x1 + m_border_width;
- m_ys1:=m_y1 + m_border_width;
- m_xs2:=m_x2 - m_border_width;
- m_ys2:=m_y2 - m_border_width;
-
-end;
-
-{ CALC_CURVE }
-procedure spline_ctrl_impl.calc_curve;
-var
- i : int;
-
-begin
- m_curve_pnt.remove_all;
- m_curve_pnt.move_to(m_xs1 ,m_ys1 + (m_ys2 - m_ys1 ) * m_spline_values[0 ] );
-
- for i:=1 to 255 do
- m_curve_pnt.line_to(
- m_xs1 + (m_xs2 - m_xs1 ) * i / 255.0 ,
- m_ys1 + (m_ys2 - m_ys1 ) * m_spline_values[i ] );
-
-end;
-
-{ CALC_XP }
-function spline_ctrl_impl.calc_xp;
-begin
- result:=m_xs1 + (m_xs2 - m_xs1 ) * m_xp[idx ];
-
-end;
-
-{ CALC_YP }
-function spline_ctrl_impl.calc_yp;
-begin
- result:=m_ys1 + (m_ys2 - m_ys1 ) * m_yp[idx ];
-
-end;
-
-{ SET_XP }
-procedure spline_ctrl_impl.set_xp;
-begin
- if val < 0.0 then
- val:=0.0;
-
- if val > 1.0 then
- val:=1.0;
-
- if idx = 0 then
- val:=0.0
- else
- if idx = m_num_pnt - 1 then
- val:=1.0
- else
- begin
- if val < m_xp[idx - 1 ] + 0.001 then
- val:=m_xp[idx - 1 ] + 0.001;
-
- if val > m_xp[idx + 1 ] - 0.001 then
- val:=m_xp[idx + 1 ] - 0.001;
-
- end;
-
- m_xp[idx ]:=val;
-
-end;
-
-{ SET_YP }
-procedure spline_ctrl_impl.set_yp;
-begin
- if val < 0.0 then
- val:=0.0;
-
- if val > 1.0 then
- val:=1.0;
-
- m_yp[idx ]:=val;
-
-end;
-
-{ CONSTRUCT }
-constructor spline_ctrl.Construct;
-begin
- inherited Construct(x1 ,y1 ,x2 ,y2 ,num_pnt ,flip_y );
-
- m_background_color.ConstrDbl (1.0 ,1.0 ,0.9 );
- m_border_color.ConstrDbl (0.0 ,0.0 ,0.0 );
- m_curve_color.ConstrDbl (0.0 ,0.0 ,0.0 );
- m_inactive_pnt_color.ConstrDbl(0.0 ,0.0 ,0.0 );
- m_active_pnt_color.ConstrDbl (1.0 ,0.0 ,0.0 );
-
- m_colors[0 ]:=@m_background_color;
- m_colors[1 ]:=@m_border_color;
- m_colors[2 ]:=@m_curve_color;
- m_colors[3 ]:=@m_inactive_pnt_color;
- m_colors[4 ]:=@m_active_pnt_color;
-
-end;
-
-{ BACKGROUND_COLOR_ }
-procedure spline_ctrl.background_color_;
-begin
- m_background_color:=c^;
-
-end;
-
-{ BORDER_COLOR_ }
-procedure spline_ctrl.border_color_;
-begin
- m_border_color:=c^;
-
-end;
-
-{ CURVE_COLOR_ }
-procedure spline_ctrl.curve_color_;
-begin
- m_curve_color:=c^;
-
-end;
-
-{ INACTIVE_PNT_COLOR_ }
-procedure spline_ctrl.inactive_pnt_color_;
-begin
- m_inactive_pnt_color:=c^;
-
-end;
-
-{ ACTIVE_PNT_COLOR_ }
-procedure spline_ctrl.active_pnt_color_;
-begin
- m_active_pnt_color:=c^;
-
-end;
-
-{ _COLOR }
-function spline_ctrl._color;
-begin
- result:=m_colors[i ];
-
-end;
-
-END.
-
+//---------------------------------------------------------------------------- +// Anti-Grain Geometry - Version 2.4 (Public License) +// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) +// +// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) +// Pascal Port By: Milan Marusinec alias Milano +// milan@marusinec.sk +// http://www.aggpas.org +// Copyright (c) 2005-2006 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +//---------------------------------------------------------------------------- +// Contact: mcseem@antigrain.com +// mcseemagg@yahoo.com +// http://www.antigrain.com +// +//---------------------------------------------------------------------------- +// +// classes spline_ctrl_impl, spline_ctrl +// +// Class that can be used to create an interactive control to set up +// gamma arrays. +// +// [Pascal Port History] ----------------------------------------------------- +// +// 23.02.2006-Milano: Unit port establishment +// +{ agg_spline_ctrl.pas } +unit + agg_spline_ctrl ; + +INTERFACE + +{$I agg_mode.inc } + +uses + agg_basics , + agg_ellipse , + agg_bspline , + agg_conv_stroke , + agg_path_storage , + agg_trans_affine , + agg_color , + agg_ctrl , + agg_math ; + +{ TYPES DEFINITION } +type + spline_ctrl_impl = object(ctrl ) + m_num_pnt : unsigned; + + m_xp , + m_yp : array[0..31 ] of double; + + m_spline : bspline; + + m_spline_values : array[0..255 ] of double; + m_spline_values8 : array[0..255 ] of int8u; + m_border_width , + m_border_extra , + m_curve_width , + m_point_size , + + m_xs1 , + m_ys1 , + m_xs2 , + m_ys2 : double; + + m_curve_pnt : path_storage; + m_curve_poly : conv_stroke; + m_ellipse : ellipse; + + m_idx , + m_vertex : unsigned; + + m_vx , + m_vy : array[0..31 ] of double; + + m_active_pnt , + m_move_pnt : int; + + m_pdx , + m_pdy : double; + + constructor Construct(x1 ,y1 ,x2 ,y2 : double; num_pnt : unsigned; flip_y : boolean = false ); + destructor Destruct; virtual; + + // Set other parameters + procedure border_width_(t : double; extra : double = 0.0 ); + procedure curve_width_ (t : double ); + procedure point_size_ (s : double ); + + // Event handlers. Just call them if the respective events + // in your system occure. The functions return true if redrawing + // is required. + function in_rect(x ,y : double ) : boolean; virtual; + + function on_mouse_button_down(x ,y : double ) : boolean; virtual; + function on_mouse_button_up (x ,y : double ) : boolean; virtual; + + function on_mouse_move(x ,y : double; button_flag : boolean ) : boolean; virtual; + function on_arrow_keys(left ,right ,down ,up : boolean ) : boolean; virtual; + + // Spline + procedure active_point_(i : int ); + + function _spline : double_ptr; + function _spline8 : int8u_ptr; + + function _value(x : double ) : double; + procedure value_(idx : unsigned; y : double ); + procedure point_(idx : unsigned; x ,y : double ); + + procedure x_(idx : unsigned; x : double ); + procedure y_(idx : unsigned; y : double ); + function _x(idx : unsigned ) : double; + function _y(idx : unsigned ) : double; + + procedure update_spline; + + // Vertex soutce interface + function num_paths : unsigned; virtual; + procedure rewind(path_id : unsigned ); virtual; + function vertex(x ,y : double_ptr ) : unsigned; virtual; + + // Private + procedure calc_spline_box; + procedure calc_curve; + function calc_xp(idx : unsigned ) : double; + function calc_yp(idx : unsigned ) : double; + procedure set_xp (idx : unsigned; val : double ); + procedure set_yp (idx : unsigned; val : double ); + + end; + + spline_ctrl = object(spline_ctrl_impl ) + m_background_color , + m_border_color , + m_curve_color , + m_inactive_pnt_color , + m_active_pnt_color : aggclr; + + m_colors : array[0..4 ] of aggclr_ptr; + + constructor Construct(x1 ,y1 ,x2 ,y2 : double; num_pnt : unsigned; flip_y : boolean = false ); + + procedure background_color_ (c : aggclr_ptr ); + procedure border_color_ (c : aggclr_ptr ); + procedure curve_color_ (c : aggclr_ptr ); + procedure inactive_pnt_color_(c : aggclr_ptr ); + procedure active_pnt_color_ (c : aggclr_ptr ); + + function _color(i : unsigned ) : aggclr_ptr; virtual; + + end; + +{ GLOBAL PROCEDURES } + + +IMPLEMENTATION +{ LOCAL VARIABLES & CONSTANTS } +{ UNIT IMPLEMENTATION } +{ CONSTRUCT } +constructor spline_ctrl_impl.Construct; +var + i : unsigned; + +begin + inherited Construct(x1 ,y1 ,x2 ,y2 ,flip_y ); + + m_num_pnt:=num_pnt; + + m_border_width:=1.0; + m_border_extra:=0.0; + m_curve_width :=1.0; + m_point_size :=3.0; + + m_spline.Construct; + m_curve_pnt.Construct; + m_curve_poly.Construct(@m_curve_pnt ); + m_ellipse.Construct; + + m_idx :=0; + m_vertex :=0; + m_active_pnt:=-1; + m_move_pnt :=-1; + + m_pdx:=0.0; + m_pdy:=0.0; + + if m_num_pnt < 4 then + m_num_pnt:=4; + + if m_num_pnt > 32 then + m_num_pnt:=32; + + for i:=0 to m_num_pnt - 1 do + begin + m_xp[i ]:=i / (m_num_pnt - 1 ); + m_yp[i ]:=0.5; + + end; + + calc_spline_box; + update_spline; + +end; + +{ DESTRUCT } +destructor spline_ctrl_impl.Destruct; +begin + m_spline.Destruct; + m_curve_pnt.Destruct; + m_curve_poly.Destruct; + +end; + +{ BORDER_WIDTH_ } +procedure spline_ctrl_impl.border_width_; +begin + m_border_width:=t; + m_border_extra:=extra; + + calc_spline_box; + +end; + +{ CURVE_WIDTH_ } +procedure spline_ctrl_impl.curve_width_; +begin + m_curve_width:=t; + +end; + +{ POINT_SIZE_ } +procedure spline_ctrl_impl.point_size_; +begin + m_point_size:=s; + +end; + +{ IN_RECT } +function spline_ctrl_impl.in_rect; +begin + inverse_transform_xy(@x ,@y ); + + result:= + (x >= m_x1 ) and + (x <= m_x2 ) and + (y >= m_y1 ) and + (y <= m_y2 ); + +end; + +{ ON_MOUSE_BUTTON_DOWN } +function spline_ctrl_impl.on_mouse_button_down; +var + i : unsigned; + + xp ,yp : double; + +begin + inverse_transform_xy(@x ,@y ); + + for i:=0 to m_num_pnt - 1 do + begin + xp:=calc_xp(i ); + yp:=calc_yp(i ); + + if calc_distance(x ,y ,xp ,yp ) <= m_point_size + 1 then + begin + m_pdx:=xp - x; + m_pdy:=yp - y; + + m_active_pnt:=i; + m_move_pnt :=i; + + result:=true; + + exit; + + end; + + end; + + result:=false; + +end; + +{ ON_MOUSE_BUTTON_UP } +function spline_ctrl_impl.on_mouse_button_up; +begin + if m_move_pnt >= 0 then + begin + m_move_pnt:=-1; + + result:=true; + + end + else + result:=false; + +end; + +{ ON_MOUSE_MOVE } +function spline_ctrl_impl.on_mouse_move; +var + xp ,yp : double; + +begin + inverse_transform_xy(@x ,@y ); + + if not button_flag then + begin + result:=on_mouse_button_up(x ,y ); + + exit; + + end; + + if m_move_pnt >= 0 then + begin + xp:=x + m_pdx; + yp:=y + m_pdy; + + set_xp(m_move_pnt ,(xp - m_xs1 ) / (m_xs2 - m_xs1 ) ); + set_yp(m_move_pnt ,(yp - m_ys1 ) / (m_ys2 - m_ys1 ) ); + + update_spline; + + result:=true; + + end + else + result:=false; + +end; + +{ ON_ARROW_KEYS } +function spline_ctrl_impl.on_arrow_keys; +var + kx ,ky : double; + + ret : boolean; + +begin + kx :=0.0; + ky :=0.0; + ret:=false; + + if m_active_pnt >= 0 then + begin + kx:=m_xp[m_active_pnt ]; + ky:=m_yp[m_active_pnt ]; + + if left then + begin + kx :=kx - 0.001; + ret:=true; + + end; + + if right then + begin + kx :=kx + 0.001; + ret:=true; + + end; + + if down then + begin + ky :=ky - 0.001; + ret:=true; + + end; + + if up then + begin + ky :=ky + 0.001; + ret:=true; + + end; + + end; + + if ret then + begin + set_xp(m_active_pnt ,kx ); + set_yp(m_active_pnt ,ky ); + + update_spline; + + end; + + result:=ret; + +end; + +{ ACTIVE_POINT_ } +procedure spline_ctrl_impl.active_point_; +begin + m_active_pnt:=i; + +end; + +{ _SPLINE } +function spline_ctrl_impl._spline; +begin + result:=@m_spline_values; + +end; + +{ _SPLINE8 } +function spline_ctrl_impl._spline8; +begin + result:=@m_spline_values8; + +end; + +{ _VALUE } +function spline_ctrl_impl._value; +begin + x:=m_spline.get(x ); + + if x < 0.0 then + x:=0.0; + + if x > 1.0 then + x:=1.0; + + result:=x; + +end; + +{ VALUE_ } +procedure spline_ctrl_impl.value_; +begin + if idx < m_num_pnt then + set_yp(idx ,y ); + +end; + +{ POINT_ } +procedure spline_ctrl_impl.point_; +begin + if idx < m_num_pnt then + begin + set_xp(idx ,x ); + set_yp(idx ,y ); + + end; + +end; + +{ X_ } +procedure spline_ctrl_impl.x_; +begin + m_xp[idx ]:=x; + +end; + +{ Y_ } +procedure spline_ctrl_impl.y_; +begin + m_yp[idx ]:=y; + +end; + +{ _X } +function spline_ctrl_impl._x; +begin + result:=m_xp[idx ]; + +end; + +{ _Y } +function spline_ctrl_impl._y; +begin + result:=m_yp[idx ]; + +end; + +{ UPDATE_SPLINE } +procedure spline_ctrl_impl.update_spline; +var + i : int; + +begin + m_spline.init(m_num_pnt ,@m_xp ,@m_yp ); + + for i:=0 to 255 do + begin + m_spline_values[i ]:=m_spline.get(i / 255.0 ); + + if m_spline_values[i ] < 0.0 then + m_spline_values[i ]:=0.0; + + if m_spline_values[i ] > 1.0 then + m_spline_values[i ]:=1.0; + + m_spline_values8[i ]:=int8u(trunc(m_spline_values[i ] * 255.0 ) ); + + end; + +end; + +{ NUM_PATHS } +function spline_ctrl_impl.num_paths; +begin + result:=5; + +end; + +{ REWIND } +procedure spline_ctrl_impl.rewind; +var + i : unsigned; + +begin + m_idx:=path_id; + + case path_id of + 0 : // Background + begin + m_vertex:=0; + + m_vx[0 ]:=m_x1 - m_border_extra; + m_vy[0 ]:=m_y1 - m_border_extra; + m_vx[1 ]:=m_x2 + m_border_extra; + m_vy[1 ]:=m_y1 - m_border_extra; + m_vx[2 ]:=m_x2 + m_border_extra; + m_vy[2 ]:=m_y2 + m_border_extra; + m_vx[3 ]:=m_x1 - m_border_extra; + m_vy[3 ]:=m_y2 + m_border_extra; + + end; + + 1 : // Border + begin + m_vertex:=0; + + m_vx[0 ]:=m_x1; + m_vy[0 ]:=m_y1; + m_vx[1 ]:=m_x2; + m_vy[1 ]:=m_y1; + m_vx[2 ]:=m_x2; + m_vy[2 ]:=m_y2; + m_vx[3 ]:=m_x1; + m_vy[3 ]:=m_y2; + m_vx[4 ]:=m_x1 + m_border_width; + m_vy[4 ]:=m_y1 + m_border_width; + m_vx[5 ]:=m_x1 + m_border_width; + m_vy[5 ]:=m_y2 - m_border_width; + m_vx[6 ]:=m_x2 - m_border_width; + m_vy[6 ]:=m_y2 - m_border_width; + m_vx[7 ]:=m_x2 - m_border_width; + m_vy[7 ]:=m_y1 + m_border_width; + + end; + + 2 : // Curve + begin + calc_curve; + + m_curve_poly.width_(m_curve_width ); + m_curve_poly.rewind(0 ); + + end; + + 3 : // Inactive points + begin + m_curve_pnt.remove_all; + + for i:=0 to m_num_pnt - 1 do + if i <> m_active_pnt then + begin + m_ellipse.init( + calc_xp(i ) ,calc_yp(i ) , + m_point_size ,m_point_size ,32 ); + + m_curve_pnt.add_path(@m_ellipse ,0 ,false ); + + end; + + m_curve_poly.rewind(0 ); + + end; + + 4 : // Active point + begin + m_curve_pnt.remove_all; + + if m_active_pnt >= 0 then + begin + m_ellipse.init( + calc_xp(m_active_pnt ) ,calc_yp(m_active_pnt ) , + m_point_size ,m_point_size ,32 ); + + m_curve_pnt.add_path(@m_ellipse ); + + end; + + m_curve_poly.rewind(0 ); + + end; + + end; + +end; + +{ VERTEX } +function spline_ctrl_impl.vertex; +var + cmd : unsigned; + +begin + cmd:=path_cmd_line_to; + + case m_idx of + 0 : + begin + if m_vertex = 0 then + cmd:=path_cmd_move_to; + + if m_vertex >= 4 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 1 : + begin + if (m_vertex = 0 ) or + (m_vertex = 4 ) then + cmd:=path_cmd_move_to; + + if m_vertex >= 8 then + cmd:=path_cmd_stop; + + x^:=m_vx[m_vertex ]; + y^:=m_vy[m_vertex ]; + + inc(m_vertex ); + + end; + + 2 : + cmd:=m_curve_poly.vertex(x ,y ); + + 3 ,4 : + cmd:=m_curve_pnt.vertex(x ,y ); + + else + cmd:=path_cmd_stop; + + end; + + if not is_stop(cmd ) then + transform_xy(x ,y ); + + result:=cmd; + +end; + +{ CALC_SPLINE_BOX } +procedure spline_ctrl_impl.calc_spline_box; +begin + m_xs1:=m_x1 + m_border_width; + m_ys1:=m_y1 + m_border_width; + m_xs2:=m_x2 - m_border_width; + m_ys2:=m_y2 - m_border_width; + +end; + +{ CALC_CURVE } +procedure spline_ctrl_impl.calc_curve; +var + i : int; + +begin + m_curve_pnt.remove_all; + m_curve_pnt.move_to(m_xs1 ,m_ys1 + (m_ys2 - m_ys1 ) * m_spline_values[0 ] ); + + for i:=1 to 255 do + m_curve_pnt.line_to( + m_xs1 + (m_xs2 - m_xs1 ) * i / 255.0 , + m_ys1 + (m_ys2 - m_ys1 ) * m_spline_values[i ] ); + +end; + +{ CALC_XP } +function spline_ctrl_impl.calc_xp; +begin + result:=m_xs1 + (m_xs2 - m_xs1 ) * m_xp[idx ]; + +end; + +{ CALC_YP } +function spline_ctrl_impl.calc_yp; +begin + result:=m_ys1 + (m_ys2 - m_ys1 ) * m_yp[idx ]; + +end; + +{ SET_XP } +procedure spline_ctrl_impl.set_xp; +begin + if val < 0.0 then + val:=0.0; + + if val > 1.0 then + val:=1.0; + + if idx = 0 then + val:=0.0 + else + if idx = m_num_pnt - 1 then + val:=1.0 + else + begin + if val < m_xp[idx - 1 ] + 0.001 then + val:=m_xp[idx - 1 ] + 0.001; + + if val > m_xp[idx + 1 ] - 0.001 then + val:=m_xp[idx + 1 ] - 0.001; + + end; + + m_xp[idx ]:=val; + +end; + +{ SET_YP } +procedure spline_ctrl_impl.set_yp; +begin + if val < 0.0 then + val:=0.0; + + if val > 1.0 then + val:=1.0; + + m_yp[idx ]:=val; + +end; + +{ CONSTRUCT } +constructor spline_ctrl.Construct; +begin + inherited Construct(x1 ,y1 ,x2 ,y2 ,num_pnt ,flip_y ); + + m_background_color.ConstrDbl (1.0 ,1.0 ,0.9 ); + m_border_color.ConstrDbl (0.0 ,0.0 ,0.0 ); + m_curve_color.ConstrDbl (0.0 ,0.0 ,0.0 ); + m_inactive_pnt_color.ConstrDbl(0.0 ,0.0 ,0.0 ); + m_active_pnt_color.ConstrDbl (1.0 ,0.0 ,0.0 ); + + m_colors[0 ]:=@m_background_color; + m_colors[1 ]:=@m_border_color; + m_colors[2 ]:=@m_curve_color; + m_colors[3 ]:=@m_inactive_pnt_color; + m_colors[4 ]:=@m_active_pnt_color; + +end; + +{ BACKGROUND_COLOR_ } +procedure spline_ctrl.background_color_; +begin + m_background_color:=c^; + +end; + +{ BORDER_COLOR_ } +procedure spline_ctrl.border_color_; +begin + m_border_color:=c^; + +end; + +{ CURVE_COLOR_ } +procedure spline_ctrl.curve_color_; +begin + m_curve_color:=c^; + +end; + +{ INACTIVE_PNT_COLOR_ } +procedure spline_ctrl.inactive_pnt_color_; +begin + m_inactive_pnt_color:=c^; + +end; + +{ ACTIVE_PNT_COLOR_ } +procedure spline_ctrl.active_pnt_color_; +begin + m_active_pnt_color:=c^; + +end; + +{ _COLOR } +function spline_ctrl._color; +begin + result:=m_colors[i ]; + +end; + +END. + |