Examples grouped by GUI and console
58
Examples/GUI/ColorButtons/ColorButtons.dpr
Normal file
@@ -0,0 +1,58 @@
|
||||
program ColorButtons;
|
||||
|
||||
uses
|
||||
KolibriOS;
|
||||
|
||||
const
|
||||
COLOR_BLUE = $000000FF;
|
||||
COLOR_RED = $00FF0000;
|
||||
COLOR_GREEN = $0000FF00;
|
||||
COLOR_BLACK = $00000000;
|
||||
|
||||
BLACK_BUTTON = 1000;
|
||||
BLUE_BUTTON = 2000;
|
||||
GREEN_BUTTON = 3000;
|
||||
RED_BUTTON = 4000;
|
||||
|
||||
var
|
||||
WndLeft, WndTop, WndWidth, WndHeight: Integer;
|
||||
|
||||
begin
|
||||
with GetScreenSize do
|
||||
begin
|
||||
WndWidth := Width div 4;
|
||||
WndHeight := Height div 4;
|
||||
WndLeft := (Width - WndWidth) div 2;
|
||||
WndTop := (Height - WndHeight) div 2;
|
||||
end;
|
||||
|
||||
while True do
|
||||
case WaitEvent of
|
||||
REDRAW_EVENT:
|
||||
begin
|
||||
BeginDraw;
|
||||
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Color Buttons', $00FFFFFF,
|
||||
WS_SKINNED_FIXED + WS_CLIENT_COORDS + 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;
|
||||
KEY_EVENT:
|
||||
GetKey;
|
||||
BUTTON_EVENT:
|
||||
case GetButton.ID of
|
||||
BLUE_BUTTON:
|
||||
SetWindowCaption('Blue');
|
||||
GREEN_BUTTON:
|
||||
SetWindowCaption('Green');
|
||||
RED_BUTTON:
|
||||
SetWindowCaption('Red');
|
||||
BLACK_BUTTON:
|
||||
SetWindowCaption('Black');
|
||||
1:
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
end.
|
1
Examples/GUI/ColorButtons/build.bat
Normal file
@@ -0,0 +1 @@
|
||||
@call "%~dp0..\..\..\Lib\build.bat" "%~dp0ColorButtons"
|
95
Examples/GUI/DrawImage/DrawImage.dpr
Normal file
@@ -0,0 +1,95 @@
|
||||
program DrawImageApp;
|
||||
|
||||
uses
|
||||
KolibriOS;
|
||||
|
||||
const
|
||||
AppPath = PPKolibriChar(32);
|
||||
|
||||
type
|
||||
THeader = 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;
|
||||
|
||||
PTargaFile = ^TTargaFile;
|
||||
TTargaFile = packed record
|
||||
Header: THeader;
|
||||
end;
|
||||
|
||||
procedure ExtractFileDirectory(Source, Dest: PKolibriChar); stdcall;
|
||||
asm
|
||||
PUSH ESI
|
||||
PUSH EDI
|
||||
XOR EAX, EAX
|
||||
MOV EDI, Source
|
||||
MOV ESI, EDI
|
||||
MOV ECX, $FFFFFFFF
|
||||
REPNE SCASB
|
||||
MOV AL, '/'
|
||||
STD
|
||||
REPNE SCASB
|
||||
CLD
|
||||
SUB EDI, ESI
|
||||
MOV ECX, EDI
|
||||
INC ECX
|
||||
MOV EDI, Dest
|
||||
REP MOVSB
|
||||
MOV byte [EDI], 0
|
||||
POP EDI
|
||||
POP ESI
|
||||
end;
|
||||
|
||||
var
|
||||
WndLeft, WndTop, WndWidth, WndHeight: Integer;
|
||||
TargaFile: PTargaFile;
|
||||
Image: Pointer;
|
||||
FileSize: LongWord;
|
||||
|
||||
begin
|
||||
HeapInit;
|
||||
|
||||
ExtractFileDirectory(AppPath^, AppPath^);
|
||||
SetCurrentDirectory(AppPath^);
|
||||
|
||||
TargaFile := LoadFile('Lena.tga', FileSize);
|
||||
|
||||
with TargaFile^ do
|
||||
Image := Pointer(PKolibriChar(TargaFile) + SizeOf(Header) + Header.IDLength);
|
||||
|
||||
with GetScreenSize do
|
||||
begin
|
||||
WndWidth := Width div 4;
|
||||
WndHeight := Height div 4;
|
||||
WndLeft := (Width - WndWidth) div 2;
|
||||
WndTop := (Height - WndHeight) div 2;
|
||||
end;
|
||||
|
||||
while True do
|
||||
case WaitEvent of
|
||||
REDRAW_EVENT:
|
||||
begin
|
||||
BeginDraw;
|
||||
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Draw Image', $00FFFFFF,
|
||||
WS_SKINNED_FIXED + WS_CLIENT_COORDS + WS_CAPTION, CAPTION_MOVABLE);
|
||||
with TargaFile.Header do
|
||||
DrawImage(Image^, 30, 20, Width, Height);
|
||||
EndDraw;
|
||||
end;
|
||||
KEY_EVENT:
|
||||
GetKey;
|
||||
BUTTON_EVENT:
|
||||
if GetButton.ID = 1 then
|
||||
Break;
|
||||
end;
|
||||
end.
|
BIN
Examples/GUI/DrawImage/Lena.tga
Normal file
After Width: | Height: | Size: 9.5 KiB |
3
Examples/GUI/DrawImage/build.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
call "%~dp0..\..\..\Lib\build.bat" "%~dp0DrawImage"
|
||||
copy "%~dp0*.tga" "%~dp0..\..\..\Bin" >nul
|
153
Examples/GUI/DrawImageEx/DrawImageEx.dpr
Normal file
@@ -0,0 +1,153 @@
|
||||
program DrawImageExApp;
|
||||
|
||||
uses
|
||||
KolibriOS;
|
||||
|
||||
const
|
||||
AppPath = PPKolibriChar(32);
|
||||
|
||||
Picture1 = 'Flower(4bpp).bmp';
|
||||
Picture2 = 'Mario(1bpp).bmp';
|
||||
Picture3 = 'House(24bpp).bmp';
|
||||
|
||||
type
|
||||
TBitmapFileHeader = packed record
|
||||
bfType: Word;
|
||||
bfSize: LongWord;
|
||||
bfReserved1: Word;
|
||||
bfReserved2: Word;
|
||||
bfOffBits: LongWord;
|
||||
end;
|
||||
|
||||
TBitmapInfoHeader = packed record
|
||||
biSize: LongWord;
|
||||
biWidth: LongInt;
|
||||
biHeight: LongInt;
|
||||
biPlanes: Word;
|
||||
biBitCount: Word;
|
||||
biCompression: LongWord;
|
||||
biSizeImage: LongWord;
|
||||
biXPelsPerMeter: LongInt;
|
||||
biYPelsPerMeter: LongInt;
|
||||
biClrUsed: LongWord;
|
||||
biClrImportant: LongWord;
|
||||
end;
|
||||
|
||||
TRGBQuad = packed record
|
||||
Blue: Byte;
|
||||
Green: Byte;
|
||||
Red: Byte;
|
||||
Reserved: Byte;
|
||||
end;
|
||||
|
||||
PBitmapFile = ^TBitmapFile;
|
||||
TBitmapFile = packed record
|
||||
BitmapFileHeader: TBitmapFileHeader;
|
||||
BitmapInfoHeader: TBitmapInfoHeader;
|
||||
Palette: array[0..0] of TRGBQuad;
|
||||
end;
|
||||
|
||||
procedure ExtractFileDirectory(Src, Dst: PKolibriChar); 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;
|
||||
|
||||
var
|
||||
WndLeft, WndTop, WndWidth, WndHeight: Integer;
|
||||
BitmapFile1, BitmapFile2, BitmapFile3: PBitmapFile;
|
||||
Image1, Image2, Image3: Pointer;
|
||||
Padding1, Padding2, Padding3: LongWord;
|
||||
BytesRead: LongWord;
|
||||
FileAttributes: TFileAttributes;
|
||||
|
||||
begin
|
||||
HeapInit;
|
||||
|
||||
ExtractFileDirectory(AppPath^, AppPath^);
|
||||
SetCurrentDirectory(AppPath^);
|
||||
|
||||
GetFileAttributes(Picture1, FileAttributes);
|
||||
BitmapFile1 := HeapAllocate(FileAttributes.Size);
|
||||
ReadFile(Picture1, BitmapFile1^, FileAttributes.Size, 0, BytesRead);
|
||||
|
||||
with BitmapFile1^, BitmapFileHeader, BitmapInfoHeader do
|
||||
begin
|
||||
Padding1 := (32 - biWidth * biBitCount mod 32) and not 32 div 8;
|
||||
Image1 := Pointer(LongWord(BitmapFile1) + bfOffBits);
|
||||
end;
|
||||
|
||||
GetFileAttributes(Picture2, FileAttributes);
|
||||
BitmapFile2 := HeapAllocate(FileAttributes.Size);
|
||||
ReadFile(Picture2, BitmapFile2^, FileAttributes.Size, 0, BytesRead);
|
||||
|
||||
with BitmapFile2^, BitmapFileHeader, BitmapInfoHeader do
|
||||
begin
|
||||
Padding2 := (32 - biWidth * biBitCount mod 32) and not 32 div 8;
|
||||
Image2 := Pointer(LongWord(BitmapFile2) + bfOffBits);
|
||||
end;
|
||||
|
||||
GetFileAttributes(Picture3, FileAttributes);
|
||||
BitmapFile3 := HeapAllocate(FileAttributes.Size);
|
||||
ReadFile(Picture3, BitmapFile3^, FileAttributes.Size, 0, BytesRead);
|
||||
|
||||
with BitmapFile3^, BitmapFileHeader, BitmapInfoHeader do
|
||||
begin
|
||||
Padding3 := (32 - biWidth * biBitCount mod 32) and not 32 div 8;
|
||||
Image3 := Pointer(LongWord(BitmapFile3) + bfOffBits);
|
||||
end;
|
||||
|
||||
with GetScreenSize do
|
||||
begin
|
||||
WndWidth := 340;
|
||||
WndHeight := Height div 4;
|
||||
WndLeft := (Width - WndWidth) div 2;
|
||||
WndTop := (Height - WndHeight) div 2;
|
||||
end;
|
||||
|
||||
while True do
|
||||
case WaitEvent of
|
||||
REDRAW_EVENT:
|
||||
begin
|
||||
BeginDraw;
|
||||
|
||||
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Draw Image Extended', $00FFFFFF,
|
||||
WS_SKINNED_FIXED + WS_CLIENT_COORDS + 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^, BitmapFileHeader, BitmapInfoHeader do
|
||||
DrawImageEx(Image1^, 20, 35, biWidth, -biHeight, biBitCount, @Palette, Padding1);
|
||||
with BitmapFile2^, BitmapFileHeader, BitmapInfoHeader do
|
||||
DrawImageEx(Image2^, 120, 35, biWidth, -biHeight, biBitCount, @Palette, Padding2);
|
||||
with BitmapFile3^, BitmapFileHeader, BitmapInfoHeader do
|
||||
DrawImageEx(Image3^, 220, 45, biWidth, -biHeight, biBitCount, @Palette, Padding3);
|
||||
|
||||
EndDraw;
|
||||
end;
|
||||
KEY_EVENT:
|
||||
GetKey;
|
||||
BUTTON_EVENT:
|
||||
if GetButton.ID = 1 then
|
||||
Break;
|
||||
end;
|
||||
end.
|
BIN
Examples/GUI/DrawImageEx/Flower(4bpp).bmp
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
Examples/GUI/DrawImageEx/House(24bpp).bmp
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
Examples/GUI/DrawImageEx/Mario(1bpp).bmp
Normal file
After Width: | Height: | Size: 1.2 KiB |
3
Examples/GUI/DrawImageEx/build.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
call "%~dp0..\..\..\Lib\build.bat" "%~dp0DrawImageEx"
|
||||
copy "%~dp0*.bmp" "%~dp0..\..\..\Bin" >nul
|
48
Examples/GUI/DrawText/DrawText.dpr
Normal file
@@ -0,0 +1,48 @@
|
||||
program DrawTextApp;
|
||||
|
||||
uses
|
||||
KolibriOS;
|
||||
|
||||
var
|
||||
WndLeft, WndTop, WndWidth, WndHeight, CurX, CurY: Integer;
|
||||
Key: TKeyboardInput;
|
||||
|
||||
begin
|
||||
with GetScreenSize do
|
||||
begin
|
||||
WndWidth := Width div 4;
|
||||
WndHeight := Height div 4;
|
||||
WndLeft := (Width - WndWidth) div 2;
|
||||
WndTop := (Height - WndHeight) div 2;
|
||||
end;
|
||||
|
||||
CurX := 0;
|
||||
CurY := 0;
|
||||
|
||||
while True do
|
||||
case WaitEvent of
|
||||
REDRAW_EVENT:
|
||||
begin
|
||||
CurX := 0;
|
||||
CurY := 0;
|
||||
BeginDraw;
|
||||
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Please type text to draw', $00FFFFFF,
|
||||
WS_SKINNED_FIXED + WS_CLIENT_COORDS + WS_CAPTION, CAPTION_MOVABLE);
|
||||
EndDraw;
|
||||
end;
|
||||
KEY_EVENT:
|
||||
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;
|
||||
BUTTON_EVENT:
|
||||
if GetButton.ID = 1 then
|
||||
Break;
|
||||
end;
|
||||
end.
|
1
Examples/GUI/DrawText/build.bat
Normal file
@@ -0,0 +1 @@
|
||||
@call "%~dp0..\..\..\Lib\build.bat" "%~dp0DrawText"
|
58
Examples/GUI/GetPixel/GetPixel.dpr
Normal file
@@ -0,0 +1,58 @@
|
||||
program GetPixelApp;
|
||||
|
||||
uses
|
||||
KolibriOS;
|
||||
|
||||
var
|
||||
WndLeft, WndTop, WndWidth, WndHeight: Integer;
|
||||
Rect: TRect;
|
||||
Point: TPoint;
|
||||
begin
|
||||
with GetScreenSize do
|
||||
begin
|
||||
WndWidth := Width div 4;
|
||||
WndHeight := Height div 4;
|
||||
WndLeft := (Width - WndWidth) div 2;
|
||||
WndTop := (Height - WndHeight) div 2;
|
||||
end;
|
||||
|
||||
with Rect do
|
||||
begin
|
||||
Left := 10;
|
||||
Top := 10;
|
||||
Right := WndWidth - 20;
|
||||
Bottom := WndHeight - 40;
|
||||
end;
|
||||
|
||||
SetEventMask(EM_REDRAW + EM_BUTTON + EM_MOUSE);
|
||||
|
||||
while True do
|
||||
case WaitEvent of
|
||||
REDRAW_EVENT:
|
||||
begin
|
||||
BeginDraw;
|
||||
|
||||
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Get Pixel', $00FFFFFF,
|
||||
WS_SKINNED_FIXED + WS_CLIENT_COORDS + WS_CAPTION, CAPTION_MOVABLE);
|
||||
|
||||
with Rect 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;
|
||||
MOUSE_EVENT:
|
||||
begin
|
||||
Point := GetMousePos;
|
||||
with Rect, Point do
|
||||
DrawRectangle(Left + 1, Top + 1, Right - Left - 1, Bottom - Top - 1, GetPixel(X, Y));
|
||||
end;
|
||||
BUTTON_EVENT:
|
||||
if GetButton.ID = 1 then
|
||||
Break;
|
||||
end;
|
||||
end.
|
1
Examples/GUI/GetPixel/build.bat
Normal file
@@ -0,0 +1 @@
|
||||
@call "%~dp0..\..\..\Lib\build.bat" "%~dp0GetPixel"
|
64
Examples/GUI/GetPointOwner/GetPointOwner.dpr
Normal file
@@ -0,0 +1,64 @@
|
||||
program GetPointOwnerApp;
|
||||
|
||||
uses
|
||||
KolibriOS;
|
||||
|
||||
procedure UpdateInfo;
|
||||
const
|
||||
CHAR_WIDTH = 8;
|
||||
CHAR_HEIGHT = 16;
|
||||
var
|
||||
MousePos: TPoint;
|
||||
ID: LongWord;
|
||||
ThreadInfo: TThreadInfo;
|
||||
I: LongWord;
|
||||
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;
|
||||
|
||||
const
|
||||
NO_EVENT = 0;
|
||||
|
||||
var
|
||||
Left, Top, Width, Height: Integer;
|
||||
Screen: TSize;
|
||||
|
||||
begin
|
||||
Screen := GetScreenSize;
|
||||
Width := 189;
|
||||
Height := 79;
|
||||
Left := (Screen.Width - Width) div 2;
|
||||
Top := (Screen.Height - Height) div 2;
|
||||
|
||||
SetEventMask(EM_BUTTON + EM_REDRAW);
|
||||
|
||||
while True do
|
||||
case WaitEventByTime(5) of
|
||||
REDRAW_EVENT:
|
||||
begin
|
||||
BeginDraw;
|
||||
DrawWindow(Left, Top, Width, Height, 'Get Point Owner', $00FFFFFF,
|
||||
WS_SKINNED_FIXED + WS_CLIENT_COORDS + WS_CAPTION, CAPTION_MOVABLE);
|
||||
DrawText(16, 16, 'Name:', $00000000, $00FFFFFF, DT_CP866_8x16 + DT_ZSTRING, 0);
|
||||
EndDraw;
|
||||
end;
|
||||
BUTTON_EVENT:
|
||||
if GetButton.ID = 1 then
|
||||
Break;
|
||||
NO_EVENT:
|
||||
UpdateInfo;
|
||||
end;
|
||||
end.
|
1
Examples/GUI/GetPointOwner/build.bat
Normal file
@@ -0,0 +1 @@
|
||||
@call "%~dp0..\..\..\Lib\build.bat" "%~dp0GetPointOwner"
|
33
Examples/GUI/Hello/HelloGUI.dpr
Normal file
@@ -0,0 +1,33 @@
|
||||
program HelloGUI;
|
||||
|
||||
uses
|
||||
KolibriOS;
|
||||
|
||||
var
|
||||
WndLeft, WndTop, WndWidth, WndHeight: Integer;
|
||||
|
||||
begin
|
||||
with GetScreenSize do
|
||||
begin
|
||||
WndWidth := Width div 4;
|
||||
WndHeight := Height div 4;
|
||||
WndLeft := (Width - WndWidth) div 2;
|
||||
WndTop := (Height - WndHeight) div 2;
|
||||
end;
|
||||
|
||||
while True do
|
||||
case WaitEvent of
|
||||
REDRAW_EVENT:
|
||||
begin
|
||||
BeginDraw;
|
||||
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Hello!', $00FFFFFF,
|
||||
WS_SKINNED_FIXED + WS_CLIENT_COORDS + WS_CAPTION, CAPTION_MOVABLE);
|
||||
EndDraw;
|
||||
end;
|
||||
KEY_EVENT:
|
||||
GetKey;
|
||||
BUTTON_EVENT:
|
||||
if GetButton.ID = 1 then
|
||||
TerminateThread;
|
||||
end;
|
||||
end.
|
1
Examples/GUI/Hello/build.bat
Normal file
@@ -0,0 +1 @@
|
||||
@call "%~dp0..\..\..\Lib\build.bat" "%~dp0HelloGUI"
|
95
Examples/GUI/Screenshot/Screenshot.dpr
Normal file
@@ -0,0 +1,95 @@
|
||||
program Screenshot;
|
||||
|
||||
uses
|
||||
KolibriOS;
|
||||
|
||||
const
|
||||
BORDER_SIZE = 5;
|
||||
|
||||
type
|
||||
TRGBTriple = packed record
|
||||
Blue: Byte;
|
||||
Green: Byte;
|
||||
Red: Byte;
|
||||
end;
|
||||
|
||||
PRGBTripleArray = ^TRGBTripleArray;
|
||||
TRGBTripleArray = array[0..0] of TRGBTriple;
|
||||
|
||||
var
|
||||
WndLeft, WndTop, WndWidth, WndHeight: Integer;
|
||||
ScreenSize: TSize;
|
||||
Image, Preview: PRGBTripleArray;
|
||||
|
||||
function Red(A, B: LongWord): LongWord;
|
||||
begin
|
||||
Red := Image[(ScreenSize.Width * B + A)].Red;
|
||||
end;
|
||||
|
||||
function Green(A, B: LongWord): LongWord;
|
||||
begin
|
||||
Green := Image[(ScreenSize.Width * B + A)].Green;
|
||||
end;
|
||||
|
||||
function Blue(A, B: LongWord): LongWord;
|
||||
begin
|
||||
Blue := Image[(ScreenSize.Width * B + A)].Blue;
|
||||
end;
|
||||
|
||||
procedure ResizeImage;
|
||||
var
|
||||
A, B, I: LongWord;
|
||||
begin
|
||||
A := 0;
|
||||
while A < ScreenSize.Width do
|
||||
begin
|
||||
B := 0;
|
||||
while B < ScreenSize.Height do
|
||||
begin
|
||||
I := ((ScreenSize.Width div 2) * B + A) div 2;
|
||||
Preview[i].Red := (Red(A, B) + Red(A+ 1, B) + Red(A, B + 1) + Red(A + 1, B + 1)) div 4;
|
||||
Preview[i].Green := (Green(A, B) + Green(A + 1, B) + Green(A, B + 1) + Green(A + 1, B + 1)) div 4;
|
||||
Preview[i].Blue := (Blue(A, B) + Blue(A + 1, B) + Blue(A, B + 1) + Blue(A + 1, B + 1)) div 4;
|
||||
Inc(B, 2);
|
||||
end;
|
||||
Inc(A, 2);
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
HeapInit;
|
||||
|
||||
ScreenSize := GetScreenSize;
|
||||
|
||||
with ScreenSize do
|
||||
begin
|
||||
WndWidth := BORDER_SIZE * 2 + Width div 2 - 1;
|
||||
WndHeight := BORDER_SIZE + GetSkinHeight + Height div 2 - 1;
|
||||
WndLeft := (Width - WndWidth) div 2;
|
||||
WndTop := (Height - WndHeight) div 2;
|
||||
|
||||
Image := HeapAllocate(Width * Height * 3);
|
||||
Preview := HeapAllocate(Width * Height * 3 div 2);
|
||||
|
||||
GetScreenImage(Image^, 0, 0, Width, Height);
|
||||
ResizeImage;
|
||||
end;
|
||||
|
||||
while True do
|
||||
case WaitEvent of
|
||||
REDRAW_EVENT:
|
||||
begin
|
||||
BeginDraw;
|
||||
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Screenshot', $00FFFFFF,
|
||||
WS_SKINNED_FIXED + WS_CLIENT_COORDS + WS_CAPTION + WS_TRANSPARENT_FILL, CAPTION_MOVABLE);
|
||||
with ScreenSize do
|
||||
DrawImage(Preview^, 0, 0, Width div 2, Height div 2);
|
||||
EndDraw;
|
||||
end;
|
||||
KEY_EVENT:
|
||||
GetKey;
|
||||
BUTTON_EVENT:
|
||||
if GetButton.ID = 1 then
|
||||
Break;
|
||||
end;
|
||||
end.
|
1
Examples/GUI/Screenshot/build.bat
Normal file
@@ -0,0 +1 @@
|
||||
@call "%~dp0..\..\..\Lib\build.bat" "%~dp0Screenshot"
|
136
Examples/GUI/SetCursor/SetCursor.dpr
Normal file
@@ -0,0 +1,136 @@
|
||||
program SetCursorApp;
|
||||
|
||||
uses
|
||||
KolibriOS;
|
||||
|
||||
const
|
||||
AppPath = PPKolibriChar(32);
|
||||
|
||||
ARROW_BUTTON = 2;
|
||||
POINT_BUTTON = 3;
|
||||
WAIT_BUTTON = 4;
|
||||
|
||||
type
|
||||
TBitmapFileHeader = packed record
|
||||
bfType: Word;
|
||||
bfSize: LongWord;
|
||||
bfReserved1: Word;
|
||||
bfReserved2: Word;
|
||||
bfOffBits: LongWord;
|
||||
end;
|
||||
|
||||
TBitmapInfoHeader = packed record
|
||||
biSize: LongWord;
|
||||
biWidth: LongInt;
|
||||
biHeight: LongInt;
|
||||
biPlanes: Word;
|
||||
biBitCount: Word;
|
||||
biCompression: LongWord;
|
||||
biSizeImage: LongWord;
|
||||
biXPelsPerMeter: LongInt;
|
||||
biYPelsPerMeter: LongInt;
|
||||
biClrUsed: LongWord;
|
||||
biClrImportant: LongWord;
|
||||
end;
|
||||
|
||||
PBitmapFile = ^TBitmapFile;
|
||||
TBitmapFile = packed record
|
||||
BitmapFileHeader: TBitmapFileHeader;
|
||||
BitmapInfoHeader: TBitmapInfoHeader;
|
||||
end;
|
||||
|
||||
procedure ExtractFileDirectory(Src, Dst: PKolibriChar); 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;
|
||||
|
||||
var
|
||||
WndLeft, WndTop, WndWidth, WndHeight: Integer;
|
||||
|
||||
ArrowBitmapFile, PointBitmapFile, WaitBitmapFile: PBitmapFile;
|
||||
ArrowBitmap, PointBitmap, WaitBitmap: Pointer;
|
||||
hArrowCursor, hPointCursor, hWaitCursor: THandle;
|
||||
|
||||
FileSize: LongWord;
|
||||
|
||||
begin
|
||||
HeapInit;
|
||||
|
||||
ExtractFileDirectory(AppPath^, AppPath^);
|
||||
SetCurrentDirectory(AppPath^);
|
||||
|
||||
ArrowBitmapFile := LoadFile('arrow.bmp', FileSize);
|
||||
PointBitmapFile := LoadFile('point.bmp', FileSize);
|
||||
WaitBitmapFile := LoadFile('wait.bmp', FileSize);
|
||||
|
||||
ArrowBitmap := Pointer(LongWord(ArrowBitmapFile) + ArrowBitmapFile.BitmapFileHeader.bfOffBits);
|
||||
PointBitmap := Pointer(LongWord(PointBitmapFile) + PointBitmapFile.BitmapFileHeader.bfOffBits);
|
||||
WaitBitmap := Pointer(LongWord(WaitBitmapFile) + WaitBitmapFile.BitmapFileHeader.bfOffBits);
|
||||
|
||||
hArrowCursor := LoadCursorIndirect(ArrowBitmap^, 0, 0);
|
||||
hPointCursor := LoadCursorIndirect(PointBitmap^, 12, 0);
|
||||
hWaitCursor := LoadCursorIndirect(WaitBitmap^, 0, 0);
|
||||
|
||||
with GetScreenSize do
|
||||
begin
|
||||
WndWidth := Width div 4;
|
||||
WndHeight := Height div 4;
|
||||
WndLeft := (Width - WndWidth) div 2;
|
||||
WndTop := (Height - WndHeight) div 2;
|
||||
end;
|
||||
|
||||
while True do
|
||||
case WaitEvent of
|
||||
REDRAW_EVENT:
|
||||
begin
|
||||
BeginDraw;
|
||||
|
||||
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Set Cursor', $00FFFFFF,
|
||||
WS_SKINNED_FIXED + WS_CLIENT_COORDS + 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_TRANSPARENT_FILL, ARROW_BUTTON);
|
||||
DrawButton(52, 40, 32, 32, 0, BS_TRANSPARENT_FILL, POINT_BUTTON);
|
||||
DrawButton(96, 40, 32, 32, 0, BS_TRANSPARENT_FILL, 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;
|
||||
KEY_EVENT:
|
||||
GetKey;
|
||||
BUTTON_EVENT:
|
||||
case GetButton.ID of
|
||||
ARROW_BUTTON:
|
||||
SetCursor(hArrowCursor);
|
||||
POINT_BUTTON:
|
||||
SetCursor(hPointCursor);
|
||||
WAIT_BUTTON:
|
||||
SetCursor(hWaitCursor);
|
||||
1:
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
end.
|
BIN
Examples/GUI/SetCursor/arrow.bmp
Normal file
After Width: | Height: | Size: 4.1 KiB |
3
Examples/GUI/SetCursor/build.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
call "%~dp0..\..\..\Lib\build.bat" "%~dp0SetCursor"
|
||||
copy "%~dp0*.bmp" "%~dp0..\..\..\Bin" >nul
|
BIN
Examples/GUI/SetCursor/point.bmp
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
Examples/GUI/SetCursor/wait.bmp
Normal file
After Width: | Height: | Size: 4.1 KiB |
51
Examples/GUI/SetPixel/SetPixel.dpr
Normal file
@@ -0,0 +1,51 @@
|
||||
program SetPixelApp;
|
||||
|
||||
uses
|
||||
KolibriOS;
|
||||
|
||||
var
|
||||
WndLeft, WndTop, WndWidth, WndHeight: Integer;
|
||||
X, Y: Integer;
|
||||
|
||||
begin
|
||||
with GetScreenSize do
|
||||
begin
|
||||
WndWidth := 180;
|
||||
WndHeight := 180;
|
||||
WndLeft := (Width - WndWidth) div 2;
|
||||
WndTop := (Height - WndHeight) div 2;
|
||||
end;
|
||||
|
||||
while True do
|
||||
case WaitEvent of
|
||||
REDRAW_EVENT:
|
||||
begin
|
||||
BeginDraw;
|
||||
|
||||
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Set Pixel', $00FFFFFF,
|
||||
WS_SKINNED_FIXED + WS_CLIENT_COORDS + 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;
|
||||
KEY_EVENT:
|
||||
GetKey;
|
||||
BUTTON_EVENT:
|
||||
if GetButton.ID = 1 then
|
||||
Break;
|
||||
end;
|
||||
end.
|
1
Examples/GUI/SetPixel/build.bat
Normal file
@@ -0,0 +1 @@
|
||||
@call "%~dp0..\..\..\Lib\build.bat" "%~dp0SetPixel"
|
86
Examples/GUI/SetWindowPos/SetWindowPos.dpr
Normal file
@@ -0,0 +1,86 @@
|
||||
program SetWindowPosApp;
|
||||
|
||||
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;
|
||||
|
||||
procedure OnKey;
|
||||
var
|
||||
Key: TKeyboardInput;
|
||||
ThreadInfo: TThreadInfo;
|
||||
ControlKeyState: LongWord;
|
||||
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
|
||||
case Key.ScanCode 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
|
||||
else
|
||||
case Key.ScanCode 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;
|
||||
SetWindowPos(Left, Top, Right, Bottom);
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
WndLeft, WndTop, WndWidth, WndHeight: Integer;
|
||||
|
||||
begin
|
||||
with GetScreenSize do
|
||||
begin
|
||||
WndWidth := Width div 4;
|
||||
if WndWidth < 280 then
|
||||
WndWidth := 280; // to center the prompt
|
||||
WndHeight := Height div 4;
|
||||
WndLeft := (Width - WndWidth) div 2;
|
||||
WndTop := (Height - WndHeight) div 2;
|
||||
end;
|
||||
|
||||
while True do
|
||||
case WaitEvent of
|
||||
REDRAW_EVENT:
|
||||
begin
|
||||
BeginDraw;
|
||||
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Set Window Position', $00FFFFFF,
|
||||
WS_SKINNED_SIZABLE + WS_CLIENT_COORDS + WS_CAPTION, CAPTION_MOVABLE);
|
||||
DrawText(24, 26, 'Use arrow keys(Left, Right, Up, Down)', $00000000, $00FFFFFF, DT_ZSTRING, 0);
|
||||
DrawText(24, 35, 'to move the window.', $00000000, $00FFFFFF, DT_ZSTRING, 0);
|
||||
DrawText(24, 44, 'Use Ctrl+arrow keys to resize window.', $00000000, $00FFFFFF, DT_ZSTRING, 0);
|
||||
EndDraw;
|
||||
end;
|
||||
KEY_EVENT:
|
||||
OnKey;
|
||||
BUTTON_EVENT:
|
||||
if GetButton.ID = 1 then
|
||||
Break;
|
||||
end;
|
||||
end.
|
1
Examples/GUI/SetWindowPos/build.bat
Normal file
@@ -0,0 +1 @@
|
||||
@call "%~dp0..\..\..\Lib\build.bat" "%~dp0SetWindowPos"
|