Author Topic: Post your questions here  (Read 14282 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete Malcom

  • Newbie
  • *
  • Posts: 4
Re: Post your questions here
« Reply #30 on: July 03, 2012, 04:52:52 PM »
And the next ...

Taking the GDWDDT example again, if we add a sprite to the GDImage Control:

CONTROL ADD $GDImageClassName, hDlg, %IDC_GDimageCTRL1, _
    $MyImage1, 7, 5, 420, 190, %WS_CHILD OR %WS_VISIBLE _
    OR %WS_HSCROLL OR %WS_VSCROLL, %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
    %WS_EX_RIGHTSCROLLBAR

LOCAL hCtl AS LONG
CONTROL HANDLE hDlg, %IDC_GDimageCTRL1 TO hCtl
ZD_FillRect(ZI_GetDC(hCtl), 10,10, 50,50, RGB(255,0,0))

ZD_DrawRectangleToCtrl(hCtl, 10,10,100,100, &HFFFFFFFF, 0, %IDC_Sprite, %ZS_VISIBLE, %ZD_DRAW_FILLED)

We get a nice independant sprite rectangle overlaid, which we can move, manipulate (and remove) without affecting the underlying image.   This is really cool.

Two questions:

1.   Without adding any code to GDWDDT, hovering over the sprite changes the mouse cursor, and you can drag the sprite anywhere you want in the GDImage control.   Again, very cool, EXCEPT if you don't want the user to be able to do this ....   How do we prevent the mouse hover and the drag?

2.    With a standard PowerBasic Image control, adding the %SS_NOTIFY attribute causes the callback to fire if the user clicks anywhere on the control.   But the same does not happen with the custom control.    How do we get mouseclicks on the GDImage control, and how do we get them one of the sprites?

Thanks!

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2382
  • Gender: Male
    • www.zapsolution.com
Re: Post your questions here
« Reply #31 on: July 03, 2012, 05:20:22 PM »
Quote
1.  Without adding any code to GDWDDT, hovering over the sprite changes the mouse cursor, and you can drag the sprite anywhere you want in the GDImage control.   Again, very cool, EXCEPT if you don't want the user to be able to do this ....   How do we prevent the mouse hover and the drag?

Easy, just lock and disable the sprite image, using:
ZD_SetObjectLocked(nSpriteID, %TRUE)

Quote
2.  How do we get mouseclicks on the GDImage control, and how do we get them one of the sprites?

Use a GDImage callback, in correlation with the ZI_EventMessage you want to monitor.
Search in the AEROGLASS demo project for:
CALL ZI_EventMessage(CODEPTR(MyCallBack), %WM_LBUTTONDOWN, %TRUE)

and look inside
Code: [Select]
FUNCTION MyCallBack(BYVAL hWnd AS LONG, BYVAL Msg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) EXPORT AS LONG
    LOCAL sMessage AS STRING, ObjectID AS LONG, rc AS RECT, nRet AS LONG
    LOCAL x AS LONG, y AS LONG

    nRet = %FALSE ' Do not stop the event processing in GDImage
   
    IF hWnd = GetDlgItem(hMain, %ID_CTRL) THEN ' In case we use the same callback for several GDImage control
                                               ' make sure that we handle the good one.
       SELECT CASE LONG Msg                 

       CASE %WM_LBUTTONDOWN
            ObjectID = ZI_MouseOverObjectID()
            IF ObjectID = GetDlgCtrlID(hWnd) THEN LabelIs$ = $Background ELSE LabelIs$ = ZD_GetObjectImageLabel(ObjectID)
'nID& = ZD_GetItemObjectAndColorAtXY(hWnd, LO(INTEGER, lParam), HI(INTEGER, lParam), ColorRGB&)
            sMessage = "WM_LBUTTONDOWN on object" + str$(ObjectID) + " >" + LabelIs$ + "<" '+ str$(nID&)+" &H"+HEX$(ColorRGB&)
            CALL SetWindowText(GetDlgItem(hMain, %ID_STATUSBAR), (sMessage))

       CASE %WM_RBUTTONDOWN
            ObjectID = ZI_MouseOverObjectID()
            IF ObjectID = GetDlgCtrlID(hWnd) THEN LabelIs$ = $Background ELSE LabelIs$ = ZD_GetObjectImageLabel(ObjectID)
            sMessage = "WM_RBUTTONDOWN on object" + str$(ObjectID) + " >" + LabelIs$ + "< at location" + str$(LOWRD(lParam))+","+str$(HIWRD(lParam))
            CALL SetWindowText(GetDlgItem(hMain, %ID_STATUSBAR), (sMessage))

       CASE %WM_MOUSEMOVE
            ObjectID = ZI_GetMovingSpriteID()
            IF ObjectID THEN
             ' Does %ID_BTN_CHECK is checked ?
               IF SendMessage(GetDlgItem(GetParent(hWnd), %ID_BTN_CHECK), %BM_GETCHECK, 0, 0) THEN
                  x = LOWRD(lParam): y = HIWRD(lParam)
                  xCurrentScroll& = ZI_GetProperty(hWnd, %ZI_Horizontal)
                  yCurrentScroll& = ZI_GetProperty(hWnd, %ZI_Vertical)
                  ZD_GetObjectXY(ObjectID, x1&, y1&)
                  ZD_GetObjectXYcapture(ObjectID, xCapture&, yCapture&)
                  DX& = (x - xCapture& +  xCurrentScroll&) - x1&
                  DY& = (y - yCapture& +  yCurrentScroll&) - y1&
                  FOR ID& = %ID_FIRST TO %ID_LAST
                      IF ID& <> ObjectID THEN
                         CALL ZD_GetObjectXY(ID&, x, y)
                       ' Add the DX,DY offset
                         CALL ZD_SetObjectXY(ID&, x + DX&, y + DY&, %ZD_DRAW_DEFERRED) ' Move, without immediate redraw
                      END IF
                  NEXT
                ' Note: The display's refresh is yeld by the default GDImage WM_MOUSE event
               END IF
            END IF

       CASE %WM_KEYDOWN
            ObjectID = ZI_GetObjectFocusID()
            IF ObjectID THEN
               CALL ZD_GetObjectXY(ObjectID, x, y)
               x1& = x ' Make a copy to keep the orignal x location unchanged
               y1& = y ' Make a copy to keep the orignal y location unchanged

             ' Check accelerator keys to compute the step range
               IF ZI_IsCtrlKeyPressed THEN
                  UseStep& = 4
                  IF ZI_IsShiftKeyPressed THEN UseStep& = 16
               ELSEIF ZI_IsShiftKeyPressed THEN
                  UseStep& = 2
               ELSE
                  UseStep& = 1
               END IF
               
               IF ZD_GetObjectScroll(ObjectID) THEN ' If object scroll with the bitmap background
                ' Get the size of the bitmap background
                  CALL ZI_GetBitmapSize(ZI_GetBMP(GetDlgItem(hMain, %ID_CTRL)), useWidth&, useHeight&)
               ELSE
                ' Get the control client size 
                  CALL GetClientRect(GetDlgItem(hMain, %ID_CTRL), rc)
                  useWidth& = rc.nRight: useHeight& = rc.nBottom
               END IF
             ' Get the sprite object size
               CALL ZD_GetObjectBound(ObjectID, BoundWidth&, BoundHeight&)

               x2Div2& = (BoundWidth& \ 2): y2Div2& = BoundHeight& \ 2
               SELECT CASE wParam
               CASE %VK_HOME
                    x1& = 0
               CASE %VK_END
                    x1& = MAX&(useWidth& - BoundWidth&, 0)
               CASE %VK_PRIOR
                    y1& = 0
               CASE %VK_NEXT
                    y1& = MAX&(useHeight& - BoundHeight&, 0)
               CASE %VK_LEFT, %VK_NUMPAD4
                    IF x1& > -x2Div2& THEN x1& = MAX&(x1& - UseStep&, -x2Div2&)
               CASE %VK_UP, %VK_NUMPAD8
                    IF y1& > -y2Div2& THEN y1& = MAX&(y1& - UseStep&, -y2Div2&)
               CASE %VK_RIGHT, %VK_NUMPAD6
                    IF x1& < useWidth& - x2Div2& THEN
                       x1& = MIN&(x1& + UseStep&, useWidth& - x2Div2&)
                    END IF
               CASE %VK_DOWN, %VK_NUMPAD2
                    IF y1& < useHeight& - y2Div2& THEN
                    y1& = MIN&(y1& + UseStep&, useHeight& - y2Div2&)
                    END IF
               END SELECT
               
               IF x <> x1& OR y <> y1& THEN
                  x = x1&: y = y1&         
                  CALL ZD_SetObjectXY(ObjectID, x1&, y1&, %TRUE)
               END IF
               sMessage = "Object" + str$(ObjectID) + " coordinates" + str$(x&)+","+str$(y&)
               CALL SetWindowText(GetDlgItem(hMain, %ID_STATUSBAR), (sMessage))
               
            END IF
       END SELECT
    END IF

    FUNCTION = nRet
END FUNCTION

« Last Edit: July 03, 2012, 05:23:35 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com