Moving Lines on an ImagGadget
Moving Lines on an ImagGadget
Hi,
my intention is to move Lines on an an Imagegadget where a Movieframesample is shown and where I can move those Lines ONLY using the mousepointer WHEN the left tab of the mouse holded.
I already searched at the code compilation on purearea.net, but no luck.
It will be an application where people beside other things can determine the borders of the image which will should be cropped.
So at the beginning the lines are at the very image edges. If catching one of these lines using the mouse incl. holding the left mousebutton down these lines should be movable in a senseful way up to the vertical hor horizontal middle each.
So how can I ...
a) write those Lines on an laready assignet Image in the Imagegadget (I assume a sprite generating way would be the approach)?
b) how can I move these elements (sprites maybe?) over the already assignet image?
I hope the demonstration below does show what I mean
Thanks a lot
my intention is to move Lines on an an Imagegadget where a Movieframesample is shown and where I can move those Lines ONLY using the mousepointer WHEN the left tab of the mouse holded.
I already searched at the code compilation on purearea.net, but no luck.
It will be an application where people beside other things can determine the borders of the image which will should be cropped.
So at the beginning the lines are at the very image edges. If catching one of these lines using the mouse incl. holding the left mousebutton down these lines should be movable in a senseful way up to the vertical hor horizontal middle each.
So how can I ...
a) write those Lines on an laready assignet Image in the Imagegadget (I assume a sprite generating way would be the approach)?
b) how can I move these elements (sprites maybe?) over the already assignet image?
I hope the demonstration below does show what I mean
Thanks a lot
Long time ago, but Im still trying to receive some help.
Lets say I got now the Image as a rgb32 bit one in memory. Normally I would assign that image to the Imagegadget.
Now, should I first render that image into a sprite where the lines will be separate sprites which will be moved using the mouse+leftklick?
Could someone at least give me an approach in words, so I get an Idea how to start on that issue. Or pointing me to a codesniplet in the web like purearea where I can see the logic.
Thank you very much.
Lets say I got now the Image as a rgb32 bit one in memory. Normally I would assign that image to the Imagegadget.
Now, should I first render that image into a sprite where the lines will be separate sprites which will be moved using the mouse+leftklick?
Could someone at least give me an approach in words, so I get an Idea how to start on that issue. Or pointing me to a codesniplet in the web like purearea where I can see the logic.
Thank you very much.
oh, but this is easy
1. create an image object (#1) that holds your original image
2. create another image object (#2) with the same size
3. draw #1 on top of #2
4. create image gadget with image #2
5. you can either use getasynckeystate (hope i spelled that right) or mouse events to catch when the mouse button is pressed
6. then you look for the coords relative to the picture (ie. subtract position of image #2 from the mouse coords
7. draw the lines on image #2 at the appropriate position
8. then updage the imagegadget with the modified image #2
9. go to step 2
that is, if i understood your question right
1. create an image object (#1) that holds your original image
2. create another image object (#2) with the same size
3. draw #1 on top of #2
4. create image gadget with image #2
5. you can either use getasynckeystate (hope i spelled that right) or mouse events to catch when the mouse button is pressed
6. then you look for the coords relative to the picture (ie. subtract position of image #2 from the mouse coords
7. draw the lines on image #2 at the appropriate position
8. then updage the imagegadget with the modified image #2
9. go to step 2
that is, if i understood your question right
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
I went with the first thing that came to my mind...
* PB 4 Beta6
* PB 4 Beta6
Code: Select all
;...Red horizontal lines for gadgets 0 and 1 (top and bottom lines)
CreateImage(0, 300, 1)
StartDrawing(ImageOutput(0))
Box(0, 0, 300, 1, #Red)
StopDrawing()
;...Red vertical lines for gadgets 2 and 3 (left and right lines)
CreateImage(1, 1, 300)
StartDrawing(ImageOutput(1))
Box(0, 0, 1, 300, #Red)
StopDrawing()
;...Our main image
CreateImage(2, 300, 300)
StartDrawing(ImageOutput(2))
Circle(150, 150, 150, #Yellow)
StopDrawing()
;...Load cursors
cursorNS = LoadCursor_(0, #IDC_SIZENS)
cursorWE = LoadCursor_(0, #IDC_SIZEWE)
If OpenWindow(0, 0, 0, 300, 300, "Guide Lines", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
;...Make sure none of the 'line' gadgets have an ID of 0
;...as this will not work properly
ImageGadget(1, 0, 10, 300, 1, ImageID(0)) ;...top line
ImageGadget(2, 0, 290, 300, 1, ImageID(0)) ;...bottom line
ImageGadget(3, 10, 0, 1, 300, ImageID(1)) ;...left line
ImageGadget(4, 290, 0, 1, 300, ImageID(1)) ;...right line
ImageGadget(5, 0, 0, 300, 300, ImageID(2)) ;...main image
;...Clip sibling gadgets for proper redraw while moving lines
For i = 1 To 5
SetWindowLong_(GadgetID(i), #GWL_STYLE, GetWindowLong_(GadgetID(i), #GWL_STYLE) | #WS_CLIPSIBLINGS)
Next i
Repeat
event = WaitWindowEvent()
Select event
Case #WM_LBUTTONUP
gadId = 0
Case #WM_MOUSEMOVE
;...If mouse is moving and left button is down
If GetAsyncKeyState_(#VK_LBUTTON) And gadId > 0
Select gadId
Case 1, 2
SetCursor_(cursorNS)
;...Prevent lines from moving outside main image
If WindowMouseY(0) > GadgetY(5) - 1 And WindowMouseY(0) < (GadgetY(5) + GadgetHeight(5))
ResizeGadget(gadId, #PB_Ignore, WindowMouseY(0), #PB_Ignore, #PB_Ignore)
EndIf
Case 3, 4
SetCursor_(cursorWE)
;...Prevent lines from moving outside main image
If WindowMouseX(0) > GadgetX(5) - 1 And WindowMouseX(0) < (GadgetX(5) + GadgetWidth(5))
ResizeGadget(gadId, WindowMouseX(0), #PB_Ignore, #PB_Ignore, #PB_Ignore)
EndIf
EndSelect
Else
;...If mouse is moving but left button is not down
;...set the cursor when it's over a red line
gadId = GetDlgCtrlID_(ChildWindowFromPoint_(WindowID(0), WindowMouseX(0), WindowMouseY(0)))
Select gadId
Case 1, 2
SetCursor_(cursorNS)
Case 3, 4
SetCursor_(cursorWE)
EndSelect
EndIf
Case #PB_Event_Gadget
;...If one of our lines is clicked, set the gadID and the cursor
If EventGadget() > 0 And EventGadget() < 5
gadId = EventGadget()
Select gadId
Case 1, 2
SetCursor_(cursorNS)
Case 3, 4
SetCursor_(cursorWE)
EndSelect
EndIf
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
second that, we are not worthy
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
You are all too kind. What's going to happen when I screw up Damn!...all the pressure.
@inc:
@inc:
In other words, when a gadget is being redrawn, it only redraws the areas that do not overlap sibling gadgets (did I say that right?). Comment out the line that sets the #WS_CLIPSIBLINGS flag and you'll see what happens.msdn SDK wrote:WS_CLIPSIBLINGS
Clips child windows relative to each other; that is, when a particular child window receives a WM_PAINT message, the WS_CLIPSIBLINGS style clips all other overlapping child windows out of the region of the child window to be updated. If WS_CLIPSIBLINGS is not specified and child windows overlap, it is possible, when drawing within the client area of a child window, to draw within the client area of a neighboring child window.
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1