Page 1 of 1
Moving Lines on an ImagGadget
Posted: Sun Jun 12, 2005 12:39 am
by inc.
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

Posted: Tue Mar 14, 2006 1:59 pm
by inc.
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.
Posted: Tue Mar 14, 2006 11:53 pm
by blueznl
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
Posted: Wed Mar 15, 2006 2:25 am
by Sparkie
I went with the first thing that came to my mind...
* 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
Posted: Wed Mar 15, 2006 2:31 am
by Rescator
* votes for Sparkies forum title to be changed from "PureBasic Expert" to "PureBasic Deity" *
Posted: Wed Mar 15, 2006 10:06 am
by blueznl
second that, we are not worthy
Posted: Wed Mar 15, 2006 2:23 pm
by inc.
Thank you very much sparkie!
Although Im actually still on Pb 3.94 on that project (the part above is just a routine for a big code). Ill test your approach on my separate PB 4 beta 6 install.

Posted: Wed Mar 15, 2006 2:30 pm
by Dare2
Another Sparkie Spectacular!
* bows *
Posted: Wed Mar 15, 2006 2:34 pm
by Fangbeast
it's Sparktacular. get it right!! You wouldn't want Sparkie to shove a thunderbolt our way for getting it wrong would you???
Posted: Thu Mar 16, 2006 11:29 pm
by inc.
Thanks again Sparkie! I tested it using PB4b7 and this code does EXACTLY what I want!
PS: What is this for:
SetWindowLong_(GadgetID(i), #GWL_STYLE, GetWindowLong_(GadgetID(i), #GWL_STYLE) | #WS_CLIPSIBLINGS)
I had a look in the (F1) Platform SDK Docu, found it but I cant figure it out.
Posted: Sat Mar 18, 2006 6:45 am
by Sparkie
You are all too kind.

What's going to happen when I screw up

Damn!...all the pressure.
@inc:
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.
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.
