From ee3178a8e185292162f6265e14d92750b7bc211e Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Wed, 28 Mar 2007 01:11:52 +0000 Subject: [PATCH] Fixed replace bug (#338) and cleaned search and replace code up a bit. Originally committed to SVN as r957. --- aegisub/dialog_search_replace.cpp | 79 +++++++++++++------------------ aegisub/dialog_search_replace.h | 1 + aegisub/video_frame.cpp | 39 +++++++++++---- 3 files changed, 65 insertions(+), 54 deletions(-) diff --git a/aegisub/dialog_search_replace.cpp b/aegisub/dialog_search_replace.cpp index db82d679c..0922047b7 100644 --- a/aegisub/dialog_search_replace.cpp +++ b/aegisub/dialog_search_replace.cpp @@ -190,9 +190,12 @@ void DialogSearchReplace::OnKeyDown (wxKeyEvent &event) { } -///////////// -// Find next -void DialogSearchReplace::OnFindNext (wxCommandEvent &event) { +/////////////////// +// Find or replace +void DialogSearchReplace::FindReplace(int mode) { + // Check mode + if (mode < 0 || mode > 2) return; + // Variables wxString LookFor = FindEdit->GetValue(); if (LookFor.IsEmpty()) return; @@ -205,67 +208,50 @@ void DialogSearchReplace::OnFindNext (wxCommandEvent &event) { Search.CanContinue = true; Search.affect = Affect->GetSelection(); Search.field = Field->GetSelection(); - Search.FindNext(); - - if (hasReplace) { + + // Find + if (mode == 0) { + Search.FindNext(); + if (hasReplace) { + wxString ReplaceWith = ReplaceEdit->GetValue(); + Search.ReplaceWith = ReplaceWith; + Options.AddToRecentList(ReplaceWith,_T("Recent replace")); + } + } + + // Replace + else { wxString ReplaceWith = ReplaceEdit->GetValue(); Search.ReplaceWith = ReplaceWith; + if (mode == 1) Search.ReplaceNext(); + else Search.ReplaceAll(); Options.AddToRecentList(ReplaceWith,_T("Recent replace")); - } - + } + // Add to history Options.AddToRecentList(LookFor,_T("Recent find")); UpdateDropDowns(); } +///////////// +// Find next +void DialogSearchReplace::OnFindNext (wxCommandEvent &event) { + FindReplace(0); +} + + //////////////// // Replace next void DialogSearchReplace::OnReplaceNext (wxCommandEvent &event) { - // Variables - wxString LookFor = FindEdit->GetValue(); - wxString ReplaceWith = ReplaceEdit->GetValue(); - if (LookFor.IsEmpty()) return; - - // Setup - Search.isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled(); - Search.matchCase = CheckMatchCase->IsChecked(); - Search.LookFor = LookFor; - Search.ReplaceWith = ReplaceWith; - Search.affect = Affect->GetSelection(); - Search.field = Field->GetSelection(); - Search.updateVideo = CheckUpdateVideo->IsChecked() && CheckUpdateVideo->IsEnabled(); - Search.ReplaceNext(); - - // Add to history - Options.AddToRecentList(LookFor,_T("Recent find")); - Options.AddToRecentList(ReplaceWith,_T("Recent replace")); - UpdateDropDowns(); + FindReplace(1); } /////////////// // Replace all void DialogSearchReplace::OnReplaceAll (wxCommandEvent &event) { - // Setup - wxString LookFor = FindEdit->GetValue(); - wxString ReplaceWith = ReplaceEdit->GetValue(); - if (LookFor.IsEmpty()) return; - - // Do search - Search.isReg = CheckRegExp->IsChecked() && CheckRegExp->IsEnabled(); - Search.matchCase = CheckMatchCase->IsChecked(); - Search.LookFor = LookFor; - Search.ReplaceWith = ReplaceWith; - Search.affect = Affect->GetSelection(); - Search.field = Field->GetSelection(); - Search.updateVideo = CheckUpdateVideo->IsChecked() && CheckUpdateVideo->IsEnabled(); - Search.ReplaceAll(); - - // Add to history - Options.AddToRecentList(LookFor,_T("Recent find")); - Options.AddToRecentList(ReplaceWith,_T("Recent replace")); - UpdateDropDowns(); + FindReplace(2); } @@ -509,6 +495,7 @@ void SearchReplaceEngine::ReplaceAll() { if (count > 0) { grid->ass->FlagAsModified(_("replace")); grid->CommitChanges(); + grid->editBox->Update(); wxMessageBox(wxString::Format(_("%i matches were replaced."),count)); } diff --git a/aegisub/dialog_search_replace.h b/aegisub/dialog_search_replace.h index 1d21b7554..508aeb9ad 100644 --- a/aegisub/dialog_search_replace.h +++ b/aegisub/dialog_search_replace.h @@ -105,6 +105,7 @@ private: wxRadioBox *Field; void UpdateDropDowns(); + void FindReplace(int mode); // 0 = find, 1 = replace next, 2 = replace all void OnClose (wxCommandEvent &event); void OnFindNext (wxCommandEvent &event); diff --git a/aegisub/video_frame.cpp b/aegisub/video_frame.cpp index 95161511a..d31c77744 100644 --- a/aegisub/video_frame.cpp +++ b/aegisub/video_frame.cpp @@ -42,6 +42,10 @@ ///////// // Reset void AegiVideoFrame::Reset() { + // Note that this function DOES NOT unallocate memory. + // Use Clear() for that + + // Zero variables for (int i=0;i<4;i++) { data[i] = NULL; pitch[i] = 0; @@ -49,6 +53,8 @@ void AegiVideoFrame::Reset() { memSize = 0; w = 0; h = 0; + + // Set properties format = FORMAT_NONE; flipped = false; cppAlloc = true; @@ -66,19 +72,25 @@ AegiVideoFrame::AegiVideoFrame() { ////////////////// // Create default AegiVideoFrame::AegiVideoFrame(int width,int height,VideoFrameFormat fmt) { + // Clear Reset(); + + // Set format format = fmt; w = width; h = height; pitch[0] = w * GetBpp(); - - Allocate(); - for (int i=0;i<4;i++) { - int height = h; - if (format == FORMAT_YV12 && i > 0) height/=2; - int size = pitch[i]*height; - memset(data[0],0,size); + if (fmt == FORMAT_YV12) { + pitch[1] = w/2; + pitch[2] = w/2; } + + // Allocate + Allocate(); + + // Clear data + int size = pitch[0]*height + (pitch[1]+pitch[2])*height/2; + memset(data[0],0,size); } @@ -126,8 +138,11 @@ void AegiVideoFrame::Allocate() { ///////// // Clear void AegiVideoFrame::Clear() { + // Free memory if (cppAlloc) delete[] data[0]; else free(data[0]); + + // Zero variables for (int i=0;i<4;i++) { data[i] = NULL; pitch[i] = 0; @@ -135,7 +150,9 @@ void AegiVideoFrame::Clear() { memSize = 0; w = 0; h = 0; - format = FORMAT_RGB24; + + // Reset properties + format = FORMAT_NONE; flipped = false; cppAlloc = true; invertChannels = true; @@ -161,6 +178,7 @@ void AegiVideoFrame::CopyFrom(const AegiVideoFrame &source) { // ------ // This function is only used on screenshots, so it doesn't have to be fast wxImage AegiVideoFrame::GetImage() const { + // RGB if (format == FORMAT_RGB32 || format == FORMAT_RGB24) { // Create unsigned char *buf = (unsigned char*)malloc(w*h*3); @@ -189,6 +207,11 @@ wxImage AegiVideoFrame::GetImage() const { return img; } + // YV12 + //else if (format == FORMAT_YV12) { + // TODO + //} + else { return wxImage(w,h); }