Aide sur les Interfaces Graphique Utilisateurs (GUI).
TT22
Membre émérite
Messages : 1566 Enregistré le : lun. 18 avr. 2011 15:21
Localisation : La Quatrième Dimension
Status :
Hors ligne
#1
Message
par TT22 » mer. 25 juil. 2012 11:51
Bonjour à tous !
Voici ma question : Est-il possible d'afficher une image en trapèze dans une GUI ?
Par exemple, j'ai cette image :
Avatar.png (14.79 Kio) Vu 3188 fois
Je voudrais qu'elle s'affiche de cette façon dans la GUI :
Avatar.png (16.06 Kio) Vu 3188 fois
Et évidemment qu'il soit possible de choisir le niveau de déformation
Voilà, merci d'avance à ceux qui me répondrons
Modifié en dernier par
TT22 le ven. 27 juil. 2012 12:10, modifié 1 fois.
Cordialement,
TT22
TT22
Membre émérite
Messages : 1566 Enregistré le : lun. 18 avr. 2011 15:21
Localisation : La Quatrième Dimension
Status :
Hors ligne
#3
Message
par TT22 » mer. 25 juil. 2012 18:04
Heu, ça permet de faire pivoter des images, mais est-ce qu'on peut les déformer en trapèze ?
Cordialement,
TT22
sylvanie
Niveau 11
Messages : 1556 Enregistré le : jeu. 26 juil. 2007 21:31
Localisation : Paris
Status :
Hors ligne
#4
Message
par sylvanie » jeu. 26 juil. 2012 14:04
j'arrive à un truc assez brouillon, mais si ça te permet d'avancer :
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
_Main()
Func _Main()
Local $hGUI, $hGraphic, $aPoints[5][2]
; Create GUI
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
; Draw a polygon
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(200, 200,$hGraphic); précisement, alors je me contente de les utilisé comme je vois dans
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; les scripts de pros!
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) ; ca, c'est pour l'anti-aliasing
$aPoints[0][0] = 4
$aPoints[1][0] = 150
$aPoints[1][1] = 150
$aPoints[2][0] = 350
$aPoints[2][1] = 175
$aPoints[3][0] = 350
$aPoints[3][1] = 225
$aPoints[4][0] = 150
$aPoints[4][1] = 250
_GDIPlus_GraphicsDrawPolygon($hGraphic, $aPoints)
$hImg = _GDIPlus_ImageLoadFromFile("tortue.gif")
$step=1
For $ind= 0 to 200 step $step
_GDIPlus_GraphicsDrawImage($hBuffer, $hImg, -$ind, 0)
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hBitmap, $ind,0,$step,200,$ind,$ind/2,$step,100-$ind/4 )
Next
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc ;==>_Main
Laisse tomber le trapèze en noire, il sert à rien
En gros la philosophie, c'est de construire plein de petit rectangle les un derrière les autres pour former un trapèze et de remplir chacun d'eux avec un découpage de l'image ( _GDIPlus_GraphicsDrawImage($hBuffer, $hImg, -$ind, 0) )
c'est pas génial mais si ça peut aider ...
Toi qui cherche à mettre le doigt sur la solution, appuie sur F1.
silvere
Niveau 8
Messages : 532 Enregistré le : sam. 24 sept. 2011 22:56
Status :
Hors ligne
#5
Message
par silvere » jeu. 26 juil. 2012 15:38
Tu ne pourrais pas reprendre la 2ème image et de jouer avec la transparance ?
Enfin a part si se n'est pas toi qui défini l'image.
Quand le mensonge prend l'ascenseur, la vérité prend l'escalier. Elle met plus de temps, mais elle fini toujours par arriver.
sylvanie
Niveau 11
Messages : 1556 Enregistré le : jeu. 26 juil. 2007 21:31
Localisation : Paris
Status :
Hors ligne
#6
Message
par sylvanie » jeu. 26 juil. 2012 16:52
Bon, je l'ai nettoyé en enlevant le superflu et en le mettant un peu plus en forme de trapeze.
Et je l'ai adapté à l'avater
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
_Main()
Func _Main()
; Create GUI
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
; Draw a polygon
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(100, 100,$hGraphic); précisement, alors je me contente de les utilisé comme je vois dans
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; les scripts de pros!
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) ; ca, c'est pour l'anti-aliasing
$hImg = _GDIPlus_ImageLoadFromFile("avatar.png")
$step=1
For $ind= 0 to 100 step $step
_GDIPlus_GraphicsDrawImage($hBuffer, $hImg, -$ind, 0)
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hBitmap, $ind,0,$step,100,100+$ind,50+$ind/5,$step,100-2*$ind/5 )
Next
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc ;==>_Main
Toi qui cherche à mettre le doigt sur la solution, appuie sur F1.
mikell
Spammer !
Messages : 6292 Enregistré le : dim. 29 mai 2011 17:32
Localisation : Deep Cévennes
Status :
Hors ligne
#7
Message
par mikell » jeu. 26 juil. 2012 18:41
sylvanie les proportions sont étranges avec ton script
C'est mieux comme ça mais c'est pas bufferisé
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("file.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
For $i = 0 to $w step 0.5
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, 1, $h, _
$x+$i, $y+$i/8, 1, $h-2*$i/8 )
Next
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
En tout cas ton idée est super bien trouvée (les autres solutions possibles sont des *grosses* prises de tête) et je me mets le script de côté derechef
" L'échec est le fondement de la réussite. " (Lao-Tseu )
" Plus ça rate, plus on a de chances que ça marche " (les Shadoks )
sylvanie
Niveau 11
Messages : 1556 Enregistré le : jeu. 26 juil. 2007 21:31
Localisation : Paris
Status :
Hors ligne
#8
Message
par sylvanie » jeu. 26 juil. 2012 21:13
c'est clair que je n'ai pas cherché vraiment l’harmonie
ce qui me gène plus, c'est que dans mon cas, l'image disparaît en cas de réduction au switch de fenêtre ... ça reste du balbutiement ...
[EDIT]
en reprenant l'adaptation de Mikell :
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("avatar.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
MY_WM_PAINT()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func MY_WM_PAINT()
For $i = 0 to $w step 0.5
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, 1, $h, _
$x+$i, $y+$i/8, 1, $h-2*$i/8 )
Next
EndFunc
On s'enregistre à l'évènement WM_PAINT pour retracer le dessin en cas de switch, mais ça ne marche pas pour la réduction ... A suivre
[RE-EDIT]
Et bah voilà
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("GDI+", 400, 300)
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("avatar.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
MY_WM_PAINT()
GUISetState()
Do
$msg=GUIGetMsg()
If $msg = $GUI_EVENT_RESTORE Then MY_WM_PAINT()
Sleep(100)
Until $msg = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func MY_WM_PAINT()
For $i = 0 to $w step 0.5
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, 1, $h, _
$x+$i, $y+$i/8, 1, $h-2*$i/8 )
Next
Return
EndFunc
Mais ce n'est pas encore très élégant ...
Toi qui cherche à mettre le doigt sur la solution, appuie sur F1.
TT22
Membre émérite
Messages : 1566 Enregistré le : lun. 18 avr. 2011 15:21
Localisation : La Quatrième Dimension
Status :
Hors ligne
#9
Message
par TT22 » ven. 27 juil. 2012 12:09
silvere a écrit : Enfin a part si se n'est pas toi qui défini l'image.
Ben oui, c'était ça mon problème
@ sylvanie et mikell : Merci à vous deux ça fonctionne parfaitement
PS : Essayez ça :
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("GDI+", 400, 300)
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("avatar.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
MY_WM_PAINT()
GUISetState()
Do
$msg=GUIGetMsg()
If $msg = $GUI_EVENT_RESTORE Then MY_WM_PAINT()
Until $msg = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func MY_WM_PAINT()
For $i = 0 to $w step 0.5
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, 1, $h, _
$x+$i, $y+$i/0.8, 1, $h-2*$i/0.8 )
Next
Return
EndFunc
Cordialement,
TT22
sylvanie
Niveau 11
Messages : 1556 Enregistré le : jeu. 26 juil. 2007 21:31
Localisation : Paris
Status :
Hors ligne
#10
Message
par sylvanie » ven. 27 juil. 2012 17:35
Oui, j'avais remarqué aussi qu'on pouvait inverser l'affichage.
De même dans les trucs assez marrant, c'est de jouer avec la valeur du pas de boucle afin d'exagérer le côté "Rectangle":
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("GDI+", 400, 300)
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("avatar.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
MY_WM_PAINT()
GUISetState()
Do
$msg=GUIGetMsg()
If $msg = $GUI_EVENT_RESTORE Then MY_WM_PAINT()
Until $msg = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func MY_WM_PAINT()
Local $step=5
For $i = 0 to $w step $step
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, $step, $h, _
$x+$i, $y+$i/0.8, $step, $h-2*$i/0.8 )
Next
Return
EndFunc
Mais bon là on s'écarte
Toi qui cherche à mettre le doigt sur la solution, appuie sur F1.
mikell
Spammer !
Messages : 6292 Enregistré le : dim. 29 mai 2011 17:32
Localisation : Deep Cévennes
Status :
Hors ligne
#11
Message
par mikell » ven. 27 juil. 2012 21:54
Hum pour maintenir l'image, c'est ça
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("file.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
MY_WM_PAINT()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func MY_WM_PAINT()
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
For $i = 0 to $w step 0.5
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, 1, $h, _
$x+$i, $y+$i/8, 1, $h-2*$i/8 )
Next
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
Return $GUI_RUNDEFMSG
EndFunc
@sylvanie
On est des bourrins, la solution était dans l'aide à GUICtrlCreatePic
" L'échec est le fondement de la réussite. " (Lao-Tseu )
" Plus ça rate, plus on a de chances que ça marche " (les Shadoks )
sylvanie
Niveau 11
Messages : 1556 Enregistré le : jeu. 26 juil. 2007 21:31
Localisation : Paris
Status :
Hors ligne
#12
Message
par sylvanie » sam. 28 juil. 2012 23:16
mikell a écrit :
On est des bourrins, la solution était dans l'aide à GUICtrlCreatePic
ouaiiis
Ceci dit c'est courant chez les nains
Toi qui cherche à mettre le doigt sur la solution, appuie sur F1.