Moving Lines on an ImagGadget

Just starting out? Need help? Post your questions and find answers here.
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Moving Lines on an ImagGadget

Post 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

Image
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post 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.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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
( 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... )
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

* votes for Sparkies forum title to be changed from "PureBasic Expert" to "PureBasic Deity" *
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

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... )
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post 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. :)
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Another Sparkie Spectacular!

* bows *
@}--`--,-- A rose by any other name ..
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post 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???
Amateur Radio, D-STAR/VK3HAF
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post 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.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You are all too kind. :oops: What's going to happen when I screw up :?: Damn!...all the pressure. :shock:

@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. ;)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply