1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
//
// AggPas 2.4 RM3 Demo application
// Note: Press F1 key on run to see more info about this demo
//
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
//
program
rounded_rect ;
uses
agg_basics ,
agg_platform_support ,
agg_color ,
agg_pixfmt ,
agg_pixfmt_rgb ,
agg_ctrl ,
agg_slider_ctrl ,
agg_cbox_ctrl ,
agg_renderer_base ,
agg_renderer_scanline ,
agg_rasterizer_scanline_aa ,
agg_scanline_p ,
agg_render_scanlines ,
agg_gamma_functions ,
agg_gamma_lut ,
agg_ellipse ,
agg_rounded_rect ,
agg_conv_stroke ,
agg_vertex_source ;
{$I agg_mode.inc }
const
flip_y = true;
type
the_application = object(platform_support )
m_x ,
m_y : array[0..1 ] of double;
m_dx ,
m_dy : double;
m_idx : int;
m_radius ,
m_gamma ,
m_offset : slider_ctrl;
m_white_on_black : cbox_ctrl;
constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
destructor Destruct;
procedure on_draw; virtual;
procedure on_mouse_move (x ,y : int; flags : unsigned ); virtual;
procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
procedure on_mouse_button_up (x ,y : int; flags : unsigned ); virtual;
procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
end;
{ CONSTRUCT }
constructor the_application.Construct;
var
rgba8 : aggclr;
begin
inherited Construct(format_ ,flip_y_ );
m_radius.Construct(10 ,10 ,600 - 10 ,19 ,not flip_y_ );
m_gamma.Construct (10 ,10 + 20 ,600 - 10 ,19 + 20 ,not flip_y_ );
m_offset.Construct(10 ,10 + 40 ,600 - 10 ,19 + 40 ,not flip_y_ );
m_white_on_black.Construct(10 ,10 + 60 ,'White on black' );
m_idx:=-1;
m_x[0 ]:=100; m_y[0 ]:=100;
m_x[1 ]:=500; m_y[1 ]:=350;
add_ctrl(@m_radius );
add_ctrl(@m_gamma );
add_ctrl(@m_offset );
add_ctrl(@m_white_on_black );
m_gamma.label_('gamma=%4.3f' );
m_gamma.range_(0.0 ,3.0 );
m_gamma.value_(1.8 );
m_radius.label_('radius=%4.3f' );
m_radius.range_(0.0 ,50.0 );
m_radius.value_(25.0 );
m_offset.label_('subpixel offset=%4.3f' );
m_offset.range_(-2.0 ,3.0 );
rgba8.ConstrInt(127 ,127 ,127 );
m_white_on_black.text_color_ (@rgba8 );
m_white_on_black.inactive_color_(@rgba8 );
end;
{ DESTRUCT }
destructor the_application.Destruct;
begin
inherited Destruct;
m_radius.Destruct;
m_gamma.Destruct;
m_offset.Destruct;
m_white_on_black.Destruct;
end;
{ ON_DRAW }
procedure the_application.on_draw;
var
pixf : pixel_formats;
rb : renderer_base;
ren : renderer_scanline_aa_solid;
ras : rasterizer_scanline_aa;
sl : scanline_p8;
rgba : aggclr;
gamma : gamma_lut;
gm_no : vertex_source;
e : ellipse;
r : agg_rounded_rect.rounded_rect;
p : conv_stroke;
d : double;
begin
// Initialize structures
gamma.Construct(m_gamma._value ,8 ,8 );
pixfmt_bgr24_gamma(pixf ,rbuf_window ,@gamma );
rb.Construct (@pixf );
ren.Construct(@rb );
if m_white_on_black._status then
rgba.ConstrDbl(0 ,0 ,0 )
else
rgba.ConstrDbl(1 ,1 ,1 );
rb.clear(@rgba );
ras.Construct;
sl.Construct;
// Render two "control" circles
e.Construct;
rgba.ConstrInt(127 ,127 ,127 );
ren.color_ (@rgba );
e.init (m_x[0 ] ,m_y[0 ] ,3 ,3 ,16 );
ras.add_path(@e );
render_scanlines(@ras ,@sl ,@ren );
e.init (m_x[1 ] ,m_y[1 ] ,3 ,3 ,16 );
ras.add_path(@e );
render_scanlines(@ras ,@sl ,@ren );
// Creating a rounded rectangle
d:=m_offset._value;
r.Construct(m_x[0 ] + d ,m_y[0 ] + d ,m_x[1 ] + d ,m_y[1 ] + d ,m_radius._value );
r.normalize_radius;
// Drawing as an outline
p.Construct(@r );
p.width_ (1.0 );
ras.add_path(@p );
if m_white_on_black._status then
rgba.ConstrDbl(1 ,1 ,1 )
else
rgba.ConstrDbl(0 ,0 ,0 );
ren.color_(@rgba );
render_scanlines(@ras ,@sl ,@ren );
gm_no.Construct;
ras.gamma(@gm_no );
// Render the controls
render_ctrl(@ras ,@sl ,@ren ,@m_radius );
render_ctrl(@ras ,@sl ,@ren ,@m_gamma );
render_ctrl(@ras ,@sl ,@ren ,@m_offset );
render_ctrl(@ras ,@sl ,@ren ,@m_white_on_black );
// Free AGG resources
ras.Destruct;
sl.Destruct;
gamma.Destruct;
p.Destruct;
end;
{ ON_MOUSE_MOVE }
procedure the_application.on_mouse_move;
begin
if flags and mouse_left <> 0 then
if m_idx >= 0 then
begin
m_x[m_idx ]:=x - m_dx;
m_y[m_idx ]:=y - m_dy;
force_redraw;
end
else
else
on_mouse_button_up(x ,y ,flags );
end;
{ ON_MOUSE_BUTTON_DOWN }
procedure the_application.on_mouse_button_down;
var
i : unsigned;
begin
if flags and mouse_left <> 0 then
for i:=0 to 1 do
if Sqrt((x - m_x[i ] ) * (x - m_x[i ] ) + (y - m_y[i ] ) * (y - m_y[i ] ) ) < 5.0 then
begin
m_dx :=x - m_x[i ];
m_dy :=y - m_y[i ];
m_idx:=i;
break;
end;
end;
{ ON_MOUSE_BUTTON_UP }
procedure the_application.on_mouse_button_up;
begin
m_idx:=-1;
end;
{ ON_KEY }
procedure the_application.on_key;
begin
if key = key_f1 then
message_(
'Yet another example dedicated to Gamma Correction. If you have a CRT monitor: '#13 +
'The rectangle looks bad - the rounded corners are thicker than its side lines. '#13 +
'First try to drag the "subpixel offset" control it simply adds some fractional '#13 +
'value to the coordinates. When dragging you will see that the rectangle is'#13 +
'"blinking". Then increase "Gamma" to about 1.5. The result will look almost '#13 +
'perfect the visual thickness of the rectangle remains the same. That''s good, '#13 +
'but turn the checkbox "White on black" on what do we see ? Our rounded '#13 +
'rectangle looks terrible. Drag the "subpixel offset" slider it''s blinking as hell. '#13 +
'Now decrease "Gamma" to about 0.6. What do we see now ? Perfect result ! '#13 +
'If you use an LCD monitor, the good value of gamma will be closer to 1.0 in both '#13 +
'cases black on white or white on black. There''s no perfection in this world, but '#13 +
'at least you can control Gamma in Anti-Grain Geometry :-)' +
#13#13'Note: F2 key saves current "screenshot" file in this demo''s directory. ' );
end;
VAR
app : the_application;
BEGIN
app.Construct(pix_format_bgr24 ,flip_y );
app.caption_ ('AGG Example. Rounded rectangle with gamma-correction & stuff (F1-Help)' );
if app.init(600 ,400 ,window_resize ) then
app.run;
app.Destruct;
END.
|