Page 1 of 1

Change the Scale of a Window from within the window?

Posted: Sat Feb 02, 2013 11:10 am
by GeneB
Is it possible to change the scale of a window by incrementing the scale from within the window?
Press a button (or test a condition) and have the window resize while it is open?
Something like:

Code: Select all

#INCLUDE "dcdialog.ch"

PROC appsys
return

FUNCTION MAIN()
local aScale[5], GetOptions, GetList[0]

AFILL(aScale, 1.2)
aScale[5] := .F.

@ 1,1 DCSAY "Some Text On The Screen" SAYSIZE 20

@ 3,1 DCPUSHBUTTON CAPTION "Dummy Button" SIZE 12,1.5

@ 10,1 DCPUSHBUTTON CAPTION "<<" SIZE 3,1  ;
       TOOLTIP "make window smaller"       ;
       ACTION {|| WindowRescale(0,@aScale) ;
                 , DC_GetRefresh(getlist) }

@ 10,4 DCPUSHBUTTON CAPTION ">>" SIZE 3,1  ;
       TOOLTIP "make window larger"        ;
       ACTION {|| WindowRescale(1,@aScale) ;
                 , DC_GetRefresh(getlist) }

DCGETOPTIONS ;
   SAYWIDTH 50 ;
   SCALEFACTOR aScale ;
   AUTORESIZE

DCREAD GUI FIT ADDBUTTONS OPTIONS GetOptions

RETURN NIL

*--------------

FUNCTION WindowRescale(nOpt,aScale)
local nCurSize, nNewSize

nCurSize := aScale[1]

IF nOpt==0   

   nNewSize := nCurSize - 0.1
   nNewSize := MAX(nNewSize, 0.9 )

   AFILL(aScale,nNewSize)
   aScale[5] := .F.

ELSE // nOpt==1

   nNewSize := nCurSize + 0.1
   nNewSize := MIN(nNewSize, 2.0 )

   AFILL(aScale,nNewSize)
   aScale[5] := .F.

ENDIF

RETURN aScale

Re: Change the Scale of a Window from within the window?

Posted: Sun Feb 03, 2013 2:12 pm
by rdonnay
Gene - I don't know if this is what you want but give it a look.

Resize the window and watch what happens.

Code: Select all

#INCLUDE "dcdialog.CH"

FUNCTION Main()

LOCAL GetList[0], GetOptions, i, aTest[10]

AFill(aTest,'Some Text')

FOR i := 1 TO 10
  @ i,0 DCSAY 'This is a test' GET aTest[i] SAYSIZE 0 SAYFONT '10.Arial' SAYRIGHTBOTTOM
NEXT

DCGETOPTIONS RESIZE RESIZEDEFAULT DCGUI_RESIZE_AUTORESIZE_SCALEFONT

DCREAD GUI FIT TITLE 'Scaling a font' OPTIONS GetOptions

RETURN nil

* ------------

PROC appsys ; return

Re: Change the Scale of a Window from within the window?

Posted: Mon Feb 04, 2013 10:59 am
by GeneB
You just answered my next question.
This helps tremendously with what I'm doing with my old Clipper application.

Also, is it possible to resize the dimensions of a window without stretching the sides with a mouse,
but by having the user change the SCALEFACTOR aSize values from within the window.
If this cannot be done directly, if I change the values used by DCGETOPTIONS SCALEFACTOR
within a window, is there a way to then have the window close and reopen itself, giving the illusion that by incrementing the scalefactor the window is instantly changing dimensions? (please see the sample code in the first post).

Thank you in advance.
GeneB

Re: Change the Scale of a Window from within the window?

Posted: Mon Feb 04, 2013 11:36 am
by rdonnay
This might be what you are looking for:

Code: Select all

#INCLUDE "dcdialog.ch"

PROC appsys
return

FUNCTION MAIN()

local aScale[5], GetOptions, GetList[0], oDlg

AFILL(aScale, 1.2)
aScale[5] := .F.

@ 1,1 DCSAY "Some Text On The Screen" SAYSIZE 20

@ 3,1 DCPUSHBUTTON CAPTION "Dummy Button" SIZE 12,1.5

@ 10,1 DCPUSHBUTTON CAPTION "<<" SIZE 3,1  ;
       TOOLTIP "make window smaller"       ;
       ACTION {|| WindowRescale(-30,oDlg) }

@ 10,4 DCPUSHBUTTON CAPTION ">>" SIZE 3,1  ;
       TOOLTIP "make window larger"        ;
       ACTION {|| WindowRescale(30,oDlg) }

DCGETOPTIONS ;
   SAYWIDTH 50 ;
   SCALEFACTOR aScale ;
   RESIZE RESIZEDEFAULT DCGUI_RESIZE_AUTORESIZE_SCALEFONT

DCREAD GUI FIT ADDBUTTONS OPTIONS GetOptions PARENT @oDlg

RETURN NIL

*--------------

FUNCTION WindowRescale(nIncrement,oDlg)

oDlg:setSize({oDlg:currentSize()[1]+nIncrement,oDlg:currentSize()[2]+nIncrement})

RETURN nil

Re: Change the Scale of a Window from within the window?

Posted: Mon Feb 04, 2013 5:32 pm
by GeneB
Perfect.
Nice 'bell and whistle'.
You're making me look good.
GeneB