+void CWindowMaskLoadList::create_objects()
+{
+ shape_items.remove_all_objects();
+ ArrayList<SubMask *> masks;
+ gui->load_masks(masks);
+ for( int i=0; i<masks.size(); ++i )
+ shape_items.append(new CWindowMaskItem(masks[i]->name, i));
+ masks.remove_all_objects();
+ update(&shape_items, 0, 0, 1);
+}
+
+CWindowMaskLoad::CWindowMaskLoad(MWindow *mwindow,
+ CWindowMaskGUI *gui, int x, int y, int w)
+ : BC_Button(x, y, mwindow->theme->get_image_set("mask_prst_load_images"))
+{
+ this->mwindow = mwindow;
+ this->gui = gui;
+ set_tooltip(_("Load preset"));
+}
+
+int CWindowMaskLoad::handle_event()
+{
+ gui->mask_load_list->create_objects();
+ int px, py;
+ get_abs_cursor(px, py);
+ return gui->mask_load_list->activate(px, py, xS(120),yS(160));
+}
+
+
+CWindowMaskSave::CWindowMaskSave(MWindow *mwindow,
+ CWindowMaskGUI *gui, int x, int y, int w)
+ : BC_Button(x, y, mwindow->theme->get_image_set("mask_prst_save_images"))
+{
+ this->mwindow = mwindow;
+ this->gui = gui;
+ set_tooltip(_("Save preset"));
+}
+
+CWindowMaskSave::~CWindowMaskSave()
+{
+}
+
+int CWindowMaskSave::handle_event()
+{
+ Track *track;
+ MaskAutos *autos;
+ MaskAuto *keyframe;
+ SubMask *mask;
+ MaskPoint *point;
+ gui->get_keyframe(track, autos, keyframe, mask, point, 0);
+ if( track ) {
+ int sx = 0, sy = 0;
+ gui->get_abs_cursor(sx, sy);
+ if( !gui->preset_dialog )
+ gui->preset_dialog = new CWindowMaskPresetDialog(mwindow, gui);
+ gui->preset_dialog->start_dialog(sx, sy, keyframe);
+ }
+ return 1;
+}
+
+CWindowMaskPresetDialog::CWindowMaskPresetDialog(MWindow *mwindow, CWindowMaskGUI *gui)
+ : BC_DialogThread()
+{
+ this->mwindow = mwindow;
+ this->gui = gui;
+ pgui = 0;
+}
+
+CWindowMaskPresetDialog::~CWindowMaskPresetDialog()
+{
+ close_window();
+}
+
+void CWindowMaskPresetDialog::handle_close_event(int result)
+{
+ pgui = 0;
+}
+
+void CWindowMaskPresetDialog::handle_done_event(int result)
+{
+ if( result ) return;
+ const char *nm = pgui->preset_text->get_text();
+ if( keyframe )
+ gui->save_mask(nm);
+ else
+ gui->del_mask(nm);
+}
+
+BC_Window* CWindowMaskPresetDialog::new_gui()
+{
+ pgui = new CWindowMaskPresetGUI(this, sx, sy,
+ keyframe ? _(PROGRAM_NAME ": Save Mask") :
+ _(PROGRAM_NAME ": Delete Mask"));
+ pgui->create_objects();
+ return pgui;
+}
+
+void CWindowMaskPresetDialog::start_dialog(int sx, int sy, MaskAuto *keyframe)
+{
+ close_window();
+ this->sx = sx; this->sy = sy;
+ this->keyframe = keyframe;
+ start();
+}
+
+CWindowMaskPresetGUI::CWindowMaskPresetGUI(CWindowMaskPresetDialog *preset_dialog,
+ int x, int y, const char *title)
+ : BC_Window(title, x, y, xS(320), yS(100), xS(320), yS(100), 0, 0, 1)
+{
+ this->preset_dialog = preset_dialog;
+// *** CONTEXT_HELP ***
+ context_help_set_keyword("Masks");
+}
+
+void CWindowMaskPresetGUI::create_objects()
+{
+ int xs8 = xS(8), xs10 = xS(10);
+ int ys10 = yS(10);
+ int x = xs10, y = ys10;
+ lock_window("CWindowMaskPresetGUI::create_objects");
+ BC_Title *title;
+ add_subwindow(title = new BC_Title(x, y,
+ preset_dialog->keyframe ? _("Save mask:") : _("Delete mask:")));
+ int x1 = x + title->get_w() + xs8;
+ int x2 = get_w() - x - xs8 - x1 -
+ BC_WindowBase::get_resources()->listbox_button[0]->get_w();
+ CWindowMaskGUI *gui = preset_dialog->gui;
+ preset_text = new CWindowMaskPresetText(this,
+ x1, y, x2, yS(120), gui->mask_name->get_text());
+ preset_text->create_objects();
+ preset_text->set_tooltip(_("Mask name"));
+ preset_text->update_items();
+ add_subwindow(new BC_OKButton(this));
+ add_subwindow(new BC_CancelButton(this));
+ show_window();
+ raise_window();
+ unlock_window();
+}
+
+CWindowMaskPresetText::CWindowMaskPresetText(CWindowMaskPresetGUI *pgui,
+ int x, int y, int w, int h, const char *text)
+ : BC_PopupTextBox(pgui, 0, text, x, y, w, h)
+{
+ this->pgui = pgui;
+}
+
+int CWindowMaskPresetText::handle_event()
+{
+ int k = get_number();
+ if( k >= 0 && k<mask_items.size() )
+ update(mask_items[k]->get_text());
+ return 1;
+}
+
+void CWindowMaskPresetText::update_items()
+{
+ mask_items.remove_all_objects();
+ ArrayList<SubMask *> masks;
+ pgui->preset_dialog->gui->load_masks(masks);
+ for( int i=0; i<masks.size(); ++i ) {
+ char text[BCSTRLEN]; memset(text, 0, sizeof(text));
+ strncpy(text, masks[i]->name, sizeof(text)-1);
+ mask_items.append(new CWindowMaskItem(text));
+ }
+ masks.remove_all_objects();
+ update_list(&mask_items);
+}
+
+
+CWindowMaskDelete::CWindowMaskDelete(MWindow *mwindow,
+ CWindowMaskGUI *gui, int x, int y, int w)
+ : BC_Button(x, y, mwindow->theme->get_image_set("mask_prst_trsh_images"))
+{
+ this->mwindow = mwindow;
+ this->gui = gui;
+ set_tooltip(_("Delete preset"));
+}
+
+int CWindowMaskDelete::handle_event()
+{
+ int sx = 0, sy = 0;
+ gui->get_abs_cursor(sx, sy);
+ if( !gui->preset_dialog )
+ gui->preset_dialog = new CWindowMaskPresetDialog(mwindow, gui);
+ gui->preset_dialog->start_dialog(sx, sy, 0);
+ return 1;
+}
+
+
+CWindowMaskCenter::CWindowMaskCenter(MWindow *mwindow,
+ CWindowMaskGUI *gui, int x, int y, int w)
+ : BC_Button(x, y, mwindow->theme->get_image_set("mask_pstn_cen_images"))
+{
+ this->mwindow = mwindow;
+ this->gui = gui;
+ set_tooltip(_("center mask"));
+}
+
+int CWindowMaskCenter::handle_event()
+{
+ return gui->center_mask();
+}
+
+
+CWindowMaskNormal::CWindowMaskNormal(MWindow *mwindow,
+ CWindowMaskGUI *gui, int x, int y, int w)
+ : BC_Button(x, y, mwindow->theme->get_image_set("mask_pstn_nrm_images"))
+{
+ this->mwindow = mwindow;
+ this->gui = gui;
+ set_tooltip(_("normalize mask"));
+}
+
+int CWindowMaskNormal::handle_event()
+{
+ return gui->normal_mask();
+}
+
+
+CWindowMaskShape::CWindowMaskShape(MWindow *mwindow, CWindowMaskGUI *gui,
+ const char *images, int shape, int x, int y, const char *tip)
+ : BC_Button(x, y, mwindow->theme->get_image_set(images))
+{
+ this->mwindow = mwindow;
+ this->gui = gui;
+ this->shape = shape;
+ set_tooltip(tip);
+}
+
+CWindowMaskShape::~CWindowMaskShape()
+{
+}
+
+void CWindowMaskShape::builtin_shape(int i, SubMask *sub_mask)
+{
+ int out_w = mwindow->edl->session->output_w;
+ int out_h = mwindow->edl->session->output_h;
+ float cx = out_w/2.f, cy = out_h/2.f;
+ float r = bmax(cx, cy) / 4.f;
+ double c = 4*(sqrt(2.)-1)/3; // bezier aprox circle
+ float r2 = r / 2.f, rc = r*c, r4 = r / 4.f;
+ MaskPoint *pt = 0;
+ MaskPoints &points = sub_mask->points;
+ points.remove_all_objects();
+ switch( i ) {
+ case MASK_SHAPE_SQUARE:
+ points.append(pt = new MaskPoint());
+ pt->x = cx - r; pt->y = cy - r;
+ points.append(pt = new MaskPoint());
+ pt->x = cx + r; pt->y = cy - r;
+ points.append(pt = new MaskPoint());
+ pt->x = cx + r; pt->y = cy + r;
+ points.append(pt = new MaskPoint());
+ pt->x = cx - r; pt->y = cy + r;
+ break;
+ case MASK_SHAPE_CIRCLE:
+ points.append(pt = new MaskPoint());
+ pt->x = cx - r; pt->y = cy - r;
+ pt->control_x1 = -rc; pt->control_y1 = rc;
+ pt->control_x2 = rc; pt->control_y2 = -rc;
+ points.append(pt = new MaskPoint());
+ pt->x = cx + r; pt->y = cy - r;
+ pt->control_x1 = -rc; pt->control_y1 = -rc;
+ pt->control_x2 = rc; pt->control_y2 = rc;
+ points.append(pt = new MaskPoint());
+ pt->x = cx + r; pt->y = cy + r;
+ pt->control_x1 = rc; pt->control_y1 = -rc;
+ pt->control_x2 = -rc; pt->control_y2 = rc;
+ points.append(pt = new MaskPoint());
+ pt->x = cx - r; pt->y = cy + r;
+ pt->control_x1 = rc; pt->control_y1 = rc;
+ pt->control_x2 = -rc; pt->control_y2 = -rc;
+ break;
+ case MASK_SHAPE_TRIANGLE:
+ points.append(pt = new MaskPoint());
+ pt->x = cx + 0; pt->y = cy - r*(sqrt(3.)-1.);
+ points.append(pt = new MaskPoint());
+ pt->x = cx + r; pt->y = cy + r;
+ points.append(pt = new MaskPoint());
+ pt->x = cx - r; pt->y = cy + r;
+ break;
+ case MASK_SHAPE_OVAL:
+ points.append(pt = new MaskPoint());
+ pt->x = cx - r; pt->y = cy - r2;
+ pt->control_x1 = -r2; pt->control_y1 = r4;
+ pt->control_x2 = r2; pt->control_y2 = -r4;
+ points.append(pt = new MaskPoint());
+ pt->x = cx + r; pt->y = cy - r2;
+ pt->control_x1 = -r2; pt->control_y1 = -r4;
+ pt->control_x2 = r2; pt->control_y2 = r4;
+ points.append(pt = new MaskPoint());
+ pt->x = cx + r; pt->y = cy + r2;
+ pt->control_x1 = r2; pt->control_y1 = -r4;
+ pt->control_x2 = -r2; pt->control_y2 = r4;
+ points.append(pt = new MaskPoint());
+ pt->x = cx - r; pt->y = cy + r2;
+ pt->control_x1 = r2; pt->control_y1 = r4;
+ pt->control_x2 = -r2; pt->control_y2 = -r4;
+ break;
+ }
+}
+
+int CWindowMaskShape::handle_event()
+{
+ MaskAutos *autos;
+ MaskAuto *keyframe;
+ Track *track;
+ MaskPoint *point;
+ SubMask *mask;
+#ifdef USE_KEYFRAME_SPANNING
+ int create_it = 0;