KolibriOS examples © 0CodErr
70
KolibriOS/Examples/{10} ReadFolder/Unit1.pas
Normal file
@ -0,0 +1,70 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
hConsole: Pointer;
|
||||
ConsoleInit: Procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: Dword; Caption: PChar); StdCall;
|
||||
ConsoleExit: Procedure(bCloseWindow: Cardinal); StdCall;
|
||||
printf: Function(Const Format: PChar): Integer; CDecl VarArgs;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Const
|
||||
FolderPath = '/sys';
|
||||
Var
|
||||
FolderInformation: TFolderInformation;
|
||||
BlocksRead: Dword;
|
||||
Pos: Dword;
|
||||
Begin
|
||||
hConsole := LoadLibrary('/sys/lib/console.obj');
|
||||
ConsoleInit := GetProcAddress(hConsole, 'con_init');
|
||||
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
|
||||
printf := GetProcAddress(hConsole, 'con_printf');
|
||||
|
||||
If ReadFolder(FolderPath, FolderInformation, 0, 0, 0, BlocksRead) = 0 Then
|
||||
Begin
|
||||
With FolderInformation Do Begin
|
||||
ConsoleInit($FFFFFFFF, $FFFFFFFF, $FFFFFFFF, {11 printf In Loop}11 * FileCount + {2 printf below}2 + 1, 'ReadFolder');
|
||||
printf('Folder "%s" contains %u files and/or folders.'#10, FolderPath, FileCount);
|
||||
printf(#10);
|
||||
End;
|
||||
End
|
||||
Else
|
||||
Begin
|
||||
ConsoleInit($FFFFFFFF, $FFFFFFFF, $FFFFFFFF, $FFFFFFFF, 'ReadFolder');
|
||||
printf('Folder "%s" can not be read.'#10, FolderPath);
|
||||
End;
|
||||
|
||||
Pos := 0;
|
||||
While ReadFolder(FolderPath, FolderInformation, 1, Pos, 0, BlocksRead) = 0 Do Begin
|
||||
With FolderInformation Do Begin
|
||||
With FileInformation[0] Do Begin
|
||||
printf('FileName = %s'#10, FileName);
|
||||
With FileAttributes Do Begin
|
||||
printf('SizeHi = %u'#10, SizeHi);
|
||||
printf('SizeLo = %u'#10, SizeLo);
|
||||
With ModifyDate Do printf('ModifyDate = %02d.%02d.%02d'#10, Day, Month, Year);
|
||||
With ModifyTime Do printf('ModifyTime = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
|
||||
With AccessDate Do printf('AccessDate = %02d.%02d.%02d'#10, Day, Month, Year);
|
||||
With AccessTime Do printf('AccessTime = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
|
||||
With CreationDate Do printf('CreationDate = %02d.%02d.%02d'#10, Day, Month, Year);
|
||||
With CreationTime Do printf('CreationTime = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
|
||||
printf('Attributes = 0x%08x'#10, Attributes);
|
||||
End;
|
||||
End;
|
||||
printf(#10);
|
||||
End;
|
||||
Inc(Pos);
|
||||
End;
|
||||
|
||||
ConsoleExit(0);
|
||||
ThreadTerminate;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
1
KolibriOS/Examples/{10} ReadFolder/make.bat
Normal file
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
BIN
KolibriOS/Examples/{11} DrawImageEx/Flower(4bpp).bmp
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
KolibriOS/Examples/{11} DrawImageEx/House(24bpp).bmp
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
KolibriOS/Examples/{11} DrawImageEx/Mario(1bpp).bmp
Normal file
After Width: | Height: | Size: 1.2 KiB |
202
KolibriOS/Examples/{11} DrawImageEx/Unit1.pas
Normal file
@ -0,0 +1,202 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Const
|
||||
AppPath = PPChar(32);
|
||||
Picture1 = 'Flower(4bpp).bmp';
|
||||
Picture2 = 'Mario(1bpp).bmp';
|
||||
Picture3 = 'House(24bpp).bmp';
|
||||
(* -------------------------------------------------------- *)
|
||||
Type
|
||||
TBitmapFileHeader = Packed Record
|
||||
bfType: Word;
|
||||
bfSize: Dword;
|
||||
bfReserved1: Word;
|
||||
bfReserved2: Word;
|
||||
bfOffBits: Dword;
|
||||
End;
|
||||
|
||||
TBitmapInfoHeader = Packed Record
|
||||
biSize: Dword;
|
||||
biWidth: Longint;
|
||||
biHeight: Longint;
|
||||
biPlanes: Word;
|
||||
biBitCount: Word;
|
||||
biCompression: Dword;
|
||||
biSizeImage: Dword;
|
||||
biXPelsPerMeter: Longint;
|
||||
biYPelsPerMeter: Longint;
|
||||
biClrUsed: Dword;
|
||||
biClrImportant: Dword;
|
||||
End;
|
||||
|
||||
TRGBQuad = Packed Record
|
||||
Blue: Byte;
|
||||
Green: Byte;
|
||||
Red: Byte;
|
||||
reserved: Byte;
|
||||
end;
|
||||
|
||||
TBitmapFile = Packed Record
|
||||
BitmapFileHeader: TBitmapFileHeader;
|
||||
BitmapInfoHeader: TBitmapInfoHeader;
|
||||
Palette: Packed Array[0..0] Of TRGBQuad;
|
||||
End;
|
||||
|
||||
PBitmapFile = ^TBitmapFile;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
Window: TRect;
|
||||
Screen: TSize;
|
||||
BitmapFile1: PBitmapFile;
|
||||
BitmapFile2: PBitmapFile;
|
||||
BitmapFile3: PBitmapFile;
|
||||
Image1: Pointer;
|
||||
Image2: Pointer;
|
||||
Image3: Pointer;
|
||||
Padding1: Dword;
|
||||
Padding2: Dword;
|
||||
Padding3: Dword;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Procedure On_Key;
|
||||
Procedure On_Button;
|
||||
Procedure On_Redraw;
|
||||
Procedure ExtractFileDirectory(Src, Dst: PChar); StdCall;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Var
|
||||
BytesRead: Dword;
|
||||
FileAttributes: TFileAttributes;
|
||||
Begin
|
||||
HeapCreate;
|
||||
|
||||
ExtractFileDirectory(AppPath^, AppPath^);
|
||||
SetCurrentDirectory(AppPath^);
|
||||
|
||||
|
||||
GetFileAttributes(Picture1, FileAttributes);
|
||||
BitmapFile1 := HeapAllocate(FileAttributes.SizeLo);
|
||||
ReadFile(Picture1, BitmapFile1^, FileAttributes.SizeLo, 0, 0, BytesRead);
|
||||
|
||||
With BitmapFile1^ Do
|
||||
With BitmapFileHeader Do
|
||||
With BitmapInfoHeader Do Begin
|
||||
Padding1 := (32 - biWidth * biBitCount Mod 32) And Not 32 Shr 3;
|
||||
Image1 := Pointer(Dword(BitmapFile1) + bfOffBits);
|
||||
End;
|
||||
|
||||
|
||||
GetFileAttributes(Picture2, FileAttributes);
|
||||
BitmapFile2 := HeapAllocate(FileAttributes.SizeLo);
|
||||
ReadFile(Picture2, BitmapFile2^, FileAttributes.SizeLo, 0, 0, BytesRead);
|
||||
|
||||
With BitmapFile2^ Do
|
||||
With BitmapFileHeader Do
|
||||
With BitmapInfoHeader Do Begin
|
||||
Padding2 := (32 - biWidth * biBitCount Mod 32) And Not 32 Shr 3;
|
||||
Image2 := Pointer(Dword(BitmapFile2) + bfOffBits);
|
||||
End;
|
||||
|
||||
|
||||
GetFileAttributes(Picture3, FileAttributes);
|
||||
BitmapFile3 := HeapAllocate(FileAttributes.SizeLo);
|
||||
ReadFile(Picture3, BitmapFile3^, FileAttributes.SizeLo, 0, 0, BytesRead);
|
||||
|
||||
With BitmapFile3^ Do
|
||||
With BitmapFileHeader Do
|
||||
With BitmapInfoHeader Do Begin
|
||||
Padding3 := (32 - biWidth * biBitCount Mod 32) And Not 32 Shr 3;
|
||||
Image3 := Pointer(Dword(BitmapFile3) + bfOffBits);
|
||||
End;
|
||||
|
||||
Screen := GetScreenSize();
|
||||
|
||||
With Window Do Begin
|
||||
With Screen Do Begin
|
||||
Right := 340;
|
||||
Bottom := Height Shr 2;
|
||||
Left := (Width - Right) Shr 1;
|
||||
Top := (Height - Bottom) Shr 1;
|
||||
End;
|
||||
End;
|
||||
|
||||
While TRUE Do Begin
|
||||
Case WaitEvent() Of
|
||||
REDRAW_EVENT: On_Redraw;
|
||||
KEY_EVENT: On_Key;
|
||||
BUTTON_EVENT: On_Button;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Redraw;
|
||||
Begin
|
||||
BeginDraw;
|
||||
|
||||
With Window Do
|
||||
DrawWindow(Left, Top, Right, Bottom, 'DrawImageEx', $00FFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CAPTION_MOVABLE);
|
||||
|
||||
(* these image files was saved with 'flip row order' parameter *)
|
||||
(* therefore they have negative biHeight field *)
|
||||
(* also it is possible to use Nil instead of @Palette if you sure palette is absent *)
|
||||
|
||||
With BitmapFile1^ Do
|
||||
With BitmapFileHeader Do
|
||||
With BitmapInfoHeader Do
|
||||
DrawImageEx(Image1^, 20, 35, biWidth, -biHeight, biBitCount, @Palette, Padding1);
|
||||
|
||||
With BitmapFile2^ Do
|
||||
With BitmapFileHeader Do
|
||||
With BitmapInfoHeader Do
|
||||
DrawImageEx(Image2^, 120, 35, biWidth, -biHeight, biBitCount, @Palette, Padding2);
|
||||
|
||||
With BitmapFile3^ Do
|
||||
With BitmapFileHeader Do
|
||||
With BitmapInfoHeader Do
|
||||
DrawImageEx(Image3^, 220, 45, biWidth, -biHeight, biBitCount, @Palette, Padding3);
|
||||
|
||||
EndDraw;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Key;
|
||||
Begin
|
||||
GetKey;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Button;
|
||||
Begin
|
||||
Case GetButton().ID Of
|
||||
1: ThreadTerminate;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure ExtractFileDirectory(Src, Dst: PChar); StdCall;
|
||||
Asm
|
||||
push esi
|
||||
push edi
|
||||
xor eax, eax
|
||||
mov edi, Src
|
||||
mov esi, edi
|
||||
mov ecx, $FFFFFFFF
|
||||
repne scasb
|
||||
mov al, '/'
|
||||
std
|
||||
repne scasb
|
||||
cld
|
||||
sub edi, esi
|
||||
mov ecx, edi
|
||||
inc ecx
|
||||
mov edi, Dst
|
||||
rep movsb
|
||||
mov byte [edi], 0
|
||||
pop edi
|
||||
pop esi
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
1
KolibriOS/Examples/{11} DrawImageEx/make.bat
Normal file
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
170
KolibriOS/Examples/{13} LoadCursorIndirect, SetCursor/Unit1.pas
Normal file
@ -0,0 +1,170 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Const
|
||||
AppPath = PPChar(32);
|
||||
|
||||
ARROW_BUTTON = 2;
|
||||
POINT_BUTTON = 3;
|
||||
WAIT_BUTTON = 4;
|
||||
|
||||
(* -------------------------------------------------------- *)
|
||||
Type
|
||||
TBitmapFileHeader = Packed Record
|
||||
bfType: Word;
|
||||
bfSize: Dword;
|
||||
bfReserved1: Word;
|
||||
bfReserved2: Word;
|
||||
bfOffBits: Dword;
|
||||
End;
|
||||
|
||||
TBitmapInfoHeader = Packed Record
|
||||
biSize: Dword;
|
||||
biWidth: Longint;
|
||||
biHeight: Longint;
|
||||
biPlanes: Word;
|
||||
biBitCount: Word;
|
||||
biCompression: Dword;
|
||||
biSizeImage: Dword;
|
||||
biXPelsPerMeter: Longint;
|
||||
biYPelsPerMeter: Longint;
|
||||
biClrUsed: Dword;
|
||||
biClrImportant: Dword;
|
||||
End;
|
||||
|
||||
TBitmapFile = Packed Record
|
||||
BitmapFileHeader: TBitmapFileHeader;
|
||||
BitmapInfoHeader: TBitmapInfoHeader;
|
||||
End;
|
||||
|
||||
PBitmapFile = ^TBitmapFile;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
Window: TRect;
|
||||
Screen: TSize;
|
||||
|
||||
ArrowBitmapFile,
|
||||
PointBitmapFile,
|
||||
WaitBitmapFile: PBitmapFile;
|
||||
|
||||
ArrowBitmap,
|
||||
PointBitmap,
|
||||
WaitBitmap: Pointer;
|
||||
|
||||
hArrowCursor,
|
||||
hPointCursor,
|
||||
hWaitCursor: Dword;
|
||||
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Procedure On_Key;
|
||||
Procedure On_Button;
|
||||
Procedure On_Redraw;
|
||||
Procedure ExtractFileDirectory(Src, Dst: PChar); StdCall;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Var
|
||||
FileSize: Dword;
|
||||
Begin
|
||||
HeapCreate;
|
||||
|
||||
ExtractFileDirectory(AppPath^, AppPath^);
|
||||
SetCurrentDirectory(AppPath^);
|
||||
|
||||
ArrowBitmapFile := LoadFile('arrow.bmp', FileSize);
|
||||
PointBitmapFile := LoadFile('point.bmp', FileSize);
|
||||
WaitBitmapFile := LoadFile('wait.bmp', FileSize);
|
||||
|
||||
ArrowBitmap := Pointer(Dword(ArrowBitmapFile) + ArrowBitmapFile^.BitmapFileHeader.bfOffBits);
|
||||
PointBitmap := Pointer(Dword(PointBitmapFile) + PointBitmapFile^.BitmapFileHeader.bfOffBits);
|
||||
WaitBitmap := Pointer(Dword(WaitBitmapFile) + WaitBitmapFile^.BitmapFileHeader.bfOffBits);
|
||||
|
||||
hArrowCursor := LoadCursorIndirect(ArrowBitmap^, 0, 0);
|
||||
hPointCursor := LoadCursorIndirect(PointBitmap^, 12, 0);
|
||||
hWaitCursor := LoadCursorIndirect(WaitBitmap^, 0, 0);
|
||||
|
||||
Screen := GetScreenSize();
|
||||
|
||||
With Window Do Begin
|
||||
With Screen Do Begin
|
||||
Right := Width Shr 2;
|
||||
Bottom := Height Shr 2;
|
||||
Left := (Width - Right) Shr 1;
|
||||
Top := (Height - Bottom) Shr 1;
|
||||
End;
|
||||
End;
|
||||
|
||||
While TRUE Do Begin
|
||||
Case WaitEvent() Of
|
||||
REDRAW_EVENT: On_Redraw;
|
||||
KEY_EVENT: On_Key;
|
||||
BUTTON_EVENT: On_Button;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Redraw;
|
||||
Begin
|
||||
BeginDraw;
|
||||
|
||||
With Window Do
|
||||
DrawWindow(Left, Top, Right, Bottom, 'LoadCursorIndirect', $00FFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CAPTION_MOVABLE);
|
||||
|
||||
DrawText( 8, 8, 'Click on picture buttons', 0, $00FFFFFF, DT_CP866_8X16 + DT_FILL_OPAQUE + DT_ZSTRING, 0);
|
||||
DrawText( 8, 25, 'below to select cursor:', 0, $00FFFFFF, DT_CP866_8X16 + DT_FILL_OPAQUE + DT_ZSTRING, 0);
|
||||
|
||||
DrawButton(8, 40, 32, 32, 0, BS_FILL_TRANSPARENT, ARROW_BUTTON);
|
||||
DrawButton(52, 40, 32, 32, 0, BS_FILL_TRANSPARENT, POINT_BUTTON);
|
||||
DrawButton(96, 40, 32, 32, 0, BS_FILL_TRANSPARENT, WAIT_BUTTON );
|
||||
|
||||
Blit(ArrowBitmap^, 0, 0, 32, 32, 8, 40, 32, 32, 32*4, BLIT_CLIENT_RELATIVE);
|
||||
Blit(PointBitmap^, 0, 0, 32, 32, 52, 40, 32, 32, 32*4, BLIT_CLIENT_RELATIVE);
|
||||
Blit(WaitBitmap^, 0, 0, 32, 32, 96, 40, 32, 32, 32*4, BLIT_CLIENT_RELATIVE);
|
||||
|
||||
EndDraw;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Key;
|
||||
Begin
|
||||
GetKey;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Button;
|
||||
Begin
|
||||
Case GetButton().ID Of
|
||||
1: ThreadTerminate;
|
||||
ARROW_BUTTON: SetCursor(hArrowCursor);
|
||||
POINT_BUTTON: SetCursor(hPointCursor);
|
||||
WAIT_BUTTON: SetCursor(hWaitCursor);
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure ExtractFileDirectory(Src, Dst: PChar); StdCall;
|
||||
Asm
|
||||
push esi
|
||||
push edi
|
||||
xor eax, eax
|
||||
mov edi, Src
|
||||
mov esi, edi
|
||||
mov ecx, $FFFFFFFF
|
||||
repne scasb
|
||||
mov al, '/'
|
||||
std
|
||||
repne scasb
|
||||
cld
|
||||
sub edi, esi
|
||||
mov ecx, edi
|
||||
inc ecx
|
||||
mov edi, Dst
|
||||
rep movsb
|
||||
mov byte [edi], 0
|
||||
pop edi
|
||||
pop esi
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
BIN
KolibriOS/Examples/{13} LoadCursorIndirect, SetCursor/arrow.bmp
Normal file
After Width: | Height: | Size: 4.1 KiB |
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
BIN
KolibriOS/Examples/{13} LoadCursorIndirect, SetCursor/point.bmp
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
KolibriOS/Examples/{13} LoadCursorIndirect, SetCursor/wait.bmp
Normal file
After Width: | Height: | Size: 4.1 KiB |
123
KolibriOS/Examples/{14} GetScreenImage/Unit1.pas
Normal file
@ -0,0 +1,123 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Const
|
||||
BORDER_SIZE = 5;
|
||||
(* -------------------------------------------------------- *)
|
||||
Type
|
||||
TRGBTriple = Packed Record
|
||||
Blue: Byte;
|
||||
Green: Byte;
|
||||
Red: Byte;
|
||||
End;
|
||||
|
||||
TRGBTripleArray = Packed Array[0..0] Of TRGBTriple;
|
||||
|
||||
PRGBTripleArray = ^TRGBTripleArray;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
Window: TRect;
|
||||
Screen: TSize;
|
||||
Image, ImagePreview: PRGBTripleArray;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Procedure On_Key;
|
||||
Procedure On_Button;
|
||||
Procedure On_Redraw;
|
||||
Procedure ImageResize;
|
||||
Function SrcR(a, b: Dword): Dword;
|
||||
Function SrcG(a, b: Dword): Dword;
|
||||
Function SrcB(a, b: Dword): Dword;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Begin
|
||||
HeapCreate;
|
||||
|
||||
Screen := GetScreenSize();
|
||||
|
||||
With Window Do Begin
|
||||
With Screen Do Begin
|
||||
Right := BORDER_SIZE * 2 + Width Shr 1 - 1;
|
||||
Bottom := BORDER_SIZE + GetSkinHeight + Height Shr 1 - 1;
|
||||
Left := (Width - Right) Shr 1;
|
||||
Top := (Height - Bottom) Shr 1;
|
||||
|
||||
Image := HeapAllocate(Width * Height * 3);
|
||||
ImagePreview := HeapAllocate(Width * Height * 3 Shr 1);
|
||||
|
||||
GetScreenImage(Image^, 0, 0, Width, Height);
|
||||
ImageResize;
|
||||
End;
|
||||
End;
|
||||
|
||||
While TRUE Do Begin
|
||||
Case WaitEvent() Of
|
||||
REDRAW_EVENT: On_Redraw;
|
||||
KEY_EVENT: On_Key;
|
||||
BUTTON_EVENT: On_Button;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Redraw;
|
||||
Begin
|
||||
BeginDraw;
|
||||
|
||||
With Window Do
|
||||
DrawWindow(Left, Top, Right, Bottom, 'GetScreenImage', $00FFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION + WS_FILL_TRANSPARENT, CAPTION_MOVABLE);
|
||||
|
||||
With Screen Do
|
||||
DrawImage(ImagePreview^, 0, 0, Width Shr 1, Height Shr 1);
|
||||
|
||||
EndDraw;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Key;
|
||||
Begin
|
||||
GetKey;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Button;
|
||||
Begin
|
||||
Case GetButton().ID Of
|
||||
1: ThreadTerminate;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Function SrcR(a, b: Dword): Dword;
|
||||
Begin
|
||||
SrcR := Image[(Screen.Width * b + a)].Red;
|
||||
End;
|
||||
Function SrcG(a, b: Dword): Dword;
|
||||
Begin
|
||||
SrcG := Image[(Screen.Width * b + a)].Green;
|
||||
End;
|
||||
Function SrcB(a, b: Dword): Dword;
|
||||
Begin
|
||||
SrcB := Image[(Screen.Width * b + a)].Blue;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure ImageResize;
|
||||
Var
|
||||
a, b, i: Dword;
|
||||
Begin
|
||||
a := 0;
|
||||
While a < Screen.Width Do Begin
|
||||
b := 0;
|
||||
While b < Screen.Height Do Begin
|
||||
i := ((Screen.Width Shr 1) * b + a) Shr 1;
|
||||
ImagePreview[i].Red := (SrcR(a, b) + SrcR(a + 1, b) + SrcR(a, b + 1) + SrcR(a + 1, b + 1)) Shr 2;
|
||||
ImagePreview[i].Green := (SrcG(a, b) + SrcG(a + 1, b) + SrcG(a, b + 1) + SrcG(a + 1, b + 1)) Shr 2;
|
||||
ImagePreview[i].Blue := (SrcB(a, b) + SrcB(a + 1, b) + SrcB(a, b + 1) + SrcB(a + 1, b + 1)) Shr 2;
|
||||
Inc(b, 2);
|
||||
End;
|
||||
Inc(a, 2);
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
1
KolibriOS/Examples/{14} GetScreenImage/make.bat
Normal file
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
@ -0,0 +1,60 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
hConsole: Pointer;
|
||||
ConsoleInit: Procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: Dword; Caption: PChar); StdCall;
|
||||
ConsoleExit: Procedure(bCloseWindow: Cardinal); StdCall;
|
||||
Printf: Function(Const Format: PChar): Integer; CDecl VarArgs;
|
||||
GetConsoleCursorPos: Procedure(X, Y: PInteger); StdCall;
|
||||
SetConsoleCursorPos: Procedure(X, Y: Integer); StdCall;
|
||||
kbhit: Function: Boolean;
|
||||
SetConsoleCursorHeight: Function(Height: Integer): Integer; StdCall;
|
||||
ConsoleCls: Procedure;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main();
|
||||
Var
|
||||
SystemDate: TSystemDate;
|
||||
SystemTime: TSystemTime;
|
||||
X, Y: Integer;
|
||||
Begin
|
||||
|
||||
hConsole := LoadLibrary('/sys/lib/console.obj');
|
||||
ConsoleInit := GetProcAddress(hConsole, 'con_init');
|
||||
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
|
||||
GetConsoleCursorPos := GetProcAddress(hConsole, 'con_get_cursor_pos');
|
||||
SetConsoleCursorPos := GetProcAddress(hConsole, 'con_set_cursor_pos');
|
||||
SetConsoleCursorHeight := GetProcAddress(hConsole, 'con_set_cursor_height');
|
||||
Printf := GetProcAddress(hConsole, 'con_printf');
|
||||
KBHit := GetProcAddress(hConsole, 'con_kbhit');
|
||||
|
||||
ConsoleInit($FFFFFFFF, $FFFFFFFF, $FFFFFFFF, $FFFFFFFF, 'Test');
|
||||
|
||||
SetConsoleCursorHeight(0);
|
||||
SetConsoleCursorPos(27, 11);
|
||||
Printf('SystemDate and SystemTime'#10' ');
|
||||
GetConsoleCursorPos(@X, @Y);
|
||||
Repeat
|
||||
SystemDate := GetSystemDate();
|
||||
SystemTime := GetSystemTime();
|
||||
With SystemDate, SystemTime Do
|
||||
Begin
|
||||
Printf('%02x.%02x.%02x', Day, Month, Year);
|
||||
Printf(' - %02x:%02x:%02x', Hours, Minutes, Seconds);
|
||||
End;
|
||||
SetConsoleCursorPos(X, Y);
|
||||
Sleep(50);
|
||||
Until KBHit;
|
||||
|
||||
ConsoleExit(1);
|
||||
ThreadTerminate;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
96
KolibriOS/Examples/{17} SetWindowPos/Unit1.pas
Normal file
@ -0,0 +1,96 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Const
|
||||
KS_UP = #$48;
|
||||
KS_DOWN = #$50;
|
||||
KS_LEFT = #$4B;
|
||||
KS_RIGHT = #$4D;
|
||||
MOVE_STEP = 10;
|
||||
LEFT_CTRL_PRESSED = 4;
|
||||
RIGHT_CTRL_PRESSED = 8;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
Window: TRect;
|
||||
Screen: TSize;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Procedure On_Key;
|
||||
Procedure On_Button;
|
||||
Procedure On_Redraw;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Begin
|
||||
Screen := GetScreenSize();
|
||||
|
||||
With Window, Screen Do Begin
|
||||
Right := Width Shr 2;
|
||||
Bottom := Height Shr 2;
|
||||
Left := (Width - Right) Shr 1;
|
||||
Top := (Height - Bottom) Shr 1;
|
||||
End;
|
||||
|
||||
While TRUE Do Begin
|
||||
Case WaitEvent() Of
|
||||
REDRAW_EVENT: On_Redraw;
|
||||
KEY_EVENT: On_Key;
|
||||
BUTTON_EVENT: On_Button;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Redraw;
|
||||
Begin
|
||||
BeginDraw;
|
||||
With Window Do
|
||||
DrawWindow(Left, Top, Right, Bottom, 'SetWindowPos', $00FFFFFF, WS_SKINNED_SIZABLE + WS_COORD_CLIENT + WS_CAPTION, CAPTION_MOVABLE);
|
||||
DrawText(24, 26, 'Use arrow keys(Left, Right, Up, Down)', $00000000, $00FFFFFF, DT_ZSTRING, 0);
|
||||
DrawText(24, 35, 'to move window.', $00000000, $00FFFFFF, DT_ZSTRING, 0);
|
||||
DrawText(24, 44, 'Use Ctrl+arrow keys to resize window.', $00000000, $00FFFFFF, DT_ZSTRING, 0);
|
||||
EndDraw;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Key;
|
||||
Var
|
||||
Key: TKeyboardInput;
|
||||
ThreadInfo: TThreadInfo;
|
||||
ControlKeyState: Dword;
|
||||
Begin
|
||||
GetThreadInfo($FFFFFFFF, ThreadInfo);
|
||||
ControlKeyState := GetControlKeyState;
|
||||
Key := GetKey;
|
||||
With ThreadInfo.Window Do
|
||||
Begin
|
||||
If Boolean(ControlKeyState And (RIGHT_CTRL_PRESSED Or LEFT_CTRL_PRESSED)) Then Begin
|
||||
Case Key.Scan Of
|
||||
KS_UP: Dec(Bottom, MOVE_STEP);
|
||||
KS_DOWN: Inc(Bottom, MOVE_STEP);
|
||||
KS_LEFT: Dec(Right, MOVE_STEP);
|
||||
KS_RIGHT: Inc(Right, MOVE_STEP);
|
||||
End;
|
||||
End
|
||||
Else Begin
|
||||
Case Key.Scan Of
|
||||
KS_UP: Dec(Top, MOVE_STEP);
|
||||
KS_DOWN: Inc(Top, MOVE_STEP);
|
||||
KS_LEFT: Dec(Left, MOVE_STEP);
|
||||
KS_RIGHT: Inc(Left, MOVE_STEP);
|
||||
End;
|
||||
End;
|
||||
SetWindowPos(Left, Top, Right, Bottom);
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Button;
|
||||
Begin
|
||||
Case GetButton().ID Of
|
||||
1: ThreadTerminate;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
1
KolibriOS/Examples/{17} SetWindowPos/make.bat
Normal file
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
@ -0,0 +1,82 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Const
|
||||
NO_EVENT = 0;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
Window: TBox;
|
||||
Screen: TSize;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Procedure On_Button;
|
||||
Procedure On_Redraw;
|
||||
Procedure UpdateInfo;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Begin
|
||||
Screen := GetScreenSize();
|
||||
|
||||
With Window Do Begin
|
||||
Width := 189;
|
||||
Height := 79;
|
||||
Left := (Screen.Width - Width) Shr 1;
|
||||
Top := (Screen.Height - Height) Shr 1;
|
||||
End;
|
||||
|
||||
SetEventMask(EM_BUTTON + EM_REDRAW);
|
||||
|
||||
While TRUE Do Begin
|
||||
Case WaitEventByTime(5) Of
|
||||
REDRAW_EVENT: On_Redraw;
|
||||
BUTTON_EVENT: On_Button;
|
||||
NO_EVENT: UpdateInfo;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Redraw;
|
||||
Begin
|
||||
BeginDraw;
|
||||
With Window Do
|
||||
DrawWindow(Left, Top, Width, Height, 'GetPointOwner', $00FFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CAPTION_MOVABLE);
|
||||
DrawText(16, 16, 'Name:', $00000000, $00FFFFFF, DT_CP866_8X16 + DT_ZSTRING, 0);
|
||||
EndDraw;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure UpdateInfo;
|
||||
Const
|
||||
CHAR_WIDTH = 8;
|
||||
CHAR_HEIGHT = 16;
|
||||
Var
|
||||
MousePos: TPoint;
|
||||
ID: Dword;
|
||||
ThreadInfo: TThreadInfo;
|
||||
i: Dword;
|
||||
Begin
|
||||
MousePos := GetMousePos;
|
||||
With MousePos Do
|
||||
ID := GetPointOwner(X, Y);
|
||||
GetThreadInfo(ID, ThreadInfo);
|
||||
(* get length of current name *)
|
||||
i := 0;
|
||||
While ThreadInfo.Name[i] <> #0 Do Inc(i);
|
||||
(* clear unnecessary part of possible previous name by white rectangle *)
|
||||
DrawRectangle(64 + i * CHAR_WIDTH, 16, (SizeOf(ThreadInfo.Name) - i) * CHAR_WIDTH, CHAR_HEIGHT, $00FFFFFF);
|
||||
(* draw current name *)
|
||||
DrawText(64, 16, ThreadInfo.Name, $00000000, $00FFFFFF, DT_CP866_8X16 + DT_FILL_OPAQUE + DT_ZSTRING, 0);
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Button;
|
||||
Begin
|
||||
Case GetButton().ID Of
|
||||
1: ThreadTerminate;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
62
KolibriOS/Examples/{1} DrawWindow/Unit1.pas
Normal file
@ -0,0 +1,62 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
Window: TRect;
|
||||
Screen: TSize;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Procedure On_Key;
|
||||
Procedure On_Button;
|
||||
Procedure On_Redraw;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Begin
|
||||
Screen := GetScreenSize();
|
||||
|
||||
With Window Do Begin
|
||||
With Screen Do Begin
|
||||
Right := Width Shr 2;
|
||||
Bottom := Height Shr 2;
|
||||
Left := (Width - Right) Shr 1;
|
||||
Top := (Height - Bottom) Shr 1;
|
||||
End;
|
||||
End;
|
||||
|
||||
While TRUE Do Begin
|
||||
Case WaitEvent() Of
|
||||
REDRAW_EVENT: On_Redraw;
|
||||
KEY_EVENT: On_Key;
|
||||
BUTTON_EVENT: On_Button;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Redraw;
|
||||
Begin
|
||||
BeginDraw;
|
||||
|
||||
With Window Do
|
||||
DrawWindow(Left, Top, Right, Bottom, 'Hello!', $00FFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CAPTION_MOVABLE);
|
||||
|
||||
EndDraw;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Key;
|
||||
Begin
|
||||
GetKey;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Button;
|
||||
Begin
|
||||
Case GetButton().ID Of
|
||||
1: ThreadTerminate;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
1
KolibriOS/Examples/{1} DrawWindow/make.bat
Normal file
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
@ -0,0 +1,83 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Const
|
||||
COLOR_BLUE = $000000FF;
|
||||
COLOR_RED = $00FF0000;
|
||||
COLOR_GREEN = $0000FF00;
|
||||
COLOR_BLACK = $00000000;
|
||||
|
||||
BLUE_BUTTON = 10050;
|
||||
GREEN_BUTTON = 9000;
|
||||
RED_BUTTON = 42;
|
||||
BLACK_BUTTON = 0;
|
||||
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
Window: TRect;
|
||||
Screen: TSize;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Procedure On_Key;
|
||||
Procedure On_Button;
|
||||
Procedure On_Redraw;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Begin
|
||||
Screen := GetScreenSize();
|
||||
|
||||
With Window Do Begin
|
||||
With Screen Do Begin
|
||||
Right := Width Shr 2;
|
||||
Bottom := Height Shr 2;
|
||||
Left := (Width - Right) Shr 1;
|
||||
Top := (Height - Bottom) Shr 1;
|
||||
End;
|
||||
End;
|
||||
|
||||
While TRUE Do Begin
|
||||
Case WaitEvent() Of
|
||||
REDRAW_EVENT: On_Redraw;
|
||||
KEY_EVENT: On_Key;
|
||||
BUTTON_EVENT: On_Button;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Redraw;
|
||||
Begin
|
||||
BeginDraw;
|
||||
|
||||
With Window Do
|
||||
DrawWindow(Left, Top, Right, Bottom, 'DrawButton', $00FFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CAPTION_MOVABLE);
|
||||
|
||||
DrawButton(10, 20, 50, 30, COLOR_RED, 0, RED_BUTTON);
|
||||
DrawButton(70, 20, 50, 30, COLOR_GREEN, 0, GREEN_BUTTON);
|
||||
DrawButton(10, 60, 50, 30, COLOR_BLUE, 0, BLUE_BUTTON);
|
||||
DrawButton(70, 60, 50, 30, COLOR_BLACK, 0, BLACK_BUTTON);
|
||||
|
||||
EndDraw;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Key;
|
||||
Begin
|
||||
GetKey;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Button;
|
||||
Begin
|
||||
Case GetButton().ID Of
|
||||
1: ThreadTerminate;
|
||||
BLUE_BUTTON: SetWindowCaption('Blue');
|
||||
GREEN_BUTTON: SetWindowCaption('Green');
|
||||
RED_BUTTON: SetWindowCaption('Red');
|
||||
BLACK_BUTTON: SetWindowCaption('Black');
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
73
KolibriOS/Examples/{3} GetKey, DrawText/Unit1.pas
Normal file
@ -0,0 +1,73 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
Window: TRect;
|
||||
Screen: TSize;
|
||||
CurX, CurY: Integer;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Procedure On_Key;
|
||||
Procedure On_Button;
|
||||
Procedure On_Redraw;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Begin
|
||||
Screen := GetScreenSize();
|
||||
|
||||
With Window Do Begin
|
||||
With Screen Do Begin
|
||||
Right := Width Shr 2;
|
||||
Bottom := Height Shr 2;
|
||||
Left := (Width - Right) Shr 1;
|
||||
Top := (Height - Bottom) Shr 1;
|
||||
End;
|
||||
End;
|
||||
|
||||
While TRUE Do Begin
|
||||
Case WaitEvent() Of
|
||||
REDRAW_EVENT: On_Redraw;
|
||||
KEY_EVENT: On_Key;
|
||||
BUTTON_EVENT: On_Button;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Redraw;
|
||||
Begin
|
||||
CurX := 0;
|
||||
CurY := 0;
|
||||
BeginDraw;
|
||||
|
||||
With Window Do
|
||||
DrawWindow(Left, Top, Right, Bottom, 'GetKey', $00FFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CAPTION_MOVABLE);
|
||||
|
||||
EndDraw;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Key;
|
||||
Var
|
||||
Key: TKeyboardInput;
|
||||
Begin
|
||||
Key := GetKey();
|
||||
DrawText(CurX, CurY, @Key.Code, $00000000, $00FFFFFF, 0, 1);
|
||||
Inc(CurX, 6);
|
||||
If CurX > 100 Then Begin
|
||||
Inc(CurY, 10);
|
||||
CurX := 0;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Button;
|
||||
Begin
|
||||
Case GetButton().ID Of
|
||||
1: ThreadTerminate;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
1
KolibriOS/Examples/{3} GetKey, DrawText/make.bat
Normal file
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
36
KolibriOS/Examples/{4} LoadFile/Unit1.pas
Normal file
@ -0,0 +1,36 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
hConsole: Pointer;
|
||||
ConsoleInit: Procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: Dword; Caption: PChar); StdCall;
|
||||
ConsoleExit: Procedure(bCloseWindow: Cardinal); StdCall;
|
||||
WriteN: Procedure(Str: PChar; Count: Dword); StdCall;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Var
|
||||
FileSize: Dword;
|
||||
Buffer: Pointer;
|
||||
Begin
|
||||
hConsole := LoadLibrary('/sys/lib/console.obj');
|
||||
ConsoleInit := GetProcAddress(hConsole, 'con_init');
|
||||
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
|
||||
WriteN := GetProcAddress(hConsole, 'con_write_string');
|
||||
|
||||
ConsoleInit($FFFFFFFF, $FFFFFFFF, $FFFFFFFF, $FFFFFFFF, 'Test');
|
||||
|
||||
Buffer := LoadFile('/sys/example.asm', FileSize);
|
||||
WriteN(Buffer, FileSize);
|
||||
|
||||
ConsoleExit(0);
|
||||
ThreadTerminate;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
1
KolibriOS/Examples/{4} LoadFile/make.bat
Normal file
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
@ -0,0 +1,43 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Const
|
||||
AppPath = PPChar(32);
|
||||
CmdLine = PPChar(28);
|
||||
Var
|
||||
hConsole: Pointer;
|
||||
ConsoleInit: Procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: Dword; Caption: PChar); StdCall;
|
||||
ConsoleExit: Procedure(bCloseWindow: Cardinal); StdCall;
|
||||
printf: Function(Const Format: PChar): Integer; CDecl VarArgs;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Const
|
||||
BUFFER_SIZE = 256;
|
||||
Var
|
||||
Buffer: Array[0..BUFFER_SIZE - 1] Of Char;
|
||||
Begin
|
||||
hConsole := LoadLibrary('/sys/lib/console.obj');
|
||||
ConsoleInit := GetProcAddress(hConsole, 'con_init');
|
||||
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
|
||||
printf := GetProcAddress(hConsole, 'con_printf');
|
||||
|
||||
ConsoleInit($FFFFFFFF, $FFFFFFFF, $FFFFFFFF, $FFFFFFFF, 'Test');
|
||||
|
||||
GetCurrentDirectory(Buffer, BUFFER_SIZE);
|
||||
|
||||
printf('AppPath is "%s"'#10, AppPath^);
|
||||
printf('CmdLine is "%s"'#10, CmdLine^);
|
||||
printf('CurrentDirectory is "%s"'#10, Buffer);
|
||||
|
||||
ConsoleExit(0);
|
||||
ThreadTerminate;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
BIN
KolibriOS/Examples/{6} DrawImage/Lena.tga
Normal file
After Width: | Height: | Size: 9.5 KiB |
130
KolibriOS/Examples/{6} DrawImage/Unit1.pas
Normal file
@ -0,0 +1,130 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Const
|
||||
AppPath = PPChar(32);
|
||||
(* -------------------------------------------------------- *)
|
||||
Type
|
||||
TTargaFileHeader = Packed Record
|
||||
IDLength: Byte;
|
||||
ColorMapType: Byte;
|
||||
ImageType: Byte;
|
||||
CMapStart: Word;
|
||||
CMapLength: Word;
|
||||
CMapDepth: Byte;
|
||||
XOffset: Word;
|
||||
YOffset: Word;
|
||||
Width: Word;
|
||||
Height: Word;
|
||||
PixelDepth: Byte;
|
||||
ImageDescriptor: Byte;
|
||||
End;
|
||||
|
||||
TTargaFile = Packed Record
|
||||
TargaFileHeader: TTargaFileHeader;
|
||||
End;
|
||||
|
||||
PTargaFile = ^TTargaFile;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
Window: TRect;
|
||||
Screen: TSize;
|
||||
TargaFile: PTargaFile;
|
||||
Image: Pointer;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Procedure On_Key;
|
||||
Procedure On_Button;
|
||||
Procedure On_Redraw;
|
||||
Procedure ExtractFileDirectory(Src, Dst: PChar); StdCall;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Var
|
||||
FileSize: Dword;
|
||||
Begin
|
||||
HeapCreate;
|
||||
|
||||
ExtractFileDirectory(AppPath^, AppPath^);
|
||||
SetCurrentDirectory(AppPath^);
|
||||
|
||||
TargaFile := LoadFile('Lena.tga', FileSize);
|
||||
|
||||
With TargaFile^ Do
|
||||
With TargaFileHeader Do
|
||||
Image := Pointer(Dword(TargaFile) + SizeOf(TargaFileHeader) + IDLength);
|
||||
|
||||
Screen := GetScreenSize();
|
||||
|
||||
With Window Do Begin
|
||||
With Screen Do Begin
|
||||
Right := Width Shr 2;
|
||||
Bottom := Height Shr 2;
|
||||
Left := (Width - Right) Shr 1;
|
||||
Top := (Height - Bottom) Shr 1;
|
||||
End;
|
||||
End;
|
||||
|
||||
While TRUE Do Begin
|
||||
Case WaitEvent() Of
|
||||
REDRAW_EVENT: On_Redraw;
|
||||
KEY_EVENT: On_Key;
|
||||
BUTTON_EVENT: On_Button;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Redraw;
|
||||
Begin
|
||||
BeginDraw;
|
||||
|
||||
With Window Do
|
||||
DrawWindow(Left, Top, Right, Bottom, 'DrawImage', $00FFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CAPTION_MOVABLE);
|
||||
|
||||
With TargaFile^ Do
|
||||
With TargaFileHeader Do
|
||||
DrawImage(Image^, 30, 20, Width, Height);
|
||||
|
||||
EndDraw;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Key;
|
||||
Begin
|
||||
GetKey;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Button;
|
||||
Begin
|
||||
Case GetButton().ID Of
|
||||
1: ThreadTerminate;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure ExtractFileDirectory(Src, Dst: PChar); StdCall;
|
||||
Asm
|
||||
push esi
|
||||
push edi
|
||||
xor eax, eax
|
||||
mov edi, Src
|
||||
mov esi, edi
|
||||
mov ecx, $FFFFFFFF
|
||||
repne scasb
|
||||
mov al, '/'
|
||||
std
|
||||
repne scasb
|
||||
cld
|
||||
sub edi, esi
|
||||
mov ecx, edi
|
||||
inc ecx
|
||||
mov edi, Dst
|
||||
rep movsb
|
||||
mov byte [edi], 0
|
||||
pop edi
|
||||
pop esi
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
1
KolibriOS/Examples/{6} DrawImage/make.bat
Normal file
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
79
KolibriOS/Examples/{7} SetPixel/Unit1.pas
Normal file
@ -0,0 +1,79 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
Window: TRect;
|
||||
Screen: TSize;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Procedure On_Key;
|
||||
Procedure On_Button;
|
||||
Procedure On_Redraw;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Begin
|
||||
Screen := GetScreenSize();
|
||||
|
||||
With Window Do Begin
|
||||
With Screen Do Begin
|
||||
Right := 180;
|
||||
Bottom := 180;
|
||||
Left := (Width - Right) Shr 1;
|
||||
Top := (Height - Bottom) Shr 1;
|
||||
End;
|
||||
End;
|
||||
|
||||
While TRUE Do Begin
|
||||
Case WaitEvent() Of
|
||||
REDRAW_EVENT: On_Redraw;
|
||||
KEY_EVENT: On_Key;
|
||||
BUTTON_EVENT: On_Button;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Redraw;
|
||||
Var
|
||||
X, Y: Integer;
|
||||
Begin
|
||||
BeginDraw;
|
||||
|
||||
With Window Do
|
||||
DrawWindow(Left, Top, Right, Bottom, 'SetPixel', $00FFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CAPTION_MOVABLE);
|
||||
|
||||
For Y := 0 To 50 Do
|
||||
For X := 0 To 50 Do
|
||||
If ((X Mod 2) = 0) Or ((Y Mod 2) = 0) Then
|
||||
SetPixel(X, Y, $00FF0000);
|
||||
|
||||
For Y := 50 To 100 Do
|
||||
For X := 50 To 100 Do
|
||||
If ((X Mod 3) = 0) Or ((Y Mod 3) = 0) Then
|
||||
SetPixel(X, Y, $00007F00);
|
||||
|
||||
For Y := 100 To 150 Do
|
||||
For X := 100 To 150 Do
|
||||
If ((X Mod 4) = 0) Or ((Y Mod 4) = 0) Then
|
||||
SetPixel(X, Y, $000000FF);
|
||||
|
||||
EndDraw;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Key;
|
||||
Begin
|
||||
GetKey;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Button;
|
||||
Begin
|
||||
Case GetButton().ID Of
|
||||
1: ThreadTerminate;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
1
KolibriOS/Examples/{7} SetPixel/make.bat
Normal file
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|
86
KolibriOS/Examples/{9} GetPixel/Unit1.pas
Normal file
@ -0,0 +1,86 @@
|
||||
Unit Unit1;
|
||||
(* -------------------------------------------------------- *)
|
||||
Interface
|
||||
(* -------------------------------------------------------- *)
|
||||
Uses KolibriOS;
|
||||
(* -------------------------------------------------------- *)
|
||||
Var
|
||||
Window: TRect;
|
||||
Screen: TSize;
|
||||
Rectangle: TRect;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Procedure On_Button;
|
||||
Procedure On_Redraw;
|
||||
Procedure On_Mouse;
|
||||
(* -------------------------------------------------------- *)
|
||||
Implementation
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure Main;
|
||||
Begin
|
||||
Screen := GetScreenSize();
|
||||
|
||||
With Window Do Begin
|
||||
With Screen Do Begin
|
||||
Right := Width Shr 2;
|
||||
Bottom := Height Shr 2;
|
||||
Left := (Width - Right) Shr 1;
|
||||
Top := (Height - Bottom) Shr 1;
|
||||
End;
|
||||
End;
|
||||
|
||||
With Rectangle Do Begin
|
||||
Left := 10;
|
||||
Top := 10;
|
||||
Right := Window.Right - 20;
|
||||
Bottom := Window.Bottom - 40;
|
||||
End;
|
||||
|
||||
SetEventMask(EM_REDRAW + EM_BUTTON + EM_MOUSE);
|
||||
|
||||
While TRUE Do Begin
|
||||
Case WaitEvent() Of
|
||||
REDRAW_EVENT: On_Redraw;
|
||||
BUTTON_EVENT: On_Button;
|
||||
MOUSE_EVENT: On_Mouse;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Redraw;
|
||||
Begin
|
||||
BeginDraw;
|
||||
|
||||
With Window Do
|
||||
DrawWindow(Left, Top, Right, Bottom, 'GetPixel', $00FFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CAPTION_MOVABLE);
|
||||
|
||||
With Rectangle Do Begin
|
||||
DrawLine(Left, Top, Left, Bottom, 0);
|
||||
DrawLine(Right, Top, Right, Bottom, 0);
|
||||
DrawLine(Left, Top, Right, Top, 0);
|
||||
DrawLine(Left, Bottom, Right, Bottom, 0);
|
||||
End;
|
||||
|
||||
EndDraw;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Button;
|
||||
Begin
|
||||
Case GetButton().ID Of
|
||||
1: ThreadTerminate;
|
||||
End;
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
Procedure On_Mouse;
|
||||
Var
|
||||
Point: TPoint;
|
||||
Begin
|
||||
Point := GetMousePos();
|
||||
|
||||
With Rectangle Do
|
||||
With Point Do
|
||||
DrawRectangle(Left + 1, Top + 1, Right - Left - 1, Bottom - Top - 1, GetPixel(X, Y));
|
||||
|
||||
End;
|
||||
(* -------------------------------------------------------- *)
|
||||
End.
|
1
KolibriOS/Examples/{9} GetPixel/make.bat
Normal file
@ -0,0 +1 @@
|
||||
../make.bat Unit1
|