| 1 |
unit Main; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses |
| 6 |
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, |
| 7 |
Menus, StdCtrls, ExtCtrls, Buttons, |
| 8 |
libmng; |
| 9 |
|
| 10 |
{****************************************************************************} |
| 11 |
{* For conditions of distribution and use, *} |
| 12 |
{* see copyright notice in libmng.pas *} |
| 13 |
{****************************************************************************} |
| 14 |
{* *} |
| 15 |
{* project : libmng *} |
| 16 |
{* file : main.pas copyright (c) 2000-2002 G.Juyn *} |
| 17 |
{* version : 1.0.5 *} |
| 18 |
{* *} |
| 19 |
{* purpose : Main form for mngview application *} |
| 20 |
{* *} |
| 21 |
{* author : G.Juyn *} |
| 22 |
{* web : http://www.3-t.com *} |
| 23 |
{* email : mailto:[email protected] *} |
| 24 |
{* *} |
| 25 |
{* comment : this is the heart of the mngview applciation *} |
| 26 |
{* *} |
| 27 |
{* changes : 0.5.1 - 05/02/2000 - G.Juyn *} |
| 28 |
{* - added this version block *} |
| 29 |
{* - made the initialization part more robust *} |
| 30 |
{* eg. program aborts on initialization errors *} |
| 31 |
{* - B002(105797) - added check for existence of default sRGB *} |
| 32 |
{* profile (now included in distribution) *} |
| 33 |
{* - added mng_cleanup to program exit *} |
| 34 |
{* 0.5.1 - 05/08/2000 - G.Juyn *} |
| 35 |
{* - changed to stdcall convention *} |
| 36 |
{* 0.5.1 - 05/11/2000 - G.Juyn *} |
| 37 |
{* - changed callback function declarations *} |
| 38 |
{* *} |
| 39 |
{* 0.5.3 - 06/16/2000 - G.Juyn *} |
| 40 |
{* - removed processmessages call from refresh callback *} |
| 41 |
{* 0.5.3 - 06/17/2000 - G.Juyn *} |
| 42 |
{* - switched "storechunks" off *} |
| 43 |
{* 0.5.3 - 06/26/2000 - G.Juyn *} |
| 44 |
{* - changed definition of userdata to mng_ptr *} |
| 45 |
{* 0.5.3 - 06/28/2000 - G.Juyn *} |
| 46 |
{* - changed the default icon to something more appropriate *} |
| 47 |
{* - changed definition of memory alloc size to mng_size_t *} |
| 48 |
{* 0.5.3 - 06/29/2000 - G.Juyn *} |
| 49 |
{* - changed order of refresh parameters *} |
| 50 |
{* *} |
| 51 |
{* 0.9.0 - 06/30/2000 - G.Juyn *} |
| 52 |
{* - changed refresh parameters to 'x,y,width,height' *} |
| 53 |
{* *} |
| 54 |
{* 0.9.1 - 07/08/2000 - G.Juyn *} |
| 55 |
{* - fixed to use returncode constants *} |
| 56 |
{* - changed to accomodate MNG_NEEDTIMERWAIT returncode *} |
| 57 |
{* 0.9.1 - 07/10/2000 - G.Juyn *} |
| 58 |
{* - changed to use suspension-mode *} |
| 59 |
{* *} |
| 60 |
{* 0.9.3 - 09/11/2000 - G.Juyn *} |
| 61 |
{* - removed some tesst-stuff *} |
| 62 |
{* *} |
| 63 |
{* 1.0.1 - 05/02/2000 - G.Juyn *} |
| 64 |
{* - removed loading default sRGB profile (auto in libmng) *} |
| 65 |
{* *} |
| 66 |
{* 1.0.5 - 09/16/2002 - G.Juyn *} |
| 67 |
{* - added dynamic MNG features *} |
| 68 |
{* 1.0.5 - 11/27/2002 - G.Juyn *} |
| 69 |
{* - fixed freeze during read-cycle *} |
| 70 |
{* *} |
| 71 |
{****************************************************************************} |
| 72 |
|
| 73 |
type |
| 74 |
TMainForm = class(TForm) |
| 75 |
|
| 76 |
OFMainMenu: TMainMenu; |
| 77 |
OFMenuFile: TMenuItem; |
| 78 |
OFMenuFileOpen: TMenuItem; |
| 79 |
OFMenuFileProfile: TMenuItem; |
| 80 |
OFMenuFileN1: TMenuItem; |
| 81 |
OFMenuFileExit: TMenuItem; |
| 82 |
|
| 83 |
OFMenuOptions: TMenuItem; |
| 84 |
OFMenuOptionsModemSpeed: TMenuItem; |
| 85 |
OFMenuOptionsModem28k8: TMenuItem; |
| 86 |
OFMenuOptionsModem33k6: TMenuItem; |
| 87 |
OFMenuOptionsModem56k: TMenuItem; |
| 88 |
OFMenuOptionsModemISDN64: TMenuItem; |
| 89 |
OFMenuOptionsModemISDN128: TMenuItem; |
| 90 |
OFMenuOptionsModemCable512: TMenuItem; |
| 91 |
OFMenuOptionsModemUnlimited: TMenuItem; |
| 92 |
|
| 93 |
OFTimer: TTimer; |
| 94 |
|
| 95 |
OFOpenDialog: TOpenDialog; |
| 96 |
OFOpenDialogProfile: TOpenDialog; |
| 97 |
|
| 98 |
OFImage: TImage; |
| 99 |
|
| 100 |
procedure FormCreate(Sender: TObject); |
| 101 |
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
| 102 |
procedure FormShow(Sender: TObject); |
| 103 |
procedure FormResize(Sender: TObject); |
| 104 |
procedure FormKeyDown(Sender: TObject; var Key: Word; |
| 105 |
Shift: TShiftState); |
| 106 |
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, |
| 107 |
Y: Integer); |
| 108 |
|
| 109 |
procedure OFImageMouseMove(Sender: TObject; Shift: TShiftState; X, |
| 110 |
Y: Integer); |
| 111 |
procedure OFImageMouseDown(Sender: TObject; Button: TMouseButton; |
| 112 |
Shift: TShiftState; X, Y: Integer); |
| 113 |
procedure OFImageMouseUp(Sender: TObject; Button: TMouseButton; |
| 114 |
Shift: TShiftState; X, Y: Integer); |
| 115 |
|
| 116 |
procedure OFTimerTimer(Sender: TObject); |
| 117 |
|
| 118 |
procedure OFMenuFileOpenClick(Sender: TObject); |
| 119 |
procedure OFMenuFileProfileClick(Sender: TObject); |
| 120 |
procedure OFMenuFileExitClick(Sender: TObject); |
| 121 |
|
| 122 |
procedure OFMenuOptionsModemSpeedClick(Sender: TObject); |
| 123 |
procedure OFMenuOptionsModemXClick(Sender: TObject); |
| 124 |
|
| 125 |
private |
| 126 |
{ Private declarations } |
| 127 |
|
| 128 |
SFFileName : string; { filename of the input stream } |
| 129 |
OFFile : TFileStream; { input stream } |
| 130 |
IFHandle : mng_handle; { the libray handle } |
| 131 |
OFBitmap : TBitmap; { drawing canvas } |
| 132 |
BFCancelled : boolean; { <esc> or app-exit } |
| 133 |
BFHasMouse : boolean; { mouse is/was over image } |
| 134 |
|
| 135 |
IFTicks : cardinal; { used to fake slow connections } |
| 136 |
IFBytes : cardinal; |
| 137 |
IFBytesPerSec : integer; |
| 138 |
|
| 139 |
procedure MNGerror (SHMsg : string); |
| 140 |
|
| 141 |
public |
| 142 |
{ Public declarations } |
| 143 |
|
| 144 |
end; |
| 145 |
|
| 146 |
var |
| 147 |
MainForm: TMainForm; |
| 148 |
|
| 149 |
{****************************************************************************} |
| 150 |
|
| 151 |
implementation |
| 152 |
|
| 153 |
{$R *.DFM} |
| 154 |
|
| 155 |
{****************************************************************************} |
| 156 |
|
| 157 |
{$F+} |
| 158 |
function Memalloc (iLen : mng_uint32) : mng_ptr; stdcall; |
| 159 |
{$F-} |
| 160 |
begin |
| 161 |
getmem (Result, iLen); { get memory from the heap } |
| 162 |
fillchar (Result^, iLen, 0); { and initialize it } |
| 163 |
end; |
| 164 |
|
| 165 |
{****************************************************************************} |
| 166 |
|
| 167 |
{$F+} |
| 168 |
procedure Memfree (iPtr : mng_ptr; |
| 169 |
iLen : mng_size_t); stdcall; |
| 170 |
{$F-} |
| 171 |
begin |
| 172 |
freemem (iPtr, iLen); { free the memory } |
| 173 |
end; |
| 174 |
|
| 175 |
{****************************************************************************} |
| 176 |
|
| 177 |
{$F+} |
| 178 |
function Openstream (hHandle : mng_handle) : mng_bool; stdcall; |
| 179 |
{$F-} |
| 180 |
|
| 181 |
var OHForm : TMainForm; |
| 182 |
|
| 183 |
begin { get a fix on our form } |
| 184 |
OHForm := TMainForm (mng_get_userdata (hHandle)); |
| 185 |
|
| 186 |
with OHFORM do |
| 187 |
begin |
| 188 |
if OFFile <> nil then { free previous stream (if any) } |
| 189 |
OFFile.Free; |
| 190 |
{ open a new stream } |
| 191 |
OFFile := TFileStream.Create (SFFileName, fmOpenRead or fmShareDenyWrite); |
| 192 |
end; |
| 193 |
|
| 194 |
Result := MNG_TRUE; |
| 195 |
end; |
| 196 |
|
| 197 |
{****************************************************************************} |
| 198 |
|
| 199 |
{$F+} |
| 200 |
function Closestream (hHandle : mng_handle) : mng_bool; stdcall; |
| 201 |
{$F-} |
| 202 |
|
| 203 |
var OHForm : TMainForm; |
| 204 |
|
| 205 |
begin { get a fix on our form } |
| 206 |
OHForm := TMainForm (mng_get_userdata (hHandle)); |
| 207 |
|
| 208 |
with OHFORM do |
| 209 |
begin |
| 210 |
OFFile.Free; { cleanup the stream } |
| 211 |
OFFile := nil; { don't use it again ! } |
| 212 |
end; |
| 213 |
|
| 214 |
Result := MNG_TRUE; |
| 215 |
end; |
| 216 |
|
| 217 |
{****************************************************************************} |
| 218 |
|
| 219 |
{$F+} |
| 220 |
function Readdata ( hHandle : mng_handle; |
| 221 |
pBuf : mng_ptr; |
| 222 |
iBuflen : mng_uint32; |
| 223 |
var pRead : mng_uint32) : mng_bool; stdcall; |
| 224 |
{$F-} |
| 225 |
|
| 226 |
var OHForm : TMainForm; |
| 227 |
IHTicks : cardinal; |
| 228 |
IHByte1 : cardinal; |
| 229 |
IHByte2 : cardinal; |
| 230 |
IHBytesPerSec : cardinal; |
| 231 |
|
| 232 |
begin |
| 233 |
{ get a fix on our form } |
| 234 |
OHForm := TMainForm (mng_get_userdata (hHandle)); |
| 235 |
|
| 236 |
with OHForm do |
| 237 |
begin { are we at EOF ? } |
| 238 |
if OFFile.Position >= OFFile.Size then |
| 239 |
begin |
| 240 |
pRead := 0; { indicate so } |
| 241 |
end |
| 242 |
else |
| 243 |
begin |
| 244 |
IHBytesPerSec := IFBytesPerSec; { fake a slow connection } |
| 245 |
|
| 246 |
if IHBytesPerSec > 0 then |
| 247 |
begin |
| 248 |
IHTicks := Windows.GetTickCount; |
| 249 |
IHByte1 := round (((IHTicks - IFTicks) / 1000) * IHBytesPerSec); |
| 250 |
IHByte2 := (IFBytes + iBuflen); |
| 251 |
|
| 252 |
if ((IHByte2 - IHByte1) div IHBytesPerSec) > 10 then |
| 253 |
Windows.Sleep ((IHByte2 - IHByte1) div IHBytesPerSec); |
| 254 |
|
| 255 |
end; |
| 256 |
{ read the requested data } |
| 257 |
pRead := OFFile.Read (pBuf^, iBuflen); |
| 258 |
IFBytes := IFBytes + pRead; |
| 259 |
end; |
| 260 |
end; |
| 261 |
|
| 262 |
Result := MNG_TRUE; |
| 263 |
end; |
| 264 |
|
| 265 |
{****************************************************************************} |
| 266 |
|
| 267 |
{$F+} |
| 268 |
function ProcessHeader (hHandle : mng_handle; |
| 269 |
iWidth : mng_uint32; |
| 270 |
iHeight : mng_uint32) : mng_bool; stdcall; |
| 271 |
{$F-} |
| 272 |
|
| 273 |
var OHForm : TMainForm; |
| 274 |
|
| 275 |
begin { get a fix on our form } |
| 276 |
OHForm := TMainForm (mng_get_userdata (hHandle)); |
| 277 |
|
| 278 |
with OHForm do |
| 279 |
begin |
| 280 |
OFBitmap.Width := iWidth; { store the new dimensions } |
| 281 |
OFBitmap.Height := iHeight; |
| 282 |
OFImage.Left := 0; { adjust the visible component } |
| 283 |
OFImage.Top := 0; |
| 284 |
OFImage.Width := iWidth; |
| 285 |
OFImage.Height := iHeight; |
| 286 |
|
| 287 |
FormResize (OHForm); { force re-centering the image} |
| 288 |
{ clear the canvas & draw an outline } |
| 289 |
OFBitmap.Canvas.Brush.Color := clGray; |
| 290 |
OFBitmap.Canvas.Brush.Style := bsSolid; |
| 291 |
OFBitmap.Canvas.FillRect (OFBitmap.Canvas.ClipRect); |
| 292 |
OFBitmap.Canvas.Brush.Color := clRed; |
| 293 |
OFBitmap.Canvas.Brush.Style := bsSolid; |
| 294 |
OFBitmap.Canvas.Pen.Color := clRed; |
| 295 |
OFBitmap.Canvas.Pen.Style := psSolid; |
| 296 |
OFBitmap.Canvas.FrameRect (OFBitmap.Canvas.ClipRect); |
| 297 |
|
| 298 |
OFImage.Picture.Assign (OFBitmap); { make sure it gets out there } |
| 299 |
{ tell the library we want funny windows-bgr} |
| 300 |
if mng_set_canvasstyle (hHandle, MNG_CANVAS_BGRX8) <> 0 then |
| 301 |
MNGerror ('libmng reported an error setting the canvas style'); |
| 302 |
|
| 303 |
end; |
| 304 |
|
| 305 |
Result := MNG_TRUE; |
| 306 |
end; |
| 307 |
|
| 308 |
{****************************************************************************} |
| 309 |
|
| 310 |
{$F+} |
| 311 |
function GetCanvasLine (hHandle : mng_handle; |
| 312 |
iLinenr : mng_uint32) : mng_ptr; stdcall; |
| 313 |
{$F-} |
| 314 |
|
| 315 |
var OHForm : TMainForm; |
| 316 |
|
| 317 |
begin { get a fix on our form } |
| 318 |
OHForm := TMainForm (mng_get_userdata (hHandle)); |
| 319 |
{ easy with these bitmap objects ! } |
| 320 |
Result := OHForm.OFBitmap.ScanLine [iLinenr]; |
| 321 |
end; |
| 322 |
|
| 323 |
{****************************************************************************} |
| 324 |
|
| 325 |
{$F+} |
| 326 |
function ImageRefresh (hHandle : mng_handle; |
| 327 |
iX : mng_uint32; |
| 328 |
iY : mng_uint32; |
| 329 |
iWidth : mng_uint32; |
| 330 |
iHeight : mng_uint32) : mng_bool; stdcall; |
| 331 |
{$F-} |
| 332 |
|
| 333 |
var OHForm : TMainForm; |
| 334 |
|
| 335 |
begin { get a fix on our form } |
| 336 |
OHForm := TMainForm (mng_get_userdata (hHandle)); |
| 337 |
{ force redraw } |
| 338 |
OHForm.OFImage.Picture.Assign (OHForm.OFBitmap); |
| 339 |
|
| 340 |
Result := MNG_TRUE; |
| 341 |
end; |
| 342 |
|
| 343 |
|
| 344 |
{****************************************************************************} |
| 345 |
|
| 346 |
{$F+} |
| 347 |
function GetTickCount (hHandle : mng_handle) : mng_uint32; stdcall; |
| 348 |
{$F-} |
| 349 |
begin |
| 350 |
Result := Windows.GetTickCount; { windows knows that } |
| 351 |
end; |
| 352 |
|
| 353 |
{****************************************************************************} |
| 354 |
|
| 355 |
{$F+} |
| 356 |
function SetTimer (hHandle : mng_handle; |
| 357 |
iMsecs : mng_uint32) : mng_bool; stdcall; |
| 358 |
{$F-} |
| 359 |
|
| 360 |
var OHForm : TMainForm; |
| 361 |
|
| 362 |
begin { get a fix on our form } |
| 363 |
OHForm := TMainForm (mng_get_userdata (hHandle)); |
| 364 |
OHForm.OFTimer.Interval := iMsecs; { and set the timer } |
| 365 |
OHForm.OFTimer.Enabled := true; |
| 366 |
|
| 367 |
Result := MNG_TRUE; |
| 368 |
end; |
| 369 |
|
| 370 |
{****************************************************************************} |
| 371 |
|
| 372 |
procedure TMainForm.FormCreate(Sender: TObject); |
| 373 |
|
| 374 |
var IHRed, IHGreen, IHBlue : word; |
| 375 |
|
| 376 |
begin { initialize } |
| 377 |
OFBitmap := TBitmap.Create; |
| 378 |
IFBytesPerSec := 10000000; |
| 379 |
BFHasMouse := false; |
| 380 |
OFFile := nil; |
| 381 |
|
| 382 |
OFOpenDialog.Initialdir := ''; |
| 383 |
OFBitmap.HandleType := bmDIB; { make it a 24-bit DIB } |
| 384 |
OFBitmap.PixelFormat := pf32bit; |
| 385 |
{ now initialize the library } |
| 386 |
IFHandle := mng_initialize (mng_ptr(self), Memalloc, Memfree, nil); |
| 387 |
|
| 388 |
if IFHandle = NIL then |
| 389 |
begin |
| 390 |
MNGerror ('libmng initialization error' + #13#10 + |
| 391 |
'Program aborted'); |
| 392 |
Windows.Postmessage (handle, WM_Close, 0, 0); |
| 393 |
Exit; |
| 394 |
end; |
| 395 |
{ no need to store chunk-info ! } |
| 396 |
mng_set_storechunks (IFHandle, MNG_FALSE); |
| 397 |
{ do not use suspension-buffer } |
| 398 |
mng_set_suspensionmode (IFHandle, MNG_FALSE); |
| 399 |
{ set all the callbacks } |
| 400 |
if (mng_setcb_openstream (IFHandle, Openstream ) <> MNG_NOERROR) or |
| 401 |
(mng_setcb_closestream (IFHandle, Closestream ) <> MNG_NOERROR) or |
| 402 |
(mng_setcb_readdata (IFHandle, Readdata ) <> MNG_NOERROR) or |
| 403 |
(mng_setcb_processheader (IFHandle, ProcessHeader) <> MNG_NOERROR) or |
| 404 |
(mng_setcb_getcanvasline (IFHandle, GetCanvasLine) <> MNG_NOERROR) or |
| 405 |
(mng_setcb_refresh (IFHandle, ImageRefresh ) <> MNG_NOERROR) or |
| 406 |
(mng_setcb_gettickcount (IFHandle, GetTickCount ) <> MNG_NOERROR) or |
| 407 |
(mng_setcb_settimer (IFHandle, SetTimer ) <> MNG_NOERROR) then |
| 408 |
begin |
| 409 |
MNGerror ('libmng reported an error setting a callback function!' + #13#10 + |
| 410 |
'Program aborted'); |
| 411 |
Windows.Postmessage (handle, WM_Close, 0, 0); |
| 412 |
Exit; |
| 413 |
end; |
| 414 |
|
| 415 |
IHRed := (Color ) and $FF; { supply our own bg-color } |
| 416 |
IHGreen := (Color shr 8) and $FF; |
| 417 |
IHBlue := (Color shr 16) and $FF; |
| 418 |
|
| 419 |
IHRed := (IHRed shl 8) + IHRed; |
| 420 |
IHGreen := (IHGreen shl 8) + IHGreen; |
| 421 |
IHBlue := (IHBlue shl 8) + IHBlue; |
| 422 |
|
| 423 |
if mng_set_bgcolor (IFHandle, IHRed, IHGreen, IHBlue) <> MNG_NOERROR then |
| 424 |
MNGerror ('libmng reported an error setting the background color!'); |
| 425 |
|
| 426 |
end; |
| 427 |
|
| 428 |
{****************************************************************************} |
| 429 |
|
| 430 |
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
| 431 |
begin |
| 432 |
OFTimer.Enabled := false; |
| 433 |
BFCancelled := true; |
| 434 |
{ if we're still animating then stop it } |
| 435 |
if mng_status_running (IFHandle) and not mng_status_reading (IFHandle) then |
| 436 |
if mng_display_freeze (IFHandle) <> MNG_NOERROR then |
| 437 |
MNGerror ('libmng reported an error during display_freeze!'); |
| 438 |
|
| 439 |
mng_cleanup (IFHandle); |
| 440 |
end; |
| 441 |
|
| 442 |
{****************************************************************************} |
| 443 |
|
| 444 |
procedure TMainForm.FormShow(Sender: TObject); |
| 445 |
begin |
| 446 |
FormResize (self); |
| 447 |
end; |
| 448 |
|
| 449 |
{****************************************************************************} |
| 450 |
|
| 451 |
procedure TMainForm.FormResize(Sender: TObject); |
| 452 |
begin { center the image in the window } |
| 453 |
if ClientWidth < OFImage.Width then |
| 454 |
OFImage.Left := 0 |
| 455 |
else |
| 456 |
OFImage.Left := (ClientWidth - OFImage.Width ) div 2; |
| 457 |
|
| 458 |
if ClientHeight < OFImage.Height then |
| 459 |
OFImage.Top := 0 |
| 460 |
else |
| 461 |
OFImage.Top := (ClientHeight - OFImage.Height) div 2; |
| 462 |
|
| 463 |
end; |
| 464 |
|
| 465 |
{****************************************************************************} |
| 466 |
|
| 467 |
procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word; |
| 468 |
Shift: TShiftState); |
| 469 |
begin |
| 470 |
if Key = vk_Escape then { pressing <esc> will freeze an animation } |
| 471 |
begin |
| 472 |
OFTimer.Enabled := false; { don't let that timer go off then ! } |
| 473 |
BFCancelled := true; |
| 474 |
|
| 475 |
if mng_status_running (IFHandle) and not mng_status_reading (IFHandle) then |
| 476 |
if mng_display_freeze (IFHandle) <> MNG_NOERROR then |
| 477 |
MNGerror ('libmng reported an error during display_freeze!'); |
| 478 |
end; |
| 479 |
end; |
| 480 |
|
| 481 |
{****************************************************************************} |
| 482 |
|
| 483 |
procedure TMainForm.FormMouseMove(Sender: TObject; Shift: TShiftState; X, |
| 484 |
Y: Integer); |
| 485 |
begin |
| 486 |
if mng_status_dynamic (IFHandle) then |
| 487 |
begin |
| 488 |
if BFHasMouse then { if we had the mouse, it's left ! } |
| 489 |
begin |
| 490 |
if mng_trapevent (IFHandle, 3, 0, 0) <> MNG_NOERROR then |
| 491 |
MNGerror ('libmng reported an error during trapevent!'); |
| 492 |
|
| 493 |
BFHasMouse := false; |
| 494 |
end; |
| 495 |
end; |
| 496 |
end; |
| 497 |
|
| 498 |
{****************************************************************************} |
| 499 |
|
| 500 |
procedure TMainForm.OFImageMouseMove(Sender: TObject; Shift: TShiftState; |
| 501 |
X, Y: Integer); |
| 502 |
begin |
| 503 |
if mng_status_dynamic (IFHandle) then |
| 504 |
begin |
| 505 |
if BFHasMouse then { did we have the mouse already ? } |
| 506 |
begin |
| 507 |
if mng_trapevent (IFHandle, 2, X, Y) <> MNG_NOERROR then |
| 508 |
MNGerror ('libmng reported an error during trapevent!'); |
| 509 |
end |
| 510 |
else |
| 511 |
begin { if not, it has entered ! } |
| 512 |
if mng_trapevent (IFHandle, 1, X, Y) <> MNG_NOERROR then |
| 513 |
MNGerror ('libmng reported an error during trapevent!'); |
| 514 |
|
| 515 |
BFHasMouse := true; |
| 516 |
end; |
| 517 |
end; |
| 518 |
end; |
| 519 |
|
| 520 |
{****************************************************************************} |
| 521 |
|
| 522 |
procedure TMainForm.OFImageMouseDown(Sender: TObject; Button: TMouseButton; |
| 523 |
Shift: TShiftState; X, Y: Integer); |
| 524 |
begin |
| 525 |
if mng_status_dynamic (IFHandle) then |
| 526 |
if mng_trapevent (IFHandle, 4, X, Y) <> MNG_NOERROR then |
| 527 |
MNGerror ('libmng reported an error during trapevent!'); |
| 528 |
end; |
| 529 |
|
| 530 |
{****************************************************************************} |
| 531 |
|
| 532 |
procedure TMainForm.OFImageMouseUp(Sender: TObject; Button: TMouseButton; |
| 533 |
Shift: TShiftState; X, Y: Integer); |
| 534 |
begin |
| 535 |
if mng_status_dynamic (IFHandle) then |
| 536 |
if mng_trapevent (IFHandle, 5, X, Y) <> MNG_NOERROR then |
| 537 |
MNGerror ('libmng reported an error during trapevent!'); |
| 538 |
end; |
| 539 |
|
| 540 |
{****************************************************************************} |
| 541 |
|
| 542 |
procedure TMainForm.OFTimerTimer(Sender: TObject); |
| 543 |
|
| 544 |
var IHRslt : mng_retcode; |
| 545 |
|
| 546 |
begin |
| 547 |
OFTimer.Enabled := false; { only once ! } |
| 548 |
|
| 549 |
if not BFCancelled then |
| 550 |
begin { and inform the library } |
| 551 |
IHRslt := mng_display_resume (IFHandle); |
| 552 |
|
| 553 |
if (IHRslt <> MNG_NOERROR) and (IHRslt <> MNG_NEEDTIMERWAIT) then |
| 554 |
MNGerror ('libmng reported an error during display_resume!'); |
| 555 |
|
| 556 |
end; |
| 557 |
end; |
| 558 |
|
| 559 |
{****************************************************************************} |
| 560 |
|
| 561 |
procedure TMainForm.OFMenuFileOpenClick(Sender: TObject); |
| 562 |
|
| 563 |
var IHRslt : mng_retcode; |
| 564 |
|
| 565 |
begin |
| 566 |
OFOpenDialog.InitialDir := ''; |
| 567 |
OFOpenDialog.FileName := SFFileName; |
| 568 |
|
| 569 |
if OFOpenDialog.Execute then { get the filename } |
| 570 |
begin |
| 571 |
if OFTimer.Enabled then { if the lib was active; stop it } |
| 572 |
begin |
| 573 |
OFTimer.Enabled := false; |
| 574 |
|
| 575 |
Application.ProcessMessages; { process any timer requests (for safety) } |
| 576 |
{ now freeze the animation } |
| 577 |
if mng_display_freeze (IFHandle) <> MNG_NOERROR then |
| 578 |
MNGerror ('libmng reported an error during display_freeze!'); |
| 579 |
end; |
| 580 |
{ save interesting fields } |
| 581 |
SFFileName := OFOpenDialog.FileName; |
| 582 |
IFTicks := Windows.GetTickCount; |
| 583 |
IFBytes := 0; |
| 584 |
BFCancelled := false; |
| 585 |
{ always reset (just in case) } |
| 586 |
if mng_reset (IFHandle) <> MNG_NOERROR then |
| 587 |
MNGerror ('libmng reported an error during reset!') |
| 588 |
else |
| 589 |
begin { and let the lib do it's job ! } |
| 590 |
IHRslt := mng_readdisplay (IFHandle); |
| 591 |
|
| 592 |
if (IHRslt <> MNG_NOERROR) and (IHRSLT <> MNG_NEEDTIMERWAIT) then |
| 593 |
MNGerror ('libmng reported an error reading the input file!'); |
| 594 |
|
| 595 |
end; |
| 596 |
end; |
| 597 |
end; |
| 598 |
|
| 599 |
{****************************************************************************} |
| 600 |
|
| 601 |
procedure TMainForm.OFMenuFileProfileClick(Sender: TObject); |
| 602 |
|
| 603 |
var SHProfileDir : array [0 .. MAX_PATH + 20] of char; |
| 604 |
|
| 605 |
begin |
| 606 |
GetSystemDirectory (@SHProfileDir, MAX_PATH); |
| 607 |
strcat (@SHProfileDir, '\Color'); |
| 608 |
|
| 609 |
OFOpenDialogProfile.InitialDir := strpas (@SHProfileDir); |
| 610 |
|
| 611 |
if OFOpenDialogProfile.Execute then |
| 612 |
if mng_set_outputprofile (IFHandle, pchar (OFOpenDialogProfile.FileName)) <> 0 then |
| 613 |
MNGerror ('libmng reported an error setting the output-profile!'); |
| 614 |
|
| 615 |
end; |
| 616 |
|
| 617 |
{****************************************************************************} |
| 618 |
|
| 619 |
procedure TMainForm.OFMenuFileExitClick(Sender: TObject); |
| 620 |
begin |
| 621 |
if mng_cleanup (IFHandle) <> MNG_NOERROR then |
| 622 |
MNGerror ('libmng cleanup error'); |
| 623 |
|
| 624 |
Close; |
| 625 |
end; |
| 626 |
|
| 627 |
{****************************************************************************} |
| 628 |
|
| 629 |
procedure TMainForm.OFMenuOptionsModemSpeedClick(Sender: TObject); |
| 630 |
begin |
| 631 |
OFMenuOptionsModem28k8.Checked := false; |
| 632 |
OFMenuOptionsModem33k6.Checked := false; |
| 633 |
OFMenuOptionsModem56k.Checked := false; |
| 634 |
OFMenuOptionsModemISDN64.Checked := false; |
| 635 |
OFMenuOptionsModemISDN128.Checked := false; |
| 636 |
OFMenuOptionsModemCable512.Checked := false; |
| 637 |
OFMenuOptionsModemUnlimited.Checked := false; |
| 638 |
|
| 639 |
if IFBytesPerSec = OFMenuOptionsModem28k8.Tag div 10 then |
| 640 |
OFMenuOptionsModem28k8.Checked := true |
| 641 |
else |
| 642 |
if IFBytesPerSec = OFMenuOptionsModem33k6.Tag div 10 then |
| 643 |
OFMenuOptionsModem33k6.Checked := true |
| 644 |
else |
| 645 |
if IFBytesPerSec = OFMenuOptionsModem56k.Tag div 10 then |
| 646 |
OFMenuOptionsModem56k.Checked := true |
| 647 |
else |
| 648 |
if IFBytesPerSec = OFMenuOptionsModemISDN64.Tag div 10 then |
| 649 |
OFMenuOptionsModemISDN64.Checked := true |
| 650 |
else |
| 651 |
if IFBytesPerSec = OFMenuOptionsModemISDN128.Tag div 10 then |
| 652 |
OFMenuOptionsModemISDN128.Checked := true |
| 653 |
else |
| 654 |
if IFBytesPerSec = OFMenuOptionsModemUnlimited.Tag div 10 then |
| 655 |
OFMenuOptionsModemCable512.Checked := true |
| 656 |
else |
| 657 |
OFMenuOptionsModemUnlimited.Checked := true; |
| 658 |
|
| 659 |
end; |
| 660 |
|
| 661 |
{****************************************************************************} |
| 662 |
|
| 663 |
procedure TMainForm.OFMenuOptionsModemXClick(Sender: TObject); |
| 664 |
begin |
| 665 |
IFBytesPerSec := TMenuItem (Sender).Tag div 10; |
| 666 |
end; |
| 667 |
|
| 668 |
{****************************************************************************} |
| 669 |
|
| 670 |
procedure TMainForm.MNGerror; |
| 671 |
|
| 672 |
var iErrorcode : mng_uint32; |
| 673 |
iSeverity : mng_uint8; |
| 674 |
iChunkname : mng_chunkid; |
| 675 |
iChunkseq : mng_uint32; |
| 676 |
iExtra1 : mng_int32; |
| 677 |
iExtra2 : mng_int32; |
| 678 |
zErrortext : mng_pchar; |
| 679 |
|
| 680 |
begin { get extended info } |
| 681 |
iErrorcode := mng_getlasterror (IFHandle, iSeverity, iChunkname, iChunkseq, |
| 682 |
iExtra1, iExtra2, zErrortext); |
| 683 |
|
| 684 |
MessageDlg (SHMsg + #13#10#13#10 + strpas (zErrortext) + #13#10#13#10 + |
| 685 |
Format ('Error = %d; Severity = %d; Chunknr = %d; Extra1 = %d', |
| 686 |
[iErrorcode, iSeverity, iChunkseq, iExtra1]), |
| 687 |
mtError, [mbOK], 0); |
| 688 |
end; |
| 689 |
|
| 690 |
{****************************************************************************} |
| 691 |
|
| 692 |
end. |