|
Post by tsh73 on Dec 26, 2021 14:24:37 GMT -5
Try this 10 pix lower right corner made into "resize spot" Try dragging by it.
' Form created with the help of Freeform-J v.261006 ' Generated on Dec 26, 2021 at 22:10:10
' nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "Drag lower right corner to resize graphicbox", 10, 5, 312, 20 graphicbox #main.gr, 10, 30, 100, 100 open "resize graphicbox" for window as #main print #main.gr,"down; fill white; flush" print #main.gr, "home; posxy cx cy" 'reads size of graphicbox as 2*cx, 2*cy print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
#main.gr "when leftButtonDown [start]" #main.gr "when leftButtonUp [fin]"
drag=0
wait
[quit.main] Close #main END
[start] if MouseX<2*cx-10 then wait if MouseY<2*cy-10 then wait drag=1 'sx=MouseX 'sy=MouseY wait
[fin] if not(drag) then wait #main.gr "locate 10 30 ";MouseX;" ";MouseY #main "refresh" print #main.gr, "home; posxy cx cy" 're-read size of graphicbox print 2*cx, 2*cy drag=0 wait
|
|
|
Post by tsh73 on Dec 27, 2021 9:44:51 GMT -5
Of cource you have to redraw There is a (native) way to make LB resize your picture, but quality is poor (picture 2). (linear resizing, like in Paint) (using sprite engine. Restriction is you can use only one graphicbox with sprites) And it works only UP-scaling There is should be API way - could we get bicubic resampling there? but my BASIC is too basic for that. Let's someone else show their Kung-Fu But if you redraw it in new size you can get it really nice. (picture 3) Program below redraws from scratch, but if you comment out " vectorRedraw=1", it will stretch bitmap instead. ' Form created with the help of Freeform-J v.261006 ' Generated on Dec 26, 2021 at 22:10:10 nomainwin
'cooment it out to get bitmap redraw vectorRedraw=1
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "Drag lower right corner to resize graphicbox", 10, 5, 312, 20 graphicbox #main.gr, 10, 30, 100, 100 open "resize graphicbox" for window as #main print #main.gr,"down; fill white; flush" print #main.gr, "home; posxy cx cy" 'reads size of graphicbox as 2*cx, 2*cy print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
#main.gr "when leftButtonDown [start]" #main.gr "when leftButtonUp [fin]"
drag=0 gosub [draw]
wait
[quit.main] Close #main END
[start] if MouseX<2*cx-10 then wait if MouseY<2*cy-10 then wait drag=1 'sx=MouseX 'sy=MouseY wait
[fin] if not(drag) then wait #main.gr "locate 10 30 ";MouseX;" ";MouseY #main "refresh" print #main.gr, "home; posxy cx cy" 're-read size of graphicbox 'print 2*cx, 2*cy if vectorRedraw then gosub [draw] else #main.gr "background bmp" #main.gr, "drawsprites" end if drag=0 wait
[draw] 'first time draw for bitmap redraw 'or every time for vector redraw #main.gr, "cls" r=.8*min(cx,cy) pi=acs(-1) n = 7 a=0 x=cx+r*cos(a) y=cy+r*sin(a) #main.gr, "place ";x;" ";y for i = 0 to n*int(n/2) step int(n/2) a=2*pi/n*i x=cx+r*cos(a) y=cy+r*sin(a) #main.gr, "goto ";x;" ";y 'print i, x,y next #main.gr, "flush"
#main.gr "getbmp bmp 0 0 ";2*cx;" ";2*cy #main.gr "background bmp"
return
|
|
|
Post by rodsweb on Dec 27, 2021 10:32:35 GMT -5
Yes I figured that, my graph has text on it, (stocks and share graphs), so auto resize would make the text huge or too small. Also I change the ordinate spacings to suit the window size. The problem currently is that it appears that graphics window is not returning the resized info, WindowWidth etc, which I need to redraw the graph. Could just be my coding, will experiment some more, unless someone knows for sure how it works.
|
|
|
Post by Walt Decker on Dec 28, 2021 16:59:40 GMT -5
Here is an alternate method:
' SRCCOPY = HEXDEC("&H00CC0020")
OPEN "USER32.DLL" FOR DLL AS #USER
RetVal = 0 GfxWide = 0 GfxHigh = 0
Scale = 1
PropVal = 0
OrigSzx = 0 OrigSzy = 0
WinHndl = 0 GfxHndl = 0
MENU #DMO, "CANVAS", "Resize Canvas", [ENLARGE], "Scale Image", [SCALE.IMG], _ "Stretch Image", [STRETCH] MENU #DMO, "HELP", "About", ABOUT
UpperLeftX = 50 UpperLeftY = 100 WindowWidth = DisplayWidth / 2 WindowHeight = DisplayHeight / 2
GfxWide = WindowWidth / 2 GfxHigh = WindowHeight / 2
OPEN "GFX BOX" FOR WINDOW AS #DMO WinHndl = FN.GetHandle("DMO") RetVal = FN.NewWin(WinHndl, GfxWide, GfxHigh)
GfxHndl = FN.GetHandle("GFX.GFX") RetVal = FN.SetProp(GfxHndl, "SCALE", 0)
WinHndl = FN.GetHandle("GFX") RetVal = FN.ClientSize(WinHndl, Wide, High) OrigSzx = Wide OrigSzy = High
RetVal = FN.Polygon(WinHndl, Wide, High, 25, Scale) RetVal = FN.SaveBmp("GFX.GFX", "ORIG", "Orig.bmp", OrigSzx, OrigSzy)
PRINT #DMO, "TRAPCLOSE DMO.DONE"
[BEGIN.WAIT] WAIT
'----------------------------------------------------------------- '-----------------------------------------------------------------
'################################################################## ' the following three block set property values for the resize ' handler '################################################################## [ENLARGE]
RetVal = FN.SetProp(GfxHndl, "SCALE", 1)
GOTO [BEGIN.WAIT] [END.ENLARGE]
'----------------------------------------------------------------- '-----------------------------------------------------------------
[SCALE.IMG]
RetVal = FN.SetProp(GfxHndl, "SCALE", 2)
GOTO [BEGIN.WAIT] [END.SCALE.IMG]
'----------------------------------------------------------------- '-----------------------------------------------------------------
[STRETCH]
RetVal = FN.SetProp(GfxHndl, "SCALE", 3)
GOTO [BEGIN.WAIT] [END.STRETCH]
'----------------------------------------------------------------- '-----------------------------------------------------------------
[GFX.SIZE] '############################################################# ' Resize handler '#############################################################
Wscale = 0 '<--- differnce between original size and current size Hscale = 0
DtHndl = 0 '<--- desktop handle GfxDc = 0 '<--- graphic control context DtDc = 0 '<--- desktop device context DtCmDc = 0 '<--- private device context
BmpHndl = 0 '<--- handle of loaded bitmap BmWide = 0 '<--- width and height of bitmap BmHigh = 0
OldBmp = 0 '<--- old object from Windoz
PropVal = FN.GetProp(GfxHndl, "SCALE") '<--- get current value
'############################################################## ' because LB sends multiple size notifications that have the ' same size parameters, the control property "SCALE" must be ' set to zero in the select case block '############################################################## SELECT CASE PropVal '<--- select value CASE 0 GOTO [BEGIN.WAIT] '<--- do nothing
CASE 1 '<--- resize graphic control PropVal = FN.SetProp(GfxHndl, "SCALE", 0) '<--- set property value RetVal = FN.ClientSize(WinHndl, Wide, High) '<--- get current size PRINT #GFX.GFX, "LOCATE 0 0 ";Wide;" ";High PRINT #GFX, "REFRESH"
CASE 2 '<--- scale image based on change in control size PropVal = FN.SetProp(GfxHndl, "SCALE", 0) RetVal = FN.ClientSize(WinHndl, Wide, High)
'<---------------- calculate change in size --------------> IF (Wide <> OrigSzx) OR (High <> OrigSzy) THEN Wscale = OrigSzx - Wide Hscale = OrigSzy - High
IF Wscale = 0 THEN Wscale = 1 IF Hscale = 0 THEN Hscale = 1
Scale = (Wscale / Hscale) END IF
PRINT #GFX.GFX, "LOCATE 0 0 ";Wide;" ";High '<--- resize graphic control PRINT #GFX, "REFRESH" RetVal = FN.Polygon(WinHndl, OrigSzx, OrigSzy, 25, Scale) '<--- redraw
CASE 3 '<--- stretch image using API PropVal = FN.SetProp(GfxHndl, "SCALE", 0) RetVal = FN.ClientSize(WinHndl, Wide, High) PRINT #GFX.GFX, "LOCATE 0 0 ";Wide;" ";High PRINT #GFX, "REFRESH"
BmpHndl = FN.LoadBmpFile("ORIG", "Orig.bmp") '<--- load saved bmp
OPEN "gdi32.DLL" FOR DLL AS #GDI '<--- activate gfx routines RetVal = FN.BmpInfo(BmpHndl, BmWide, BmHigh) '<--- get bmp size DtHndl = FN.DeskTop() '<--- get desktop handle DtDc = FN.GetDc(DtHndl) '<--- get desktop context DtCmDc = FN.CompatDc(DtDc) '<--- create private context DtDc = FN.DetachDc(DtHndl, DtDc) '<--- release desktop context GfxDc = FN.GetDc(GfxHndl) '<--- get control context
OldBmp = FN.AttachObj(DtCmDc, BmpHndl) '<--- activate bitmap CALLDLL #GDI, "StretchBlt", GfxDc AS ULONG, 0 AS LONG, 0 AS LONG, _ Wide AS LONG, High AS LONG, DtCmDc AS ULONG, 0 AS LONG, _ 0 AS LONG, BmWide AS LONG, BmHigh AS LONG, _ SRCCOPY AS LONG, RetVal AS LONG '<--- render bitmap on 'graphic control OldBmp = FN.DetachDc(DtCmDc, OldBmp) '<--- deactivate bitmap GfxDc = FN.DetachDc(GfxHndl, GfxDc) '<--- release control context DtCmDc = FN.KillDc(DtCmDc) '<--- destroy private context RetVal = FN.KillMemBmp("ORIG") '<--- destroy memory bitmap RetVal = FN.Flush("GFX.GFX", "ORIG", Wide, High) '<--- make it stick CLOSE #GDI '<--- deactivate graphic routines END SELECT
GOTO [BEGIN.WAIT] '<--- go back [END.GFX.SIZE]
'----------------------------------------------------------------- '-----------------------------------------------------------------
SUB ABOUT '######################################################## ' just info '########################################################
NOTICE "HELP" + CHR$(13) + "Select a CANVAS menu item then drag one of the " + _ "borders of the graphic control." END SUB
'----------------------------------------------------------------- '-----------------------------------------------------------------
SUB DMO.DONE Dummy$ '###################################################### ' cleanup '######################################################
KILL "Orig.bmp" CLOSE #USER CLOSE #GFX CLOSE #DMO END
END SUB
'----------------------------------------------------------------- '-----------------------------------------------------------------
FUNCTION FN.CheckHandle$(Tag$)
IF LEFT$(Tag$, 1) <> "#" THEN Tag$ = "#" + Tag$
FN.CheckHandle$ = Tag$ END FUNCTION
'----------------------------------------------------------------- '-----------------------------------------------------------------
FUNCTION FN.GetHandle(Tag$)
WinHndl = 0
Tag$ = FN.CheckHandle$(Tag$)
WinHndl = HWND(#Tag$)
FN.GetHandle = WinHndl END FUNCTION
'----------------------------------------------------------------- '-----------------------------------------------------------------
FUNCTION FN.Flush(GfxTag$, BmpTag$, Bx, By)
RetVal = 0
GfxTag$ = FN.CheckHandle$(GfxTag$)
PRINT #GfxTag$, "getbmp ";BmpTag$;" 0 0 ";Bx;" ";By PRINT #GfxTag$, "drawbmp ";BmpTag$;" 0 0" PRINT #GfxTag$, "flush"
RetVal = FN.KillMemBmp(BmpTag$) END FUNCTION
'----------------------------------------------------------------- '-----------------------------------------------------------------
FUNCTION FN.NewWin(WinHndl, GfxWide, GfxHigh) '##################################################### ' create a new window '##################################################### WS.BORDER = HEXDEC("&H00800000")
RetVal = 0 '<--- dummy variable GfxHndl = 0 '<--- graphic control handle GfxWin = 0 '<--- parent window handle
Ux = 0 '<--- size bounds Uy = 0 Bx = 0 By = 0
Cx = 0 '<--- center of main window Cy = 0 Px = 0 Py = 0
Wide = 0 '<--- sizes High = 0 '<--- window style ----------> Style = _WS_CHILD OR _WS_VISIBLE OR _WS_CLIPCHILDREN OR _WS_CLIPSIBLINGS OR _ _WS_THICKFRAME
STYLEBITS #GFX.GFX, 0, WS.BORDER, 0, 0 '<--- graphic style GRAPHICBOX #GFX.GFX, 0, 0, GfxWide, GfxHigh '<--- graphic size
WindowWidth = GfxWide '<--- parent window size WindowHeight = GfxHigh
OPEN "GFX" FOR WINDOW AS #GFX '<--- create window PRINT #GFX.GFX, "down" '<--- fill control with black PRINT #GFX.GFX, "fill black" PRINT #GFX.GFX, "flush"
GfxWin = FN.GetHandle("#GFX") '<--- get parent handle
'<--------- change parent window style ----------> CALLDLL #USER, "SetWindowLongA", GfxWin AS ULONG, _GWL_STYLE AS LONG, _ Style AS ULONG, RetVal AS VOID RetVal = FN.WindowSize(GfxWin, Ux, Uy, Bx, By) '<--- get its size Wide = Bx - Ux High = By - Uy
RetVal = FN.ClientSize(WinHndl, Bx, By) '<--- get size of main window Cx = INT(Bx / 2) '<--- find center Cy = INT(By / 2) Px = Cx - INT(Wide / 2) Py = Cy - INT(High / 2) '<--- graphic control parent a child of main window -------> CALLDLL #USER, "SetParent", GfxWin AS ULONG, WinHndl AS ULONG, RetVal AS VOID
'<---------- move graphic to center of main window --------> CALLDLL #USER, "MoveWindow", GfxWin AS ULONG, Px AS LONG, Py AS LONG, _ Wide AS LONG, High AS LONG, 1 AS LONG, RetVal AS VOID
PRINT #GFX.GFX, "locate 0 0 ";Wide;" ";High '<--- work-around for 'graphic control size bug PRINT #GFX, "REFRESH" PRINT #GFX, "RESIZEHANDLER [GFX.SIZE]" END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.ClientSize(WinHndl, BYREF Brx, BYREF Bry)
STRUCT tRect, _ X AS LONG, _ Y AS LONG, _ X1 AS LONG, _ Y1 AS LONG
RetVal = 0 CALLDLL #USER, "GetClientRect", WinHndl AS ULONG, tRect AS STRUCT, _ RetVal AS VOID
Brx = tRect.X1.struct Bry = tRect.Y1.struct
END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.WindowSize(WinHndl, BYREF Ulx, BYREF Uly, BYREF Brx, BYREF Bry)
STRUCT tRect, _ X AS LONG, _ Y AS LONG, _ X1 AS LONG, _ Y1 AS LONG
RetVal = 0
CALLDLL #USER, "GetWindowRect", WinHndl AS ULONG, tRect AS STRUCT, _ RetVal AS VOID
Ulx = tRect.X.struct Uly = tRect.Y.struct Brx = tRect.X1.struct Bry = tRect.Y1.struct END FUNCTION
'------------------------------------------------------------ '------------------------------------------------------------
FUNCTION FN.SetProp(WinHndl, Key$, Value)
RetVal = 0 CALLDLL #USER, "SetPropA", WinHndl AS ULONG, Key$ AS PTR, Value AS LONG, _ RetVal AS VOID
END FUNCTION
'------------------------------------------------------------ '------------------------------------------------------------
FUNCTION FN.GetProp(WinHndl, Key$)
Value = 0 CALLDLL #USER, "GetPropA", WinHndl AS ULONG, Key$ AS PTR, Value AS LONG
FN.GetProp = Value END FUNCTION
'------------------------------------------------------------ '------------------------------------------------------------
FUNCTION FN.Polygon(WinHndl, Wide, High, Radius, Scale) '########################################### ' draw a polygon on graphic control '###########################################
Rad = 4 * ATN(1) / 180.0 '<--- radian calculation
PosX = 0 '<--- postions PosY = 0 Angl = 0 Lpx = 0 Lpy = 0
I = 0 Cx = Wide / 2 '<--- center Cy = High / 2
Stp = 360 / 8
PosX = Cx PosY = Cy - Radius * Scale Lpx = PosX Lpy = PosY
PRINT #GFX.GFX, "COLOR WHITE" PRINT #GFX.GFX, "DOWN"
'<-------- draw polygon --------> FOR I = 0 TO 360 STEP Stp Angl = I * Rad PosX = Cx + Radius * SIN(Angl) * Scale PosY = Cy - Radius * COS(Angl) * Scale
PRINT #GFX.GFX, "line ";Lpx;" ";Lpy;" ";PosX;" ";PosY
Lpx = PosX Lpy = PosY NEXT I PRINT #GFX.GFX, "FLUSH" END FUNCTION
'--------------------------------------------------------------- '---------------------------------------------------------------
FUNCTION FN.SaveBmp(GfxTag$, BmpTag$, FileName$, Szx, Szy)
GfxTag$ = FN.CheckHandle$(GfxTag$)
PRINT #GfxTag$, "getbmp ";BmpTag$;" 0 0 ";Szx;" ";Szy BMPSAVE BmpTag$, FileName$ UNLOADBMP BmpTag$
END FUNCTION
'-------------------------------------------------------------------- '--------------------------------------------------------------------
FUNCTION FN.LoadBmpFile(Tag$, LoadName$)
BmpHndl = 0
LOADBMP Tag$, LoadName$
BmpHndl = HBMP(Tag$)
FN.LoadBmpFile = BmpHndl END FUNCTION
'--------------------------------------------------------------------- '---------------------------------------------------------------------
FUNCTION FN.DeskTop() '###################################################################### ' Get a handle to the monitor '######################################################################
DtHndl = 0 CALLDLL #USER, "GetDesktopWindow", DtHndl AS ULONG
FN.DeskTop = DtHndl END FUNCTION
'--------------------------------------------------------------- '---------------------------------------------------------------
FUNCTION FN.CompatDc(WinDc) '###################################################################### ' Create a context compatible with a device. ' ' ARGUMENTS: ' WinDc: Device context. ' Do NOT use user32.dll ReleaseDC(), use gdi32.DLL ' DeleteDC() instead. '######################################################################
ComPatDc = 0 CALLDLL #GDI, "CreateCompatibleDC", WinDc AS ULONG, ComPatDc AS ULONG
FN.CompatDc = ComPatDc END FUNCTION
'------------------------------------------------------------------- '-------------------------------------------------------------------
FUNCTION FN.GetDc(WinHndl) '###################################################################### ' Get a context from MSWIN for the device (form window, control, ' printer, audio, external device). '######################################################################
WinDc = 0 CALLDLL #USER, "GetDC", WinHndl AS ULONG, WinDc AS ULONG
FN.GetDc = WinDc END FUNCTION
'--------------------------------------------------------------- '---------------------------------------------------------------
FUNCTION FN.AttachObj(WinDc, ThisObject) '###################################################################### ' Make an object (pen, brush, font, bitmap) active. ' ' ARGUMENTS: ' WinDc: Device context handle ' ThisObject: Object to make active. '######################################################################
OrgObj = 0 CALLDLL #GDI, "SelectObject", WinDc AS ULONG, ThisObject AS ULONG, _ OrgObj AS ULONG
FN.AttachObj = OrgObj END FUNCTION
'--------------------------------------------------------------- '---------------------------------------------------------------
FUNCTION FN.DetachDc(WinHndl, WinDc) '###################################################################### ' Release a device context and its resources ' ' ARGUMENTS: ' WinHndl: The handle of a form window or control. ' WinDc: Device context obtained from GetDc(). '######################################################################
RetVal = 0 CALLDLL #USER, "ReleaseDC", WinHndl AS ULONG, WinDc AS ULONG, RetVal AS VOID END FUNCTION
'--------------------------------------------------------------- '---------------------------------------------------------------
FUNCTION FN.KillObj(ThisObj) '###################################################################### ' Destroy an object (brush, pen, font) and release its resources '######################################################################
DeadObj = 0 CALLDLL #GDI, "DeleteObject", ThisObj AS ULONG, DeadObj AS VOID
END FUNCTION
'--------------------------------------------------------------- '---------------------------------------------------------------
FUNCTION FN.KillDc(WinDc) '############################################################ ' Destroy a device context and release WIN resources ' ' ARGUMENTS: ' WinDc: Device context to destroy. ' Do NOT use this function to destroy a device ' context obtained with the GetDC() function. '############################################################
RetVal = 0 CALLDLL #GDI, "DeleteDC", WinDc AS ULONG, RetVal AS VOID
END FUNCTION
'----------------------------------------------------------------- '-----------------------------------------------------------------
FUNCTION FN.BmpInfo(BmpHndl, BYREF BmWide, BYREF BmHigh) '########################################################### ' Retrieves information about a memory dibsection bitmap. ' ARGUMENTS: ' BmpHndl: Handle of memory bitmap ' BmWide, BmpHigh: Width and height of memory bitmap '###########################################################
STRUCT tBITMAP, _ bmType AS LONG, _ '<--- Specifies the bitmap type. This member must be zero. bmWidth AS LONG, _ '<--- Specifies the width, in pixels, of the bitmap. bmHeight AS LONG, _ '<--- Specifies the height, in pixels, of the bitmap. bmWidthBytes AS LONG, _ '<--- Specifies the number of bytes in each scan line. bmPlanes AS USHORT, _ '<--- Specifies the count of color planes. bmBitsPixel AS USHORT, _ '<--- Specifies the number of bits required to indicate the _ 'color of a pixel. bmBits AS ULONG '<--- Pointer to a buffer that receives the 1-byte bit values 'of the BGR colors BufSize = 0 NumBytes = 0
BufSize = LEN(tBITMAP.struct)
CALLDLL #GDI, "GetObjectA", BmpHndl AS ULONG, BufSize AS ULONG, _ tBITMAP AS STRUCT, NumBytes AS LONG
BmWide = tBITMAP.bmWidth.struct BmHigh = tBITMAP.bmHeight.struct
FN.BmpInfo = NumBytes END FUNCTION
'----------------------------------------------------------------- '-----------------------------------------------------------------
FUNCTION FN.KillMemBmp(Tag$) '########################################################### ' Remove bitmap created by Liberty Basic from memory ' ARGUMENTS: ' Tag$: String name assigned to memory bitmap ' when it was created by LOADBMP or "getbmp" '###########################################################
UNLOADBMP Tag$
END FUNCTION
'--------------------------------------------------------------------- '---------------------------------------------------------------------
'
|
|