• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Post your questions here

Started by Patrice Terrier, December 10, 2008, 03:20:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Donnie Ewald

Well, I'm going to keep working on it; but, I've not figured it out yet.  I'm sure that the ZI_GetZoomValue is part of the equation; but, I'm stumped.  Patrice, do you mind sharing how the ZI_GetCropCoordinates API gains it's information? I feel like I should be getting this; but, I'm not.

On another note (and still using the zoomplus.bas example), if I added a sprite above Monaco, would it be possible that once zoomed in we could automatically center the sprite and the background image would still scroll with it using ZD_SetObjectScroll?  Any similar examples or should I start tinkering?

Patrice Terrier

#16
Donnie,

Here are some insights to help you:

Note: X1, Y1 are the mouse coordinates and hWnd is the handle of the GDImage control.


                    LOCAL lpr AS RECT, ZoomValue AS SINGLE, nW, nH, ZoomWidth, ZoomHeight, xOffset, yOffset, imgWidth, imgHeight AS LONG
                    ' Get current Zoom value
                    ZoomValue! = ZI_GetZoomValue(hWnd)
                    ' Retrieve the size of the memory bitmap
                    CALL ZI_GetImageSizeFromControl(hWnd, nW&, nH&)
                    ' Get the client size of the control
                    CALL GetClientRect(hWnd, lpr)
                    ' Compute x,y offset
                    ZoomWidth& = nW& * ZoomValue!
                    ZoomHeight& = nH& * ZoomValue!
                    xOffset& = 0: yOffset& = 0
                    IF ZoomWidth& < lpr.nRight OR ZoomHeight& < lpr.nBottom THEN
                      IF ZoomWidth& < lpr.nRight THEN xOffset& = (lpr.nRight - ZoomWidth&) \ 2
                      IF ZoomHeight& < lpr.nBottom THEN yOffset& = (lpr.nBottom - ZoomHeight&) \ 2
                    END IF
                    ' Compute real coordinates
                    IF ZoomValue! > 0 THEN
                       x1& = (x1& - xOffset&) / ZoomValue!
                       y1& = (y1& - yOffset&) / ZoomValue!
                       imgWidth& = imgWidth& / ZoomValue!
                       imgHeight& = imgHeight& / ZoomValue!
                    END IF


For your other question you can always change the location of a sprite at any time.
The ZI_GetXscroll and ZI_GetYscroll API give you the horizontal and vertical scroll range for a specific GDImage control.

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

Donnie

Here is a WinDev procedure that is being used to display the mouse coordinates in a GDImage ZOOM control.
It can be easily translated to PowerBASIC


PROCEDURE GDImageDisplayMouseXY(hWnd is int, x is int, y is int)
lpr is RECT
// Get current Zoom value
ZoomValue is 4-byte real = ZI_GetZoomValue(hWnd)
// Retrieve the size of the memory bitmap
nW, nH are int; ZI_GetImageSizeFromControl(hWnd, nW, nH)
// Get the client size of the control
GetClientRect(hWnd, lpr)
// Compute x,y offset
ZoomWidth is int = nW * ZoomValue
ZoomHeight is int = nH * ZoomValue
xOffset is int = 0; yOffset is int = 0
IF ZoomWidth < lpr:nRight OR ZoomHeight < lpr:nBottom THEN
IF ZoomWidth < lpr:nRight THEN xOffset = Round((lpr:nRight - ZoomWidth) / 2)
IF ZoomHeight < lpr:nBottom THEN yOffset = Round((lpr:nBottom - ZoomHeight)/ 2)
END
// Retrieve scroll values
xCurrentScroll is int = ZI_GetXscroll(hWnd)
yCurrentScroll is int = ZI_GetYscroll(hWnd)
// Show mouse coordinates
SC_Coord.X = NumToString(Round((x + xCurrentScroll - xOffset) / ZoomValue, 0))
SC_Coord.Y = NumToString(Round((y + yCurrentScroll - yOffset) / ZoomValue, 0))
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#18
Donnie,

I have posted a WinDev project named GeneScene there:
http://www.zapsolution.com/demo/GeneScene.zip

It displays a map(s) with pushpin sprites spread on it.
Each pushpin is a hot spot that does match a specific tunnel (Try with the one named "l'Arme" located above Monaco).



You will see also on this example that the mouse X,Y location is shown below the map while you are moving the mouse, and it display the correct location whatever the zoom being used.

Perhaps it is something like that you want to achieve?

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Donnie Ewald

This is perfect!  For whatever reason, I'm not able to replicate that functionality when I'm zoomed in.  I must be letting something slide somewhere.

Patrice Terrier

GDImage allows you to process/monitor all the messages of its graphic controls via a callback procedure.

Note: in the GeneScene project all the pushpins (except one) are clone objects, this is a very unique GDImage feature.


Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Donnie Ewald

I was handling the current scroll in the wrong spot.  The WinDev post though nearly the same as the PB showed me where I was screwing up.  I was so sure that some of my own code was accurate I was blinded to the truth.  I've attached the zoomplus sample with my changes in case anyone else is interested.  The output information is sent as a debug string.  I capture those with DebugView.

Donnie Ewald

A few more questions.  I have a bit of code:

'Find current zoom and scoll values
hCtrl& = GetDlgItem(cbhndl, %IDC_GDimageCTRL1)
ZoomValue! = ZI_GetZoomValue(hCtrl&)
xCurrentScroll = ZI_GetXscroll(hCtrl&)
yCurrentScroll = ZI_GetYscroll(hCtrl&)

'Load the new image
call GDImageLoadFile(cbhndl, FilName$)

'Reassign zoom and scroll values after loading file
CALL ZI_SetZoomValue(hCtrl&, ZoomValue!)
CALL ZI_SetZoomScrollInfo(hCtrl&, ZoomValue!, ZoomValue!)
call ZI_SetProperty(hCtrl&, %ZI_Horizontal, xCurrentScroll)
call ZI_SetProperty(hCtrl&, %ZI_Vertical, yCurrentScroll)


...that while checking each of the values they seem to be fine.  Unfortunately, the image control doesn't show the changed %ZI_Horizontal and %ZI_Vertical settings, instead they show the default zero.  I tossed in a redraw for fun and still don't see anything.  Anything I might be overlooking?

Also, I can see from ZD_GetObjectQuality that you can change the rendering quality.  Is it possible to have no adjustment at all when zooming and such?  I'd like to see pixels and all without any interpolation.

Patrice Terrier

#23
Donnie,

A GDImage ZOOM control always use HALFTONE interpolation, because the zoom can be smaller than the 1/1 pixel ratio (for example 0.33)

If you want to have full control on your image, then use it as a sprite object (a layer floating above the background, like in PhotoShop). See on this forum the PhotoSetup demo project.

Then you have a bunch of properties you can apply to your sprite, see all the API prefixed with ZD_SetOblect... and ZD_GetObject... in the GDImage.inc file (the include file is more accurate than the CHM help file).

To facilitate the manipulation of GDImage's sprite object use a Sprite type like this one


TYPE SpriteStruct
     ID              is int                         '// The unique sprite object IDentifier
     objtype         is int                         '// The object type     
     filename        is string ASCIIZ on MAX_PATH   '// File of the sprite bitmap
     label           is string ASCIIZ on 64         '// Friendly name
     xPos            is int                         '// X location
     yPos            is int                         '// Y location
     xWidth          is int                         '// Width of the sprite object
     yHeight         is int                         '// Height of the sprite object
     ARGB            is int                         '// ARGB color
     visibility      is int                         '// ZS_HIDDEN or ZS_VISIBLE state
     scrollmode      is int                         '// True/False scrolling mode
     opacity         is int                         '// True/False PNG opacity
     userotate       is int                         '// Rotate90FlipNone or Rotate270FlipNone
     flipmode        is int                         '// ZD_Reverse (FlipX) or ZD_Flip (FlipY) constant       
     angle           is int                         '// Rotation angle 0-360
     locked          is int                         '// True/False condition
     zorder          is int                         '// The z-order value
     scale           is 4-byte real                 '// The scale value
     style           is int                         '// The object style
     quality         is int                         '// The object quality
     clone           is int                         '// The unique ID of the cloned object
                                                    '//
     resizeW         is int                         '// Resize width to use
     resizeH         is int                         '// Resize height to use
     trueW           is int                         '// True width of the native bitmap
     trueH           is int                         '// True height of the native bitmap
     selected    is 1-byte unsigned int             '// Selected status
     reserved    is string ASCIIZ on 111            '// For future extension
END TYPE


I can't remember exactly what you want to achieve, because i lost a part of my latest e-mails during the blown up of my notebook, that occured 9 days ago.
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#24
Here is a WinDev example showing how to assign a GDImage sprite array.

This one can be very easily translated to PowerBASIC
WD []: is PB ().
WD : is PB .
WD zItem is ZOBJECT is PB DIM zItem AS ZOBJECT

the ZD_GetObjectProperties API allows you to retrieve all the properties of a sprite object in one single call.


'// Assign the ZOBJECT structure/type parameters to the Sprite array
PROCEDURE SpriteArrayGet(ID is int)
x, y, xW, yH are int
'//ZD_GetObjectXY(ID, x, y)
'//ZD_GetObjectBound(ID, xW, yH)
'//gSprite[ID]:ID = ID                                  '// The unique sprite object IDentifier
'//gSprite[ID]:objtype = ZD_GetObjectType(ID)           '// The object type (bitmap, text, arrow, curve, rectangle, ellipse, polypolyline)
'//gSprite[ID]:label = ZD_GetObjectImageLabel(ID)       '// Friendly name
'//gSprite[ID]:xPos = x                                 '// X location
'//gSprite[ID]:yPos = y                                 '// Y location
'//gSprite[ID]:xWidth = xW                              '// Width of the sprite object
'//gSprite[ID]:yHeight = yH                             '// Height of the sprite object
'//gSprite[ID]:ARGB = ZD_GetObjectARGBcolor(ID)         '// ARGB color
'//gSprite[ID]:visibility = ZD_IsObjectVisible(ID)      '// ZS_HIDDEN or ZS_VISIBLE state
'//gSprite[ID]:scrollmode = ZD_GetObjectScroll(ID)      '// Scrolling mode
'//gSprite[ID]:opacity = ZD_GetObjectOpacity(ID)                '// True/False PNG opacity
'//gSprite[ID]:userotate = ZD_GetObjectRotation(ID)     '// Rotate90FlipNone or Rotate270FlipNone
'//gSprite[ID]:flipmode = ZD_GetObjectFlipMode(ID)      '// True/False condition         
'//gSprite[ID]:angle = ZD_GetObjectAngle(ID)            '// Rotation angle 0-360
'//gSprite[ID]:locked = ZD_GetObjectLocked(ID)          '// True/False condition
'//gSprite[ID]:zorder = ZD_GetObjectZorder(ID)          '// The z-order value
'//gSprite[ID]:scale = ZD_GetObjectScale(ID)            '// The scale value
'//gSprite[ID]:style = ZD_GetObjectStyle(ID)            '// The object style
'//gSprite[ID]:quality = ZD_GetObjectQuality(ID)                '// The object quality
'//gSprite[ID]:clone = ZD_GetObjectClone(ID)            '// The unique ID of the cloned object
'//gSprite[ID]:selected = 0                             '// Set selected status to Off

zItem is ZOBJECT
ZD_GetObjectProperties(ID, zItem)                       '// Retrieves all the details about a GDImage sprite object in one single step.
gSprite[ID]:ID = ID                                     '// The unique sprite object IDentifier
gSprite[ID]:objtype = zItem:objType                     '// The object type (bitmap, text, arrow, curve, rectangle, ellipse, polypolyline)
gSprite[ID]:label = zItem:objLabel                      '// Friendly name
gSprite[ID]:xPos = zItem:x1                             '// X location
gSprite[ID]:yPos = zItem:y1                             '// Y location
gSprite[ID]:xWidth = zItem:x2                           '// Width of the sprite object
gSprite[ID]:yHeight = zItem:y2                          '// Height of the sprite object
gSprite[ID]:ARGB = zItem:useARGB                        '// ARGB color
gSprite[ID]:visibility = zItem:visibility               '// ZS_HIDDEN or ZS_VISIBLE state
IF BinaryAND(zItem:Style, ZS_SCROLL) = ZS_SCROLL THEN   '// Scrolling mode
        gSprite[ID]:scrollmode = -1                                     
ELSE
        gSprite[ID]:scrollmode = 0
END
gSprite[ID]:opacity = zItem:opacity                     '// True/False PNG opacity
gSprite[ID]:userotate = zItem:userotate                 '// Rotate90FlipNone or Rotate270FlipNone
gSprite[ID]:flipmode = zItem:flipmode                   '// True/False condition         
gSprite[ID]:angle = zItem:angle                         '// Rotation angle 0-360
gSprite[ID]:locked = zItem:locked                       '// True/False condition
gSprite[ID]:zorder = zItem:order                        '// The z-order value
gSprite[ID]:scale = zItem:scale                         '// The scale value
gSprite[ID]:style = zItem:Style                         '// The object style
gSprite[ID]:quality = zItem:quality                     '// The object quality
gSprite[ID]:clone = zItem:clone                         '// The unique ID of the cloned object
gSprite[ID]:selected = 0                                '// Set selected status to Off

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Pete Malcom

I can only find one example of using GDImage with PowerBasic DDT Controls – the GDWDDT example.   This is clear, but what I can't see is how to do more than create the control (and give it an initial image):

    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

Works fine, but how do I then get a handle to do other tasks on the control?  Eg:

ZD_FillRect (handle, 0, 0, 200, 200, color)

I tried ZI_GetDC and CONTROL HANDLE, but neither worked ...

Perhaps there is a more comprehensive example of using DDT?   I can't easily use direct Windows SDK as I am adding graphics to an existing program ...

Patrice Terrier

#26
Pete,

See the code below in red.

Quote
FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    LOCAL lRslt AS LONG

    LOCAL hDlg  AS DWORD

    DIALOG NEW hParent, "DDT + GDImage image control ", 108, 135, 434, 337, %WS_POPUP OR _
        %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR _
        %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
        %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
        %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg

  ' GDImage
    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))

       
  ' GDImage
    CONTROL ADD $GDImageClassName, hDlg, %IDC_GDimageCTRL2, _
        $MyImage2, 152, 210, 130, 110, %WS_CHILD OR _
        %WS_VISIBLE, %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
        %WS_EX_RIGHTSCROLLBAR

    DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt

    FUNCTION = lRslt
END FUNCTION

Note: ZD_FillRect draw a rectangle onto the provided DC using a 24-bit RGB color.
If you want to draw a rectangle with an ARGB color (alpha channel), then use ZD_DrawRectangleToCtrl.

I would rather manipulate GDImage sprite objects (multiple layers) than drawing using a DC.
Drawing using a DC = static image, GDImage sprite objects = dynamic image (you can change the location, z-order, and all parameters of each object).

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Pete Malcom

#27
Perfect, thanks Patrice.

Pete Malcom

The ZD_FillRect example above will only draw over the background image.   If there is no background image loaded (ie the CONTROL ADD specified "" as the image name) or the image is smaller than the control, ZD_FillRect only draws over the image, or not at all (if there is no image).

I know I can create a sprite overlay, but all I want is to set a background colour for the image area before I load the background bitmap (has to happen later).   

Also tried ZI_PaintBrushBitmap, but it has been deprecated (help file needs updating).

Thanks

Pete



Patrice Terrier

#29
Pete

There are several ways to tell GDImage how to paint a specific control background:

Using a gradient color
          CALL ZI_SetProperty(GetDlgItem(hMain, %ID_CTRL), %ZI_GradientTop, RGB(93,3,28))
          CALL ZI_SetProperty(GetDlgItem(hMain, %ID_CTRL), %ZI_GradientBottom, RGB(146,3,40))

Using a flat color with same color for Top and Bottom
          CALL ZI_SetProperty(GetDlgItem(hMain, %ID_CTRL), %ZI_GradientTop, RGB(255,0,0))
          CALL ZI_SetProperty(GetDlgItem(hMain, %ID_CTRL), %ZI_GradientBottom, RGB(255,0,0))

Using a tiled background
          hTiledBitmap& = ZI_CreateBitmapFromFile("038.jpg", 0,0)
          CALL ZI_SetTiledBackground(hCtrl&, hTiledBitmap&)

And of course using an image for background (that could be resized on the fly to match the control size).

See all details in the Resource.bas example.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com