Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program MinApp;
- uses OWindows, wintypes, winprocs, strings;
- type Circle = record
- top: double;
- left: double;
- r:integer;
- g:integer;
- b:integer;
- end;
- type
- TMyApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
- PGraphWindow = ^TGraphWindow;
- TGraphWindow = object(TWindow)
- circles: array[1..1000] of Circle;
- i: integer;
- k: integer;
- n: bool;
- procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
- procedure WMLButtonDown(var Msg: TMessage); virtual wm_First + wm_LButtonDown;
- procedure Render(TheDC: HDC);
- constructor Init(AParent: PWindowsObject; ATitle:PChar);
- end;
- constructor TGraphWindow.Init;
- begin
- inherited Init(AParent, ATitle);
- i := 0;
- k := 0;
- n := false;
- end;
- procedure TMyApplication.InitMainWindow;
- begin
- MainWindow := New(PGraphWindow, Init(nil,'Graph'));
- end;
- procedure TGraphWindow.WMLButtonDown;
- var
- NewBrush, OldBrush: HBrush;
- TheDC: HDC;
- MyRect: TRect;
- begin
- n := true;
- TheDC := GetDC(HWindow);
- GetClientRect(HWindow, MyRect);
- if (Msg.LParamLo < MyRect.right / 2 and Msg.LParamHi < MyRect.bottom / 2) then begin
- NewBrush:=CreateSolidBrush(RGB(0,0,255));
- OldBrush:=SelectObject(TheDC, NewBrush);
- k := k + 1;
- Ellipse(TheDC, Msg.LParamLo-15, Msg.LParamHi-15, Msg.LParamLo+15, Msg.LParamHi+15);
- circles[k].top := Msg.LParamHi/MyRect.bottom;
- circles[k].left := Msg.LParamLo/MyRect.right;
- circles[k].r := 0;
- circles[k].g := 0;
- circles[k].b := 255;
- end
- if (Msg.LParamLo < MyRect.right / 2 and Msg.LParamHi > MyRect.bottom / 2) then begin
- NewBrush:=CreateSolidBrush(RGB(255,0,0));
- OldBrush:=SelectObject(TheDC, NewBrush);
- k := k + 1;
- Ellipse(TheDC, Msg.LParamLo-15, Msg.LParamHi-15, Msg.LParamLo+15, Msg.LParamHi+15);
- circles[k].top := Msg.LParamHi/MyRect.bottom;
- circles[k].left := Msg.LParamLo/MyRect.right;
- circles[k].r := 255;
- circles[k].g := 0;
- circles[k].b := 0;
- end
- if (Msg.LParamLo > MyRect.right / 2 and Msg.LParamHi < MyRect.bottom / 2) then begin
- NewBrush:=CreateSolidBrush(RGB(0,255,0));
- OldBrush:=SelectObject(TheDC, NewBrush);
- k := k + 1;
- Ellipse(TheDC, Msg.LParamLo-15, Msg.LParamHi-15, Msg.LParamLo+15, Msg.LParamHi+15);
- circles[k].top := Msg.LParamHi/MyRect.bottom;
- circles[k].left := Msg.LParamLo/MyRect.right;
- circles[k].r := 0;
- circles[k].g := 255;
- circles[k].b := 0;
- end
- if (Msg.LParamLo > MyRect.right / 2 and Msg.LParamHi > MyRect.bottom / 2) then begin
- NewBrush:=CreateSolidBrush(RGB(255,255,255));
- OldBrush:=SelectObject(TheDC, NewBrush);
- k := k + 1;
- Ellipse(TheDC, Msg.LParamLo-15, Msg.LParamHi-15, Msg.LParamLo+15, Msg.LParamHi+15);
- circles[k].top := Msg.LParamHi/MyRect.bottom;
- circles[k].left := Msg.LParamLo/MyRect.right;
- circles[k].r := 255;
- circles[k].g := 255;
- circles[k].b := 255;
- end
- NewBrush:=SelectObject(TheDC, OldBrush);
- DeleteObject(NewBrush);
- ReleaseDC(HWindow, TheDC);
- end;
- procedure TGraphWindow.Render;
- var l: integer;
- NewBrush, OldBrush: HBrush;
- MyRect:TRect;
- begin
- TheDC := GetDC(HWindow);
- GetClientRect(HWindow, MyRect);
- for l := 1 to k do begin
- NewBrush:=CreateSolidBrush(RGB(circles[l].r, circles[l].g, circles[l].b));
- OldBrush:=SelectObject(TheDC, NewBrush);
- Ellipse(TheDC, round(MyRect.right*circles[l].left - 15), round(MyRect.bottom*circles[l].top-15),
- round(MyRect.right*circles[l].left + 15), round(MyRect.bottom*circles[l].top+15));
- end;
- end;
- procedure TGraphWindow.Paint;
- var
- MyRect:TRect;
- begin
- GetClientRect(HWindow, MyRect);
- MoveTo(PaintDC, MyRect.left, MyRect.top);
- LineTo(PaintDC, MyRect.right, MyRect.bottom);
- if (n = true) then
- Render(PaintDC);
- end;
- var
- MyApp: TMyApplication;
- begin
- MyApp.Init('TestApp');
- MyApp.Run;
- MyApp.Done;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement