+
+#pragma mark - STARTCapuj
+
+ job->anamorphic.mode = 3;
+
+ /* Set the status of our custom ana only widgets accordingly */
+ /* for mod 3 we can use modulus other than 16 */
+ [fModulusPopUp setEnabled:YES];
+ job->anamorphic.modulus = [[fModulusPopUp titleOfSelectedItem] intValue];
+
+ [fWidthStepper setEnabled: YES];
+ [fWidthField setEnabled: YES];
+
+ [fHeightStepper setEnabled: YES];
+ /* for capuj the storage field is immaterial */
+ [fHeightField setEnabled: YES];
+
+ [fRatioCheck setEnabled: YES];
+ if (sender == fRatioCheck)
+ {
+ if ([fRatioCheck state] == NSOnState)
+ {
+ [fParWidthField setEnabled: NO];
+ [fParHeightField setEnabled: NO];
+ }
+ else
+ {
+ [fParWidthField setEnabled: YES];
+ [fParHeightField setEnabled: YES];
+ }
+ }
+
+ [fParWidthField setEnabled: YES];
+ [fParHeightField setEnabled: YES];
+
+ [fDisplayWidthField setEnabled: YES];
+
+
+ /* If we are coming into custom anamorphic we reset the par to original
+ * which gives us a way back if things get hosed up.
+ */
+
+ if (sender == fAnamorphicPopUp)
+ {
+ /* When entering custom anamorphic, we start with keep ar on */
+ [fRatioCheck setState: NSOnState];
+ /*
+ KEEPING ASPECT RATIO
+ Disable editing: PIXEL WIDTH, PIXEL HEIGHT
+ */
+ [fParWidthField setEnabled: NO];
+ [fParHeightField setEnabled: NO];
+
+ job->width = [fWidthStepper intValue];
+ job->height = [fHeightStepper intValue];
+
+ /* make sure our par is set back to original */
+ job->anamorphic.par_width = titleParWidth;
+ job->anamorphic.par_height = titleParHeight;
+
+ [fParWidthField setIntValue: titleParWidth];
+ [fParHeightField setIntValue: titleParHeight];
+
+ /* modify our par dims from our storage dims */
+ hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
+ float par_display_width = (float)output_width * (float)output_par_width / (float)output_par_height;
+
+ /* go ahead and mod the display dims */
+ [fDisplayWidthField setStringValue: [NSString stringWithFormat:@"%.2f", par_display_width]];
+
+ job->anamorphic.dar_width = [fDisplayWidthField floatValue];
+ job->anamorphic.dar_height = (float)[fHeightStepper intValue];
+
+ /* Set our dar here assuming we are just coming into capuj mode */
+ dar = [fDisplayWidthField floatValue] / (float)[fHeightField intValue];
+
+ }
+
+ /* For capuj we disable these fields if we are keeping the dispay aspect */
+ if ([fRatioCheck state] == NSOnState)
+ {
+ /*
+ KEEPING ASPECT RATIO
+ DAR = DISPLAY WIDTH / DISPLAY HEIGHT (cache after every modification) */
+ /*Disable editing: PIXEL WIDTH, PIXEL HEIGHT */
+
+ [fParWidthField setEnabled: NO];
+ [fParHeightField setEnabled: NO];
+
+ /* Changing DISPLAY WIDTH: */
+ if (sender == fDisplayWidthField)
+ {
+ job->anamorphic.dar_width = [fDisplayWidthField floatValue];
+ /* Changes HEIGHT to keep DAR */
+ /* calculate the height to retain the dar */
+ int raw_calulated_height = (int)((int)[fDisplayWidthField floatValue] / dar);
+ /* now use the modulus to go lower if there is a remainder */
+ /* Note to me, raw_calulated_height % [[fModulusPopUp titleOfSelectedItem] intValue]
+ * gives me the remainder we are not mod (whatever our modulus is) subtract that from
+ * the actual calculated value derived from the dar to round down to the nearest mod value.
+ * This should be desireable over rounding up to the next mod value
+ */
+ int modulus_height = raw_calulated_height - (raw_calulated_height % [[fModulusPopUp titleOfSelectedItem] intValue]);
+ if (modulus_height > fTitle->height)
+ {
+ [fHeightStepper setMaxValue: modulus_height];
+ }
+ [fHeightStepper setIntValue: modulus_height];
+ job->anamorphic.dar_height = (float)[fHeightStepper intValue];
+ job->height = [fHeightStepper intValue];
+
+ /* Changes PIXEL WIDTH to new DISPLAY WIDTH */
+ [fParWidthField setIntValue: [fDisplayWidthField intValue]];
+ job->anamorphic.par_width = [fParWidthField intValue];
+ /* Changes PIXEL HEIGHT to STORAGE WIDTH */
+ [fParHeightField setIntValue: [fWidthField intValue]];
+ job->anamorphic.par_height = [fParHeightField intValue];
+
+ }
+ /* Changing HEIGHT: */
+ if (sender == fHeightStepper)
+ {
+ job->anamorphic.dar_height = (float)[fHeightStepper intValue];
+ job->height = [fHeightStepper intValue];
+
+ /* Changes DISPLAY WIDTH to keep DAR*/
+ [fDisplayWidthField setStringValue: [NSString stringWithFormat: @"%.2f",[fHeightStepper intValue] * dar]];
+ job->anamorphic.dar_width = [fDisplayWidthField floatValue];
+ /* Changes PIXEL WIDTH to new DISPLAY WIDTH */
+ [fParWidthField setIntValue: [fDisplayWidthField intValue]];
+ job->anamorphic.par_width = [fParWidthField intValue];
+ /* Changes PIXEL HEIGHT to STORAGE WIDTH */
+ [fParHeightField setIntValue: [fWidthField intValue]];
+ job->anamorphic.par_height = [fParHeightField intValue];
+ }
+ /* Changing STORAGE_WIDTH: */
+ if (sender == fWidthStepper)
+ {
+ job->width = [fWidthStepper intValue];
+
+ job->anamorphic.dar_width = [fDisplayWidthField floatValue];
+ job->anamorphic.dar_height = [fHeightStepper floatValue];
+
+ /* Changes PIXEL WIDTH to DISPLAY WIDTH */
+ [fParWidthField setIntValue: [fDisplayWidthField intValue]];
+ job->anamorphic.par_width = [fParWidthField intValue];
+ /* Changes PIXEL HEIGHT to new STORAGE WIDTH */
+ [fParHeightField setIntValue: [fWidthStepper intValue]];
+ job->anamorphic.par_height = [fParHeightField intValue];
+ }
+ }
+ else if ([fRatioCheck state] == NSOffState)
+ {
+ /* Changing STORAGE_WIDTH: */
+ if (sender == fWidthStepper)
+ {
+ job->width = [fWidthStepper intValue];
+ /* changes DISPLAY WIDTH to STORAGE WIDTH * PIXEL WIDTH / PIXEL HEIGHT */
+ [fDisplayWidthField setStringValue: [NSString stringWithFormat: @"%.2f",(float)[fWidthStepper intValue] * [fParWidthField intValue] / [fParHeightField intValue]]];
+ job->anamorphic.dar_width = [fDisplayWidthField floatValue];
+ }
+ /* Changing PIXEL dimensions */
+ if (sender == fParWidthField || sender == fParHeightField)
+ {
+ job->anamorphic.par_width = [fParWidthField intValue];
+ job->anamorphic.par_height = [fParHeightField intValue];
+ /* changes DISPLAY WIDTH to STORAGE WIDTH * PIXEL WIDTH / PIXEL HEIGHT */
+ [fDisplayWidthField setStringValue: [NSString stringWithFormat: @"%.2f",(float)[fWidthStepper intValue] * [fParWidthField intValue] / [fParHeightField intValue]]];
+ job->anamorphic.dar_width = [fDisplayWidthField floatValue];
+ }
+ /* Changing DISPLAY WIDTH: */
+ if (sender == fDisplayWidthField)
+ {
+ job->anamorphic.dar_width = [fDisplayWidthField floatValue];
+ job->anamorphic.dar_height = (float)[fHeightStepper intValue];
+ /* changes PIXEL WIDTH to DISPLAY WIDTH and PIXEL HEIGHT to STORAGE WIDTH */
+ [fParWidthField setIntValue: [fDisplayWidthField intValue]];
+ job->anamorphic.par_width = [fParWidthField intValue];
+
+ [fParHeightField setIntValue: [fWidthField intValue]];
+ job->anamorphic.par_height = [fParHeightField intValue];
+ hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
+ }
+ /* Changing HEIGHT: */
+ if (sender == fHeightStepper)
+ {
+ /* just....changes the height.*/
+ job->anamorphic.dar_height = [fHeightStepper intValue];
+ job->height = [fHeightStepper intValue];
+ }
+
+ }
+
+#pragma mark - END Capuj
+ }
+
+ /* if the sender is the Anamorphic checkbox, record the state
+ of KeepAspect Ratio so it can be reset if Anamorphic is unchecked again */
+ if (sender == fAnamorphicPopUp)
+ {
+ keepAspectRatioPreviousState = [fRatioCheck state];
+ }
+ if ([fAnamorphicPopUp indexOfSelectedItem] != 3)
+ {
+ [fRatioCheck setState:NSOffState];
+ }
+
+ }
+ else
+ {
+ job->width = [fWidthStepper intValue];
+ job->height = [fHeightStepper intValue];
+ job->anamorphic.mode = 0;
+ [fWidthStepper setEnabled: YES];
+ [fWidthField setEnabled: YES];
+ [fHeightStepper setEnabled: YES];
+ [fHeightField setEnabled: YES];
+ [fRatioCheck setEnabled: YES];
+ /* if the sender is the Anamorphic checkbox, we return the
+ keep AR checkbox to its previous state */
+ if (sender == fAnamorphicPopUp)
+ {
+ [fRatioCheck setState:keepAspectRatioPreviousState];
+ }
+
+ }
+
+ //job->keep_ratio = ( [fRatioCheck state] == NSOnState );
+
+ if ([fAnamorphicPopUp indexOfSelectedItem] != 3)
+ {
+ job->keep_ratio = ( [fRatioCheck state] == NSOnState );
+ if( job->keep_ratio )
+ {
+ if( sender == fWidthStepper || sender == fRatioCheck ||
+ sender == fCropTopStepper || sender == fCropBottomStepper )