~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/aggpas/src/agg_trans_viewport.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//----------------------------------------------------------------------------
2
 
// Anti-Grain Geometry - Version 2.4 (Public License)
3
 
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
 
//
5
 
// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
6
 
// Pascal Port By: Milan Marusinec alias Milano
7
 
//                 milan@marusinec.sk
8
 
//                 http://www.aggpas.org
9
 
// Copyright (c) 2005-2006
10
 
//
11
 
// Permission to copy, use, modify, sell and distribute this software
12
 
// is granted provided this copyright notice appears in all copies.
13
 
// This software is provided "as is" without express or implied
14
 
// warranty, and with no claim as to its suitability for any purpose.
15
 
//
16
 
//----------------------------------------------------------------------------
17
 
// Contact: mcseem@antigrain.com
18
 
//          mcseemagg@yahoo.com
19
 
//          http://www.antigrain.com
20
 
//
21
 
//----------------------------------------------------------------------------
22
 
//
23
 
// Viewport transformer - simple orthogonal conversions from world coordinates
24
 
//                        to screen (device) ones
25
 
//
26
 
// [Pascal Port History] -----------------------------------------------------
27
 
//
28
 
// 27.09.2005-Milano: Complete unit port
29
 
//
30
 
{ agg_trans_viewport.pas }
31
 
unit
32
 
 agg_trans_viewport ;
33
 
 
34
 
INTERFACE
35
 
 
36
 
{$I agg_mode.inc }
37
 
 
38
 
uses
39
 
 agg_basics ,
40
 
 agg_trans_affine ;
41
 
 
42
 
{ TYPES DEFINITION }
43
 
type
44
 
 aspect_ratio_e = (aspect_ratio_stretch ,aspect_ratio_meet ,aspect_ratio_slice );
45
 
 
46
 
//----------------------------------------------------------trans_viewport
47
 
 trans_viewport_ptr = ^trans_viewport;
48
 
 trans_viewport = object(trans_affine )
49
 
   m_world_x1 ,
50
 
   m_world_y1 ,
51
 
   m_world_x2 ,
52
 
   m_world_y2 ,
53
 
 
54
 
   m_device_x1 ,
55
 
   m_device_y1 ,
56
 
   m_device_x2 ,
57
 
   m_device_y2 : double;
58
 
 
59
 
   m_aspect   : aspect_ratio_e;
60
 
   m_is_valid : boolean;
61
 
 
62
 
   m_align_x ,
63
 
   m_align_y ,
64
 
 
65
 
   m_wx1 ,
66
 
   m_wy1 ,
67
 
   m_wx2 ,
68
 
   m_wy2 ,
69
 
   m_dx1 ,
70
 
   m_dy1 ,
71
 
 
72
 
   m_kx ,
73
 
   m_ky : double;
74
 
 
75
 
   constructor Construct;
76
 
 
77
 
   procedure preserve_aspect_ratio(alignx ,aligny : double; aspect : aspect_ratio_e );
78
 
 
79
 
   procedure device_viewport   (x1 ,y1 ,x2 ,y2 : double );
80
 
   procedure device_viewport_ex(var x1 ,y1 ,x2 ,y2 : double );
81
 
 
82
 
   procedure world_viewport   (x1 ,y1 ,x2 ,y2 : double );
83
 
   procedure world_viewport_ex(var x1 ,y1 ,x2 ,y2 : double );
84
 
 
85
 
   procedure world_viewport_actual(var x1 ,y1 ,x2 ,y2 : double );
86
 
 
87
 
   function  is_valid : boolean;
88
 
   function  align_x : double;
89
 
   function  align_y : double;
90
 
   function  aspect_ratio : aspect_ratio_e;
91
 
 
92
 
   procedure inverse_transform_scale_only(x ,y : double_ptr );
93
 
 
94
 
   function  device_dx : double;
95
 
   function  device_dy : double;
96
 
   function  scale_x : double;
97
 
   function  scale_y : double;
98
 
   function  scale : double;
99
 
 
100
 
   procedure to_affine           (mtx : trans_affine_ptr );
101
 
   procedure to_affine_scale_only(mtx : trans_affine_ptr );
102
 
 
103
 
   function  byte_size : unsigned;
104
 
   procedure serialize  (ptr : int8u_ptr );
105
 
   procedure deserialize(ptr : int8u_ptr);
106
 
 
107
 
   procedure update;
108
 
 
109
 
  end;
110
 
 
111
 
{ GLOBAL VARIABLES & CONSTANTS }
112
 
{ GLOBAL PROCEDURES }
113
 
 
114
 
 
115
 
IMPLEMENTATION
116
 
{ UNIT IMPLEMENTATION }
117
 
{ _transform }
118
 
procedure _transform(this : trans_viewport_ptr; x ,y : double_ptr );
119
 
begin
120
 
 x^:=x^ * this.m_kx;
121
 
 y^:=y^ * this.m_ky;
122
 
 
123
 
end;
124
 
 
125
 
{ _inverse_transform }
126
 
procedure _inverse_transform(this : trans_viewport_ptr; x ,y : double_ptr );
127
 
begin
128
 
 x^:=(x^ - this.m_dx1 ) / this.m_kx + this.m_wx1;
129
 
 y^:=(y^ - this.m_dy1 ) / this.m_ky + this.m_wy1;
130
 
 
131
 
end;
132
 
 
133
 
{ CONSTRUCT }
134
 
constructor trans_viewport.Construct;
135
 
begin
136
 
 inherited Construct;
137
 
 
138
 
 transform        :=@_transform;
139
 
 inverse_transform:=@_inverse_transform;
140
 
 
141
 
 m_world_x1:=0;
142
 
 m_world_y1:=0;
143
 
 m_world_x2:=1;
144
 
 m_world_y2:=1;
145
 
 
146
 
 m_device_x1:=0;
147
 
 m_device_y1:=0;
148
 
 m_device_x2:=1;
149
 
 m_device_y2:=1;
150
 
 
151
 
 m_aspect  :=aspect_ratio_stretch;
152
 
 m_is_valid:=true;
153
 
 
154
 
 m_align_x:=0.5;
155
 
 m_align_y:=0.5;
156
 
 
157
 
 m_wx1:=0;
158
 
 m_wy1:=0;
159
 
 m_wx2:=1;
160
 
 m_wy2:=1;
161
 
 m_dx1:=0;
162
 
 m_dy1:=0;
163
 
 
164
 
 m_kx:=1;
165
 
 m_ky:=1;
166
 
 
167
 
end;
168
 
 
169
 
{ preserve_aspect_ratio }
170
 
procedure trans_viewport.preserve_aspect_ratio;
171
 
begin
172
 
 m_align_x:=alignx;
173
 
 m_align_y:=aligny;
174
 
 m_aspect :=aspect;
175
 
 
176
 
 update;
177
 
 
178
 
end;
179
 
 
180
 
{ device_viewport }
181
 
procedure trans_viewport.device_viewport;
182
 
begin
183
 
 m_device_x1:=x1;
184
 
 m_device_y1:=y1;
185
 
 m_device_x2:=x2;
186
 
 m_device_y2:=y2;
187
 
 
188
 
 update;
189
 
 
190
 
end;
191
 
 
192
 
{ device_viewport_ex }
193
 
procedure trans_viewport.device_viewport_ex;
194
 
begin
195
 
 x1:=m_device_x1;
196
 
 y1:=m_device_y1;
197
 
 x2:=m_device_x2;
198
 
 y2:=m_device_y2;
199
 
 
200
 
end;
201
 
 
202
 
{ world_viewport }
203
 
procedure trans_viewport.world_viewport;
204
 
begin
205
 
 m_world_x1:=x1;
206
 
 m_world_y1:=y1;
207
 
 m_world_x2:=x2;
208
 
 m_world_y2:=y2;
209
 
 
210
 
 update;
211
 
 
212
 
end;
213
 
 
214
 
{ world_viewport_ex }
215
 
procedure trans_viewport.world_viewport_ex;
216
 
begin
217
 
 x1:=m_world_x1;
218
 
 y1:=m_world_y1;
219
 
 x2:=m_world_x2;
220
 
 y2:=m_world_y2;
221
 
 
222
 
end;
223
 
 
224
 
{ world_viewport_actual }
225
 
procedure trans_viewport.world_viewport_actual;
226
 
begin
227
 
 x1:=m_wx1;
228
 
 y1:=m_wy1;
229
 
 x2:=m_wx2;
230
 
 y2:=m_wy2;
231
 
 
232
 
end;
233
 
 
234
 
{ is_valid }
235
 
function trans_viewport.is_valid;
236
 
begin
237
 
 result:=m_is_valid;
238
 
 
239
 
end;
240
 
 
241
 
{ align_x }
242
 
function trans_viewport.align_x;
243
 
begin
244
 
 result:=m_align_x;
245
 
 
246
 
end;
247
 
 
248
 
{ align_y }
249
 
function trans_viewport.align_y;
250
 
begin
251
 
 result:=m_align_y;
252
 
 
253
 
end;
254
 
 
255
 
{ aspect_ratio }
256
 
function trans_viewport.aspect_ratio;
257
 
begin
258
 
 result:=m_aspect;
259
 
 
260
 
end;
261
 
 
262
 
{ inverse_transform_scale_only }
263
 
procedure trans_viewport.inverse_transform_scale_only;
264
 
begin
265
 
 x^:=x^ / m_kx;
266
 
 y^:=y^ / m_ky;
267
 
 
268
 
end;
269
 
 
270
 
{ device_dx }
271
 
function trans_viewport.device_dx;
272
 
begin
273
 
 result:=m_dx1 - m_wx1 * m_kx;
274
 
 
275
 
end;
276
 
 
277
 
{ device_dy }
278
 
function trans_viewport.device_dy;
279
 
begin
280
 
 result:=m_dy1 - m_wy1 * m_ky;
281
 
 
282
 
end;
283
 
 
284
 
{ scale_x }
285
 
function trans_viewport.scale_x;
286
 
begin
287
 
 result:=m_kx;
288
 
 
289
 
end;
290
 
 
291
 
{ scale_y }
292
 
function trans_viewport.scale_y;
293
 
begin
294
 
 result:=m_ky;
295
 
 
296
 
end;
297
 
 
298
 
{ scale }
299
 
function trans_viewport.scale;
300
 
begin
301
 
 result:=(m_kx + m_ky ) * 0.5;
302
 
 
303
 
end;
304
 
 
305
 
{ to_affine }
306
 
procedure trans_viewport.to_affine;
307
 
var
308
 
 m ,
309
 
 t : trans_affine_translation;
310
 
 s : trans_affine_scaling;
311
 
 
312
 
begin
313
 
 m.Construct(-m_wx1 ,-m_wy1 );
314
 
 s.Construct(m_kx ,m_ky );
315
 
 m.multiply (@s );
316
 
 t.Construct(m_dx1 ,m_dy1 );
317
 
 m.multiply (@t );
318
 
 
319
 
 mtx.assign(@m );
320
 
 
321
 
end;
322
 
 
323
 
{ to_affine_scale_only }
324
 
procedure trans_viewport.to_affine_scale_only;
325
 
var
326
 
 s : trans_affine_scaling;
327
 
 
328
 
begin
329
 
 s.Construct(m_kx ,m_ky );
330
 
 
331
 
 mtx.assign(@s );
332
 
 
333
 
end;
334
 
 
335
 
{ byte_size }
336
 
function trans_viewport.byte_size;
337
 
begin
338
 
 result:=sizeof(self );
339
 
 
340
 
end;
341
 
 
342
 
{ serialize }
343
 
procedure trans_viewport.serialize;
344
 
begin
345
 
 move(self ,ptr^ ,sizeof(self ) ); 
346
 
 
347
 
end;
348
 
 
349
 
{ deserialize }
350
 
procedure trans_viewport.deserialize;
351
 
begin
352
 
 move(ptr^ ,self ,sizeof(self ) );
353
 
 
354
 
end;
355
 
 
356
 
{ update }
357
 
procedure trans_viewport.update;
358
 
const
359
 
 epsilon : double = 1e-30;
360
 
 
361
 
var
362
 
 d ,
363
 
 
364
 
 world_x1 ,
365
 
 world_y1 ,
366
 
 world_x2 ,
367
 
 world_y2 ,
368
 
 
369
 
 device_x1 ,
370
 
 device_y1 ,
371
 
 device_x2 ,
372
 
 device_y2 : double;
373
 
 
374
 
begin
375
 
 if (Abs(m_world_x1  - m_world_x2 )  < epsilon ) or
376
 
    (Abs(m_world_y1  - m_world_y2 )  < epsilon ) or
377
 
    (Abs(m_device_x1 - m_device_x2 ) < epsilon ) or
378
 
    (Abs(m_device_y1 - m_device_y2 ) < epsilon ) then
379
 
  begin
380
 
   m_wx1:=m_world_x1;
381
 
   m_wy1:=m_world_y1;
382
 
   m_wx2:=m_world_x1 + 1;
383
 
   m_wy2:=m_world_y2 + 1;
384
 
   m_dx1:=m_device_x1;
385
 
   m_dy1:=m_device_y1;
386
 
   m_kx :=1;
387
 
   m_ky :=1;
388
 
 
389
 
   m_is_valid:=false;
390
 
 
391
 
  end
392
 
 else
393
 
  begin
394
 
   world_x1 :=m_world_x1;
395
 
   world_y1 :=m_world_y1;
396
 
   world_x2 :=m_world_x2;
397
 
   world_y2 :=m_world_y2;
398
 
   device_x1:=m_device_x1;
399
 
   device_y1:=m_device_y1;
400
 
   device_x2:=m_device_x2;
401
 
   device_y2:=m_device_y2;
402
 
 
403
 
   if not (m_aspect = aspect_ratio_stretch ) then
404
 
    begin
405
 
     m_kx:=(device_x2 - device_x1 ) / (world_x2 - world_x1 );
406
 
     m_ky:=(device_y2 - device_y1 ) / (world_y2 - world_y1 );
407
 
 
408
 
     if (m_aspect = aspect_ratio_meet ) = (m_kx < m_ky ) then
409
 
      begin
410
 
       d:=(world_y2 - world_y1 ) * m_ky / m_kx;
411
 
 
412
 
       world_y1:=world_y1 + ((world_y2 - world_y1 - d ) * m_align_y );
413
 
       world_y2:=world_y1 + d;
414
 
 
415
 
      end
416
 
     else
417
 
      begin
418
 
       d:=(world_x2 - world_x1 ) * m_kx / m_ky;
419
 
 
420
 
       world_x1:=world_x1 + ((world_x2 - world_x1 - d ) * m_align_x );
421
 
       world_x2:=world_x1 + d;
422
 
       
423
 
      end;
424
 
 
425
 
    end;
426
 
 
427
 
   m_wx1:=world_x1;
428
 
   m_wy1:=world_y1;
429
 
   m_wx2:=world_x2;
430
 
   m_wy2:=world_y2;
431
 
   m_dx1:=device_x1;
432
 
   m_dy1:=device_y1;
433
 
   m_kx :=(device_x2 - device_x1 ) / (world_x2 - world_x1 );
434
 
   m_ky :=(device_y2 - device_y1 ) / (world_y2 - world_y1 );
435
 
 
436
 
   m_is_valid:=true;
437
 
 
438
 
  end;
439
 
 
440
 
end;
441
 
 
442
 
END.
443