+ 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;
+#else
+ int create_it = 1;
+#endif
+
+ mwindow->undo->update_undo_before(_("mask shape"), this);
+
+// Get existing keyframe
+ gui->get_keyframe(track, autos, keyframe,
+ mask, point, create_it);
+ if( track ) {
+#ifdef USE_KEYFRAME_SPANNING
+ MaskAuto temp_keyframe(mwindow->edl, autos);
+ temp_keyframe.copy_data(keyframe);
+ keyframe = &temp_keyframe;
+ mask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
+#endif
+ if( mask ) {
+ builtin_shape(shape, mask);
+#ifdef USE_KEYFRAME_SPANNING
+ autos->update_parameter(keyframe);
+#endif
+ gui->update();
+ gui->update_preview(1);
+ }
+ }
+ mwindow->undo->update_undo_after(_("mask shape"), LOAD_AUTOMATION);
+ return 1;
+}
+
+void CWindowMaskGUI::load_masks(ArrayList<SubMask *> &masks)
+{
+ char path[BCTEXTLEN];
+ sprintf(path, "%s/%s", File::get_config_path(), MASKS_FILE);
+ FileSystem fs;
+ fs.complete_path(path);
+ FileXML file;
+ file.read_from_file(path, 1);
+
+ masks.remove_all_objects();
+ int result;
+ while( !(result = file.read_tag()) ) {
+ if( file.tag.title_is("MASK") ) {
+ SubMask *sub_mask = new SubMask(0, -1);
+ char name[BCTEXTLEN]; name[0] = 0;
+ file.tag.get_property("NAME", name);
+ strncpy(sub_mask->name, name, sizeof(sub_mask->name));
+ sub_mask->load(&file);
+ masks.append(sub_mask);
+ }
+ }
+}
+
+void CWindowMaskGUI::save_masks(ArrayList<SubMask *> &masks)
+{
+ FileXML file;
+ for( int i=0; i<masks.size(); ++i ) {
+ SubMask *sub_mask = masks[i];
+ sub_mask->copy(&file);
+ }
+ file.terminate_string();
+
+ char path[BCTEXTLEN];
+ sprintf(path, "%s/%s", File::get_config_path(), MASKS_FILE);
+ FileSystem fs;
+ fs.complete_path(path);
+ file.write_to_file(path);