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

« back to all changes in this revision

Viewing changes to components/aggpas/alpha_mask.dpr

  • 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
 
// AggPas 2.4 RM3 Demo application
3
 
// Note: Press F1 key on run to see more info about this demo
4
 
//
5
 
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
6
 
//
7
 
program
8
 
 alpha_mask ;
9
 
 
10
 
uses
11
 
 Math ,
12
 
 
13
 
 agg_basics ,
14
 
 agg_platform_support ,
15
 
 agg_color ,
16
 
 agg_pixfmt ,
17
 
 agg_pixfmt_rgb ,
18
 
 agg_pixfmt_gray ,
19
 
 
20
 
 agg_rendering_buffer ,
21
 
 agg_renderer_base ,
22
 
 agg_renderer_scanline ,
23
 
 agg_rasterizer_scanline_aa ,
24
 
 agg_scanline ,
25
 
 agg_scanline_u ,
26
 
 agg_scanline_p ,
27
 
 agg_render_scanlines ,
28
 
 
29
 
 agg_ellipse ,
30
 
 agg_path_storage ,
31
 
 agg_conv_transform ,
32
 
 agg_bounding_rect ,
33
 
 agg_alpha_mask_u8 ,
34
 
 agg_trans_affine ,
35
 
 parse_lion_ ;
36
 
 
37
 
{$I agg_mode.inc }
38
 
 
39
 
const
40
 
 flip_y = true;
41
 
 
42
 
var
43
 
 g_path     : path_storage;
44
 
 g_colors   : array[0..99 ] of aggclr;
45
 
 g_path_idx : array[0..99 ] of unsigned;
46
 
 
47
 
 g_npaths : unsigned;
48
 
 
49
 
 g_x1 ,g_y1 ,g_x2 ,g_y2 ,
50
 
 g_base_dx  ,g_base_dy  ,
51
 
 g_angle    ,g_scale    ,
52
 
 g_skew_x   ,g_skew_y   : double;
53
 
 
54
 
 g_nclick : int;
55
 
 
56
 
 g_alpha_mask_rbuf : rendering_buffer;
57
 
 g_alpha_mask      : alpha_mask_gray8;
58
 
 g_rasterizer      : rasterizer_scanline_aa;
59
 
 
60
 
type
61
 
 the_application = object(platform_support )
62
 
   m_alpha_size : unsigned;
63
 
   m_alpha_buf  : char_ptr;
64
 
   m_alpha_rbuf : rendering_buffer;
65
 
 
66
 
   constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
67
 
   destructor  Destruct;
68
 
 
69
 
   procedure generate_alpha_mask(cx ,cy : int );
70
 
 
71
 
   procedure on_resize(sx ,sy : int ); virtual;
72
 
   procedure on_draw; virtual;
73
 
 
74
 
   procedure transform(width_ ,height_ ,x ,y : double );
75
 
 
76
 
   procedure on_mouse_move       (x ,y : int; flags : unsigned ); virtual;
77
 
   procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
78
 
 
79
 
   procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
80
 
 
81
 
  end;
82
 
 
83
 
{ _PARSE_LION_ }
84
 
procedure _parse_lion_;
85
 
begin
86
 
 g_npaths:=parse_lion(@g_path ,@g_colors ,@g_path_idx );
87
 
 
88
 
 bounding_rect(@g_path ,@g_path_idx ,0 ,g_npaths ,@g_x1 ,@g_y1 ,@g_x2 ,@g_y2 );
89
 
 
90
 
 g_base_dx:=(g_x2 - g_x1 ) / 2.0;
91
 
 g_base_dy:=(g_y2 - g_y1 ) / 2.0;
92
 
 
93
 
end;
94
 
 
95
 
{ CONSTRUCT }
96
 
constructor the_application.Construct;
97
 
begin
98
 
 inherited Construct(format_ ,flip_y_ );
99
 
 
100
 
 m_alpha_size:=0;
101
 
 m_alpha_buf :=NIL;
102
 
 
103
 
 _parse_lion_;
104
 
 
105
 
end;
106
 
 
107
 
{ DESTRUCT }
108
 
destructor the_application.Destruct;
109
 
begin
110
 
 inherited Destruct;
111
 
 
112
 
 agg_freemem(pointer(m_alpha_buf ) ,m_alpha_size );
113
 
 
114
 
end;
115
 
 
116
 
{ GENERATE_ALPHA_MASK }
117
 
procedure the_application.generate_alpha_mask;
118
 
var
119
 
 pixf : pixel_formats;
120
 
 rgba : aggclr;
121
 
 
122
 
 rb : renderer_base;
123
 
 r  : renderer_scanline_aa_solid;
124
 
 sl : scanline_p8;
125
 
 
126
 
 ell : ellipse;
127
 
 
128
 
 i : unsigned;
129
 
 
130
 
begin
131
 
 agg_freemem(pointer(m_alpha_buf ) ,m_alpha_size );
132
 
 
133
 
 m_alpha_size:=cx * cy;
134
 
 
135
 
 agg_getmem(pointer(m_alpha_buf ) ,m_alpha_size );
136
 
 
137
 
 g_alpha_mask_rbuf.attach(int8u_ptr(m_alpha_buf ) ,cx ,cy ,cx );
138
 
 
139
 
 pixfmt_gray8(pixf ,@g_alpha_mask_rbuf );
140
 
 rb.Construct(@pixf );
141
 
 r.Construct (@rb );
142
 
 sl.Construct;
143
 
 
144
 
 rgba.ConstrInt(0 );
145
 
 rb.clear      (@rgba );
146
 
 
147
 
 ell.Construct;
148
 
 
149
 
 for i:=0 to 9 do
150
 
  begin
151
 
   ell.init(
152
 
    Random($7fff ) mod cx ,
153
 
    Random($7fff ) mod cy ,
154
 
    Random($7fff ) mod 100 + 20 ,
155
 
    Random($7fff ) mod 100 + 20 ,100 );
156
 
 
157
 
   g_rasterizer.add_path(@ell );
158
 
 
159
 
   rgba.ConstrInt(Random($7fff ) and $FF ,Random($7fff ) and $FF );
160
 
   r.color_      (@rgba );
161
 
 
162
 
   render_scanlines(@g_rasterizer ,@sl ,@r );
163
 
 
164
 
  end;
165
 
 
166
 
 sl.Destruct;
167
 
 
168
 
end;
169
 
 
170
 
{ ON_RESIZE }
171
 
procedure the_application.on_resize;
172
 
begin
173
 
 generate_alpha_mask(sx ,sy );
174
 
 
175
 
end;
176
 
 
177
 
{ ON_DRAW }
178
 
procedure the_application.on_draw;
179
 
var
180
 
 width_ ,height_ : int;
181
 
 
182
 
 pixf : pixel_formats;
183
 
 
184
 
 rb : renderer_base;
185
 
 r  : renderer_scanline_aa_solid;
186
 
 sl : scanline_u8_am;
187
 
 
188
 
 rgba  : aggclr;
189
 
 trans : conv_transform;
190
 
 
191
 
 mtx : trans_affine;
192
 
 tat : trans_affine_translation;
193
 
 tas : trans_affine_scaling;
194
 
 tar : trans_affine_rotation;
195
 
 taw : trans_affine_skewing;
196
 
 
197
 
begin
198
 
 width_ :=rbuf_window._width;
199
 
 height_:=rbuf_window._height;
200
 
 
201
 
// Initialize structures
202
 
 pixfmt_bgr24(pixf ,rbuf_window );
203
 
 
204
 
 rb.Construct(@pixf );
205
 
 r.Construct (@rb );
206
 
 sl.Construct(@g_alpha_mask );
207
 
 
208
 
 rgba.ConstrInt(255 ,255 ,255 );
209
 
 rb.clear      (@rgba );
210
 
 
211
 
// Transform lion
212
 
 mtx.Construct;
213
 
 
214
 
 tat.Construct(-g_base_dx ,-g_base_dy );
215
 
 mtx.multiply (@tat );
216
 
 
217
 
 tas.Construct(g_scale ,g_scale );
218
 
 mtx.multiply (@tas );
219
 
 
220
 
 tar.Construct(g_angle + pi );
221
 
 mtx.multiply (@tar );
222
 
 
223
 
 taw.Construct(g_skew_x / 1000.0 ,g_skew_y / 1000.0 );
224
 
 mtx.multiply (@taw );
225
 
 
226
 
 tat.Construct(width_ / 2 ,height_ / 2 );
227
 
 mtx.multiply (@tat );
228
 
 
229
 
// This code renders the lion
230
 
 trans.Construct(@g_path ,@mtx );
231
 
 
232
 
 render_all_paths(@g_rasterizer ,@sl ,@r ,@trans ,@g_colors ,@g_path_idx ,g_npaths );
233
 
 
234
 
// Free AGG resources
235
 
 sl.Destruct;
236
 
 
237
 
end;
238
 
 
239
 
{ TRANSFORM }
240
 
procedure the_application.transform;
241
 
begin
242
 
 x:=x - width_ / 2;
243
 
 y:=y - height_ / 2;
244
 
 
245
 
 g_angle:=ArcTan2(y ,x );
246
 
 g_scale:=Sqrt(y * y + x * x ) / 100.0;
247
 
 
248
 
end;
249
 
 
250
 
{ ON_MOUSE_MOVE }
251
 
procedure the_application.on_mouse_move;
252
 
begin
253
 
 on_mouse_button_down(x ,y ,flags );
254
 
 
255
 
end;
256
 
 
257
 
{ ON_MOUSE_BUTTON_DOWN }
258
 
procedure the_application.on_mouse_button_down;
259
 
var
260
 
 width_ ,height_ : int;
261
 
 
262
 
begin
263
 
 if flags and mouse_left <> 0 then
264
 
  begin
265
 
   width_ :=rbuf_window._width;
266
 
   height_:=rbuf_window._height;
267
 
 
268
 
   transform(width_ ,height_ ,x ,y );
269
 
 
270
 
   force_redraw;
271
 
 
272
 
  end;
273
 
 
274
 
 if flags and mouse_right <> 0 then
275
 
  begin
276
 
   g_skew_x:=x;
277
 
   g_skew_y:=y;
278
 
 
279
 
   force_redraw;
280
 
 
281
 
  end;
282
 
 
283
 
end;
284
 
 
285
 
{ ON_KEY }
286
 
procedure the_application.on_key;
287
 
begin
288
 
 if key = key_f1 then
289
 
  message_(
290
 
   'Alpha-mask is a simple method of clipping and masking polygons to a number'#13 +
291
 
   'of other arbitrary polygons. Alpha mask is a buffer that is mixed to the '#13 +
292
 
   'scanline container and controls the Anti-Aliasing values in it. It''s not the '#13 +
293
 
   'perfect mechanism of clipping, but it allows you not only to clip the polygons, '#13 +
294
 
   'but also to change the opacity in certain areas, i.e., the clipping can be '#13 +
295
 
   'translucent. '#13#13 +
296
 
   'How to play with:'#13#13 +
297
 
   'Press and drag the left mouse button to scale and rotate the lion.'#13 +
298
 
   'Resize the window to generate new alpha-mask.'#13 +
299
 
   'Use the right mouse button to skew the lion.' +
300
 
   #13#13'Note: F2 key saves current "screenshot" file in this demo''s directory.  ' );
301
 
 
302
 
end;
303
 
 
304
 
VAR
305
 
 app : the_application;
306
 
 
307
 
BEGIN
308
 
// Rendering
309
 
 g_path.Construct;
310
 
 
311
 
 g_npaths:=0;
312
 
 
313
 
 g_x1:=0;
314
 
 g_y1:=0;
315
 
 g_x2:=0;
316
 
 g_y2:=0;
317
 
 
318
 
 g_base_dx:=0;
319
 
 g_base_dy:=0;
320
 
 
321
 
 g_angle:=0;
322
 
 g_scale:=1.0;
323
 
 
324
 
 g_skew_x:=0;
325
 
 g_skew_y:=0;
326
 
 g_nclick:=0;
327
 
 
328
 
 g_alpha_mask_rbuf.Construct;
329
 
 g_alpha_mask.Construct(@g_alpha_mask_rbuf );
330
 
 g_rasterizer.Construct;
331
 
 
332
 
// App
333
 
 app.Construct(pix_format_bgr24 ,flip_y );
334
 
 app.caption_ ('AGG Example. Lion with Alpha-Masking (F1-Help)' );
335
 
 
336
 
 if app.init(512 ,400 ,window_resize ) then
337
 
  app.run;
338
 
 
339
 
 app.Destruct;
340
 
 
341
 
// Free
342
 
 g_path.Destruct;
343
 
 g_alpha_mask_rbuf.Destruct;
344
 
 g_rasterizer.Destruct;
345
 
 
346
 
END.
 
 
b'\\ No newline at end of file'