Skip to content

Commit

Permalink
2160x2160 size preset, shrink2 save option,
Browse files Browse the repository at this point in the history
preview centering on save, and other ugly solution for
the margins of label rect,
delete size member from template resource
  • Loading branch information
BlankManifold committed Nov 1, 2022
1 parent 735bf6a commit 316dfa2
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 49 deletions.
16 changes: 8 additions & 8 deletions scenes/MainControl.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -540.0
margin_top = -404.0
margin_right = 540.0
margin_bottom = 676.0
margin_left = -1080.0
margin_top = -968.0
margin_right = 1080.0
margin_bottom = 1192.0
rect_min_size = Vector2( 400, 400 )

[node name="PreviewViewport" type="Viewport" parent="PreviewViewportContainer"]
unique_name_in_owner = true
size = Vector2( 1080, 1080 )
size = Vector2( 2160, 2160 )
transparent_bg = true
handle_input_locally = false
msaa = 1
msaa = 2
disable_3d = true
keep_3d_linear = true
usage = 0
Expand All @@ -52,8 +52,8 @@ anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 0.0
margin_top = 0.0
margin_right = 1080.0
margin_bottom = 1080.0
margin_right = 2160.0
margin_bottom = 2160.0

[node name="Camera2D" type="Camera2D" parent="."]
unique_name_in_owner = true
Expand Down
12 changes: 6 additions & 6 deletions scenes/PreviewUI.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -540.0
margin_top = -960.0
margin_top = -540.0
margin_right = 540.0
margin_bottom = 960.0
margin_bottom = 540.0
mouse_filter = 2
script = ExtResource( 2 )

Expand All @@ -29,15 +29,15 @@ margin_left = -540.0
margin_top = -540.0
margin_right = 540.0
margin_bottom = 540.0
rect_pivot_offset = Vector2( 540, 540 )
rect_pivot_offset = Vector2( 1080, 1080 )

[node name="Text" type="RichTextLabel" parent="BackgroundRect"]
unique_name_in_owner = true
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 15.0
margin_top = 15.0
margin_bottom = 15.0
margin_left = 30.0
margin_top = 30.0
margin_bottom = 30.0
custom_colors/default_color = Color( 0, 0, 0, 1 )
custom_fonts/normal_font = SubResource( 1 )
bbcode_enabled = true
Expand Down
4 changes: 0 additions & 4 deletions scenes/SpacingContainer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ margin_bottom = 30.0
rect_min_size = Vector2( 30, 30 )
size_flags_horizontal = 0
min_value = -40.0
max_value = 40.0
rounded = true
align = 1
prefix = "s"
Expand All @@ -33,7 +32,6 @@ margin_bottom = 30.0
rect_min_size = Vector2( 30, 30 )
size_flags_horizontal = 0
min_value = -40.0
max_value = 40.0
rounded = true
align = 1
prefix = "c"
Expand All @@ -50,7 +48,6 @@ margin_right = 74.0
margin_bottom = 30.0
size_flags_horizontal = 2
min_value = -40.0
max_value = 40.0
rounded = true
align = 1
prefix = "t"
Expand All @@ -63,7 +60,6 @@ margin_bottom = 30.0
rect_min_size = Vector2( 30, 30 )
size_flags_horizontal = 0
min_value = -40.0
max_value = 40.0
rounded = true
align = 1
prefix = "b"
Expand Down
16 changes: 12 additions & 4 deletions scenes/ToolsUI.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ margin_bottom = 46.0
rect_min_size = Vector2( 350, 0 )
text = "1:1 (1080x1080)"
clip_text = true
items = [ "1:1 (1080x1080)", null, false, 0, null, "9:16 (1080x1920)", null, false, 1, null ]
items = [ "1:1 (1080x1080)", null, false, 0, null, "9:16 (1080x1920)", null, false, 1, null, "1:1 (2160x2160)", null, false, 2, null ]
selected = 0

[node name="TextEditor" parent="ToolContainer/TextBox1" instance=ExtResource( 4 )]
Expand Down Expand Up @@ -127,6 +127,7 @@ margin_right = 272.0
margin_bottom = 202.0
rect_min_size = Vector2( 200, 0 )
min_value = 20.0
max_value = 300.0
value = 50.0
rounded = true
align = 1
Expand Down Expand Up @@ -281,13 +282,13 @@ selected = 0

[node name="SaveBox" type="VBoxContainer" parent="TemplateContainer"]
margin_left = 835.0
margin_right = 985.0
margin_right = 1004.0
margin_bottom = 214.0
custom_constants/separation = 20

[node name="WindowLabel" type="Label" parent="TemplateContainer/SaveBox"]
unique_name_in_owner = true
margin_right = 150.0
margin_right = 169.0
margin_bottom = 40.0
size_flags_vertical = 0
text = "0/0"
Expand All @@ -296,13 +297,19 @@ valign = 1

[node name="Save" type="Button" parent="TemplateContainer/SaveBox"]
margin_top = 60.0
margin_right = 150.0
margin_right = 169.0
margin_bottom = 110.0
rect_min_size = Vector2( 150, 50 )
size_flags_vertical = 0
shortcut = SubResource( 5 )
text = "SAVE"

[node name="Shrink2Box" type="CheckBox" parent="TemplateContainer/SaveBox"]
margin_top = 130.0
margin_right = 169.0
margin_bottom = 178.0
text = "SHRINK2"

[node name="FileDialog" type="FileDialog" parent="."]
unique_name_in_owner = true
anchor_left = 0.5
Expand Down Expand Up @@ -382,6 +389,7 @@ placeholder_alpha = 0.5
[connection signal="button_down" from="TemplateContainer/FontBox/LoadBoldFont" to="." method="_on_LoadBoldFont_button_down"]
[connection signal="item_selected" from="TemplateContainer/FontBox/BoldFontSelection" to="." method="_on_BoldFontSelection_item_selected"]
[connection signal="button_down" from="TemplateContainer/SaveBox/Save" to="." method="_on_Save_button_down"]
[connection signal="toggled" from="TemplateContainer/SaveBox/Shrink2Box" to="." method="_on_Shrink2Box_toggled"]
[connection signal="confirmed" from="FileDialog" to="." method="_on_FileDialog_confirmed"]
[connection signal="file_selected" from="FileDialog" to="." method="_on_FileDialog_file_selected"]
[connection signal="files_selected" from="FileDialog" to="." method="_on_FileDialog_files_selected"]
Expand Down
4 changes: 2 additions & 2 deletions scripts/MainControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public void on_ToolsUI_Zoom(bool zoomIn, bool maxime)
if (zoom[0] >= _maxZoom[0] && zoom[1] <= _maxZoom[1])
_camera.Zoom = zoom;
}
public void on_ToolsUI_Save(string path)
public void on_ToolsUI_Save(string path, bool shrink2)
{
_previewUI.SavePNG(path);
_previewUI.SavePNG(path, shrink2);
}


Expand Down
45 changes: 32 additions & 13 deletions scripts/PreviewUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,26 @@

public class PreviewUI : Control
{



private ColorRect _backgroundRect;
private RichTextLabel _textLabel;
private TextData _textData = new TextData("", "", "", 30, new Color(0f, 0f, 0f), new Color(0f, 0f, 0f));
private Vector2 _maxSize;
private Vector2 _maxScale;
private Vector2 _minSize = new Vector2(400, 400);
private Vector2 _startSize = new Vector2(1080, 1080);
private Vector2 _startSize = new Vector2(2160, 2160);//new Vector2(1080, 1080); //
private string _symbols = "";
private string[] _symBbCode = new string[] { "[color=#000000]", "[/color]" };

[Export]
private Vector2 _baseScale = new Vector2(1, 1);



public override void _Ready()
{
_backgroundRect = GetNode<ColorRect>("%BackgroundRect");
_textLabel = GetNode<RichTextLabel>("%Text");

DynamicFont font = (DynamicFont)_textLabel.Get("custom_fonts/normal_font");
_textLabel.Set("custom_fonts/bold_font",font.Duplicate());
_textLabel.Set("custom_fonts/bold_font", font.Duplicate());
}


Expand Down Expand Up @@ -78,7 +75,22 @@ private void UpdateTextContent()
}



private void UpdateLabelMargin(Vector2 size)
{
switch (size.x)
{
case 1080:
_textLabel.MarginBottom = 30;
_textLabel.MarginLeft = 30;
_textLabel.MarginTop = 30;
break;
case 2160:
_textLabel.MarginBottom = 60;
_textLabel.MarginLeft = 60;
_textLabel.MarginTop = 60;
break;
}
}
public void UpdateMaxSize(Vector2 maxsize)
{
_maxSize = maxsize;
Expand All @@ -92,6 +104,10 @@ public void UpdateSize(Vector2 size)
_backgroundRect.RectSize = size;
_startSize = size;

_backgroundRect.RectPosition = GetRect().GetCenter() - _backgroundRect.RectSize / 2;

UpdateLabelMargin(size);

// Vector2 factorVec = _maxSize / _startSize;
// _maxScale = Math.Min(factorVec.x, factorVec.y) * Vector2.One;

Expand Down Expand Up @@ -176,14 +192,17 @@ public void UpdateBoldFont(string path)
UpdateTextContent();
}

public void SavePNG(string path)
public void SavePNG(string path, bool shrink2)
{
Image img = GetViewport().GetTexture().GetData();
img.FlipY();

Image frame =img.GetRect(_backgroundRect.GetRect());
//frame.Resize((int)_startSize[0],(int)_startSize[1]);

Image frame = img.GetRect(_backgroundRect.GetRect());
//frame.Resize((int)_startSize[0],(int)_startSize[1]);
if (shrink2)
{
frame.ShrinkX2();
}
frame.SavePng(path);
}
}
6 changes: 2 additions & 4 deletions scripts/TemplateResource.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ extends Resource
class_name TemplateResource

export var id: int
export var name: String
export(Vector2) var size: Vector2
export var name: String
export(String, "e comunque...", "o comunque...", "comunque...", "") var incipit: String
export(String, "-- INSERT --", ":wq", "") var closing: String
export var font: Font
Expand All @@ -17,11 +16,10 @@ export var spacing: Array



func init(_id: int, _name: String, _size: Vector2, _bgColor: Color, _incipit: String,
func init(_id: int, _name: String, _bgColor: Color, _incipit: String,
_closing: String, _font: Font, _fontSize: int, _fontColor: Color, _symbolColor: Color, _spacing: Array) -> void:
id = _id
name = _name
size = _size
bgColor = _bgColor
incipit = _incipit
closing = _closing
Expand Down
28 changes: 20 additions & 8 deletions scripts/ToolsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum FileDialogMode
private Godot.Collections.Dictionary<string, Vector2> _sizeDict = new Godot.Collections.Dictionary<string, Vector2>()
{
{"1:1 (1080x1080)", new Vector2(1080,1080)},
{"1:1 (2160x2160)", new Vector2(2160,2160)},
{"9:16 (1080x1920)", new Vector2(1080,1920)},
};

Expand All @@ -56,6 +57,7 @@ public enum FileDialogMode
private Color _bgColor = new Color(1f, 1f, 1f);
private Godot.Collections.Array<string> _mainTexts = new Godot.Collections.Array<string>() { };
private int _index = 0;
private bool _shrink2 = false;



Expand All @@ -82,7 +84,7 @@ public enum FileDialogMode
[Signal]
delegate void BoldFontSelected(string path);
[Signal]
delegate void Save(string path);
delegate void Save(string path, bool shrink2);



Expand Down Expand Up @@ -312,7 +314,6 @@ private void UpdateSizeSpinBox()
}
private void UpdateFromResource(Resource templateResource)
{
Vector2 size = (Vector2)templateResource.Get("size");
string incipit = (string)templateResource.Get("incipit");
string closing = (string)templateResource.Get("closing");
int fontSize = (int)templateResource.Get("fontSize");
Expand All @@ -321,7 +322,6 @@ private void UpdateFromResource(Resource templateResource)
Color fontColor = (Color)templateResource.Get("fontColor");
Godot.Collections.Array spacing = (Godot.Collections.Array)templateResource.Get("spacing");

EmitSignal(nameof(SizeSelected), size);
EmitSignal(nameof(BGColorSelected), _bgColor);
EmitSignal(nameof(FontColorSelected), fontColor);
EmitSignal(nameof(SymbolColorSelected), symbolColor);
Expand Down Expand Up @@ -485,7 +485,7 @@ public void _on_FileDialog_confirmed()
{
if (_fileDialogMode == FileDialogMode.SAVE_PNG)
{
EmitSignal(nameof(Save), _fileDialog.CurrentPath);
EmitSignal(nameof(Save), _fileDialog.CurrentPath, _shrink2);
}
}

Expand Down Expand Up @@ -528,13 +528,20 @@ public void _on_TemeplateName_text_entered(string name)
GDScript templateResourceScript = (GDScript)GD.Load("res://scripts/TemplateResource.gd");
Resource templateResource = (Resource)templateResourceScript.New();

templateResource.Call("init", 0, name + ".tres", GetFrameSize(), _bgColor, _textData.Incipit, _textData.Closing, null,
string fileName = name + ".tres";

templateResource.Call("init", 0, fileName, _bgColor, _textData.Incipit, _textData.Closing, null,
_textData.Size, _textData.Color, _textData.SymbolColor, _spacingContainer.GetSpacing());

string filePath = Globals.PATHS.TEMPLATE + "/" + name + ".tres";
string filePath = Globals.PATHS.TEMPLATE + "/" + fileName;
Godot.Error err = ResourceSaver.Save(filePath, templateResource);
Globals.PATHS.TEMPLATE_DICT[name + ".tres"] = filePath;
_templateSelection.AddItem(name + ".tres");

if (!Globals.PATHS.TEMPLATE_DICT.ContainsKey(fileName))
{
_templateSelection.AddItem(fileName);
}

Globals.PATHS.TEMPLATE_DICT[fileName] = filePath;
}
public void _on_TemplateSelection_item_focused(int idx)
{
Expand All @@ -549,4 +556,9 @@ public void _on_Save_button_down()
UpdateFileDialogFilters(FileDialogMode.SAVE_PNG);
_fileDialog.Popup_();
}
public void _on_Shrink2Box_toggled(bool buttonPressed)
{
_shrink2 = buttonPressed;
}
}

0 comments on commit 316dfa2

Please sign in to comment.