Skip to content

Commit

Permalink
Editor: Added Button.WrapText property
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Oct 9, 2024
1 parent bbfc841 commit 2124050
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Editor/AGS.Editor/AGSEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ public class AGSEditor
* 3.6.2 - Character.TurnWhenFacing, Settings.UseOldVoiceClipNaming,
* ScriptModules for interaction/event lists,
* GlobalVariable may be of array type.
* 3.6.2.2 - Button.WrapText
*/
public const int LATEST_XML_VERSION_INDEX = 3060200;
public const int LATEST_XML_VERSION_INDEX = 3060202;
/*
* LATEST_USER_DATA_VERSION is the last version of the user data file that used a
* 4-point-4-number string to identify the version of AGS that saved the file.
Expand Down
13 changes: 12 additions & 1 deletion Editor/AGS.Editor/DataFileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,16 @@ public FrameAlignment TextAlignment
}
}

public bool WrapText
{
get
{
GUIButton button = (GUIButton)this;
if (button != null) return button.WrapText;
return false;
}
}

public string OnClick
{
get
Expand Down Expand Up @@ -1122,7 +1132,8 @@ private void WriteAllButtonsAndTextWindowEdges()
foreach (GUIButtonOrTextWindowEdge ctrl in GUIButtonsAndTextWindowEdges)
{
int flags;
flags = (ctrl.ClipImage ? NativeConstants.GUIF_CLIP : 0);
flags = (ctrl.ClipImage ? NativeConstants.GUIF_CLIP : 0) |
(ctrl.WrapText ? NativeConstants.GUIF_WRAPTEXT : 0);
WriteGUIControl(ctrl, flags, new string[] { ctrl.OnClick });
writer.Write(ctrl.Image); // pic
writer.Write(ctrl.MouseoverImage); // overpic
Expand Down
1 change: 1 addition & 0 deletions Editor/AGS.Editor/Utils/NativeConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class NativeConstants
public static readonly int GUIF_VISIBLE = (int)Factory.NativeProxy.GetNativeConstant("GUIF_VISIBLE");
public static readonly int GUIF_CLIP = (int)Factory.NativeProxy.GetNativeConstant("GUIF_CLIP");
public static readonly int GUIF_TRANSLATED = (int)Factory.NativeProxy.GetNativeConstant("GUIF_TRANSLATED");
public static readonly int GUIF_WRAPTEXT = (int)Factory.NativeProxy.GetNativeConstant("GUIF_WRAPTEXT");
public static readonly int GLF_SHOWBORDER = (int)Factory.NativeProxy.GetNativeConstant("GLF_SHOWBORDER");
public static readonly int GLF_SHOWARROWS = (int)Factory.NativeProxy.GetNativeConstant("GLF_SHOWARROWS");
public static readonly int GUI_POPUP_MODAL = (int)Factory.NativeProxy.GetNativeConstant("GUI_POPUP_MODAL");
Expand Down
1 change: 1 addition & 0 deletions Editor/AGS.Native/NativeMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ namespace AGS
if (name->Equals("GUIF_VISIBLE")) return (int)Common::kGUICtrl_Visible;
if (name->Equals("GUIF_CLIP")) return (int)Common::kGUICtrl_Clip;
if (name->Equals("GUIF_TRANSLATED")) return (int)Common::kGUICtrl_Translated;
if (name->Equals("GUIF_WRAPTEXT")) return (int)Common::kGUICtrl_WrapText;
if (name->Equals("GLF_SHOWBORDER")) return (int)Common::kListBox_ShowBorder;
if (name->Equals("GLF_SHOWARROWS")) return (int)Common::kListBox_ShowArrows;
if (name->Equals("GUI_POPUP_MODAL")) return (int)Common::kGUIPopupModal;
Expand Down
1 change: 1 addition & 0 deletions Editor/AGS.Native/agsnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2730,6 +2730,7 @@ void ConvertGUIToBinaryFormat(GUI ^guiObj, GUIMain *gui)
nbut.SetMouseOverImage(button->MouseoverImage);
nbut.SetPushedImage(button->PushedImage);
nbut.TextAlignment = (::FrameAlignment)button->TextAlignment;
nbut.SetWrapText(button->WrapText);
nbut.ClickAction[Common::kGUIClickLeft] = (Common::GUIClickAction)button->ClickAction;
nbut.ClickData[Common::kGUIClickLeft] = button->NewModeNumber;
nbut.SetClipImage(button->ClipImage);
Expand Down
9 changes: 9 additions & 0 deletions Editor/AGS.Types/GUIButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public GUIButton() : base()
private int _font;
private int _textColor;
private FrameAlignment _textAlign;
private bool _wrapText;
private bool _clipImage;
private GUIClickAction _clickAction;
private int _newModeNumber;
Expand Down Expand Up @@ -86,6 +87,14 @@ public FrameAlignment TextAlignment
set { _textAlign = value; }
}

[Description("Whether button will wrap text when it exceeds button's width or has new line characters")]
[Category("Appearance")]
public bool WrapText
{
get { return _wrapText; }
set { _wrapText = value; }
}

[Description("AGS Colour Number of the button text")]
[Category("Appearance")]
[DisplayName("TextColourNumber")]
Expand Down
10 changes: 9 additions & 1 deletion Editor/Native/acgui_agsnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ void GUIInvWindow::Draw(Bitmap *ds, int x, int y)

void GUIButton::PrepareTextToDraw()
{
_textToDraw = _text;
if (IsWrapText())
{
_textToDraw = _text;
GUI::SplitLinesForDrawing(_text, false, Lines, Font, _width);
}
else
{
_textToDraw = _text;
}
}

} // namespace Common
Expand Down

0 comments on commit 2124050

Please sign in to comment.