From 171e71660b083b489790102b906042c8fd6b05c8 Mon Sep 17 00:00:00 2001 From: nuhah100 Date: Mon, 27 Mar 2023 22:47:58 +0300 Subject: [PATCH 1/2] Added buttons for text direction --- src/bitmaps/button/direction_ltr_16.png | Bin 0 -> 291 bytes src/bitmaps/button/direction_ltr_24.png | Bin 0 -> 394 bytes src/bitmaps/button/direction_ltr_32.png | Bin 0 -> 482 bytes src/bitmaps/button/direction_ltr_48.png | Bin 0 -> 945 bytes src/bitmaps/button/direction_ltr_64.png | Bin 0 -> 883 bytes src/bitmaps/button/direction_rtl_16.png | Bin 0 -> 286 bytes src/bitmaps/button/direction_rtl_24.png | Bin 0 -> 412 bytes src/bitmaps/button/direction_rtl_32.png | Bin 0 -> 502 bytes src/bitmaps/button/direction_rtl_48.png | Bin 0 -> 908 bytes src/bitmaps/button/direction_rtl_64.png | Bin 0 -> 929 bytes src/bitmaps/manifest.respack | 10 +++++++++ src/command/edit.cpp | 27 ++++++++++++++++++++++++ src/subs_edit_box.cpp | 3 +++ src/subs_edit_ctrl.cpp | 4 +++- src/text_selection_controller.h | 1 + 15 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/bitmaps/button/direction_ltr_16.png create mode 100644 src/bitmaps/button/direction_ltr_24.png create mode 100644 src/bitmaps/button/direction_ltr_32.png create mode 100644 src/bitmaps/button/direction_ltr_48.png create mode 100644 src/bitmaps/button/direction_ltr_64.png create mode 100644 src/bitmaps/button/direction_rtl_16.png create mode 100644 src/bitmaps/button/direction_rtl_24.png create mode 100644 src/bitmaps/button/direction_rtl_32.png create mode 100644 src/bitmaps/button/direction_rtl_48.png create mode 100644 src/bitmaps/button/direction_rtl_64.png diff --git a/src/bitmaps/button/direction_ltr_16.png b/src/bitmaps/button/direction_ltr_16.png new file mode 100644 index 0000000000000000000000000000000000000000..09305f7301d74b5b4497e8aa1bdd640fe7dae9cb GIT binary patch literal 291 zcmV+;0o?wHP)Px#-AP12R5(w)(?3c>K@i9BPr%OF#v)bjAQpm1u8;(K3ma{`hD0S7uoDu&6WFSy z9>BsvtUQ5*@`Lwu@lRw8_-ppf?3?e-&dhdvsDnKmpj-Iwv4N+;_x_onR{J<9>>G?R z#Q^8O0Ukb`Ji`#L%^LfQ$_!qxRQyp5xWf7(fHhoVxq(z?khmUpF~W6i4ax$g@=;Y0 z{|#`2Q{3gmvW;a1+l_ICV@!~Vj4~I`=;QV$z;`p#`T~do*$UthtMek}>|F$~iIoaK p+o6Q)EOLds+VNiix$+^>4R5_^HBgF1bs_)&002ovPDHLkV1oB;f7<{6 literal 0 HcmV?d00001 diff --git a/src/bitmaps/button/direction_ltr_24.png b/src/bitmaps/button/direction_ltr_24.png new file mode 100644 index 0000000000000000000000000000000000000000..65c0174c7428b48c166a6ceb01f3a211488b2c26 GIT binary patch literal 394 zcmV;50d@X~P)Px$L`g(JR7gwh)xRr7aTLe#7qbCjKvEVgD1!`=3@j#Pv>33qn6 zhTS@X`*2swFAJE!De}N0xWPGwlI-HUs%3=^F!xKuAg*zV;lBc&(NQMg1+8TQP7o86 zXN8n#9{XhiqUn2B%7GM;LFhJOIr-6gQlP>B70t+|JDK|~6b`6>?$P@XsJ2h)EztrN zv5JRuBWvxe3&f&}iF(2@rqPevRPZ5Y@rcO^ByVeGf$hoqh)o*Sf=*mz9FH)QoP9&; z0o2N{a-Rmo*%u@Ln;5HCrHbDu+A{ZN0eC}m0f0P-*8oJb1_}UdB*T!F+9|UKu{2l8 o0(^<%qewu!Bk`Vmi$|?K0gonDbeW(xt^fc407*qoM6N<$g398p`Tzg` literal 0 HcmV?d00001 diff --git a/src/bitmaps/button/direction_ltr_32.png b/src/bitmaps/button/direction_ltr_32.png new file mode 100644 index 0000000000000000000000000000000000000000..d7b09865013369226c1510f2ac93ea43f3a4aa45 GIT binary patch literal 482 zcmV<80UiE{P)Px$oJmAMR9Hvtmpd;7K^TUgL!nS85v88EM5ENI+!~ieLn1+;5K(AE^hzW`qM#BT z8lB)L==cE&jfhL$WJdPv&R%n7w>i_CJ+t%8`^%qrUL~W=rT!s3w(vk zI_a4oURyK?Uw~fV8qgk}!Hx3(3Px&Ye_^wRA@u(+Q+M8RS?JV&&U`siwVIzh$0H&Vho$njS;~F1_T8IxKL*l97fT> zEEo_K45;WrP|<%tTnMgQC?g7jx-bV&%mFjMq59eL?CyKp*W>Aj>6v9s$q!l@G|bgtN5+`l+BXMnngrrJDiHOI2_Ac^qVj8J}$>g z`29chAK9e|An*6YmAC}EFL2^#a4kMs;5c*Ln*eshnp(MCT1@&YKEqEXyAAfJ9n7Qm za3a$JX!9aWXcv9IsJq5 zt8{Wz#ra7m55fSZ^8f>oD4v~&kGzQOyB5qfIqUHIud(wIz%)xXB-@k|w;6V62imOC zIGLp#z>*1#Fpq>STjB@&HOa)fWafq^X{5e7vULq$FRZWHQcm|zkks}G zd_Rg{762(1uBgG^#(8+7ey1{*!qy-)eFtaZtuYIF03O6C^*-kF1#ZPtWm21Todv)- zcpQJ!-yME3P2nphfj{~#rA>3Kk>)hiZ-<`v2t*Qn)o9Ci`}ApYEY>PPHMkY*>nA3 zulRf=o6dpANBKwU{^H}l0sM@IaX&uD>E0)RDF0B!N>P4eNYWR8m`#*_pjLh^p6Ua@ zz~=9(PyQysVAlZltpw)m^6n`ASlw6W|116#>2?iZ>q>r-)FiBU61U^iak=r|-%$(! TPzElX00000NkvXXu0mjfH^a*G literal 0 HcmV?d00001 diff --git a/src/bitmaps/button/direction_ltr_64.png b/src/bitmaps/button/direction_ltr_64.png new file mode 100644 index 0000000000000000000000000000000000000000..a1cca9e32f8bd15382e3c830c34f0211121977e1 GIT binary patch literal 883 zcmV-(1C0EMP)Px&ElET{RCr$Pn@gxqK^(_F*ZWbTTk={Ul0p_XNTFC*kY^r67Obe-wRPpS6gEnp z#X_-=JT?|63k!v8tP~b@B+4V9ugF{AT8Nd#GNf z0-J!9zmjW#Jh6)b=9pmFtp z3xET_i3**10-QA1UpIW)0>~dUUTgu(23|UP_k8CiNW${P;I>1YQ6O zVg_&t*c~$fo%c=gx+@cJeZXko9nkBlI9K0W0Mc!eh4Zsy(tm8}w27q+W1ug(f93TV*K)Qzj>j2#sEVDQ- z1P35H__{S(o`lT0(p~{f3n>n8nCXA3Dsof=nJq!jfIOfUKsy84CD8hS)(N(|K)VgL zaX=dgWe7AC3F?V|C$I|8E7ob?gKg+)n;&4?URv*8MuN&II+W?)t0ZIXy-lY>0HD#H zkP~YSp(z08fIYcRod@}6w9x+PW?LTCzrIxZ3Eh-*fe#H*hAuq)%ll#F5R#4IvPyFzFZfX(RDQO72= zwj+dC00^`ZLQDXR5Ml!`2ttei1mRio()C>cCIJ@#?Y+b5@JgPvu@5*S0C#~ko^-m- zZa&ggz5poTP#Sz}McJ>@1wh-woY>R@%6(cW06IqAEb-XsJ2OR`{pl_+F?s0paVeC^ zU-}Hp1K!5C4a(=O2kxZ@5#Oh>%~>GTDDnCizuW1Dm}bBr@iEN+qxe_=bQB*0fUe?0 z2T&+J6ac1BUf(tXcZ#;S5O#t5Va{57C^H~E&ZjR!`yH;-`2+gV_CZ(x$1VT>002ov JPDHLkV1kLJh|T~2 literal 0 HcmV?d00001 diff --git a/src/bitmaps/button/direction_rtl_16.png b/src/bitmaps/button/direction_rtl_16.png new file mode 100644 index 0000000000000000000000000000000000000000..6074aaa5cf1671cf868479787f7b5546ba5cee55 GIT binary patch literal 286 zcmV+(0pb3MP)Px#*hxe|R5(w)(mhTBQ541T-%#5aDM{RcmR7ESN=aym^h7LdOOZ)1|Nq2&atXlZRH@upYc?2(HaoFecWPPx$R!KxbR7gwZ)vZeI%RM%d z_ou8}tpWW-d_&tSw!=7W7BGYpwC9MA;|SlAKbyp1vw$6ZDTqAM_6NTaur~oNFi<7n z5}&FB>|?4*zyy9)2?*`4SjvHvQsmH$S((8q`s+ZY0aDEX_2Cx=Q92+6#k9r%zEeOf zv~~1g4v#tA^X3$V_$C$-(Oz8V0Dd6mBMSW&d-#kI92YIS5Z_9oPHm!Nu5tifNjIG* zZ*dPx$ut`KgR9Hvt*1ttoBZbR47<2gb|i~YD<+xo4u>Lu z3m8d5XpCTCXEBD)WrxxbkBcNGpH3?RDA=Ly%Mttx-e+Xq@~j--1~yKV#_^ov^sGg8 zGgvxaj1znP41g>6f;jtG7QIo0MFrMd`+E@pq9VE_O0eGBT39HNx6aWAK07*qoM6N<$g1%SZVgLXD literal 0 HcmV?d00001 diff --git a/src/bitmaps/button/direction_rtl_48.png b/src/bitmaps/button/direction_rtl_48.png new file mode 100644 index 0000000000000000000000000000000000000000..edc819efa6c53a8a930574478ae20eac2d73cb94 GIT binary patch literal 908 zcmV;719SX|P)Px&MoC0LRA@u(*;}aXQxwPX&vC!YaVHP%IWLq#B%)k$Tyjg~eh(?RypR+^c_3cI zgG3#9qDV?ec{!wr+(Y8zcyK$2&`$Y!0Jg_f zxC>j>PCP~~o_`CcXN{&)O0uAN34;0ehC;U*I~tv>^a?z$-Ykb~1d2lkslvo6oU#58!&dSgUg(D{wZR z=`DZFoJ|2dh4Yd0Sv#5mh|%xipb7U;GXP1KiQV05U0>vy0!YT#byfiqLLcCOSq-5$ zeif35W^xk;;6gkx%V~7mav<$9!9Hka6L&VJY)&arJDLN?N&Yadtt{r61BmB0$3wUP zxfje=o-_#%h#YK}mP&FDWPgk+ubTx3L<~++ShnfkYZA#1Uw@JEYm^wfjPN(7W z()&r>^D+WbGo}g<_p5u&vFN|7bgQeT7?*`M!AW=!`;SzYpB8|$RBA?aU4lEXV`%_Ch97$$pMs~0 zlOD&d__IcNWJUqv`Qz~j_8p^SQh-iHI@oEM|1wAaf2&gPeP3&MC)Wo^U4JYdox}Ki zv%Ub6+Ep#z0c?ij=J9-|ut|VG9EB$_bV2{JTp#=G@oH}^vS8jC*2MUP&ht2-VuE#e z2R~QH{@)_M<~b?=X%Bvdgwd>xwE;L7Z&!8|S_51cfb=)h+X=|fNPhkXe+&t3fdBK( z_FA_G&cg%PWnkiOaX+$|r#%9&x=W)uXs*O90}xH7(e6ZEj*H7tK3CtrS%3~A^~y!_ zKr{_73US+*aB3c)A5Li%j_!$>0O%mHv9HF>*r}wPJW%Ip^}}hWpl<%5u0-y_c{#tS il)I_xQ?vin3c$ayP6Z+s%Ud-70000Px&TS-JgRCr$Pn@h-zK^Vt>9}+3|yP_!f+d_mWxs@Ucv9kEWLX=Bck;_I&E-5R? zf(172a;K1l1q(J}`<2Va#;5SFdG+>w?>T4YopZjvne)!_oOx!R|8HiVdFR$b=cN{4 zHn0Ym2TTA40o@&3_zFA%jsUM6>?&rJQ;kllV#u)PAT^C`bk07e4OfiXVLS=cHj47SMEsWG4j@WceV zqP`smUSy2t0y}dG^lC&e;|l6_0mq6eH+JiR%b7CN)h~5*0DXbaz<_22upKz%DPHEm z_JC)eV?SXRB!E7^4?scCHw6h`7VyefdB{O<6>zng0j$lLx{C4$atJI3?i5v=u?rG_ zmbV|88GzRH`Zn)Z2M9s-0O{7Js@Li)ttSXw!19M=uB-fM$e?W>r^&L+}73T8pC7z}5l;q5zQS-UyrkhB|9n?T_2Q1t4!4a{&>|G&lsf4@^&~J76w9xd_hY4FZ6cvJyWn zkGi5ipFKhb6(;f0uwE(jS7G+I7+-udTmoQ z03=>Fv9(v{lA-|63wW9N$gzbG1%MsENn6Dc}TJI^aAOc~o5^f~`z5t_L zts}_ao&b1T$JZPoaru}4I120u$@4n+`cvtextSelectionController->GetControl()->SetLayoutDirection (wxLayout_LeftToRight); + } +}; + +struct edit_text_rtl final : public Command { + CMD_NAME("edit/text_rtl") + CMD_ICON(direction_rtl) + STR_DISP("Set text to RTL") + STR_MENU("Set text to RTL") + STR_HELP("Change the direction of the text to RTL") + + void operator()(agi::Context *c) override { + c->textSelectionController->GetControl()->SetLayoutDirection (wxLayout_RightToLeft); + } +}; + } namespace cmd { @@ -1273,6 +1298,8 @@ namespace cmd { reg(agi::make_unique()); reg(agi::make_unique()); reg(agi::make_unique()); + reg(agi::make_unique()); + reg(agi::make_unique()); reg(agi::make_unique()); reg(agi::make_unique()); reg(agi::make_unique()); diff --git a/src/subs_edit_box.cpp b/src/subs_edit_box.cpp index 308023d6c0..a9d9e57dc1 100644 --- a/src/subs_edit_box.cpp +++ b/src/subs_edit_box.cpp @@ -188,6 +188,9 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context) MakeButton("edit/color/shadow"); middle_right_sizer->AddSpacer(5); MakeButton("grid/line/next/create"); + middle_right_sizer->AddSpacer(5); + MakeButton("edit/text_ltr"); + MakeButton("edit/text_rtl"); middle_right_sizer->AddSpacer(10); by_time = MakeRadio(_("T&ime"), true, _("Time by h:mm:ss.cs")); diff --git a/src/subs_edit_ctrl.cpp b/src/subs_edit_ctrl.cpp index ee5389a489..c0d353dc45 100644 --- a/src/subs_edit_ctrl.cpp +++ b/src/subs_edit_ctrl.cpp @@ -166,6 +166,8 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, a UpdateStyle(); SetFocus(); }, EDIT_MENU_REMOVE_FROM_DICT); + + SetLayoutDirection (wxLayout_RightToLeft); } SubsTextEditCtrl::~SubsTextEditCtrl() { @@ -193,7 +195,7 @@ void SubsTextEditCtrl::OnLoseFocus(wxFocusEvent &event) { void SubsTextEditCtrl::OnKeyDown(wxKeyEvent &event) { event.Skip(); - + // Workaround for wxSTC eating tabs. if (event.GetKeyCode() == WXK_TAB) Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward); diff --git a/src/text_selection_controller.h b/src/text_selection_controller.h index 634ec4a9a7..162ee7974b 100644 --- a/src/text_selection_controller.h +++ b/src/text_selection_controller.h @@ -57,6 +57,7 @@ class TextSelectionController { int GetStagedInsertionPoint() const { return has_staged_selection ? staged_selection_end : insertion_point; } void SetControl(wxStyledTextCtrl *ctrl); + wxStyledTextCtrl* GetControl() const {return ctrl;} ~TextSelectionController(); DEFINE_SIGNAL_ADDERS(AnnounceSelectionChanged, AddSelectionListener) From beebc26c9e0824e40a90fcc54c3f62efc527437d Mon Sep 17 00:00:00 2001 From: nuhah100 Date: Tue, 28 Mar 2023 02:17:33 +0300 Subject: [PATCH 2/2] simple RTL support --- src/command/edit.cpp | 12 +++++++++++- src/subs_edit_ctrl.cpp | 23 +++++++++++++++++++++-- src/subs_edit_ctrl.h | 1 + src/utils.cpp | 5 +++++ src/utils.h | 5 +++++ 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/command/edit.cpp b/src/command/edit.cpp index e6a7550b0b..b09009edfe 100644 --- a/src/command/edit.cpp +++ b/src/command/edit.cpp @@ -1274,7 +1274,9 @@ struct edit_text_ltr final : public Command { STR_HELP("Change the direction of the text to LTR") void operator()(agi::Context *c) override { - c->textSelectionController->GetControl()->SetLayoutDirection (wxLayout_LeftToRight); + if (c->textSelectionController->GetControl()->GetLayoutDirection() != wxLayout_LeftToRight) { + c->textSelectionController->GetControl()->SetLayoutDirection (wxLayout_LeftToRight); + } } }; @@ -1286,7 +1288,15 @@ struct edit_text_rtl final : public Command { STR_HELP("Change the direction of the text to RTL") void operator()(agi::Context *c) override { + if (c->textSelectionController->GetControl()->GetLayoutDirection() == wxLayout_RightToLeft) + return; + c->textSelectionController->GetControl()->SetLayoutDirection (wxLayout_RightToLeft); + wxString data = c->textSelectionController->GetControl()->GetText(); + if (data.StartsWith(RTL_MARK) != false) { + data.insert(0, RTL_MARK); + c->textSelectionController->GetControl()->SetTextRaw(data.c_str()); + } } }; diff --git a/src/subs_edit_ctrl.cpp b/src/subs_edit_ctrl.cpp index c0d353dc45..4028be8d2a 100644 --- a/src/subs_edit_ctrl.cpp +++ b/src/subs_edit_ctrl.cpp @@ -109,6 +109,7 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, a using std::bind; Bind(wxEVT_CHAR_HOOK, &SubsTextEditCtrl::OnKeyDown, this); + Bind(wxEVT_CHAR, &SubsTextEditCtrl::OnChar, this); Bind(wxEVT_MENU, bind(&SubsTextEditCtrl::Cut, this), EDIT_MENU_CUT); Bind(wxEVT_MENU, bind(&SubsTextEditCtrl::Copy, this), EDIT_MENU_COPY); @@ -166,8 +167,6 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, a UpdateStyle(); SetFocus(); }, EDIT_MENU_REMOVE_FROM_DICT); - - SetLayoutDirection (wxLayout_RightToLeft); } SubsTextEditCtrl::~SubsTextEditCtrl() { @@ -193,6 +192,26 @@ void SubsTextEditCtrl::OnLoseFocus(wxFocusEvent &event) { event.Skip(); } +void SubsTextEditCtrl::OnChar(wxKeyEvent &event) { + event.Skip(); + + // TODO upgrade system to support both RTL and LTR by fixing data + if (GetTextRaw().length() == 0) { + if (IsCharRTL(event.GetUnicodeKey())) + { + SetTextTo(RTL_MARK); + SetLayoutDirection(wxLayout_RightToLeft); + SetSelection(GetSelectionStart() + 5, GetSelectionStart() + 5); + } + else + { + SetLayoutDirection(wxLayout_LeftToRight); + } + } + + +} + void SubsTextEditCtrl::OnKeyDown(wxKeyEvent &event) { event.Skip(); diff --git a/src/subs_edit_ctrl.h b/src/subs_edit_ctrl.h index ccb38f4f85..a8dfcb8530 100644 --- a/src/subs_edit_ctrl.h +++ b/src/subs_edit_ctrl.h @@ -87,6 +87,7 @@ class SubsTextEditCtrl final : public wxStyledTextCtrl { void OnSetThesLanguage(wxCommandEvent &event); void OnLoseFocus(wxFocusEvent &event); void OnKeyDown(wxKeyEvent &event); + void OnChar(wxKeyEvent &event); void SetSyntaxStyle(int id, wxFont &font, std::string const& name, wxColor const& default_background); void Subscribe(std::string const& name); diff --git a/src/utils.cpp b/src/utils.cpp index a66f8b68f6..b482f3a6ae 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -96,6 +96,11 @@ int SmallestPowerOf2(int x) { return x; } +bool IsCharRTL(wxChar c) { + // only hebrew for now + return (((wxChar)0x5d0) <= c) && (c <= ((wxChar)0x5ea)); +} + #ifndef __WXMAC__ void RestartAegisub() { config::opt->Flush(); diff --git a/src/utils.h b/src/utils.h index bb82570d6b..83f8e667e2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -42,6 +42,11 @@ class wxMouseEvent; class wxStyledTextCtrl; class wxWindow; +const std::string LRT_MARK = "\u202A"; +const std::string RTL_MARK = "\u202B"; + +bool IsCharRTL(wxChar c); + wxString PrettySize(int bytes); std::string float_to_string(double val, int precision = 3);