autoTableEditor TableEditor_create (const char32 *title, Table table) { try { autoTableEditor me = Thing_new (TableEditor); Editor_init (me.get(), 0, 0, 700, 500, title, table); #if motif Melder_assert (XtWindow (my drawingArea -> d_widget)); #endif my topRow = 1; my leftColumn = 1; my selectedColumn = 1; my selectedRow = 1; my graphics = Graphics_create_xmdrawingarea (my drawingArea); double size_pixels = SIZE_INCHES * Graphics_getResolution (my graphics.get()); Graphics_setWsViewport (my graphics.get(), 0.0, size_pixels, 0.0, size_pixels); Graphics_setWsWindow (my graphics.get(), 0.0, size_pixels, 0.0, size_pixels); Graphics_setViewport (my graphics.get(), 0.0, size_pixels, 0.0, size_pixels); Graphics_setFont (my graphics.get(), kGraphics_font_COURIER); Graphics_setFontSize (my graphics.get(), 12); Graphics_setUnderscoreIsSubscript (my graphics.get(), false); Graphics_setAtSignIsLink (my graphics.get(), true); return me; } catch (MelderError) { Melder_throw (U"TableEditor not created."); } }
autoPicture Picture_create (GuiDrawingArea drawingArea, bool sensitive) { try { autoPicture me = Thing_new (Picture); my drawingArea = drawingArea; /* * The initial viewport is a rectangle 6 inches wide and 4 inches high. */ my selx1 = 0.0; my selx2 = 6.0; my sely1 = 8.0; my sely2 = 12.0; my sensitive = sensitive && drawingArea; if (drawingArea) { /* The drawing area must have been realized; see manual at XtWindow. */ my graphics = Graphics_create_xmdrawingarea (my drawingArea); GuiDrawingArea_setExposeCallback (my drawingArea, gui_drawingarea_cb_expose, me.get()); } else { /* * Create a dummy Graphics. */ my graphics = Graphics_create (600); } Graphics_setWsWindow (my graphics, 0.0, 12.0, 0.0, 12.0); Graphics_setViewport (my graphics, my selx1, my selx2, my sely1, my sely2); if (my sensitive) { my selectionGraphics = Graphics_create_xmdrawingarea (my drawingArea); Graphics_setWindow (my selectionGraphics, 0, 12, 0, 12); GuiDrawingArea_setClickCallback (my drawingArea, gui_drawingarea_cb_click, me.get()); } Graphics_startRecording (my graphics); return me; } catch (MelderError) { Melder_throw (U"Picture not created."); } }
static void gui_drawingarea_cb_resize (I, GuiDrawingAreaResizeEvent event) { iam (RunnerMFC); if (my graphics == NULL) return; Graphics_setWsViewport (my graphics, 0, event -> width, 0, event -> height); Graphics_setWsWindow (my graphics, 0, event -> width, 0, event -> height); Graphics_setViewport (my graphics, 0, event -> width, 0, event -> height); Graphics_updateWs (my graphics); }
Graphics_Viewport Graphics_insetViewport (Graphics me, double x1rel, double x2rel, double y1rel, double y2rel) { trace (U"enter"); Graphics_Viewport previous; previous.x1NDC = my d_x1NDC; previous.x2NDC = my d_x2NDC; previous.y1NDC = my d_y1NDC; previous.y2NDC = my d_y2NDC; Graphics_setViewport (me, (1 - x1rel) * my d_x1NDC + x1rel * my d_x2NDC, x2rel * my d_x2NDC + (1 - x2rel) * my d_x1NDC, (1 - y1rel) * my d_y1NDC + y1rel * my d_y2NDC, y2rel * my d_y2NDC + (1 - y2rel) * my d_y1NDC); return previous; }
Graphics_Viewport Graphics_insetViewport (I, double x1rel, double x2rel, double y1rel, double y2rel) { iam (Graphics); Graphics_Viewport previous; previous.x1NDC = my x1NDC; previous.x2NDC = my x2NDC; previous.y1NDC = my y1NDC; previous.y2NDC = my y2NDC; Graphics_setViewport (me, (1 - x1rel) * my x1NDC + x1rel * my x2NDC, x2rel * my x2NDC + (1 - x2rel) * my x1NDC, (1 - y1rel) * my y1NDC + y1rel * my y2NDC, y2rel * my y2NDC + (1 - y2rel) * my y1NDC); return previous; }
void Graphics_resetViewport (Graphics me, Graphics_Viewport viewport) { trace (U"enter"); Graphics_setViewport (me, viewport.x1NDC, viewport.x2NDC, viewport.y1NDC, viewport.y2NDC); }
int HyperPage_script (I, double width_inches, double height_inches, const wchar_t *script) { iam (HyperPage); wchar_t *text = Melder_wcsdup_f (script); Interpreter interpreter = Interpreter_createFromEnvironment (NULL); double topSpacing = 0.1, bottomSpacing = 0.1, minFooterDistance = 0.0; kGraphics_font font = my font; int size = my fontSize; double true_width_inches = width_inches * ( width_inches < 0.0 ? -1.0 : size / 12.0 ); double true_height_inches = height_inches * ( height_inches < 0.0 ? -1.0 : size / 12.0 ); if (! my printing) { my d_y -= ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0; if (my d_y > PAGE_HEIGHT + true_height_inches || my d_y < PAGE_HEIGHT - SCREEN_HEIGHT) { my d_y -= true_height_inches; } else { my d_y -= true_height_inches; Graphics_setFont (my g, font); Graphics_setFontStyle (my g, 0); Graphics_setFontSize (my g, size); my d_x = true_width_inches > my rightMargin ? 0 : 0.5 * (my rightMargin - true_width_inches); Graphics_setWrapWidth (my g, 0); long x1DCold, x2DCold, y1DCold, y2DCold; Graphics_inqWsViewport (my g, & x1DCold, & x2DCold, & y1DCold, & y2DCold); double x1NDCold, x2NDCold, y1NDCold, y2NDCold; Graphics_inqWsWindow (my g, & x1NDCold, & x2NDCold, & y1NDCold, & y2NDCold); { if (my praatApplication == NULL) my praatApplication = Melder_calloc_f (structPraatApplication, 1); if (my praatObjects == NULL) my praatObjects = Melder_calloc_f (structPraatObjects, 1); if (my praatPicture == NULL) my praatPicture = Melder_calloc_f (structPraatPicture, 1); theCurrentPraatApplication = (PraatApplication) my praatApplication; theCurrentPraatApplication -> batch = true; // prevent creation of editor windows theCurrentPraatApplication -> topShell = theForegroundPraatApplication. topShell; // needed for UiForm_create () in dialogs theCurrentPraatObjects = (PraatObjects) my praatObjects; theCurrentPraatPicture = (PraatPicture) my praatPicture; theCurrentPraatPicture -> graphics = my g; // has to draw into HyperPage rather than Picture window theCurrentPraatPicture -> font = font; theCurrentPraatPicture -> fontSize = size; theCurrentPraatPicture -> lineType = Graphics_DRAWN; theCurrentPraatPicture -> colour = Graphics_BLACK; theCurrentPraatPicture -> lineWidth = 1.0; theCurrentPraatPicture -> arrowSize = 1.0; theCurrentPraatPicture -> x1NDC = my d_x; theCurrentPraatPicture -> x2NDC = my d_x + true_width_inches; theCurrentPraatPicture -> y1NDC = my d_y; theCurrentPraatPicture -> y2NDC = my d_y + true_height_inches; Graphics_setViewport (my g, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC); Graphics_setWindow (my g, 0.0, 1.0, 0.0, 1.0); long x1DC, y1DC, x2DC, y2DC; Graphics_WCtoDC (my g, 0.0, 0.0, & x1DC, & y2DC); Graphics_WCtoDC (my g, 1.0, 1.0, & x2DC, & y1DC); Graphics_resetWsViewport (my g, x1DC, x2DC, y1DC, y2DC); Graphics_setWsWindow (my g, 0, width_inches, 0, height_inches); theCurrentPraatPicture -> x1NDC = 0; theCurrentPraatPicture -> x2NDC = width_inches; theCurrentPraatPicture -> y1NDC = 0; theCurrentPraatPicture -> y2NDC = height_inches; Graphics_setViewport (my g, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC); { // scope autoMelderProgressOff progress; autoMelderWarningOff warning; autoMelderSaveDefaultDir saveDir; if (! MelderDir_isNull (& my rootDirectory)) { Melder_setDefaultDir (& my rootDirectory); } try { Interpreter_run (interpreter, text); } catch (MelderError) { if (my scriptErrorHasBeenNotified) { Melder_clearError (); } else { Melder_flushError (NULL); my scriptErrorHasBeenNotified = true; } } } Graphics_setLineType (my g, Graphics_DRAWN); Graphics_setLineWidth (my g, 1.0); Graphics_setArrowSize (my g, 1.0); Graphics_setColour (my g, Graphics_BLACK); /*Graphics_Link *paragraphLinks; long numberOfParagraphLinks = Graphics_getLinks (& paragraphLinks); if (my links) for (long ilink = 1; ilink <= numberOfParagraphLinks; ilink ++) { HyperLink link = HyperLink_create (paragraphLinks [ilink]. name, paragraphLinks [ilink]. x1, paragraphLinks [ilink]. x2, paragraphLinks [ilink]. y1, paragraphLinks [ilink]. y2); Collection_addItem (my links, link); }*/ theCurrentPraatApplication = & theForegroundPraatApplication; theCurrentPraatObjects = & theForegroundPraatObjects; theCurrentPraatPicture = & theForegroundPraatPicture; } Graphics_resetWsViewport (my g, x1DCold, x2DCold, y1DCold, y2DCold); Graphics_setWsWindow (my g, x1NDCold, x2NDCold, y1NDCold, y2NDCold); Graphics_setViewport (my g, 0, 1, 0, 1); Graphics_setWindow (my g, 0, 1, 0, 1); Graphics_setTextAlignment (my g, Graphics_LEFT, Graphics_BOTTOM); } } else { Graphics_setFont (my ps, font); Graphics_setFontStyle (my ps, 0); Graphics_setFontSize (my ps, size); my d_y -= my d_y == PAPER_TOP - TOP_MARGIN ? 0 : ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0; my d_y -= true_height_inches; if (my d_y < PAPER_BOTTOM + BOTTOM_MARGIN + minFooterDistance) { Graphics_nextSheetOfPaper (my ps); if (my d_printingPageNumber) my d_printingPageNumber ++; HyperPage_initSheetOfPaper (me); Graphics_setFont (my ps, font); Graphics_setFontSize (my ps, size); my d_y -= true_height_inches; } my d_x = 3.7 - 0.5 * true_width_inches; if (my d_x < 0) my d_x = 0; Graphics_setWrapWidth (my ps, 0); long x1DCold, x2DCold, y1DCold, y2DCold; Graphics_inqWsViewport (my ps, & x1DCold, & x2DCold, & y1DCold, & y2DCold); double x1NDCold, x2NDCold, y1NDCold, y2NDCold; Graphics_inqWsWindow (my ps, & x1NDCold, & x2NDCold, & y1NDCold, & y2NDCold); { if (my praatApplication == NULL) my praatApplication = Melder_calloc_f (structPraatApplication, 1); if (my praatObjects == NULL) my praatObjects = Melder_calloc_f (structPraatObjects, 1); if (my praatPicture == NULL) my praatPicture = Melder_calloc_f (structPraatPicture, 1); theCurrentPraatApplication = (PraatApplication) my praatApplication; theCurrentPraatApplication -> batch = true; theCurrentPraatApplication -> topShell = theForegroundPraatApplication. topShell; // needed for UiForm_create () in dialogs theCurrentPraatObjects = (PraatObjects) my praatObjects; theCurrentPraatPicture = (PraatPicture) my praatPicture; theCurrentPraatPicture -> graphics = my ps; theCurrentPraatPicture -> font = font; theCurrentPraatPicture -> fontSize = size; theCurrentPraatPicture -> lineType = Graphics_DRAWN; theCurrentPraatPicture -> colour = Graphics_BLACK; theCurrentPraatPicture -> lineWidth = 1.0; theCurrentPraatPicture -> arrowSize = 1.0; theCurrentPraatPicture -> x1NDC = my d_x; theCurrentPraatPicture -> x2NDC = my d_x + true_width_inches; theCurrentPraatPicture -> y1NDC = my d_y; theCurrentPraatPicture -> y2NDC = my d_y + true_height_inches; Graphics_setViewport (my ps, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC); Graphics_setWindow (my ps, 0.0, 1.0, 0.0, 1.0); long x1DC, y1DC, x2DC, y2DC; Graphics_WCtoDC (my ps, 0.0, 0.0, & x1DC, & y2DC); Graphics_WCtoDC (my ps, 1.0, 1.0, & x2DC, & y1DC); long shift = (long) (Graphics_getResolution (my ps) * true_height_inches) + (y1DCold - y2DCold); Graphics_resetWsViewport (my ps, x1DC, x2DC, y1DC + shift, y2DC + shift); Graphics_setWsWindow (my ps, 0, width_inches, 0, height_inches); theCurrentPraatPicture -> x1NDC = 0; theCurrentPraatPicture -> x2NDC = width_inches; theCurrentPraatPicture -> y1NDC = 0; theCurrentPraatPicture -> y2NDC = height_inches; Graphics_setViewport (my ps, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC); { // scope autoMelderProgressOff progress; autoMelderWarningOff warning; autoMelderSaveDefaultDir saveDir; if (! MelderDir_isNull (& my rootDirectory)) { Melder_setDefaultDir (& my rootDirectory); } try { Interpreter_run (interpreter, text); } catch (MelderError) { Melder_clearError (); } } Graphics_setLineType (my ps, Graphics_DRAWN); Graphics_setLineWidth (my ps, 1.0); Graphics_setArrowSize (my ps, 1.0); Graphics_setColour (my ps, Graphics_BLACK); theCurrentPraatApplication = & theForegroundPraatApplication; theCurrentPraatObjects = & theForegroundPraatObjects; theCurrentPraatPicture = & theForegroundPraatPicture; } Graphics_resetWsViewport (my ps, x1DCold, x2DCold, y1DCold, y2DCold); Graphics_setWsWindow (my ps, x1NDCold, x2NDCold, y1NDCold, y2NDCold); Graphics_setViewport (my ps, 0, 1, 0, 1); Graphics_setWindow (my ps, 0, 1, 0, 1); Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM); } my previousBottomSpacing = bottomSpacing; forget (interpreter); Melder_free (text); return 1; }
void Graphics_resetViewport (I, Graphics_Viewport viewport) { iam (Graphics); Graphics_setViewport (me, viewport.x1NDC, viewport.x2NDC, viewport.y1NDC, viewport.y2NDC); }