Skip to content

Commit eaaf262

Browse files
committed
Merge pull request livecode#3539 from BerndN/patch-1
Keep selectedStops in front of unselected
2 parents 164babf + 64a49f3 commit eaaf262

2 files changed

Lines changed: 91 additions & 58 deletions

File tree

docs/notes/bugfix-16785.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Keep selectedStop in front of other stops in gradientrampeditor

extensions/widgets/gradientrampeditor/gradientrampeditor.lcb

Lines changed: 90 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Parameters:
3838
pIndex: The new selected stop index, or 0 if no stop is selected.
3939

4040
Example:
41-
on selectedStopChanged pIndex
41+
on selectedStopChanged pIndex
4242
if pIndex is 0 then
4343
exit selectedStopChanged
4444
end if
@@ -105,7 +105,7 @@ private handler configureDimensions() returns nothing
105105
put 10 into mMarginBottom
106106

107107
put (my width - (mMarginLeft + mMarginRight)) / 100 into mRulerSpacing
108-
108+
109109
put true into mShowNumbers
110110
if my width < 50 then
111111
put false into mShowNumbers
@@ -126,7 +126,7 @@ private handler configureDimensions() returns nothing
126126
put 5 into mRulerTextIncrement
127127
put 10 into mRulerLineHeight
128128
end if
129-
129+
130130
put 10 into mRulerTextSize
131131
put color [0.5, 0.5, 0.5] into mRulerColor
132132

@@ -242,8 +242,8 @@ Example:
242242

243243

244244
Description:
245-
If any gradient stop is selected, its index is returned by the <selectedStop>
246-
property. Otherwise the property returns 0. Setting the <selectedStop> property
245+
If any gradient stop is selected, its index is returned by the <selectedStop>
246+
property. Otherwise the property returns 0. Setting the <selectedStop> property
247247
to 0 causes the currently selected gradient stop to be deselected.
248248

249249
*/
@@ -306,7 +306,6 @@ public handler OnMouseUp() returns nothing
306306
OnMouseDoubleUp()
307307
else
308308
put false into mIsDraggingStop
309-
SetSelectedStop(xCoordToStopNumber(the x of the mouse position))
310309
gradientStopsChanged()
311310
end if
312311
end handler
@@ -381,13 +380,13 @@ end handler
381380
public handler OnPaint() returns nothing
382381
-- Draw the checker board that we place behind the gradient.
383382
paintCheckerboard()
384-
383+
385384
-- Draw the gradient on top of the checkerboard.
386385
paintGradient()
387386

388387
-- Draw the ruler above and below the gradient.
389388
paintRulerBottom()
390-
389+
391390
-- Draw the ramp points on top of the ruler.
392391
paintRampEditors()
393392
end handler
@@ -399,7 +398,7 @@ private handler paintCheckerboard() returns nothing
399398
-- Fill the entire widget canvas with the checkerboard then clip to the gradient region.
400399
variable tY as Real
401400
variable tX as Real
402-
401+
403402
begin layer on this canvas
404403
variable tStartAtZero as Boolean
405404
put true into tStartAtZero
@@ -485,6 +484,8 @@ end handler
485484
private handler paintRampEditors() returns nothing
486485
variable tY as Real
487486
variable tX as Real
487+
variable tHasSelected as Boolean
488+
put false into tHasSelected
488489
variable tStopIndex as Integer
489490
put 1 into tStopIndex
490491

@@ -493,71 +494,88 @@ private handler paintRampEditors() returns nothing
493494
put xCoordFromGradientOffset((the offset of tStop) * 100) into tX
494495
put the bottom of mGradientRectangle into tY
495496

497+
if tStopIndex = mCurrentlySelectedStopIndex then
498+
variable tSelStop as GradientStop
499+
put true into tHasSelected
500+
put tStop into tSelStop
501+
add 1 to tStopIndex
502+
next repeat
503+
end if
504+
505+
drawStop (tX, tY, tStop) -- BN
506+
507+
add 1 to tStopIndex
508+
509+
end repeat
510+
511+
if tHasSelected then
512+
put xCoordFromGradientOffset((the offset of tSelStop) * 100) into tX
513+
put the bottom of mGradientRectangle into tY
514+
515+
drawStop (tX, tY, tSelStop) -- BN
516+
517+
-- If this is the selected stop then draw an extra ramp point above the gradient and a line linking it.
496518
move to point [tX, tY] on this canvas
497-
line to point [tX, tY + mRulerLineHeight] on this canvas
519+
line to point [tX, tY - mRulerLineHeight] on this canvas
498520
set the paint of this canvas to solid paint with mGradientHandleBorderColor
521+
499522
set the stroke width of this canvas to 2
500523
stroke this canvas
501-
502524
variable tPath as Path
503525
put the empty path into tPath
504-
move to point [tX, tY + mRulerLineHeight] on tPath
505-
line to point [tX - 0.5 * mGradientHandleSize, tY + mRulerLineHeight + 0.5 * mGradientHandleSize] on tPath
506-
line to point [tX + 0.5 * mGradientHandleSize, tY + mRulerLineHeight + 0.5 * mGradientHandleSize] on tPath
507-
line to point [tX, tY + mRulerLineHeight] on tPath
526+
527+
move to point [tX, tY - mRulerLineHeight] on tPath
528+
line to point [tX - 0.5 * mGradientHandleSize, tY - mRulerLineHeight - 0.5 * mGradientHandleSize] on tPath
529+
line to point [tX + 0.5 * mGradientHandleSize, tY - mRulerLineHeight - 0.5 * mGradientHandleSize] on tPath
530+
line to point [tX, tY - mRulerLineHeight] on tPath
508531
set the paint of this canvas to solid paint with mGradientHandleBorderColor
509532
set the stroke width of this canvas to 2
510533
stroke tPath on this canvas
511-
512-
set the paint of this canvas to solid paint with color [1, 1, 1]
534+
set the paint of this canvas to solid paint with color [1.0, 1.0, 1.0]
513535
fill tPath on this canvas
514536
put the empty path into tPath
515-
put rectangle path of rectangle [tX - 0.5 * mGradientHandleSize, tY + mRulerLineHeight + 0.5 * mGradientHandleSize, tX + 0.5 * mGradientHandleSize, tY + mRulerLineHeight + 1.5 * mGradientHandleSize] into tPath
537+
put rectangle path of rectangle [tX - 0.5 * mGradientHandleSize, tY - mRulerLineHeight - 1.5 * mGradientHandleSize, tX + 0.5 * mGradientHandleSize, tY - mRulerLineHeight - 0.5 * mGradientHandleSize] into tPath
516538
set the paint of this canvas to solid paint with mGradientHandleBorderColor
517539
set the stroke width of this canvas to 2
518540
stroke tPath on this canvas
519-
set the paint of this canvas to solid paint with the color of tStop
541+
set the paint of this canvas to solid paint with the color of tSelStop
520542
fill tPath on this canvas
521543

522-
-- If this is the selected stop then draw an extra ramp point above the gradient and a line linking it.
523-
--
524-
if tStopIndex is mCurrentlySelectedStopIndex then
525-
put the top of mGradientRectangle into tY
526-
527-
move to point [tX, tY] on this canvas
528-
line to point [tX, tY - mRulerLineHeight] on this canvas
529-
set the paint of this canvas to solid paint with mGradientHandleBorderColor
530-
set the stroke width of this canvas to 2
531-
stroke this canvas
532-
533-
put the empty path into tPath
534-
move to point [tX, tY - mRulerLineHeight] on tPath
535-
line to point [tX - 0.5 * mGradientHandleSize, tY - mRulerLineHeight - 0.5 * mGradientHandleSize] on tPath
536-
line to point [tX + 0.5 * mGradientHandleSize, tY - mRulerLineHeight - 0.5 * mGradientHandleSize] on tPath
537-
line to point [tX, tY - mRulerLineHeight] on tPath
538-
set the paint of this canvas to solid paint with mGradientHandleBorderColor
539-
set the stroke width of this canvas to 2
540-
stroke tPath on this canvas
541-
set the paint of this canvas to solid paint with color [1.0, 1.0, 1.0]
542-
fill tPath on this canvas
543-
544-
put the empty path into tPath
545-
put rectangle path of rectangle [tX - 0.5 * mGradientHandleSize, tY - mRulerLineHeight - 1.5 * mGradientHandleSize, tX + 0.5 * mGradientHandleSize, tY - mRulerLineHeight - 0.5 * mGradientHandleSize] into tPath
546-
set the paint of this canvas to solid paint with mGradientHandleBorderColor
547-
set the stroke width of this canvas to 2
548-
stroke tPath on this canvas
549-
set the paint of this canvas to solid paint with the color of tStop
550-
fill tPath on this canvas
551-
552-
move to point [tX, the top of mGradientRectangle] on this canvas
553-
line to point [tX, the bottom of mGradientRectangle] on this canvas
554-
set the stroke width of this canvas to 2
555-
set the paint of this canvas to solid paint with mGradientHandleBorderColor
556-
stroke this canvas
544+
move to point [tX, the top of mGradientRectangle] on this canvas
545+
line to point [tX, the bottom of mGradientRectangle] on this canvas
546+
set the stroke width of this canvas to 2
547+
set the paint of this canvas to solid paint with mGradientHandleBorderColor
548+
stroke this canvas
557549
end if
558550

559-
add 1 to tStopIndex
560-
end repeat
551+
end handler
552+
553+
private handler DrawStop (in tX as Real, tY as Real, tStop as GradientStop) returns nothing
554+
move to point [tX, tY] on this canvas
555+
line to point [tX, tY + mRulerLineHeight] on this canvas
556+
set the paint of this canvas to solid paint with mGradientHandleBorderColor
557+
set the stroke width of this canvas to 2
558+
stroke this canvas
559+
560+
variable tPath as Path
561+
put the empty path into tPath
562+
move to point [tX, tY + mRulerLineHeight] on tPath
563+
line to point [tX - 0.5 * mGradientHandleSize, tY + mRulerLineHeight + 0.5 * mGradientHandleSize] on tPath
564+
line to point [tX + 0.5 * mGradientHandleSize, tY + mRulerLineHeight + 0.5 * mGradientHandleSize] on tPath
565+
line to point [tX, tY + mRulerLineHeight] on tPath
566+
set the paint of this canvas to solid paint with mGradientHandleBorderColor
567+
set the stroke width of this canvas to 2
568+
stroke tPath on this canvas
569+
570+
set the paint of this canvas to solid paint with color [1, 1, 1]
571+
fill tPath on this canvas
572+
put the empty path into tPath
573+
put rectangle path of rectangle [tX - 0.5 * mGradientHandleSize, tY + mRulerLineHeight + 0.5 * mGradientHandleSize, tX + 0.5 * mGradientHandleSize, tY + mRulerLineHeight + 1.5 * mGradientHandleSize] into tPath
574+
set the paint of this canvas to solid paint with mGradientHandleBorderColor
575+
set the stroke width of this canvas to 2
576+
stroke tPath on this canvas
577+
set the paint of this canvas to solid paint with the color of tStop
578+
fill tPath on this canvas
561579
end handler
562580

563581
private handler gradientStopsChanged() returns nothing
@@ -609,18 +627,32 @@ end handler
609627
private handler xCoordToStopNumber(in pX as Number) returns Integer
610628
variable tRampNumber as Integer
611629
put 1 into tRampNumber
630+
variable tHits as List
631+
put the empty list into tHits
612632

613633
variable tStop as GradientStop
614634
repeat for each element tStop in mGradientRamp
615635
variable tStopX as Number
616636
put xCoordFromGradientOffset((the offset of tStop) * 100 ) into tStopX
617637
if pX >= (tStopX - mGradientHandleSize * 0.5) and pX <= (tStopX + mGradientHandleSize * 0.5) then
618-
return tRampNumber
638+
push tRampNumber onto tHits
619639
end if
620640
add 1 to tRampNumber
621641
end repeat
622642

623-
return 0
643+
if the number of elements in tHits = 0 then
644+
return 0
645+
end if
646+
647+
variable tAHit as Number
648+
649+
repeat for each element tAHit in tHits
650+
if tAHit = mCurrentlySelectedStopIndex then
651+
return mCurrentlySelectedStopIndex
652+
end if
653+
end repeat
654+
655+
return element 1 of tHits
624656
end handler
625657

626658
----------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)