From 6064bfec538038fd1e1ccf4da54fa859241f98fa Mon Sep 17 00:00:00 2001 From: Pavel Perminov Date: Wed, 26 Sep 2012 19:14:19 +0000 Subject: Current line of development release (344 rev. truncated adjusted copy) git-svn-id: http://svn.miranda-ng.org/main/trunk@1669 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Chess4Net/PromotionUnit.pas | 115 +++++++++++++++++++++++++----------- 1 file changed, 79 insertions(+), 36 deletions(-) (limited to 'plugins/Chess4Net/PromotionUnit.pas') diff --git a/plugins/Chess4Net/PromotionUnit.pas b/plugins/Chess4Net/PromotionUnit.pas index 91abacbad7..10ed8a9218 100644 --- a/plugins/Chess4Net/PromotionUnit.pas +++ b/plugins/Chess4Net/PromotionUnit.pas @@ -1,9 +1,15 @@ +//////////////////////////////////////////////////////////////////////////////// +// All code below is exclusively owned by author of Chess4Net - Pavel Perminov +// (packpaul@mail.ru, packpaul1@gmail.com). +// Any changes, modifications, borrowing and adaptation are a subject for +// explicit permition from the owner. + unit PromotionUnit; interface uses - Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, + Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, // Chess4net ChessRulesEngine, ChessBoardHeaderUnit, BitmapResUnit; @@ -39,52 +45,88 @@ const // TPromotionForm procedure TPromotionForm.FormShow(Sender: TObject); + + procedure NCorrectIfOutOfScreen(var iLeft, iTop: integer); + var + R: TRect; + M: TMonitor; + frmOwner: TForm; + begin + if (Assigned(Owner)) then + frmOwner := (Owner as TForm) + else + frmOwner := nil; + if (Assigned(frmOwner)) then + begin + M := Screen.MonitorFromRect(frmOwner.BoundsRect); + R := M.WorkareaRect; + end + else + R := Screen.WorkAreaRect; + + if ((iLeft + self.Width) > R.Right) then + iLeft := R.Right - self.Width; + if (iLeft < R.Left) then + iLeft := R.Left; + if ((iTop + self.Height) > R.Bottom) then + iTop := R.Bottom - self.Height; + if (iTop < R.Top) then + iTop := R.Top; + end; + var k: byte; -begin + iLeft, iTop: integer; +begin // TPromotionForm.FormShow if (m_iSquareSize <> m_BitmapRes.SquareSize) then FLoadFigures; // Установить окно в пределах курсора - Left := Mouse.CursorPos.X - m_iSquareSize div 2; - Top := Mouse.CursorPos.Y - m_iSquareSize div 2; - if (Left + Width > Screen.Width) then - Left := Screen.Width - Width; + iLeft := Mouse.CursorPos.X - m_iSquareSize div 2; + iTop := Mouse.CursorPos.Y - m_iSquareSize div 2; + + NCorrectIfOutOfScreen(iLeft, iTop); + + Left := iLeft; + Top := iTop; with PromFigImage.Canvas do - begin - Brush.Color:= Color; - FillRect(Rect(0,0, Width, PromFigImage.Height)); - - Brush.Color:= clWhite; - for k := 0 to 3 do - FillRect(Rect((m_iSquareSize + INDENT_SIZE) * k, 0, - (m_iSquareSize + INDENT_SIZE) * k + m_iSquareSize - 1, m_iSquareSize - 1)); - - case m_fig_color of - fcWhite: - begin - Draw(0, 0, m_bmFigure[WQ]); - Draw(m_iSquareSize + 2, 0, m_bmFigure[WR]); - Draw(2 * (m_iSquareSize + INDENT_SIZE), 0, m_bmFigure[WB]); - Draw(3 * (m_iSquareSize + INDENT_SIZE), 0, m_bmFigure[WN]); - end; - fcBlack: - begin - Draw(0, 0, m_bmFigure[BQ]); - Draw(m_iSquareSize + INDENT_SIZE, 0, m_bmFigure[BR]); - Draw(2 * (m_iSquareSize + INDENT_SIZE), 0, m_bmFigure[BB]); - Draw(3 * (m_iSquareSize + INDENT_SIZE), 0, m_bmFigure[BN]); - end; - end; + begin + Brush.Color:= Color; + FillRect(Rect(0,0, Width, PromFigImage.Height)); + + Brush.Color:= clWhite; + for k := 0 to 3 do + FillRect(Rect((m_iSquareSize + INDENT_SIZE) * k, 0, + (m_iSquareSize + INDENT_SIZE) * k + m_iSquareSize - 1, m_iSquareSize - 1)); + + case m_fig_color of + fcWhite: + begin + Draw(0, 0, m_bmFigure[WQ]); + Draw(m_iSquareSize + 2, 0, m_bmFigure[WR]); + Draw(2 * (m_iSquareSize + INDENT_SIZE), 0, m_bmFigure[WB]); + Draw(3 * (m_iSquareSize + INDENT_SIZE), 0, m_bmFigure[WN]); + end; + fcBlack: + begin + Draw(0, 0, m_bmFigure[BQ]); + Draw(m_iSquareSize + INDENT_SIZE, 0, m_bmFigure[BR]); + Draw(2 * (m_iSquareSize + INDENT_SIZE), 0, m_bmFigure[BB]); + Draw(3 * (m_iSquareSize + INDENT_SIZE), 0, m_bmFigure[BN]); + end; end; + end; end; function TPromotionForm.ShowPromotion(color: TFigureColor): TFigureName; begin + m_fig := Q; m_fig_color := color; + ShowModal; + Result := m_fig; end; @@ -93,12 +135,13 @@ procedure TPromotionForm.PromFigImageMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin case X div (m_BitmapRes.SquareSize + 1) of - 1: m_fig:= R; - 2: m_fig:= B; - 3: m_fig:= N; - else - m_fig:= Q; + 1: m_fig := R; + 2: m_fig := B; + 3: m_fig := N; + else + m_fig := Q; end; + Close; end; -- cgit v1.2.3