Drag to Move/Resize Gadgets

Windows specific forum
User avatar
VisualJump3D
User
User
Posts: 75
Joined: Thu Jun 23, 2011 8:32 pm
Location: italy
Contact:

Re: Drag to Move/Resize Gadgets

Post by VisualJump3D »

Hi,

I tried your code (very good, thank), but I have a problem:

I have to be able to move only the gadget of the text and not the whole container ...

How can I do?

Ps You need to change my image with one of your ...

<<ImmaArena= LoadImage(#PB_Any,"C:\Users\guido\Desktop\Vj3D_CourseDesigner2015\10_FileTemporanei\PerStampa32.png")>>



Code: Select all

UseJPEGImageDecoder()
UseTGAImageDecoder()
UsePNGImageDecoder()
UseTIFFImageDecoder()
UseJPEGImageEncoder()
UsePNGImageEncoder()


; ---- FONT ----
FontComitato=0


;---- Gadget ----
GContainer=0
GImageArena=1
GTextComitato=2


; ---- load Font ----
LoadFont(FontComitato, "Palatino linotype",24)   


; ---- Dati caricati dall'Editor2D
NomeComitato.s="ASD I Due Leoni"
NomeManifestazione.s="Concorso Ippico Nazionale tipo A***** del 27-28-29/12/2014"
Categoria.s="C140"
Prontuario.s="19 a fasi consequtive - tempo seconda fase"
Velocita.s="350Mt/m"
LunghezzaBase.s="380Mt"
LunghezzaSecondaFase.s="240Mt"
TempoMassimoBase.s="52Sec."
TempoMassimoSecondaFase.s="38Sec."
TempoMassimoBarrage.s="   "
TempoMassimoSecondaMance.s="   "
TempoMassimoTerzoPercorso.s="  "

DirettoreDiCampo.s="Guido"
DataCategoria.s="27/12/2014"
ProntuarioInternazionale.s=" "
ImmaArena= LoadImage(#PB_Any,"C:\Users\guido\Desktop\Vj3D_CourseDesigner2015\10_FileTemporanei\PerStampa32.png")


; ---- Dati foglio cartaceo ----
A4X.f=297.0
A4Y.f=210.0
ProporzioneImma.f=3.0/4.0
Border=1
IntestazioneStandard=1;    1=Standard     2=Personalizzata
Orientamento.s="L"    ;    L=Landscape    P=Portrait


; ---- Calcolo dimensione Desktop
NbDesktops = ExamineDesktops()
SizeWindW.f=DesktopWidth(0)
SizeWindH.f=DesktopHeight(0)


; ---- Calcolo Dpi schermo per dimensione foglio
DPI_X.f = GetDeviceCaps_(GetDC_(GetDesktopWindow_()), #LOGPIXELSX)
DPI_Y.f = GetDeviceCaps_(GetDC_(GetDesktopWindow_()), #LOGPIXELSY)
ContainerX.f=((A4X.f/10.0)*DPI_X.f)/2.54
ContainerY.f=((A4Y.f/10.0)*DPI_Y.f)/2.54

; ---- Calcolo per corretta dimensione dell'immagine nel foglio virtuale
ImmaSizeW=ContainerX.f*ProporzioneImma.f
ImmaSizeH=ContainerY.f*ProporzioneImma.f
ResizeImage(ImmaArena, ImmaSizeW, ImmaSizeH)


; ---- Determina la centratura dell'immagine nel foglio ----
If Border=1 
  PosImmaX.f=(ContainerX.f-ImmaSizeW)/2.0
EndIf
If Border=2 
  PosImmaX.f=0
EndIf
If Border=3 
  PosImmaX.f=ContainerX.f-ImmaSizeW
EndIf
PosImmaY.f=ContainerY.f-ImmaSizeH


; --- Apertura della MainWindow ----

mainWin  = OpenWindow(#PB_Any  , 0, 0,SizeWindW.f,SizeWindH,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)


; ---- Calcola la dimensione dei Gadget di Testo in base al font ----
StartDrawing(WindowOutput(mainWin))
DrawingFont(FontID(FontComitato))
DimeFontComitatoW=TextWidth(NomeComitato.s)+2
DimeFontComitatoH=TextHeight(NomeComitato.s)
StopDrawing()


; ---- Crea il Cointainer "Foglio virtuale" e lo dimensiona correttamente + con all'interno i gadget ( arena testi etc etc ) ----

ContainerGadget(GContainer, 0, 0, ContainerX.f, ContainerY.f, #PB_Container_Double) 
SetGadgetColor(GContainer, #PB_Gadget_BackColor, RGB(255,255,255))
ImageGadget(GImageArena, PosImmaX.f, PosImmaY.f, ImmaSizeW, ImmaSizeH, ImageID(ImmaArena))
If IntestazioneStandard=1
  x=(ContainerX.f-DimeFontComitatoW)/2
  y=1
  TextGadget(GTextComitato, x, y, DimeFontComitatoW, DimeFontComitatoH, NomeComitato.s,#PB_Text_Center) 
  SetGadgetFont(GTextComitato, FontID(FontComitato))
  SetGadgetColor(GTextComitato, #PB_Gadget_BackColor, RGB(255,255,255))  
  SetGadgetColor(GTextComitato, #PB_Gadget_FrontColor, RGB(255,0,0)) 
  SetWindowLongPtr_(GadgetID(GTextComitato), #GWL_STYLE, GetWindowLongPtr_(GadgetID(GTextComitato), #GWL_STYLE) | #WS_CLIPSIBLINGS)
EndIf
CloseGadgetList() 



















Repeat
  Event = WaitWindowEvent()
   Select event
      
    Case #WM_LBUTTONDOWN
      ReleaseCapture_()
      GetCursorPos_(cursorpos.POINT)
      gadget = WindowFromPoint_(PeekQ(cursorpos))
      If GetAsyncKeyState_(#VK_SHIFT) & 32768
        SendMessage_(gadget, #WM_NCLBUTTONDOWN, #HTBOTTOMRIGHT, 0) ; #HTRIGHT = stretch width only
      Else
        SendMessage_(gadget, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
      EndIf
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow 
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Drag to Move/Resize Gadgets

Post by IdeasVacuum »

....You seem to be missing the Procedure that adds gadgets to the list of gadgets that are moveable/resizable. Only the gadgets in that list are allowed to move (just make sure you don't add the container to the list!). The perpose of this method is to allow the User to add/move/re-size gadgets at run time.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
VisualJump3D
User
User
Posts: 75
Joined: Thu Jun 23, 2011 8:32 pm
Location: italy
Contact:

Re: Drag to Move/Resize Gadgets

Post by VisualJump3D »

Thank ,

Can you help me fix my code, please?
User avatar
VisualJump3D
User
User
Posts: 75
Joined: Thu Jun 23, 2011 8:32 pm
Location: italy
Contact:

Re: Drag to Move/Resize Gadgets

Post by VisualJump3D »

I understood the problem!

Does not work with TextGadget , but it only works with StringGadget

But ... why ???
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Drag to Move/Resize Gadgets

Post by IdeasVacuum »

The text gadget is special, it's intended for labelling, notes etc that the User cannot edit - so that may be why, it may not have the right events associated, I don't know. A string gadget is fine though, it can do everything and more, still look exactly the same as a text gadget with the right flags. For larger amounts of text an Editor Gadget might be good.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
VisualJump3D
User
User
Posts: 75
Joined: Thu Jun 23, 2011 8:32 pm
Location: italy
Contact:

Re: Drag to Move/Resize Gadgets

Post by VisualJump3D »

Thank !
Post Reply