home *** CD-ROM | disk | FTP | other *** search
/ Geek 6 / Geek-006.iso / linux / video / xmovie-1.5.3.tar.gz / xmovie-1.5.3.tar / xmovie-1.5.3 / xmovie / settings.C < prev    next >
C/C++ Source or Header  |  2000-11-29  |  10KB  |  438 lines

  1. #include "asset.h"
  2. #include "file.h"
  3. #include "mainwindow.h"
  4. #include "mainmenu.h"
  5. #include "mwindowgui.h"
  6. #include "settings.h"
  7.  
  8. #include <string.h>
  9.  
  10. SettingsThread::SettingsThread(MainWindow *mwindow)
  11.  : Thread()
  12. {
  13.     this->mwindow = mwindow;
  14.     thread_running = 0;
  15. }
  16. SettingsThread::~SettingsThread()
  17. {
  18. }
  19.  
  20. void SettingsThread::run()
  21. {
  22.     if(thread_running) return;
  23.     thread_running = 1;
  24.  
  25.     aspect_w = mwindow->aspect_w;
  26.     aspect_h = mwindow->aspect_h;
  27.     letter_w = mwindow->letter_w;
  28.     letter_h = mwindow->letter_h;
  29.     smp = mwindow->smp;
  30.     mmx = mwindow->use_mmx;
  31.     square_pixels = mwindow->square_pixels;
  32.     crop_letterbox = mwindow->crop_letterbox;
  33.     prebuffer_size = mwindow->prebuffer_size;
  34.     convert_601 = mwindow->convert_601;
  35.     audio_priority = mwindow->audio_priority;
  36.  
  37.     change_lock.lock();
  38.     SettingsWindow window(mwindow, this);
  39.     window.initialize();
  40.     this->window = &window;
  41.     change_lock.unlock();
  42.  
  43.     int result = window.run_window();
  44.     if(!result)
  45.     {
  46.         mwindow->stop_playback();
  47.         if(mwindow->prebuffer_size != prebuffer_size)
  48.         {
  49.             mwindow->error_thread->show_error("You must restart XMovie for the changes\nto take effect.");
  50.         }
  51.         
  52.         if(mwindow->smp != smp || mwindow->use_mmx != mmx)
  53.         {
  54.             mwindow->smp = smp;
  55.             mwindow->use_mmx = mmx;
  56.             if(mwindow->video_file)
  57.             {
  58.                 mwindow->video_file->lock_read();
  59.                 mwindow->video_file->set_processors(smp + 1);
  60.                 mwindow->video_file->set_mmx(mmx);
  61.                 mwindow->video_file->unlock_read();
  62.             }
  63.             if(mwindow->audio_file)
  64.             {
  65.                 mwindow->audio_file->lock_read();
  66.                 mwindow->audio_file->set_processors(smp + 1);
  67.                 mwindow->audio_file->set_mmx(mmx);
  68.                 mwindow->audio_file->unlock_read();
  69.             }
  70.         }
  71.  
  72.         if(aspect_w <= 0) aspect_w = 1;
  73.         if(aspect_h <= 0) aspect_h = 1;
  74.         mwindow->aspect_w = aspect_w;
  75.         mwindow->aspect_h = aspect_h;
  76.         mwindow->letter_w = letter_w;
  77.         mwindow->letter_h = letter_h;
  78.         mwindow->square_pixels = square_pixels;
  79.         mwindow->crop_letterbox = crop_letterbox;
  80.         mwindow->convert_601 = convert_601;
  81.         mwindow->audio_priority = audio_priority;
  82.         mwindow->prebuffer_size = prebuffer_size;
  83.  
  84.         mwindow->save_defaults();
  85.  
  86. // Update GUI
  87.         if(mwindow->asset && mwindow->asset->video_data)
  88.         {
  89.             int w = mwindow->canvas_w;
  90.             mwindow->gui->lock_window();
  91.             mwindow->get_canvas_sizes(w);
  92.             mwindow->gui->resize_canvas(mwindow->canvas_w, mwindow->canvas_h);
  93.             mwindow->gui->unlock_window();
  94.         }
  95.  
  96.  
  97.         mwindow->gui->lock_window();
  98.         mwindow->flash_frame(mwindow->current_percentage);
  99.         mwindow->gui->canvas->flash();
  100.         mwindow->gui->unlock_window();
  101.     }
  102.  
  103. // Lock out changes to the framerate
  104.     change_lock.lock();
  105.     this->window = 0;
  106.     change_lock.unlock();
  107.     thread_running = 0;
  108. }
  109.  
  110. int SettingsThread::update_framerate()
  111. {
  112.     change_lock.lock();
  113.     if(window)
  114.     {
  115.         char string[1024];
  116.         sprintf(string, "%.02f", mwindow->actual_framerate);
  117.         window->lock_window();
  118.         window->frame_rate->update(string);
  119.         window->unlock_window();
  120.     }
  121.     change_lock.unlock();
  122.     return 0;
  123. }
  124.  
  125.  
  126.  
  127. SettingsWindow::SettingsWindow(MainWindow *mwindow, SettingsThread *thread)
  128.  : BC_Window("XMovie: Settings", 
  129.      mwindow->gui->get_abs_cursor_x(), 
  130.     mwindow->gui->get_abs_cursor_y(),
  131.     210, 
  132.     470, 
  133.     210, 
  134.     470,
  135.     0,
  136.     0,
  137.     1)
  138. {
  139.     this->mwindow = mwindow;
  140.     this->thread = thread;
  141. }
  142. SettingsWindow::~SettingsWindow()
  143. {
  144. }
  145.     
  146. int SettingsWindow::initialize()
  147. {
  148.     char string[1024];
  149.     int x, y;
  150.     BC_TextBox *textbox_w, *textbox_h;
  151.     
  152.     aspect_ratios.append(new BC_ListBoxItem("4:3"));
  153.     aspect_ratios.append(new BC_ListBoxItem("16:9"));
  154.     aspect_ratios.append(new BC_ListBoxItem("2.25:1"));
  155.     aspect_ratios.append(new BC_ListBoxItem("2.35:1"));
  156.     aspect_ratios.append(new BC_ListBoxItem("2.66:1"));
  157.     x = 10;
  158.     y = 10;
  159.     add_tool(new BC_Title(x, y, "Aspect ratio"));
  160.     y += 20;
  161.     sprintf(string, "%.2f", thread->aspect_w);
  162.     add_tool(textbox_w = new SettingsW(thread, x, y, string));
  163.     x += textbox_w->get_w() + 5;
  164.     add_tool(new BC_Title(x, y, ":"));
  165.     x += 10;
  166.     sprintf(string, "%.2f", thread->aspect_h);
  167.     add_tool(textbox_h = new SettingsH(thread, x, y, string));
  168.     x += textbox_h->get_w() + 5;
  169.     add_tool(new AspectPulldown(this, x, y, textbox_w, textbox_h, &thread->aspect_w, &thread->aspect_h));
  170.     y += 25;
  171.     x = 10;
  172.     add_tool(new SettingsEnableAspect(thread, x, y));
  173.     y += 40;
  174.     add_tool(new BC_Title(x, y, "Letterbox ratio:"));
  175.     y += 20;
  176.     sprintf(string, "%.2f", thread->letter_w);
  177.     add_tool(textbox_w = new SettingsLetterW(thread, x, y, string));
  178.     x += textbox_w->get_w() + 5;
  179.     add_tool(new BC_Title(x, y, ":"));
  180.     x += 10;
  181.     sprintf(string, "%.2f", thread->letter_h);
  182.     add_tool(textbox_h = new SettingsLetterH(thread, x, y, string));
  183.     x += textbox_h->get_w() + 5;
  184.     add_tool(new AspectPulldown(this, x, y, textbox_w, textbox_h, &thread->letter_w, &thread->letter_h));
  185.     y += 25;
  186.     x = 10;
  187.     add_tool(new SettingsEnableLetter(thread, x, y));
  188.     y += 40;
  189.     add_tool(new SettingsEnable601(thread, x, y));
  190.     y += 30;
  191.     add_tool(new SettingsSMP(thread, x, y));
  192.     y += 30;
  193.     add_tool(new SettingsMMX(thread, x, y));
  194.     y += 40;
  195.     add_tool(new BC_Title(x, y, "Audio Priority"));
  196.     y += 20;
  197.     sprintf(string, "%ld", thread->audio_priority);
  198.     add_tool(new SettingsAudioPri(thread, x, y, string));
  199.     y += 30;
  200.     add_tool(new BC_Title(x, y, "Preload size"));
  201.     y += 20;
  202.     sprintf(string, "%ld", thread->prebuffer_size);
  203.     add_tool(new SettingsPrebuff(thread, x, y, string));
  204.     y += 40;
  205.     add_tool(new BC_Title(x, y, "Actual framerate:"));
  206.     sprintf(string, "%.2f", mwindow->actual_framerate);
  207.     add_tool(frame_rate = new BC_Title(x + 130, y, string, MEDIUMFONT, RED));
  208.     y += 35;
  209.  
  210.     y = get_h() - 50;
  211.     x = 10;
  212.     add_tool(new BC_OKButton(x, y));
  213.     x = get_w() - 80;
  214.     add_tool(new BC_CancelButton(x, y));
  215.     show_window();
  216.     return 0;
  217. }
  218.  
  219. SettingsW::SettingsW(SettingsThread *thread, int x, int y, char *string)
  220.  : BC_TextBox(x, y, 60, 1, string)
  221. {
  222.     this->thread = thread;
  223. }
  224. SettingsW::~SettingsW()
  225. {
  226. }
  227. int SettingsW::handle_event()
  228. {
  229.     thread->aspect_w = atof(get_text());
  230.     return 1;
  231. }
  232.  
  233. SettingsH::SettingsH(SettingsThread *thread, int x, int y, char *string)
  234.  : BC_TextBox(x, y, 60, 1, string)
  235. {
  236.     this->thread = thread;
  237. }
  238. SettingsH::~SettingsH()
  239. {
  240. }
  241. int SettingsH::handle_event()
  242. {
  243.     thread->aspect_h = atof(get_text());
  244.     return 1;
  245. }
  246.  
  247. SettingsLetterW::SettingsLetterW(SettingsThread *thread, int x, int y, char *string)
  248.  : BC_TextBox(x, y, 60, 1, string)
  249. {
  250.     this->thread = thread;
  251. }
  252. SettingsLetterW::~SettingsLetterW()
  253. {
  254. }
  255. int SettingsLetterW::handle_event()
  256. {
  257.     thread->letter_w = atof(get_text());
  258.     return 1;
  259. }
  260.  
  261. SettingsLetterH::SettingsLetterH(SettingsThread *thread, int x, int y, char *string)
  262.  : BC_TextBox(x, y, 60, 1, string)
  263. {
  264.     this->thread = thread;
  265. }
  266. SettingsLetterH::~SettingsLetterH()
  267. {
  268. }
  269. int SettingsLetterH::handle_event()
  270. {
  271.     thread->letter_h = atof(get_text());
  272.     return 1;
  273. }
  274.  
  275.  
  276. SettingsPrebuff::SettingsPrebuff(SettingsThread *thread, int x, int y, char *string)
  277.  : BC_TextBox(x, y, 150, 1, string)
  278. {
  279.     this->thread = thread;
  280. }
  281. SettingsPrebuff::~SettingsPrebuff()
  282. {
  283. }
  284.     
  285. int SettingsPrebuff::handle_event()
  286. {
  287.     if(atol(get_text()) >= 0)
  288.         thread->prebuffer_size = atol(get_text());
  289.     return 1;
  290. }
  291.  
  292. SettingsAudioPri::SettingsAudioPri(SettingsThread *thread, int x, int y, char *string)
  293.  : BC_TextBox(x, y, 150, 1, string)
  294. {
  295.     this->thread = thread;
  296. }
  297. SettingsAudioPri::~SettingsAudioPri()
  298. {
  299. }
  300.     
  301. int SettingsAudioPri::handle_event()
  302. {
  303.     if(atol(get_text()) >= 0)
  304.         thread->audio_priority = atol(get_text());
  305.     return 1;
  306. }
  307.  
  308.  
  309. SettingsEnableAspect::SettingsEnableAspect(SettingsThread *thread, int x, int y)
  310.  : BC_CheckBox(x, y, !thread->square_pixels, "Enable aspect ratio")
  311. {
  312.     this->thread = thread;
  313.     set_tooltip("Force window size to\nconform to aspect ratio.");
  314. }
  315. SettingsEnableAspect::~SettingsEnableAspect()
  316. {
  317. }
  318. int SettingsEnableAspect::handle_event()
  319. {
  320.     thread->square_pixels = !get_value();
  321.     return 1;
  322. }
  323.  
  324. SettingsEnableLetter::SettingsEnableLetter(SettingsThread *thread, int x, int y)
  325.  : BC_CheckBox(x, y, thread->crop_letterbox, "Crop letterbox")
  326. {
  327.     this->thread = thread;
  328.     set_tooltip("Crop letterbox to conform\nto letterbox ratio.");
  329. }
  330. SettingsEnableLetter::~SettingsEnableLetter()
  331. {
  332. }
  333. int SettingsEnableLetter::handle_event()
  334. {
  335.     thread->crop_letterbox = get_value();
  336.     return 1;
  337. }
  338.  
  339. SettingsEnable601::SettingsEnable601(SettingsThread *thread, int x, int y)
  340.  : BC_CheckBox(x, y, thread->convert_601, "Convert 601 luminance")
  341. {
  342.     this->thread = thread;
  343.     set_tooltip("Expand luminance\n(required for hardware acceleration)");
  344. }
  345. SettingsEnable601::~SettingsEnable601()
  346. {
  347. }
  348. int SettingsEnable601::handle_event()
  349. {
  350.     thread->convert_601 = get_value();
  351.     return 1;
  352. }
  353.  
  354.  
  355. SettingsSMP::SettingsSMP(SettingsThread *thread, int x, int y)
  356.  : BC_CheckBox(x, y, thread->smp, "Enable SMP extensions")
  357. {
  358.     this->thread = thread;
  359.     set_tooltip("Use 2 CPUs to decompress video.");
  360. }
  361. SettingsSMP::~SettingsSMP()
  362. {
  363. }
  364.  
  365. int SettingsSMP::handle_event()
  366. {
  367.     thread->smp = get_value();
  368.     return 1;
  369. }
  370.  
  371.  
  372.  
  373.  
  374. SettingsMMX::SettingsMMX(SettingsThread *thread, int x, int y)
  375.  : BC_CheckBox(x, y, thread->mmx, "Enable MMX")
  376. {
  377.     this->thread = thread;
  378.     set_tooltip("Enable MMX.  (Lower quality)");
  379. }
  380. SettingsMMX::~SettingsMMX()
  381. {
  382. }
  383.  
  384. int SettingsMMX::handle_event()
  385. {
  386.     thread->mmx = get_value();
  387.     return 1;
  388. }
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396. AspectPulldown::AspectPulldown(SettingsWindow *window, 
  397.     int x, 
  398.     int y, 
  399.     BC_TextBox *textbox_w, 
  400.     BC_TextBox *textbox_h, 
  401.     float *output_w, 
  402.     float *output_h)
  403.  : BC_ListBox(x, y, 100, 100, 
  404.         LISTBOX_TEXT, 
  405.         &window->aspect_ratios, 
  406.         0, 
  407.         0, 
  408.         1, 
  409.         0, 
  410.         1)
  411. {
  412.     this->window = window;
  413.     this->textbox_w = textbox_w;
  414.     this->textbox_h = textbox_h;
  415.     this->output_w = output_w;
  416.     this->output_h = output_h;
  417. }
  418.  
  419. int AspectPulldown::handle_event()
  420. {
  421.     char string1[1024], *letter;
  422.     float w, h;
  423.  
  424.     strcpy(string1, get_selection(0, 0)->get_text());
  425.     letter = strchr(string1, ':');
  426.     *letter = 0;
  427.     w = atof(string1);
  428.     letter++;
  429.     h = atof(letter);
  430.     textbox_w->update(w);
  431.     textbox_h->update(h);
  432.     *output_w = w;
  433.     *output_h = h;
  434.     return 1;
  435. }
  436.  
  437.  
  438.