X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fswindow.C;h=423dd55d0ada2e3e1ec1cd2fa51346ac65ac3b65;hp=65799c4bba5ac82c55fc71ee4588c1535ed16dda;hb=a4de4732339bf38b5b225c533be1bdf60748f04a;hpb=5820b5f022aeec75ec03f7dd0121aa8a3d7f7590 diff --git a/cinelerra-5.1/cinelerra/swindow.C b/cinelerra-5.1/cinelerra/swindow.C index 65799c4b..423dd55d 100644 --- a/cinelerra-5.1/cinelerra/swindow.C +++ b/cinelerra-5.1/cinelerra/swindow.C @@ -5,6 +5,7 @@ #include "cstrdup.h" #include "edl.h" #include "filesystem.h" +#include "language.h" #include "localsession.h" #include "mainerror.h" #include "mainmenu.h" @@ -75,27 +76,15 @@ SWindowLoadPath::SWindowLoadPath(SWindowGUI *gui, int x, int y, char *path) : BC_TextBox(x, y, 200, 1, path) { this->sw_gui = gui; - - file_entries = new ArrayList; - FileSystem fs; char string[BCTEXTLEN]; -// Load current directory - fs.update(getcwd(string, BCTEXTLEN)); - int total_files = fs.total_files(); - for(int i = 0; i < total_files; i++) { - const char *name = fs.get_entry(i)->get_name(); - file_entries->append(new BC_ListBoxItem(name)); - } } SWindowLoadPath::~SWindowLoadPath() { - file_entries->remove_all_objects(); - delete file_entries; } int SWindowLoadPath::handle_event() { - calculate_suggestions(file_entries); + calculate_suggestions(); strcpy(sw_gui->script_path, get_text()); return 1; } @@ -113,9 +102,14 @@ SWindowLoadFile::~SWindowLoadFile() int SWindowLoadFile::handle_event() { - sw_gui->load_path->set_suggestions(0,0); - sw_gui->load_script(); - sw_gui->set_script_pos(0); + if( sw_gui->script_path[0] ) { + sw_gui->load_path->set_suggestions(0,0); + sw_gui->load_script(); + sw_gui->set_script_pos(0); + } + else { + eprintf(_("script text file path required")); + } return 1; } @@ -131,7 +125,12 @@ SWindowSaveFile::~SWindowSaveFile() int SWindowSaveFile::handle_event() { - sw_gui->save_spumux_data(); + if( sw_gui->script_path[0] ) { + sw_gui->save_spumux_data(); + } + else { + eprintf(_("script microdvd file path required")); + } return 1; } @@ -182,11 +181,16 @@ void SWindowGUI::create_objects() x1 = x + pad; blank_line = new char[2]; blank_line[0] = ' '; blank_line[1] = 0; - int rows = (ok_y - y - 4*pad) / text_rowsz - 3; - int w1 = get_w()-x1-pad; + add_subwindow(script_title = new BC_Title(x1, y, _("Script Text:"))); + y += script_title->get_h() + pad; + int rows = (ok_y - y - BC_Title::calculate_h(this,_("Line Text:")) - + 4*pad) / text_rowsz - 3; + int w1 = get_w() - x1 - pad; script_entry = new ScriptEntry(this, x1, y, w1, rows, blank_line); script_entry->create_objects(); y += script_entry->get_h() + pad; + add_subwindow(line_title = new BC_Title(x1, y, _("Line Text:"))); + y += line_title->get_h() + pad; line_entry = new ScriptEntry(this, x1, y, w1, 3); line_entry->create_objects(); ok = new SWindowOK(this, ok_x, ok_y); @@ -197,19 +201,36 @@ void SWindowGUI::create_objects() void SWindowGUI::load() { + const char *script_text = + _("Adding Subtitles: quick \"How To\" (= or * indicates comment)\n" + "*2345678901234567890123456789012345678901234567890123456789\n" + "For regular DVD subtitles, put script in a text file. " + "Lines can be any length but they will be broken up " + "to fit according to some criteria below.\n" + "Running text used as script lines will be broken into multilple lines.\n" + "The target line length is 60 characters.\n" + "Punctuation may be flagged to create an early line break.\n" + "Single carriage return ends an individual script line.\n" + "Double carriage return indicates the end of an entry.\n" + "Whitespace at beginning or end of line is removed.\n" + "You can edit the active line in the Line Text box.\n" + "\n" + "== A new entry is here for illustration purposes.\n" + "* Entry 2\n" + "This is the second entry.\n"); + if( script_path[0] && !access(script_path,R_OK) ) { load_script(); - int text_no = script_text_no; - script_text_no = -1; - load_selection(script_entry_no, text_no); } else { - script.remove_all_objects(); script_path[0] = 0; load_path->update(script_path); - script_entry_no = 0; - script_text_no = 0; + FILE *fp = fmemopen((void *)script_text, strlen(script_text), "r"); + load_script(fp); } + int text_no = script_text_no; + script_text_no = -1; + load_selection(script_entry_no, text_no); } SWindowGUI::SWindowGUI(SWindow *swindow, int x, int y, int w, int h) @@ -297,10 +318,14 @@ int SWindowGUI::resize_event(int w, int h) int w1 = w - x1 - pad; script_scroll->reposition_window(x1, y, w1); y += hh + 2*pad; + script_title->reposition_window(x, y); + y += script_title->get_h() + pad; w1 = w - x - pad; - int rows = (ok_y - y - 4*pad) / text_rowsz - 3; + int rows = (ok_y - y - line_title->get_h() - 4*pad) / text_rowsz - 3; script_entry->reposition_window(x, y, w1, rows); - y += script_entry->get_h() + pad; + y += script_entry->get_h() + 2*pad; + line_title->reposition_window(x, y); + y += line_title->get_h() + pad; line_entry->reposition_window(x, y, w1, 3); return 0; } @@ -342,8 +367,9 @@ int SWindowGUI::load_selection(int pos, int row) script_entry->set_text_row(0); } script_text_no = row; - char line[BCTEXTLEN], *bp = line, *cp = rp; - while( *cp && *cp!='\n' ) *bp++ = *cp++; + char line[BCTEXTLEN], *bp = line; + char *ep = bp+sizeof(line)-1, *cp = rp; + while( bp < ep && *cp && *cp!='\n' ) *bp++ = *cp++; *bp = 0; bp = texts->text; int char1 = rp-bp, char2 = cp-bp; script_entry->set_selection(char1, char2, char2); @@ -602,15 +628,15 @@ int ScriptLines::break_lines() memmove(cp,sp,dp+1-sp); used -= n; dp -= n; ep -= n; } - // constrain line_limit - if( (n=(ep-cp)/2) < limit2 || n > line_limit ) + // target about half remaining line, constrain line_limit + if( (n=(ep-1-cp)/2) < limit2 || n > line_limit ) n = line_limit; - // search for last punct, last space + // search for last punct, last space before line_limit for( bp=cp, pp=sp=0; --n>=0 && cp= limit4 ) @@ -709,11 +735,26 @@ ScriptEntry::~ScriptEntry() void ScriptEntry::set_text(char *text, int isz) { if( !text || !*text ) return; - if( isz < 0 ) isz = strlen(text); + if( isz < 0 ) isz = strlen(text)+1; BC_ScrollTextBox::set_text(text, isz); ttext = text; } +int ScriptEntry::handle_event() +{ + if( sw_gui->get_button_down() && + sw_gui->get_buttonpress() == 1 && + sw_gui->get_triple_click() ) { + int ibeam = get_ibeam_letter(), row = 0; + const char *tp = ttext; + while( *tp && tp-ttext < ibeam ) { + if( *tp++ == '\n' ) ++row; + } + int pos = sw_gui->script_entry_no; + sw_gui->load_selection(pos, row); + } + return 1; +} int SWindowGUI::load_script_line(FILE *fp) { @@ -731,10 +772,10 @@ int SWindowGUI::load_script_line(FILE *fp) for(;;) { // load non-blank lines //int len = strlen(line); - //if( cp[len-1] == '\n' ) cp[len-1] = 0; + //if( line[len-1] == '\n' ) line[len-1] = ' '; entry->append(line); char *cp = fgets(line,sizeof(line),fp); - if( !cp ) return 1; + if( !cp ) break; ++script_line_no; while( *cp && isspace(*cp) ) ++cp; if( !*cp ) break; @@ -752,7 +793,11 @@ void SWindowGUI::load_script() MainError::show_error(string); return; } + load_script(fp); +} +void SWindowGUI::load_script(FILE *fp) +{ script.remove_all_objects(); script_line_no = 0; script_text_lines = 0; @@ -760,11 +805,11 @@ void SWindowGUI::load_script() char value[64]; sprintf(value,"%ld",ftell(fp)); script_filesz->update(value); - sprintf(value,"%ld",script_line_no); + sprintf(value,"%jd",script_line_no); script_lines->update(value); sprintf(value,"%d",script.size()); script_entries->update(value); - sprintf(value,"%ld",script_text_lines); + sprintf(value,"%jd",script_text_lines); script_texts->update(value); int hw = 2*script_scroll->get_h(); script_scroll->update_length(script.size(), script_entry_no, hw, 0); @@ -795,6 +840,10 @@ void SWindowGUI::save_spumux_data() *cp = 0; snprintf(ext,len,"-%s.udvd",track_title); FILE *fp = fopen(filename, "w"); + if( !fp ) { + eprintf(_("Unable to open %s:\n%m"), filename); + continue; + } int64_t start = 0; for( Edit *edit=track->edits->first; edit; edit=edit->next ) { SEdit *sedit = (SEdit *)edit; @@ -802,7 +851,7 @@ void SWindowGUI::save_spumux_data() int64_t end = start + sedit->length; char *text = sedit->get_text(); if( *text ) { - fprintf(fp, "{%ld}{%ld}%s\n", start, end-1, text); + fprintf(fp, "{%jd}{%jd}%s\n", start, end-1, text); } start = end; } @@ -852,8 +901,8 @@ void SWindow::stop() if( gui ) gui->stop(1); window_lock->unlock(); Thread::cancel(); - Thread::join(); } + Thread::join(); } void SWindow::run()