Skip to content

Commit 32894bd

Browse files
committed
Read LayoutRes headers and support editing them
Initial support for LayoutRes. Allow editing the values in the properties and respect them in the visual tools. However, resolution resampling and the resolution mismatch dialogs still need to be adjusted.
1 parent 41d8e42 commit 32894bd

8 files changed

Lines changed: 95 additions & 16 deletions

File tree

src/ass_file.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
#include "ass_info.h"
2222
#include "ass_style.h"
2323
#include "ass_style_storage.h"
24+
#include "async_video_provider.h"
2425
#include "options.h"
26+
#include "project.h"
27+
#include "include/aegisub/context.h"
2528

2629
#include <algorithm>
2730
#include <boost/algorithm/string/case_conv.hpp>
@@ -152,6 +155,23 @@ void AssFile::GetResolution(int &sw, int &sh) const {
152155
sh = sw == 1280 ? 1024 : sw * 3 / 4;
153156
}
154157

158+
void AssFile::GetLayoutResolution(int &lw, int &lh) const {
159+
lw = GetScriptInfoAsInt("LayoutResX");
160+
lh = GetScriptInfoAsInt("LayoutResY");
161+
}
162+
163+
void AssFile::GetEffectiveLayoutResolution(agi::Context *c, int &lw, int &lh) const {
164+
GetLayoutResolution(lw, lh);
165+
if (lw == 0 || lh == 0) {
166+
if (c->project->VideoProvider()) {
167+
lw = c->project->VideoProvider()->GetWidth();
168+
lh = c->project->VideoProvider()->GetHeight();
169+
} else {
170+
GetResolution(lw, lh);
171+
}
172+
}
173+
}
174+
155175
std::vector<std::string> AssFile::GetStyles() const {
156176
std::vector<std::string> styles;
157177
for (auto& style : Styles)

src/ass_file.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class AssDialogue;
4444
class AssInfo;
4545
class AssStyle;
4646
class wxString;
47+
namespace agi { struct Context; }
4748

4849
template<typename T>
4950
using EntryList = typename boost::intrusive::make_list<T, boost::intrusive::constant_time_size<false>, boost::intrusive::base_hook<AssEntryListHook>>::type;
@@ -127,6 +128,14 @@ class AssFile {
127128
/// @param[out] w Width
128129
/// @param[in] h Height
129130
void GetResolution(int &w,int &h) const;
131+
/// @brief Get the specified layout resolution, if present, or 0 if it is not present
132+
/// @param[out] w Width
133+
/// @param[in] h Height
134+
void GetLayoutResolution(int &w,int &h) const;
135+
/// @brief Get the effective layout resolution (i.e. falling back to the video resolution, if present)
136+
/// @param[out] w Width
137+
/// @param[in] h Height
138+
void GetEffectiveLayoutResolution(agi::Context *c, int &w,int &h) const;
130139
/// Get the value in a [Script Info] key as int, or 0 if it is not present
131140
int GetScriptInfoAsInt(std::string_view key) const;
132141
/// Get the value in a [Script Info] key as string.

src/dialog_properties.cpp

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "project.h"
3737
#include "resolution_resampler.h"
3838
#include "validators.h"
39+
#include "video_controller.h"
3940

4041
#include <boost/algorithm/string/predicate.hpp>
4142
#include <vector>
@@ -59,13 +60,17 @@ class DialogProperties {
5960
wxComboBox *WrapStyle; ///< Wrapping style for long lines
6061
wxTextCtrl *ResX; ///< Script x resolution
6162
wxTextCtrl *ResY; ///< Script y resolution
63+
wxTextCtrl *LayoutResX; ///< Layout x resolution
64+
wxTextCtrl *LayoutResY; ///< Layout y resolution
6265
wxCheckBox *ScaleBorder; ///< If script resolution != video resolution how should borders be handled
6366
wxComboBox *YCbCrMatrix;
6467

6568
/// OK button handler
6669
void OnOK(wxCommandEvent &event);
6770
/// Set script resolution to video resolution button
6871
void OnSetFromVideo(wxCommandEvent &event);
72+
/// Set layout resolution to video resolution button
73+
void OnSetLayoutResFromVideo(wxCommandEvent &event);
6974
/// Set a script info field
7075
/// @param key Name of field
7176
/// @param value New value
@@ -119,18 +124,36 @@ DialogProperties::DialogProperties(agi::Context *c)
119124
ResX = new wxTextCtrl(&d,-1,"",wxDefaultPosition,wxDefaultSize,0,IntValidator(c->ass->GetScriptInfoAsInt("PlayResX")));
120125
ResY = new wxTextCtrl(&d,-1,"",wxDefaultPosition,wxDefaultSize,0,IntValidator(c->ass->GetScriptInfoAsInt("PlayResY")));
121126

127+
LayoutResX = new wxTextCtrl(&d,-1,"",wxDefaultPosition,wxDefaultSize,0,IntValidator(c->ass->GetScriptInfoAsInt("LayoutResX")));
128+
LayoutResY = new wxTextCtrl(&d,-1,"",wxDefaultPosition,wxDefaultSize,0,IntValidator(c->ass->GetScriptInfoAsInt("LayoutResY")));
129+
122130
wxButton *FromVideo = new wxButton(&d,-1,_("From &video"));
123131
if (!c->project->VideoProvider())
124132
FromVideo->Enable(false);
125133
else
126134
FromVideo->Bind(wxEVT_BUTTON, &DialogProperties::OnSetFromVideo, this);
127135

128-
auto res_sizer = new wxBoxSizer(wxHORIZONTAL);
129-
res_sizer->Add(ResX, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
130-
res_sizer->Add(new wxStaticText(&d, -1, _(L"\u00D7")), 0, wxALIGN_CENTER | wxRIGHT, 5); // U+00D7 multiplication sign
131-
res_sizer->Add(ResY, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
136+
auto res_sizer = new wxFlexGridSizer(5, 5, 5);
137+
res_sizer->AddGrowableCol(1, 1);
138+
res_sizer->AddGrowableCol(3, 1);
139+
res_sizer->Add(new wxStaticText(&d, -1, _("Script: ")), wxSizerFlags().Center().Left());
140+
res_sizer->Add(ResX, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
141+
res_sizer->Add(new wxStaticText(&d, -1, _(L"\u00D7")), 0, wxALIGN_CENTER | wxRIGHT, 2); // U+00D7 multiplication sign
142+
res_sizer->Add(ResY, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
132143
res_sizer->Add(FromVideo, 1, 0, 0);
133144

145+
wxButton *LayoutResFromVideo = new wxButton(&d,-1,_("From video"));
146+
if (!c->project->VideoProvider())
147+
LayoutResFromVideo->Enable(false);
148+
else
149+
LayoutResFromVideo->Bind(wxEVT_BUTTON, &DialogProperties::OnSetLayoutResFromVideo, this);
150+
151+
res_sizer->Add(new wxStaticText(&d, -1, _("Layout: ")), wxSizerFlags().Center().Left());
152+
res_sizer->Add(LayoutResX, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
153+
res_sizer->Add(new wxStaticText(&d, -1, _(L"\u00D7")), 0, wxALIGN_CENTER | wxRIGHT, 2); // U+00D7 multiplication sign
154+
res_sizer->Add(LayoutResY, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2);
155+
res_sizer->Add(LayoutResFromVideo, 1, 0, 0);
156+
134157
YCbCrMatrix = new wxComboBox(&d, -1, to_wx(c->ass->GetScriptInfo("YCbCr Matrix")),
135158
wxDefaultPosition, wxDefaultSize, to_wx(MatrixNames()), wxCB_READONLY);
136159

@@ -189,6 +212,8 @@ void DialogProperties::OnOK(wxCommandEvent &) {
189212

190213
count += SetInfoIfDifferent("PlayResX", from_wx(ResX->GetValue()));
191214
count += SetInfoIfDifferent("PlayResY", from_wx(ResY->GetValue()));
215+
count += SetInfoIfDifferent("LayoutResX", from_wx(LayoutResX->GetValue()));
216+
count += SetInfoIfDifferent("LayoutResY", from_wx(LayoutResY->GetValue()));
192217
count += SetInfoIfDifferent("WrapStyle", std::to_string(WrapStyle->GetSelection()));
193218
count += SetInfoIfDifferent("ScaledBorderAndShadow", ScaleBorder->GetValue() ? "yes" : "no");
194219
count += SetInfoIfDifferent("YCbCr Matrix", from_wx(YCbCrMatrix->GetValue()));
@@ -206,9 +231,28 @@ int DialogProperties::SetInfoIfDifferent(std::string_view key, std::string_view
206231
return 0;
207232
}
208233

234+
std::pair<int, int> GetVideoDisplayResolution(agi::Context *c) {
235+
double dar = c->videoController->GetAspectRatioValue();
236+
int width = c->project->VideoProvider()->GetWidth();
237+
int height = c->project->VideoProvider()->GetHeight();
238+
double sar = double(width) / double(height);
239+
240+
return std::make_pair(
241+
width * std::max(1., dar / sar),
242+
height * std::max(1., sar / dar)
243+
);
244+
}
245+
209246
void DialogProperties::OnSetFromVideo(wxCommandEvent &) {
210-
ResX->SetValue(std::to_wstring(c->project->VideoProvider()->GetWidth()));
211-
ResY->SetValue(std::to_wstring(c->project->VideoProvider()->GetHeight()));
247+
auto [width, height] = GetVideoDisplayResolution(c);
248+
ResX->SetValue(std::to_wstring(width));
249+
ResY->SetValue(std::to_wstring(height));
250+
}
251+
252+
void DialogProperties::OnSetLayoutResFromVideo(wxCommandEvent &) {
253+
auto [width, height] = GetVideoDisplayResolution(c);
254+
LayoutResX->SetValue(std::to_wstring(width));
255+
LayoutResY->SetValue(std::to_wstring(height));
212256
}
213257
}
214258

src/gl_wrap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,11 @@ void OpenGLWrapper::SetScale(Vector2D scale) {
401401
glScalef(scale.X() / 100.f, scale.Y() / 100.f, 1.f);
402402
}
403403

404-
void OpenGLWrapper::SetRotation(float x, float y, float z) {
404+
void OpenGLWrapper::SetRotation(float x, float y, float z, float zScale) {
405405
PrepareTransform();
406406
float matrix[16] = { 2500, 0, 0, 0, 0, 2500, 0, 0, 0, 0, 1, 1, 0, 0, 2500, 2500 };
407407
glMultMatrixf(matrix);
408-
glScalef(1.f, 1.f, 8.f);
408+
glScalef(1.f, 1.f, 8.f / zScale);
409409
glRotatef(y, 0.f, -1.f, 0.f);
410410
glRotatef(x, -1.f, 0.f, 0.f);
411411
glRotatef(z, 0.f, 0.f, -1.f);

src/gl_wrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class OpenGLWrapper {
4848

4949
void SetScale(Vector2D scale);
5050
void SetOrigin(Vector2D origin);
51-
void SetRotation(float x, float y, float z);
51+
void SetRotation(float x, float y, float z, float zScale = 1);
5252
void SetShear(float x, float y);
5353
void ResetTransform();
5454

src/visual_tool.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,27 @@ VisualToolBase::VisualToolBase(VideoDisplay *parent, agi::Context *context)
5555
, shaded_area_alpha_opt(OPT_GET("Colour/Visual Tools/Shaded Area Alpha"))
5656
, file_changed_connection(c->ass->AddCommitListener(&VisualToolBase::OnCommit, this))
5757
{
58-
int script_w, script_h;
59-
c->ass->GetResolution(script_w, script_h);
60-
script_res = Vector2D(script_w, script_h);
58+
SetResolutions();
6159
active_line = GetActiveDialogueLine();
6260
connections.push_back(c->selectionController->AddActiveLineListener(&VisualToolBase::OnActiveLineChanged, this));
6361
connections.push_back(c->videoController->AddSeekListener(&VisualToolBase::OnSeek, this));
6462
parent->Bind(wxEVT_MOUSE_CAPTURE_LOST, &VisualToolBase::OnMouseCaptureLost, this);
6563
}
6664

65+
void VisualToolBase::SetResolutions() {
66+
int script_w, script_h, layout_w, layout_h;
67+
c->ass->GetResolution(script_w, script_h);
68+
c->ass->GetEffectiveLayoutResolution(c, layout_w, layout_h);
69+
script_res = Vector2D(script_w, script_h);
70+
layout_res = Vector2D(layout_w, layout_h);
71+
}
72+
6773
void VisualToolBase::OnCommit(int type) {
6874
holding = false;
6975
dragging = false;
7076

7177
if (type == AssFile::COMMIT_NEW || type & AssFile::COMMIT_SCRIPTINFO) {
72-
int script_w, script_h;
73-
c->ass->GetResolution(script_w, script_h);
74-
script_res = Vector2D(script_w, script_h);
78+
SetResolutions();
7579
OnCoordinateSystemsChanged();
7680
}
7781

src/visual_tool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace agi {
4343
/// functionality as possible is implemented here to avoid having four copies
4444
/// of each method for no good reason (and four times as many error messages)
4545
class VisualToolBase {
46+
void SetResolutions();
4647
void OnCommit(int type);
4748
void OnSeek(int new_frame);
4849

@@ -98,6 +99,7 @@ class VisualToolBase {
9899
Vector2D mouse_pos; ///< Last seen mouse position
99100
Vector2D drag_start; ///< Mouse position at the beginning of the last drag
100101
Vector2D script_res; ///< Script resolution
102+
Vector2D layout_res; ///< Layout resolution
101103
Vector2D canvas_size; ///< The size of the display area
102104
Vector2D video_pos; ///< Top-left corner of the video in the display area
103105
Vector2D video_size; ///< Size of the video on screen. Not necessarily equal to the video resolution

src/visual_tool_rotatexy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void VisualToolRotateXY::Draw() {
5050
// Transform grid
5151
gl.SetOrigin(org->pos);
5252
gl.SetScale(100 * video_size / script_res);
53-
gl.SetRotation(angle_x, angle_y, angle_z);
53+
gl.SetRotation(angle_x, angle_y, angle_z, script_res.Y() / layout_res.Y());
5454
gl.SetScale(fsc);
5555
gl.SetShear(fax, fay);
5656

0 commit comments

Comments
 (0)