diff --git a/app/src/gambas3/.src/Editor/Image/CImageSelection.class b/app/src/gambas3/.src/Editor/Image/CImageSelection.class index 4c5cf5343..776fda422 100644 --- a/app/src/gambas3/.src/Editor/Image/CImageSelection.class +++ b/app/src/gambas3/.src/Editor/Image/CImageSelection.class @@ -1,7 +1,6 @@ ' Gambas class file Public Enum ACTION_NONE, ACTION_STROKE, ACTION_FILL, ACTION_CLEAR, ACTION_CLIP, ACTION_EXTENT, ACTION_HANDLE, ACTION_MAGNET, ACTION_SELECT - Public Enum MAGNET_NONE, MAGNET_RECTANGLE, MAGNET_ELLIPSE Private Enum CMD_MOVE_TO, CMD_LINE_TO ', CMD_RECTANGLE, CMD_ELLIPSE @@ -384,7 +383,7 @@ Public Sub Rectangle(X As Integer, Y As Integer, W As Integer, H As Integer) End -Public Sub Text(X As Integer, Y As Integer, sText As String, sFont As String, iAlign As Integer) +Public Sub Text(X As Integer, Y As Integer, sText As String, sFont As String, iAlign As Integer, bAlignBase As Boolean) Dim hImage As Image Dim hOutline As PointF[][] @@ -401,7 +400,28 @@ Public Sub Text(X As Integer, Y As Integer, sText As String, sFont As String, iA Paint.Begin(hImage) Paint.Font = Font[sFont] hExtents = Paint.TextExtents(sText) - Paint.Text(sText, X, Y, hExtents.Width, hExtents.Height, Align.TopNormal + iAlign) ', W, H, iAlign) + + Debug iAlign;; bAlignBase + + If Align.IsLeft(iAlign) Then + 'X = X + Else If Align.IsRight(iAlign) Then + X -= hExtents.Width + Else If Align.IsCenter(iAlign) Then + X -= hExtents.Width / 2 + Endif + + If bAlignBase Then + Y -= Paint.Font.Ascent + Else If Align.IsTop(iAlign) Then + 'Y = Y + Else If Align.IsBottom(iAlign) Then + Y -= hExtents.Height + Else If Align.IsMiddle(iAlign) Then + Y -= hExtents.Height / 2 + Endif + + Paint.Text(sText, X, Y, hExtents.Width, hExtents.Height, Align.TopLeft) ', W, H, iAlign) hOutline = Paint.PathOutline For Each hPoly In hOutline diff --git a/app/src/gambas3/.src/Editor/Image/FImageEditor.class b/app/src/gambas3/.src/Editor/Image/FImageEditor.class index 8223277e2..736f90250 100644 --- a/app/src/gambas3/.src/Editor/Image/FImageEditor.class +++ b/app/src/gambas3/.src/Editor/Image/FImageEditor.class @@ -2763,10 +2763,10 @@ Public Sub btnHide_Click() End -Public Sub UpdateText(sText As String, sFont As String, iAlign As Integer) +Public Sub UpdateText(sText As String, sFont As String, iAlign As Integer, bAlignBase As Boolean) $hSelect = $hTextSelect.Copy() - $hSelect.Text($hLastPoint.X, $hLastPoint.Y, sText, sFont, iAlign) + $hSelect.Text($hLastPoint.X, $hLastPoint.Y, sText, sFont, iAlign, bAlignBase) imvImage.Refresh End diff --git a/app/src/gambas3/.src/Editor/Image/FImageProperty.class b/app/src/gambas3/.src/Editor/Image/FImageProperty.class index 959702c3f..fdf489c2d 100644 --- a/app/src/gambas3/.src/Editor/Image/FImageProperty.class +++ b/app/src/gambas3/.src/Editor/Image/FImageProperty.class @@ -9,6 +9,8 @@ Private $aClipboard As New CImageClipboard[] Private $aGradientPos As Float[] Private $aGradientColors As Integer[] +Private $aTextAlign As String[] = ["nw", "n", "ne", "w", "ce", "e", "bw", "b", "be", "sw", "s", "se"] + Private $iCurrentColor As Integer = -1 Private $aLabel As Label[] @@ -44,6 +46,12 @@ Public Sub _new() 'fchIcon.Filter = ["*.png,*.jpg,*.jpeg,*.xpm,*.gif", ("Image files")] 'fchIcon.Root = Project.Dir + Dim X As Integer + Dim Y As Integer + Dim hButton As ToolButton + Dim W, H, I As Integer + Dim iDefault As Integer + $aGradientColors = [Color.Black, Color.White] $aGradientPos = [0, 1] @@ -67,6 +75,29 @@ Public Sub _new() $aGradient.Add(CReportBrush["LinearGradient(0,0.5,1,0.5,[#000000,#FFFFFF],[0,1])"]) $aGradient.Add(CReportBrush["LinearGradient(0,0.5,1,0.5,[#000000,#FFFFFFFF],[0,1])"]) + W = panTextAlign.W \ 3 + H = panTextAlign.H \ 4 + + If System.RightToLeft Then + iDefault = 8 + Else + iDefault = 6 + Endif + + For Y = 0 To 3 + For X = 0 To 2 + hButton = New ToolButton(panTextAlign) As "TextAlign" + hButton.Move(X * W, Y * H, W, H) + hButton.Toggle = True + hButton.Radio = True + hButton.Border = False + hButton.Tag = I + Try hButton.Picture = Picture["img/draw/text-" & $aTextAlign[I] & ".png"] + hButton.Value = I = iDefault + Inc I + Next + Next + End Public Sub Form_Open() @@ -1287,16 +1318,40 @@ End Public Sub RefreshTextOption() Dim iAlign As Integer + Dim hCtrl As ToolButton + Dim bAlignBase As Boolean - If btnAlignCenter.Value Then - iAlign = Align.Center - Else If btnAlignRight.Value Then - iAlign = Align.Right - Else - iAlign = Align.Left - Endif + For Each hCtrl In panTextAlign.Children + If hCtrl.Value Then + iAlign = hCtrl.Tag + Break + Endif + Next - GetCurrent().UpdateText(txtText.Text, fchText.Value, iAlign) + bAlignBase = iAlign >= 6 And iAlign <= 8 + + Select Case iAlign + Case 0 + iAlign = Align.TopLeft + Case 1 + iAlign = Align.Top + Case 2 + iAlign = Align.TopRight + Case 3, 6 + iAlign = Align.Left + Case 4, 7 + iAlign = Align.Center + Case 5, 8 + iAlign = Align.Right + Case 9 + iAlign = Align.BottomLeft + Case 10 + iAlign = Align.Bottom + Case 11 + iAlign = Align.BottomRight + End Select + + GetCurrent().UpdateText(txtText.Text, fchText.Value, iAlign, bAlignBase) End diff --git a/app/src/gambas3/.src/Editor/Image/FImageProperty.form b/app/src/gambas3/.src/Editor/Image/FImageProperty.form index fdf4718cc..ef5e75ced 100644 --- a/app/src/gambas3/.src/Editor/Image/FImageProperty.form +++ b/app/src/gambas3/.src/Editor/Image/FImageProperty.form @@ -433,38 +433,12 @@ Margin = True { Panel11 HBox MoveScaled(1,1,58,8) - { HPanel11 HPanel - MoveScaled(1,0,12,8) - { Label14 Label - MoveScaled(1,0,6,4) - Expand = True - Text = ("Font") - } - { btnAlignLeft ToolButton - MoveScaled(0,4,4,4) - ToolTip = ("Left align") - Picture = Picture["icon:/small/text-left"] - Radio = True - Toggle = True - Value = True - } - { btnAlignCenter ToolButton - MoveScaled(4,4,4,4) - ToolTip = ("Center align") - Picture = Picture["icon:/small/text-center"] - Radio = True - Toggle = True - } - { btnAlignRight ToolButton - MoveScaled(8,4,4,4) - ToolTip = ("Right align") - Picture = Picture["icon:/small/text-right"] - Radio = True - Toggle = True - } + Spacing = True + { panTextAlign Panel + MoveScaled(0,0,8,8) } { fchText FontChooser - MoveScaled(19,0,38,8) + MoveScaled(20,0,38,8) Expand = True Border = False } diff --git a/app/src/gambas3/img/draw/text-b.png b/app/src/gambas3/img/draw/text-b.png new file mode 100644 index 000000000..4a6ba5b1e Binary files /dev/null and b/app/src/gambas3/img/draw/text-b.png differ diff --git a/app/src/gambas3/img/draw/text-be.png b/app/src/gambas3/img/draw/text-be.png new file mode 100644 index 000000000..59f56ae83 Binary files /dev/null and b/app/src/gambas3/img/draw/text-be.png differ diff --git a/app/src/gambas3/img/draw/text-bw.png b/app/src/gambas3/img/draw/text-bw.png new file mode 100644 index 000000000..163438547 Binary files /dev/null and b/app/src/gambas3/img/draw/text-bw.png differ diff --git a/app/src/gambas3/img/draw/text-ce.png b/app/src/gambas3/img/draw/text-ce.png new file mode 100644 index 000000000..e82026296 Binary files /dev/null and b/app/src/gambas3/img/draw/text-ce.png differ diff --git a/app/src/gambas3/img/draw/text-e.png b/app/src/gambas3/img/draw/text-e.png new file mode 100644 index 000000000..1e7132483 Binary files /dev/null and b/app/src/gambas3/img/draw/text-e.png differ diff --git a/app/src/gambas3/img/draw/text-n.png b/app/src/gambas3/img/draw/text-n.png new file mode 100644 index 000000000..e7e00ba9e Binary files /dev/null and b/app/src/gambas3/img/draw/text-n.png differ diff --git a/app/src/gambas3/img/draw/text-ne.png b/app/src/gambas3/img/draw/text-ne.png new file mode 100644 index 000000000..4ff785f2a Binary files /dev/null and b/app/src/gambas3/img/draw/text-ne.png differ diff --git a/app/src/gambas3/img/draw/text-nw.png b/app/src/gambas3/img/draw/text-nw.png new file mode 100644 index 000000000..f071be050 Binary files /dev/null and b/app/src/gambas3/img/draw/text-nw.png differ diff --git a/app/src/gambas3/img/draw/text-s.png b/app/src/gambas3/img/draw/text-s.png new file mode 100644 index 000000000..9d318ff24 Binary files /dev/null and b/app/src/gambas3/img/draw/text-s.png differ diff --git a/app/src/gambas3/img/draw/text-se.png b/app/src/gambas3/img/draw/text-se.png new file mode 100644 index 000000000..f5f09a124 Binary files /dev/null and b/app/src/gambas3/img/draw/text-se.png differ diff --git a/app/src/gambas3/img/draw/text-sw.png b/app/src/gambas3/img/draw/text-sw.png new file mode 100644 index 000000000..4e4568f0d Binary files /dev/null and b/app/src/gambas3/img/draw/text-sw.png differ diff --git a/app/src/gambas3/img/draw/text-w.png b/app/src/gambas3/img/draw/text-w.png new file mode 100644 index 000000000..34904d653 Binary files /dev/null and b/app/src/gambas3/img/draw/text-w.png differ