static void gui_drawingarea_cb_click (Picture me, GuiDrawingArea_ClickEvent event) { int xstart = event -> x; int ystart = event -> y; double xWC, yWC; int ixstart, iystart, ix, iy, oldix = 0, oldiy = 0; Graphics_DCtoWC (my selectionGraphics.get(), xstart, ystart, & xWC, & yWC); ix = ixstart = 1 + floor (xWC * SQUARES / SIDE); iy = iystart = SQUARES - floor (yWC * SQUARES / SIDE); if (ixstart < 1 || ixstart > SQUARES || iystart < 1 || iystart > SQUARES) return; if (event -> shiftKeyPressed) { int ix1 = 1 + floor (my selx1 * SQUARES / SIDE); int ix2 = floor (my selx2 * SQUARES / SIDE); int iy1 = SQUARES + 1 - floor (my sely2 * SQUARES / SIDE); int iy2 = SQUARES - floor (my sely1 * SQUARES / SIDE); ixstart = ix < (ix1 + ix2) / 2 ? ix2 : ix1; iystart = iy < (iy1 + iy2) / 2 ? iy2 : iy1; } //while (Graphics_mouseStillDown (my selectionGraphics)) { do { Graphics_getMouseLocation (my selectionGraphics.get(), & xWC, & yWC); ix = 1 + floor (xWC * SQUARES / SIDE); iy = SQUARES - floor (yWC * SQUARES / SIDE); if (ix >= 1 && ix <= SQUARES && iy >= 1 && iy <= SQUARES && (ix != oldix || iy != oldiy)) { int ix1, ix2, iy1, iy2; if (ix < ixstart) { ix1 = ix; ix2 = ixstart; } else { ix1 = ixstart; ix2 = ix; } if (iy < iystart) { iy1 = iy; iy2 = iystart; } else { iy1 = iystart; iy2 = iy; } if (my mouseSelectsInnerViewport) { int fontSize = Graphics_inqFontSize (my graphics.get()); double xmargin = fontSize * 4.2 / 72.0, ymargin = fontSize * 2.8 / 72.0; if (xmargin > ix2 - ix1 + 1) xmargin = ix2 - ix1 + 1; if (ymargin > iy2 - iy1 + 1) ymargin = iy2 - iy1 + 1; Picture_setSelection (me, 0.5 * (ix1 - 1) - xmargin, 0.5 * ix2 + xmargin, 0.5 * (SQUARES - iy2) - ymargin, 0.5 * (SQUARES + 1 - iy1) + ymargin, false); } else { Picture_setSelection (me, 0.5 * (ix1 - 1), 0.5 * ix2, 0.5 * (SQUARES - iy2), 0.5 * (SQUARES + 1 - iy1), false); } oldix = ix; oldiy = iy; } } while (Graphics_mouseStillDown (my selectionGraphics.get())); // } #if cocoa Graphics_updateWs (my selectionGraphics.get()); // to change the dark red back into black #endif if (my selectionChangedCallback) { //Melder_casual (U"selectionChangedCallback from gui_drawingarea_cb_click"); my selectionChangedCallback (me, my selectionChangedClosure, my selx1, my selx2, my sely1, my sely2); } }
bool structFormantGridEditor :: v_click (double xWC, double yWC, bool shiftKeyPressed) { FormantGrid grid = (FormantGrid) our data; Ordered tiers = editingBandwidths ? grid -> bandwidths : grid -> formants; RealTier tier = (RealTier) tiers -> item [selectedFormant]; double ymin = our editingBandwidths ? our p_bandwidthFloor : our p_formantFloor; double ymax = our editingBandwidths ? our p_bandwidthCeiling : our p_formantCeiling; long inearestPoint, ifirstSelected, ilastSelected; RealPoint nearestPoint; double dt = 0, df = 0; bool draggingSelection; /* * Perform the default action: move cursor. */ //d_startSelection = d_endSelection = xWC; our ycursor = (1.0 - yWC) * ymin + yWC * ymax; Graphics_setWindow (our d_graphics, our d_startWindow, our d_endWindow, ymin, ymax); yWC = our ycursor; /* * Clicked on a point? */ inearestPoint = AnyTier_timeToNearestIndex (tier, xWC); if (inearestPoint == 0) { return FormantGridEditor_Parent :: v_click (xWC, yWC, shiftKeyPressed); } nearestPoint = (RealPoint) tier -> points -> item [inearestPoint]; if (Graphics_distanceWCtoMM (our d_graphics, xWC, yWC, nearestPoint -> number, nearestPoint -> value) > 1.5) { return our FormantGridEditor_Parent :: v_click (xWC, yWC, shiftKeyPressed); } /* * Clicked on a selected point? */ draggingSelection = shiftKeyPressed && nearestPoint -> number > our d_startSelection && nearestPoint -> number < our d_endSelection; if (draggingSelection) { ifirstSelected = AnyTier_timeToHighIndex (tier, our d_startSelection); ilastSelected = AnyTier_timeToLowIndex (tier, our d_endSelection); Editor_save (this, U"Drag points"); } else { ifirstSelected = ilastSelected = inearestPoint; Editor_save (this, U"Drag point"); } /* * Drag. */ Graphics_xorOn (our d_graphics, Graphics_MAROON); drawWhileDragging (this, xWC, yWC, ifirstSelected, ilastSelected, dt, df); while (Graphics_mouseStillDown (our d_graphics)) { double xWC_new, yWC_new; Graphics_getMouseLocation (our d_graphics, & xWC_new, & yWC_new); if (xWC_new != xWC || yWC_new != yWC) { drawWhileDragging (this, xWC, yWC, ifirstSelected, ilastSelected, dt, df); dt += xWC_new - xWC, df += yWC_new - yWC; xWC = xWC_new, yWC = yWC_new; drawWhileDragging (this, xWC, yWC, ifirstSelected, ilastSelected, dt, df); } } Graphics_xorOff (our d_graphics); /* * Dragged inside window? */ if (xWC < d_startWindow || xWC > d_endWindow) return 1; /* * Points not dragged past neighbours? */ RealPoint *points = (RealPoint *) tier -> points -> item; double newTime = points [ifirstSelected] -> number + dt; if (newTime < our tmin) return 1; // outside domain if (ifirstSelected > 1 && newTime <= points [ifirstSelected - 1] -> number) return 1; // past left neighbour newTime = points [ilastSelected] -> number + dt; if (newTime > our tmax) return 1; // outside domain if (ilastSelected < tier -> points -> size && newTime >= points [ilastSelected + 1] -> number) return FunctionEditor_UPDATE_NEEDED; // past right neighbour /* * Drop. */ for (long i = ifirstSelected; i <= ilastSelected; i ++) { RealPoint point = (RealPoint) tier -> points -> item [i]; point -> number += dt; point -> value += df; } /* * Make sure that the same points are still selected (a problem with Undo...). */ if (draggingSelection) our d_startSelection += dt, our d_endSelection += dt; if (ifirstSelected == ilastSelected) { /* * Move crosshair to only selected formant point. */ RealPoint point = (RealPoint) tier -> points -> item [ifirstSelected]; our d_startSelection = our d_endSelection = point -> number; our ycursor = point -> value; } else { /* * Move crosshair to mouse location. */ /*our cursor += dt;*/ our ycursor += df; } Editor_broadcastDataChanged (this); return FunctionEditor_UPDATE_NEEDED; }
void Graphics_waitMouseUp (Graphics me) { while (Graphics_mouseStillDown (me)) { double xWC, yWC; Graphics_getMouseLocation (me, & xWC, & yWC); } }