Page 2 sur 5

Re: Rendre transparent une couleur dans une imagegadget

Publié : lun. 15/févr./2010 8:56
par Kwai chang caine
Alors la ....je te remercie mille fois 8)
J'allais m'y remettre ce matin, la mort dans l'ame, car en fait je doit reconnaitre que le graphisme, n'est pas ma passion premiere :oops:
J'ai grand tort, car quand je vois ce que vous faites, c'est beau...mais le reve s'arrette tout de suite pour moi quand je vois le code 8O
Meme quand vous le donnez....je le comprend pas..alors imagine a le pondre :oops:

Le probleme c'est que j'en ai pas assez souvent besoin, mais quand j'en ai besoin, c'est souvent a un niveau superieur a debutant :roll:

J'ai du mettre 2 jours pour juste pondre les calculs de la premiere fleche...puis ...

KERNADEC est arrivéééééé...
Sans s'presseeeeeer, hé héééé
Le grand KERNADEEEEEEC
Le beau KERNADEEEEEC ...
Avec son chevaaal et son grand chapeaaau !!!

Ah non ça c'est zorro....
Image
Mais bon ça m'a fait le meme effet tellement j'etais désespéré 8)

Je te souhaite une excelente journée :wink:

Re: Rendre transparent une couleur dans une imagegadget

Publié : lun. 15/févr./2010 20:54
par cederavic
J'ai fais mumuse à partir du code de LSI :)

Code : Tout sélectionner

Enumeration
   #Fenetre
   #Fenetre_BG
   #Fleche
   #FlecheGadget
EndEnumeration

Declare WinCB(hWnd, Msg, wParam, lParam)

Procedure DessineFleche(x1, y1, x2, y2, Epaisseur, BorderlColor, GradientColor1, GradientColor2, GradientColor3)
   ; On organise les valeurs d'entrées
   If x1 > x2
      Depart_X = x2
      Fin_X = x1
   Else
      Depart_X = x1
      Fin_X = x2
   EndIf
   If y1 > y2
      Depart_Y = y2
      Fin_Y = y1
   Else
      Depart_Y = y1
      Fin_Y = y2
   EndIf
   Largeur = Fin_X - Depart_X 
   Hauteur = Fin_Y - Depart_Y 
   If Largeur <= 0 : Largeur = 1 : EndIf : If Hauteur <= 0 : Hauteur = 1 : EndIf
   
   CreateImage(#Fleche, Largeur, Hauteur, 32)
   StartDrawing(ImageOutput(#Fleche))

      DrawingMode(#PB_2DDrawing_Gradient)
      LinearGradient(0, Epaisseur, 0, Hauteur - Epaisseur - 1)
      FrontColor(GradientColor1) : GradientColor(0.80, GradientColor2) : BackColor(GradientColor3)
      Box(0, 0, Largeur, Hauteur)
      
      DrawingMode(#PB_2DDrawing_Default)
      LineXY(Epaisseur * 2 + 1, 1, 2, Epaisseur * 2, BorderlColor)
      LineXY(Epaisseur * 2 , 1, Epaisseur * 4 - 1, Epaisseur * 2, BorderlColor)
      LineXY(0, Epaisseur * 2 + 1, Epaisseur * 1.5 - 1, Epaisseur * 2 + 1, BorderlColor)
      LineXY(Epaisseur * 2.5, Epaisseur * 2 + 1, Epaisseur * 4, Epaisseur * 2 + 1, BorderlColor)
      LineXY(Epaisseur * 1.5, Epaisseur * 2 + 1, Epaisseur * 1.5, Hauteur - Epaisseur / 2, BorderlColor)
      LineXY(Epaisseur * 2.5 - 1, Epaisseur * 2 + 1, Epaisseur * 2.5 - 1, Hauteur - Epaisseur * 1.5, BorderlColor)
      LineXY(Epaisseur * 1.5, Hauteur - Epaisseur / 2 - 1, Largeur, Hauteur - Epaisseur / 2 - 1, BorderlColor)
      LineXY(Epaisseur * 2.5 - 1, Hauteur - Epaisseur * 1.5, Largeur, Hauteur - Epaisseur * 1.5, BorderlColor)
      LineXY( Largeur - 1, Hauteur - Epaisseur * 1.5, Largeur - 1, Hauteur - Epaisseur / 2 - 1, BorderlColor)
      
      DrawingMode(#PB_2DDrawing_AlphaChannel)
      Box(0, 0, Largeur, Hauteur, RGBA(0, 0, 0, 0))
     
      Box(Epaisseur * 1.5, Hauteur - Epaisseur - Epaisseur / 2, Largeur - Epaisseur, Epaisseur, RGBA(0, 0, 0, 255))
      Box(Epaisseur * 1.5, Epaisseur, Epaisseur, Hauteur - Epaisseur - Epaisseur / 2, RGBA(0, 0, 0, 255))
      
      For ty = 0 To Epaisseur * 2
        LineXY(Epaisseur * 2 - ty +1, ty + 1, Epaisseur * 2 + ty, ty + 1, RGBA(0, 0, 0, 255))
      Next
      
      LineXY(0, 1, Largeur, 1, RGBA(0, 0, 0, 0))
      
  StopDrawing()
      
      
  hDC = StartDrawing(ImageOutput(#Fleche))
    
    If Largeur < Epaisseur * 4 Or Hauteur < Epaisseur * 4
      DrawingMode(#PB_2DDrawing_AlphaChannel)
      Box(0, 0, Largeur, Hauteur, RGBA(0, 0, 0, 0))
    ElseIf x1 < x2  And y1  > y2 ; Haut Droit
      StretchBlt_(hDC, Largeur, 0, -Largeur, Hauteur, hDC, 0, 0, Largeur, Hauteur, #SRCCOPY)
    ElseIf x1 < x2 And y1 < y2 ; Bas Droit
      StretchBlt_(hDC, Largeur, Hauteur, -Largeur, -Hauteur, hDC, 0, 0, Largeur, Hauteur, #SRCCOPY)
    ElseIf x1   > x2 And y1 < y2  ; Haut gauche
      StretchBlt_(hDC, 0, Hauteur, Largeur, -Hauteur, hDC, 0, 0, Largeur, Hauteur, #SRCCOPY)
    EndIf
    
  StopDrawing()

  SetGadgetState(#FlecheGadget, ImageID(#Fleche))
  ResizeGadget(#FlecheGadget, Depart_X, Depart_Y, Largeur, Hauteur)
   
EndProcedure

CreateImage(#Fleche, 10, 10, 32)

OpenWindow(#Fenetre, 0, 0, 800, 600, "Fleche multidirectionnelle",  #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
  
  ImageGadget(#FlecheGadget,0, 0, 0, 0, ImageID(#Fleche))
  
  CreateImage(#Fenetre_BG, 800, 600)
  StartDrawing(ImageOutput(#Fenetre_BG))
    a = 1
    For x = 0 To 800 Step 10
      For y = 0 To 600 Step 10
        a * -1
        If a = 1 : Color = RGB(80, 80, 80) : Else : Color = #White : EndIf
        Box(x, y, 10, 10, Color)
      Next
    Next
  StopDrawing()
  
  SetWindowCallback(@WinCB())

DessineFleche(0, 0, 800, 600, 12, RGB(16, 16, 16), RGB(75, 64, 64), RGB(128, 140, 128), RGB(230, 230, 250))

Repeat
   
   Evenement = WindowEvent()
   
   Select Evenement
         
      Case #WM_MOUSEMOVE
         If GetAsyncKeyState_(#VK_LBUTTON)
            MouseX = WindowMouseX(#Fenetre)
            MouseY = WindowMouseY(#Fenetre)
            If Depart_X < 0
               Depart_X = MouseX
               Depart_Y = MouseY
            EndIf

            DessineFleche(Depart_X, Depart_Y, MouseX , MouseY, 12, RGB(16, 16, 16), RGB(75, 64, 64), RGB(128, 140, 128), RGB(230, 230, 250))

         Else
            Depart_X = -1
         EndIf         
         
   EndSelect
   
Until Evenement = #PB_Event_CloseWindow



Procedure WinCB(hWnd, Msg, wParam, lParam)

  Select Msg
    Case #WM_PAINT
  
      hBmp = ImageID(#Fenetre_BG)
      hDC = BeginPaint_(hWnd, @ps.PAINTSTRUCT)
      
        hDC2 = CreateCompatibleDC_(hDC)
        
          SelectObject_ (hDC2, hBmp)
          BitBlt_(hDC, 1, 1, 800, 600, hDC2, 0, 0, #SRCCOPY)
          ReleaseDC_(hWnd, hDC)
          
        DeleteDC_(hDC2)
      EndPaint_(hWnd, @ps)
      ProcedureReturn #True
    
    Default
      ProcedureReturn #PB_ProcessPureBasicEvents
    
  EndSelect

EndProcedure


Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 9:44
par Kwai chang caine
CEDERAVIC vous etes des amours 8)
Qu'est ce que j'aimerais pouvoir faire mumuse comme ça 8O

Nadine boudin....vous etes comme NETMAESTRO vous les sortez d'ou ce genre d'API "StretchBlt_"
Comme disait coluche, faut se lever de bonne heure pour caser une API comme celle la dans une conversation :lol:

Ta fleche est splendide, elle a meme plus de chose que je voulais....elle est dégradée 8)
Une toute simple m'aurait suffit, je voulais juste qu'elle soit transparente, car quand je fais chevaucher deux gadgets on voit le carré blanc autour qui couvre l'autre gadget :(
D'ou ma décision, d'essayer de les rendre transparentes :roll:

Mille millions de merci, je vais essayer de la rentrer dans mon code, y'a un peu de scintillement au deplacement, j'ai pensé que cela devait venir du damier, alors j'ai remplacé celui ci par un box blanc, mais c'est pareil, ça scintille au deplacement
Peut etre que ça viens de W2000 qui est trop vieux ?? :roll:

En tout cas encore merci de ton travail 8)

Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 11:56
par cederavic
J'ai le scintillement sous XP aussi, je pense que ça vient du fait qu'on dessine dans une image puis rafraichit le gadget avec l'image... Si on pouvait dessiner directement dedans ça scintillerais pas je crois, mais les commande de dessins de PB avec l'alpha fonctionnent seulement sur les images :(
Sinon ça doit pouvoir se faire en utilisant GDI (Denis à fournit un travail enorme dessus, tu devrais y jeter un coup d'oeil :) )

Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 12:16
par kernadec
bonjour
KCC, je viens de trouver un vieux post avec une procedure de Fred pour la transparence ici:
http://www.purebasic.fr/english/viewtop ... t&start=30

je pense que dans ce bout de code il y a la réponse a ton problème!!
j'ai enlevé la boucle pour que ce soit clair,

cordialement

Code : Tout sélectionner


Procedure DrawTransparentImage(DC, Bitmap, x, y, Width, Height, TransparentColor)

    ; First, create some DC's. These are our gateways To associated
    ; bitmaps in RAM
    maskDC = CreateCompatibleDC_(DC)
    tempDC = CreateCompatibleDC_(DC)
   
    SourceDC = CreateCompatibleDC_(DC)
    SelectObject_(SourceDC, Bitmap)
   

    ; Then, we need the bitmaps. Note that we create a monochrome
    ; bitmap here!
    ; This is a trick we use For creating a mask fast enough.
    hMaskBmp = CreateBitmap_(Width, Height, 1, 1, 0)
    hTempBmp = CreateCompatibleBitmap_(DC, Width, Height)

    ; Then we can assign the bitmaps to the DCs
    ;
    hMaskBmp2 = SelectObject_(maskDC, hMaskBmp)
    hTempBmp2 = SelectObject_(tempDC, hTempBmp)

    ; Now we can create a mask. First, we set the background color
    ; To the transparent color; then we copy the image into the
    ; monochrome bitmap.
    ; When we are done, we reset the background color of the
    ; original source.
    TransparentColor= SetBkColor_(SourceDC, TransparentColor)
    BitBlt_ (maskDC, 0, 0, Width, Height, SourceDC, 0, 0, #SRCCOPY)
    SetBkColor_(SourceDC, TransparentColor)

    ; The first we do with the mask is To MergePaint it into the
    ; destination.
    ; This will punch a WHITE hole in the background exactly were
    ; we want the graphics To be painted in.
    BitBlt_ (tempDC, 0, 0, Width, Height, maskDC, 0, 0, #SRCCOPY)
    BitBlt_ (DC, X, Y, Width, Height, tempDC, 0, 0, #MERGEPAINT)

    ; Now we delete the transparent part of our source image. To do
    ; this, we must invert the mask And MergePaint it into the
    ; source image. The transparent area will now appear as WHITE.
    BitBlt_ (maskDC, 0, 0, Width, Height, maskDC, 0, 0, #NOTSRCCOPY)
    BitBlt_ (tempDC, 0, 0, Width, Height, SourceDC, 0, 0, #SRCCOPY)
    BitBlt_ (tempDC, 0, 0, Width, Height, maskDC, 0, 0, #MERGEPAINT)

    ; Both target And source are clean. All we have To do is To And
    ; them together!
    BitBlt_ (DC, X, Y, Width, Height, tempDC, 0, 0, #SRCAND)

    ; Now all we have To do is To clean up after us And free system
    ; resources..
    DeleteObject_ (hMaskBmp)
    DeleteObject_ (hTempBmp)
    DeleteObject_ (hMaskBmp2)
    DeleteObject_ (hTempBmp2)
    DeleteDC_ (maskDC)
    DeleteDC_ (tempDC)
    DeleteDC_ (SourceDC)

EndProcedure

Enumeration ;Images
  #Image1
  #Image2
EndEnumeration

CreateImage(#Image1,32,32)
CreateImage(#Image2,32,32)

;ImageID(#Image1)
StartDrawing(ImageOutput(#Image1))
  Box(0,0,32,32,RGB(255,0,0))
  Box(5,5,22,22,RGB(0,0,0))
  StopDrawing()

;ImageID(#Image2)
StartDrawing(ImageOutput(#Image2))
  Box(0,0,32,32,RGB(0,0,255))
  Box(5,5,22,22,RGB(0,0,0))
  StopDrawing()

  Image = Random(#Image2)
  
OpenWindow(0,0,0,150,150,"DrawTransparentImage() NO BUG",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
Image = Random(#Image2)
X = 50
  Y = 50
  DC = StartDrawing(WindowOutput(0))
    DrawTransparentimage(DC,ImageID(Image),X,Y,32,32,RGB(0,0,0))
    ReleaseDC_(WindowID(0),DC)
  StopDrawing()
  Image = Random(#Image2)
X = 60
  Y = 60
  DC = StartDrawing(WindowOutput(0))
    DrawTransparentimage(DC,ImageID(Image),X,Y,32,32,RGB(0,0,0))
    ReleaseDC_(WindowID(0),DC)
  StopDrawing()
Repeat
  Event = WindowEvent()

  
Until Event = #PB_Event_CloseWindow

Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 13:07
par Kwai chang caine
Cederavic a écrit :Sinon ça doit pouvoir se faire en utilisant GDI (Denis à fournit un travail enorme dessus, tu devrais y jeter un coup d'oeil )
Bah une fois, le bon DENIS il a essayé de me diriger dessus aussi.
J'ai jeté un oeil et depuis j'ai un bandeau comme les pirates.

Le graphisme, c'est un truc de malades, inventé par des malades, et qui me rend malade :lol: :lol:
Faut au moins deux agregation en math pour faire une rondelle :lol:

Merci pour ta reponse

@KERNADEC
Merci, je vais regarder ça :wink:

Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 15:32
par kernadec
@KCC
j'ai aussi trouvé ce code du forum allemand de dessin de rectangles avec le GDI
mais le drawmode est difficile à gérer

voila j'ai essayé de le bricolé, mais je n'ai pas réussi a avoir les angles propre,
si ca peut te donner une idée du GDI

@Cederavic merci, pour ton très bon code, je le stock dans mes archives.

Cordialement

Code : Tout sélectionner

;************************************************************
;*   WinAPI: Fenster erstellen und darin mit GDI zeichnen   *
;* ======================================================== *
;*   - mit der Maus einen rechteckigen Rahmen ziehen        *
;************************************************************

;- Grundlage ist Beispiel aus WinAPI-Einführung von "www.red-inferno.de" und "www.willemer.de"
;- zeichnen im Zweig "WM_MOUSEMOVE"
Enumeration
#boutonGadget_0
#boutonGadget_1
#boutonGadget_2
#boutonGadget_3
EndEnumeration
Global hwnd, rc.RECT, startpt.POINT, endpt.POINT, *dc, returncode.l  ;"hwnd" muss global definiert werden
Global Width.l,color.l
Declare my_Drawframe(Width,color)

width=20
color=RGB(255,0,0)	


 
Procedure WndProc(wnd,message,wParam,lParam)
  returncode=0
  
  Select message
      
    Case #WM_LBUTTONDOWN
      ;    invalidaterect_(hwnd, #null, #true); loescht vorheriges rechteck
      startpt\x = lParam & $FFFF
      startpt\y = lParam >> 16 & $FFFF
      endpt\x = lParam & $FFFF
      endpt\y = lParam >> 16 & $FFFF   
      ;     Debug Str(startpt\x) + " " +Str(startpt\y)
      
    Case #WM_MOUSEMOVE
      ;     Debug Str(endpt\x) + " " +Str(endpt\y)   
      If wParam & #MK_LBUTTON   ;linke maustaste gedrueckt ?
        *dc=GetDC_(hwnd)
        my_Drawframe(Width,color)
        endpt\x = lParam & $FFFF
        endpt\y = lParam >> 16 & $FFFF 
        my_Drawframe(Width,color)
        ReleaseDC_(hwnd,*dc)
      EndIf
      
      
    Case #WM_CLOSE 
      Debug "WM_CLOSE"
      DestroyWindow_(hwnd);
      
    Case #WM_DESTROY
      Debug "WM_DESTROY"
      ;    UnregisterClass_(appname,hInstance)
      PostQuitMessage_(0)
      
    Default
      returncode = DefWindowProc_(wnd, message, wParam, lParam)
      
  EndSelect
  ProcedureReturn returncode
EndProcedure

t$="MZ"   ;classname

wc.WNDCLASS
wc\cbClsExtra = 0
wc\cbWndExtra = 0
wc\hbrBackground = #COLOR_BACKGROUND
wc\hInstance = hInstance
wc\hIcon = LoadIcon_(0,#IDI_APPLICATION)
wc\hCursor = LoadCursor_(0, #IDC_CROSS)
wc\lpszMenuName = 0
wc\lpszClassName = @t$
wc\lpfnWndProc = @WndProc()
wc\style = #CS_HREDRAW | #CS_VREDRAW

RegisterClass_(@wc)
hwnd = CreateWindowEx_(0,t$,"Zeichnen mit dem GDI",#WS_OVERLAPPEDWINDOW,50,50,800,650,0,0,hInstance,0)
ShowWindow_(hwnd,  #SW_SHOWNORMAL)
UpdateWindow_(hwnd)

;OpenGadgetList(#PB_Any)
	;	ButtonGadget(#boutonGadget_0, 120,80, 50, 30, "texte" )
	;	ButtonGadget(#boutonGadget_1, 440,180, 50, 30, "texte" )
	;	ButtonGadget(#boutonGadget_2, 240,390, 50, 30, "texte" )
	;	ButtonGadget(#boutonGadget_3, 620,290, 50, 30, "texte" )
;CloseGadgetList() 

While GetMessage_(msg.MSG, #Null, 0, 0 )
  TranslateMessage_(msg)
  DispatchMessage_(msg)
Wend

End

Procedure RoundRect(x,y,x1,y1,Epais,color,fram,angle1,angle2) 
  GetWindowRect_(hwnd,r.RECT):hdc=GetWindowDC_(WindowID(0)) 
  pen=CreatePen_(fram,Epais,color):SelectObject_(hdc,pen) 
  SelectObject_(hdc,brush):nDrawMode=SetROP2_(hdc,#R2_MASKPEN) 
  RoundRect_(hdc,x+4,y+51,x1+4,y1+51,angle1,angle2) 
  SetROP2_(hdc,nDrawMode):DeleteObject_(pen) 
  DeleteObject_(brush):ReleaseDC_(hwnd,hdc):DeleteDC_(hdc) 
EndProcedure 
Procedure my_Drawframe(Width,color)
  pen=CreatePen_(#PS_SOLID,1,color) 
  penOld=SelectObject_(*dc,pen) 
  SelectObject_(*dc,pen) ;SelectObject_(*dc,brush):
;  nDrawMode=SetROP2_(*dc,#R2_BLACK ) 
;  nDrawMode=SetROP2_(*dc,#R2_COPYPEN)
;  nDrawMode=SetROP2_(*dc,#R2_MASKNOTPEN)
;  nDrawMode=SetROP2_(*dc,#R2_MASKPEN)
;  nDrawMode=SetROP2_(*dc,#R2_MASKPENNOT)
;  nDrawMode=SetROP2_(*dc,#R2_MERGENOTPEN)
;  nDrawMode=SetROP2_(*dc,#R2_MERGEPEN)
;  nDrawMode=SetROP2_(*dc,#R2_MERGEPENNOT)
;  nDrawMode=SetROP2_(*dc,#R2_NOP)
;  nDrawMode=SetROP2_(*dc,#R2_NOT)
;  nDrawMode=SetROP2_(*dc,#R2_NOTCOPYPEN)
;  nDrawMode=SetROP2_(*dc,#R2_NOTMASKPEN)
;  nDrawMode=SetROP2_(*dc,#R2_NOTMERGEPEN)
  nDrawMode=SetROP2_(*dc,#R2_NOTXORPEN)
;  nDrawMode=SetROP2_(*dc,#R2_WHITE)
;  nDrawMode=SetROP2_(*dc,#R2_XORPEN)
 ; nDrawMode=SetROP2_(*dc,4)
 For i=-10 To 10
; MoveToEx_(*dc,startpt\x,startpt\y+i,#Null)
 ;LineTo_(*dc,endpt\x,startpt\y+i)
 
 
;Rectangle_(*dc,startpt\x,endpt\y+i,endpt\x,endpt\y)

;Rectangle_(*dc,startpt\x+i,endpt\y,startpt\x,startpt\y)



 ;MoveToEx_(*dc,endpt\x,endpt\y+i,#Null)
 
 ; Rectangle_(*dc,endpt\x+i,startpt\y,endpt\x,endpt\y)

   
  ;horizontale 
 MoveToEx_(*dc,startpt\x,startpt\y+i,#Null)
 LineTo_(*dc,endpt\x,startpt\y+i)


;LineTo_(*dc,startpt\x,endpt\y+i)
;LineTo_(*dc,startpt\x+i,endpt\y)

 
; verticale
 MoveToEx_(*dc,endpt\x+i,startpt\y,#Null)
 LineTo_(*dc,endpt\x+i,endpt\y)
 
  Next i
;  LineTo_(*dc,startpt\x,endpt\y)
; LineTo_(*dc,startpt\x,startpt\y)
   SetROP2_(*dc,nDrawMode)
  DeleteObject_(pen) 
  DeleteObject_(penOld) 
 
 
  ProcedureReturn 0
  
  
EndProcedure

Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 15:40
par Kwai chang caine
Ouille ouille ouille !!!! Mais comment tout ça peut il sortir d'un seul cerveau :roll:

Bon je crois que ma fleche elle va soit rester a fond blanc, soit sautiller comme la libre gazelle, dans la rosée d'une prairie un bon matin d'été :(

Tu te rend compte tout ça pour une fleche !!!
Heureusement que j'avais pas besoin de quelque chose de compliqué :lol: :lol:

Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 17:09
par kernadec
hi hi hi
tu devrais nous dire ce que tu veux garder apparent avec ta flèche
du textes des gadgets sur quel genre d'interface elle va fonctionner
car si ce n'est que du drawtexte regarde cela.
manipulation clic droit, redim. clic gauche et la flèche change de direction avec la mollette de la souris.

Cordialement

Code : Tout sélectionner

; #####################################################
; #######     kernadec en janvier 2010           ######
;        sur l'dée de fleche du projet KCC  
;      flèche au choix 8 directions avec la molette
;       deplacement clic gauche taille clic droit
; #####################################################
#WM_MOUSEWHEEL = $20A 
Enumeration
#Fenetre
#Image_0
#Image_1
#FondBlanc
#ImageGadget
EndEnumeration
Global dc.l,epais.l,fleche.l,px.l
winl.l=800
winh.l=600
Posx.l=0
Posy.l=0
Posl.l=300
Posh.l=300
epais=14
Px=30
Procedure.w MouseWheelDelta() 
	z.w=((EventwParam()>>16)&$FFFF) 
	ProcedureReturn -(z/100) 
EndProcedure 
Procedure Ligne(x,y,x1,y1,Width,color) 
pen=CreatePen_(#PS_SOLID,Width,color) 
penOld=SelectObject_(DC,pen) 
MoveToEx_(DC,x,y,0):LineTo_(DC,x1,y1) 
DeleteObject_(pen) 
DeleteObject_(penOld) 
EndProcedure 
Procedure dessin(Posx,Posy,Posl,Posh)
dc=StartDrawing( ImageOutput(#Image_1))
		Box(0,0,WindowWidth(#Fenetre),WindowHeight(#Fenetre),RGB(225,225,225))
		DrawImage(ImageID(#Image_0),Posx,Posy,Posl,Posh) 
		If fleche=0
			Ligne(Posx,Posy+px,Posx+Posl-px,Posy+px,epais,RGB(226,23,29)) ; Horizontale
			Ligne(Posx+Posl-px,Posy+px,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+Posl-px,Posy+Posh-px,Posx+Posl-px/2*3,Posy+Posh-px*2,epais,RGB(226, 23, 29))
			Ligne(Posx+Posl-px,Posy+Posh-px,Posx+Posl-px/2,Posy+Posh-px*2,epais,RGB(226, 23, 29))
		EndIf
		If fleche=1
			Ligne(Posx+px,Posy+Posh-px,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Horizontale
				Ligne(Posx+px,Posy,Posx+px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+Posl-px*2,Posy+Posh-px/2*3,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29))
			Ligne(Posx+Posl-px*2,Posy+Posh-px/2,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29))
		EndIf
		If fleche=2
			Ligne(Posx+px,Posy+px,Posx+Posl,Posy+px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+px,Posy+px,Posx+px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+px,Posy+Posh-px,Posx+px/2*3,Posy+Posh-px*2,epais,RGB(226, 23, 29))
			Ligne(Posx+px,Posy+Posh-px,Posx+px/2,Posy+Posh-px*2,epais,RGB(226, 23, 29))
		EndIf
		If fleche=3
			Ligne(Posx+px,Posy+Posh-px,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+Posl-px,Posy,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+px*2,Posy+Posh-px/2*3,Posx+px,Posy+Posh-px,epais,RGB(226, 23, 29))
			Ligne(Posx+px*2,Posy+Posh-px/2,Posx+px,Posy+Posh-px,epais,RGB(226, 23, 29))
		EndIf
		If fleche=4
			Ligne(Posx+px,Posy+Posh-px,Posx+Posl,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+px,Posy+px,Posx+px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+px,Posy+px,Posx+px/2*3,Posy+px*2,epais,RGB(226, 23, 29))
			Ligne(Posx+px,Posy+px,Posx+px/2,Posy+px*2,epais,RGB(226, 23, 29))
		EndIf
		If fleche=5
			Ligne(Posx+px,Posy+px,Posx+Posl-px,Posy+px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+Posl-px,Posy+px,Posx+Posl-px,Posy+Posh,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+px*2,Posy+px/2*3,Posx+px,Posy+px,epais,RGB(226, 23, 29))
			Ligne(Posx+px*2,Posy+px/2,Posx+px,Posy+px,epais,RGB(226, 23, 29))
		EndIf
		If fleche=6
			Ligne(Posx,Posy+Posh-px,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+Posl-px,Posy+px,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+Posl-px,Posy+px,Posx+Posl-px/2*3,Posy+px*2,epais,RGB(226, 23, 29))
			Ligne(Posx+Posl-px,Posy+px,Posx+Posl-px/2,Posy+px*2,epais,RGB(226, 23, 29))
		EndIf
		If fleche=7
			Ligne(Posx+px,Posy+px,Posx+Posl-px,Posy+px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+px,Posy+px,Posx+px,Posy+Posh,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+Posl-px*2,Posy+px/2*3-y1,Posx+Posl-px,Posy+px-y1,epais,RGB(226, 23, 29))
			Ligne(Posx+Posl-px*2,Posy+px/2-y1,Posx+Posl-px,Posy+px-y1,epais,RGB(226, 23, 29))
		EndIf
	
			DrawingMode(1)
			DrawingFont(FontID(0))
			DrawText(480,50,"NORD",RGB(0,0,255),RGB(225,225,225))
			DrawText(80,150,"OUEST",RGB(100,200,100),RGB(225,225,225))
			DrawText(680,430,"EST",RGB(255,0,255),RGB(225,225,225))
			DrawText(200,500,"SUD",RGB(205,205,0),RGB(225,225,225))
			DrawingMode(4)
	
		
		
		
		StopDrawing()
		
		SetGadgetState(#ImageGadget,ImageID(#Image_1))
		
EndProcedure

LoadFont(0, "Arial", 24)
OpenWindow(#Fenetre, 0, 0,winl,winh, "",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
	CreateImage(#Image_0,winl,winh)
	CreateImage(#Image_1,winl,winh)
		StartDrawing(ImageOutput(#Image_0))
			DrawImage(ImageID(#Image_1), 0,0 ,200,200)
			Box(0,0,winl,winh,RGB(225,225,225))
		StopDrawing()
		ImageGadget(#ImageGadget,Posx,Posy,200,200,ImageID(#Image_0))
		SetGadgetState(#ImageGadget,ImageID(#Image_0))
		bm=#False
Repeat
event = WaitWindowEvent()
	Select Event
		Case #PB_Event_Gadget
		Select EventType()
			Case #WM_LBUTTONDOWN
			Case 0 
			bm=#True
			Posx1 = WindowMouseX(0)-Posx
			Posy1 = WindowMouseY(0)-Posy
		EndSelect
		EndSelect
		If event=#WM_MOUSEWHEEL 
		fleche+Abs(MouseWheelDelta())
		fleche=fleche%8
		If fleche>7:fleche=7:EndIf
			dessin(Posx,Posy,Posl,Posh) 
		EndIf
		If event=#WM_RBUTTONUP   
		bm=#False
		EndIf
		If event=#WM_LBUTTONUP   
		bm=#False
		EndIf
		If event=#WM_RBUTTONDOWN
		Posl1 = WindowMouseX(0)-Posl
		Posh1 = WindowMouseY(0)-Posh
		EndIf
		If event=#WM_MOUSEMOVE
		If bm=#True
		Posx = WindowMouseX(0)-Posx1
		Posy = WindowMouseY(0)-Posy1
		EndIf 
		If GetAsyncKeyState_(#VK_RBUTTON) 
		Posl=WindowMouseX(0)-Posl1
		Posh=WindowMouseY(0)-Posh1
		EndIf 
		dessin(Posx,Posy,Posl,Posh)
	EndIf
Until event = #PB_Event_CloseWindow  



Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 17:29
par Kwai chang caine
Ouaaahhh !!! t'es vraiment un caid de la fleche KERNADEC 8O

Mais ça m'a l'air nickel ça....
J'ose plus me rejouir, car ça fait trois fois en un mois que j'asperge le plafond, et pis que y'a un probleme apres :mrgreen:

Ce que je veux voir bah c'est exactement ça...juste la fleche, pour pouvoir voir les autres gadgets qui sont dessous et surtout ne pas voir ce grand carré blanc qui cachent les autres gadgets quand on fait survoler l'un sur l'autre :wink:

A premiere vue c'est exactement ce que je voulais :D
Mais ou etait le probleme...ou elle est la tuile ???? j'ai le groin en l'air et je la vois pas :roll:

Quelle est la difference entre cette fleche et ton ancienne sur fond blanc ???
Si j'ai bien compris l'ancienne etait en API seulement ???

Le coup de la mousewheel, c'est une super idée, c'est un plus 8)
Par rapport à l'autre y'a juste un petit bleme que je devrais arriver a corriger...la fleche elle se transforme en langue de vipere selon le coté ou elle se trouve 8O
Je connais bien cette forme, j'my connais noir en langue de vipere, c'est comme ça que j'appelle ma femme :D

Je crois bien que cette fois c'est la bonne...pas ma femme...hein :oops: ...la fleche :mrgreen:

Merci merci...je vais essayer de modifier la "langue" et apres l'installer dans mon appli

Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 17:43
par Kwai chang caine
Bon j'ai trouvé la tuile....comme tu l'as dit ce n'est pas que du drawtext c'est des gadgets les uns a coté des autres, et j'ai essayé d'ajouter un bouton sur ton code

Code : Tout sélectionner

ButtonGadget(#Bouton, 10, 10, 100, 100, "Coucou")
L'enfer recommence comme y'a un mois :(

Prooououf !!!...plus de "tonbou" 8O

Plus de Tooonnnnboooooooooooooooouuuuuuu !!!"
Boooooouuuuuuuuu !!!
Boooooouuuuuuuuu !!!


Image

Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 17:49
par kernadec
je t'avais déjà mis un code avec mollette, et des gadget tu as du passer a coté juste avant le code des épaisseurs api
mais tu m'as dit que ca ne convenait pas, je l'avais laisser tombé et puis aujourd'hui,
comme je ne retrouvait pas l'autre sur ma bécane.

j'ai simplement mis le fond en gris identique rgb(225,225,225) a la fenêtre
ensuite un drawingmode(1) drawtext() et un drawingmode(4)
et pour les gadgets un disablegadget règle le soucis des gadgets recouvert en général.

cordialement

Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 18:12
par Kwai chang caine
Le probleme c'est que la fleche plus elle est grande...plus le carré est grand et quand on deplace le carré ça masque tous les autres gadgets, ils disparaissent, normal
Et come effet c'est assez desagreable..c'est pour ça que je cherche a faire un fond transparent...mais apparement avec ton ancien code tout en API ce n'est pas possible :cry:

Tu m'etonne que je sois passé a coté d'un de tes codes...
Ca fait un mois que j'attend alletant la langue pendante chaque code qui pourrait faire cette foutu fleche
Encore une fois ta fleche en API est parfaite, je l'avais d'ailleur inclue dans mon programme.
Masi c'est cette histoire de transparence qui la remet en question
Pour les petites images fleche apres mure discussion, je les ai passée en PNG, no bleme
Mais la fleche "personalisable"...ça marche pas :cry:

Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 18:22
par cederavic
En lisant tes posts a l'envers KCC, on comprend beaucoup de choses!
j'my connais noir en langue de vipere, c'est comme ça que j'appelle ma femme
car ça fait trois fois en un mois que j'asperge le plafond
:lol:

J'vais faire encore mumuse avec ta flèche... (euh... sans sous-entendu hein! :roll: )

Re: Rendre transparent une couleur dans une imagegadget

Publié : mar. 16/févr./2010 19:08
par kernadec
reste plus qu'a trouvé le moyen d'empêcher le flip des boutons pendant le déplacement.
les gadgets fonctionnent .

bonne soirée

Code : Tout sélectionner

; #####################################################
; #######     kernadec en janvier 2010           ######
;        sur l'dée de fleche du projet KCC  
;      flèche au choix 8 directions avec la molette
;       deplacement clic gauche taille clic droit
; #####################################################
#WM_MOUSEWHEEL = $20A 
Enumeration
#Fenetre
#Image_0
#Image_1
#FondBlanc
#ImageGadget
#boutonGadget_0
#boutonGadget_1
#boutonGadget_2
#boutonGadget_3

EndEnumeration
Global dc.l,epais.l,fleche.l,px.l,bm.l
winl.l=800
winh.l=600
Posx.l=0
Posy.l=0
Posl.l=300
Posh.l=300
epais=20
Px=45
Procedure.w MouseWheelDelta() 
	z.w=((EventwParam()>>16)&$FFFF) 
	ProcedureReturn -(z/100) 
EndProcedure 
Procedure Ligne(x,y,x1,y1,Width,color) 
pen=CreatePen_(#PS_SOLID,Width,color) 
penOld=SelectObject_(DC,pen) 
MoveToEx_(DC,x,y,0):LineTo_(DC,x1,y1) 
DeleteObject_(pen) 
DeleteObject_(penOld) 
EndProcedure 
Procedure dessin(Posx,Posy,Posl,Posh) 
 DisableGadget(#ImageGadget,0)
 dc=StartDrawing( ImageOutput(#Image_1))
		Box(0,0,WindowWidth(#Fenetre),WindowHeight(#Fenetre),RGB(225,225,225))
		DrawImage(ImageID(#Image_0),Posx,Posy,Posl,Posh)	 
		If fleche=0
			Ligne(Posx,Posy+px,Posx+Posl-px,Posy+px,epais,RGB(226,23,29)) ; Horizontale
			Ligne(Posx+Posl-px,Posy+px,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+Posl-px,Posy+Posh-px,Posx+Posl-px/2*3,Posy+Posh-px*2,epais,RGB(226, 23, 29))
			Ligne(Posx+Posl-px,Posy+Posh-px,Posx+Posl-px/2,Posy+Posh-px*2,epais,RGB(226, 23, 29))
		EndIf
		If fleche=1
			Ligne(Posx+px,Posy+Posh-px,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Horizontale
				Ligne(Posx+px,Posy,Posx+px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+Posl-px*2,Posy+Posh-px/2*3,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29))
			Ligne(Posx+Posl-px*2,Posy+Posh-px/2,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29))
		EndIf
		If fleche=2
			Ligne(Posx+px,Posy+px,Posx+Posl,Posy+px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+px,Posy+px,Posx+px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+px,Posy+Posh-px,Posx+px/2*3,Posy+Posh-px*2,epais,RGB(226, 23, 29))
			Ligne(Posx+px,Posy+Posh-px,Posx+px/2,Posy+Posh-px*2,epais,RGB(226, 23, 29))
		EndIf
		If fleche=3
			Ligne(Posx+px,Posy+Posh-px,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+Posl-px,Posy,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+px*2,Posy+Posh-px/2*3,Posx+px,Posy+Posh-px,epais,RGB(226, 23, 29))
			Ligne(Posx+px*2,Posy+Posh-px/2,Posx+px,Posy+Posh-px,epais,RGB(226, 23, 29))
		EndIf
		If fleche=4
			Ligne(Posx+px,Posy+Posh-px,Posx+Posl,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+px,Posy+px,Posx+px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+px,Posy+px,Posx+px/2*3,Posy+px*2,epais,RGB(226, 23, 29))
			Ligne(Posx+px,Posy+px,Posx+px/2,Posy+px*2,epais,RGB(226, 23, 29))
		EndIf
		If fleche=5
			Ligne(Posx+px,Posy+px,Posx+Posl-px,Posy+px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+Posl-px,Posy+px,Posx+Posl-px,Posy+Posh,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+px*2,Posy+px/2*3,Posx+px,Posy+px,epais,RGB(226, 23, 29))
			Ligne(Posx+px*2,Posy+px/2,Posx+px,Posy+px,epais,RGB(226, 23, 29))
		EndIf
		If fleche=6
			Ligne(Posx,Posy+Posh-px,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+Posl-px,Posy+px,Posx+Posl-px,Posy+Posh-px,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+Posl-px,Posy+px,Posx+Posl-px/2*3,Posy+px*2,epais,RGB(226, 23, 29))
			Ligne(Posx+Posl-px,Posy+px,Posx+Posl-px/2,Posy+px*2,epais,RGB(226, 23, 29))
		EndIf
		If fleche=7
			Ligne(Posx+px,Posy+px,Posx+Posl-px,Posy+px,epais,RGB(226, 23, 29)) ; Horizontale
			Ligne(Posx+px,Posy+px,Posx+px,Posy+Posh,epais,RGB(226, 23, 29)) ; Verticale
			Ligne(Posx+Posl-px*2,Posy+px/2*3-y1,Posx+Posl-px,Posy+px-y1,epais,RGB(226, 23, 29))
			Ligne(Posx+Posl-px*2,Posy+px/2-y1,Posx+Posl-px,Posy+px-y1,epais,RGB(226, 23, 29))
		EndIf
		DrawingMode(1)
		DrawingFont(FontID(0))
		DrawText(480,50,"NORD",RGB(0,0,255),RGB(225,225,225))
		DrawText(80,150,"OUEST",RGB(100,200,100),RGB(225,225,225))
		DrawText(680,430,"EST",RGB(255,0,255),RGB(225,225,225))
		DrawText(200,500,"SUD",RGB(205,205,0),RGB(225,225,225))
    DrawingMode(4)
		ButtonGadget(#boutonGadget_0, 120,80, 50, 30, "texte" )
    ButtonGadget(#boutonGadget_1, 440,180, 50, 30, "texte" )
    ButtonGadget(#boutonGadget_2, 240,390, 50, 30, "texte" )
    ButtonGadget(#boutonGadget_3, 620,290, 50, 30, "texte" )
    StopDrawing()
    DisableGadget(#ImageGadget,1)
    SetGadgetState(#ImageGadget,ImageID(#Image_1))
EndProcedure

LoadFont(0, "Arial", 24)
OpenWindow(#Fenetre, 0, 0,winl,winh, "",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
	  CreateImage(#Image_0,winl,winh)
	  CreateImage(#Image_1,winl,winh)
	  StartDrawing(ImageOutput(#Image_0))
			Box(0,0,winl,winh,RGB(225,225,225))
		StopDrawing()
		ImageGadget(#ImageGadget,Posx,Posy,200,200,ImageID(#Image_0))
		ButtonGadget(#boutonGadget_0, 120,80, 50, 30, "texte" )
    ButtonGadget(#boutonGadget_1, 440,180, 50, 30, "texte" )
    ButtonGadget(#boutonGadget_2, 240,390, 50, 30, "texte" )
    ButtonGadget(#boutonGadget_3, 620,290, 50, 30, "texte" )
    SetGadgetState(#ImageGadget,ImageID(#Image_0))
    dessin(Posx,Posy,Posl,Posh)
    bm=#False
Repeat
event = WaitWindowEvent()
	Select Event
		Case #PB_Event_Gadget 
		 Select EventGadget()  
		   Case #boutonGadget_0
		    Debug "B0"
		    Delay(2)
		    RedrawWindow_(WindowID(#Fenetre), 0, 0, #RDW_INVALIDATE|#RDW_UPDATENOW)
		   Case #boutonGadget_1
		    Debug "B1"
		    Delay(2)
		    RedrawWindow_(WindowID(#Fenetre), 0, 0, #RDW_INVALIDATE|#RDW_UPDATENOW)
		   Case #boutonGadget_2
		    Debug "B2"
		    Delay(2)
		    RedrawWindow_(WindowID(#Fenetre), 0, 0, #RDW_INVALIDATE|#RDW_UPDATENOW)
		   Case #boutonGadget_3
		    Debug "B3"
		    Delay(2)
		    RedrawWindow_(WindowID(#Fenetre), 0, 0, #RDW_INVALIDATE|#RDW_UPDATENOW)
		 EndSelect
		  Case #PB_Event_CloseWindow
			Quit = #True  
		EndSelect
		If event=#WM_MOUSEWHEEL 
		fleche+Abs(MouseWheelDelta())
		fleche=fleche%8
		If fleche>7:fleche=7:EndIf
			dessin(Posx,Posy,Posl,Posh) 
		EndIf
		If GetAsyncKeyState_(#VK_LBUTTON) Or GetAsyncKeyState_(#VK_RBUTTON) 
		If event=#WM_RBUTTONUP   
		bm=#False
		EndIf
		If event=#WM_LBUTTONUP   
		bm=#False
		EndIf
		If event=#WM_LBUTTONDOWN
		bm=#True
		Posx1 = WindowMouseX(0)-Posx
		Posy1 = WindowMouseY(0)-Posy
		
		EndIf
		If event=#WM_RBUTTONDOWN
		bm=#True
		Posl1 = WindowMouseX(0)-Posl
		Posh1 = WindowMouseY(0)-Posh
		EndIf
		EndIf
		If event=#WM_MOUSEMOVE
		If bm=#True
		If GetAsyncKeyState_(#VK_LBUTTON)
	  	Posx = WindowMouseX(0)-Posx1
	  	Posy = WindowMouseY(0)-Posy1
		  dessin(Posx,Posy,Posl,Posh)
		EndIf 
		EndIf 
		If GetAsyncKeyState_(#VK_RBUTTON) 
		  Posl=WindowMouseX(0)-Posl1
		  Posh=WindowMouseY(0)-Posh1
		  dessin(Posx,Posy,Posl,Posh)
		EndIf
		EndIf
Until Quit = #True