Image Repositioning WIthin a sub area of a Canvas

BlitzPlus Forums/BlitzPlus Programming/Image Repositioning WIthin a sub area of a Canvas

_PJ_(Posted 2014) [#1]
In short, I have a canvas on which only a PORTION of which is used to display a particular image. The image can be repositioned within this portion.
I am using DrawBlockRect suitably to ensure only the relevant portion of the image is drawn.

The problem I have is with the repositioning itself which is controlled by the mouse when holding down the Right-Mouse Button.

The control method essentially works, however the direction in which the image appears to 'move' is reversed.
I have tried combinations of the paramters to reverse the signs etc. but have gotten confused with the effect.

Any help with this matter will be greatly appreciated!

There's a lot of code overall in the project so far, but the relevant sections are:
Global IMAGE_OFFSET_X
Global IMAGE_OFFSET_Y
Global UI_IMG_START_OFFSET_X
Global UI_IMG_START_OFFSET_Y


Function DrawDisplayImage()
	Local X=GUIDELINE_X+((GUIDELINE_REAR_WIDTH+GUIDELINE_SPINE_WIDTH)*CANVAS_X_RATIO)
	Local Y=GUIDELINE_Y
	
	Local W=GUIDELINE_FRONT_WIDTH*CANVAS_X_RATIO
	Local H=GUIDELINE_HEIGHT*CANVAS_Y_RATIO
	
	;Local MAX_X=+W-GUIDELINE_X
	;Local MAX_Y=IMAGE_OFFSET_Y+Y+H-GUIDELINE_Y
	
	Local Offset=Not(GetImageScale())
	
	Local OFFSET_X=(IMAGE_OFFSET_X * Offset)
	Local OFFSET_Y=(IMAGE_OFFSET_Y * Offset)
	
	Debug("IMAGE: Drawing Display image at "+Str(X)+" + "+Str(OFFSET_X)+", "+Str(Y)+" + "+Str(OFFSET_Y)+" Dims: "+Str(W)+" X "+Str(H))
	
	DrawBlockRect IMAGE_WYSIWYG,X,Y,OFFSET_X,OFFSET_Y,W,H
End Function


Repeat 
		Event=WaitEvent()
		
		If (UI_IMAGE_OFFSET);IMAGE_OFFSET is a flag set to true if in 'repositioning mode'
			If ((Event=UI_EVENT_IMAGE_REPOSIT_FINISH)And (EventData()=2))
				RepositionFinishEvent(EventX(),EventY())
			End If
			
		Else
			If ((Event=UI_EVENT_IMAGE_REPOSIT)And (EventData()=2))
				If (IMAGE_CURRENT)
					RepositionEvent(EventX(),EventY())
				End If
				
			Else
				MainMenuEvent(Event)
	;			FlipCanvas UI_CAN_WYSIWYG,True
			End If
		End If
	Until (Event=UI_EVENT_CLOSE)


These two functions are potentiually where the error with the signs and direction of the changes to OFFSET_X and OFFSET_Y come in.

Function RepositionEvent(X,Y)
	UI_IMG_START_OFFSET_X=X-IMAGE_OFFSET_X
	UI_IMG_START_OFFSET_Y=Y-IMAGE_OFFSET_Y
	Debug("IMAGE: Reposition Commence: "+Str(X)+", "+Str(Y))
	UI_IMAGE_OFFSET=True
End Function

Function RepositionFinishEvent(X,Y)
	IMAGE_OFFSET_X=X-UI_IMG_START_OFFSET_X
	IMAGE_OFFSET_Y=Y-UI_IMG_START_OFFSET_Y
	Debug("IMAGE: Reposition Complete: "+Str(X)+", "+Str(Y))
	UI_IMAGE_OFFSET=False
	UpdateWYSIWYG
End Function