[résolu) Soucis CanvasGadget et API lignes pointillées.

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
kernadec
Messages : 1606
Inscription : ven. 25/avr./2008 11:14

[résolu) Soucis CanvasGadget et API lignes pointillées.

Message par kernadec »

bonsoir
Ptit problème avec CanvasGadget avec une couleur de fond pour afficher les styles de ligne avec L'API Windows ,
Je n'y arrive pas. :? sur fond noir elle s'affiche avec le rouge et avec du blanc que je n''ai pas choisi.
Alors que sur un fond blanc, aucun soucis les lignes pointillés sont affichées correctement.

j'ai également essayé le mode XOR de l'API, mais là aussi rien à faire, je n' obtiens qu'un pointillé bleu ciel.
donc voilà le code, si quelqu'un a une solution.. merci
avec PB 461 et PB 5.b5
Cordialement

Code : Tout sélectionner

#Window         = 0
#Canvas         = 1
#Window_Width   = 800 
#Window_Height  = 600 
#AxeX           = #Window_Width / 2
#AxeY           = #Window_Height / 2
#rayon          = 195


Procedure Ligne(DC,x1,y1,x,y,Width,style,color) 
  ;#PS_SOLID style=0:#PS_DASH style=1:#PS_DOT style=2:#PS_DASHDOT style=3:#PS_DASHDOTDOT style=4
  pen=CreatePen_(style,Width,color)  ; 
  hPenOld=SelectObject_(DC,pen) 
  ;nDrawMode=SetROP2_(DC,0)              ;#R2_MASKPEN  #R2_COPYPEN   Etc..  de 0 à 15
  MoveToEx_(DC,x1,y1,0):LineTo_(DC,x,y) 
  ;SetROP2_(DC,nDrawMode)
  DeleteObject_(pen) 
  DeleteObject_(hPenOld) 
EndProcedure 

OpenWindow(#Window, 0, 0, #Window_Width,#Window_Height, "PureBasic ", #WS_SYSMENU)
CanvasGadget(#Canvas, 0, 0,#Window_Width,#Window_Height,#PB_Canvas_ClipMouse)
StartDrawing(CanvasOutput(#Canvas))
 ;Box(0,0,GadgetWidth(1),GadgetHeight(1),RGB(255,255,255))
 Box(0,0,GadgetWidth(1),GadgetHeight(1),RGB(70,70,70))
StopDrawing()

DC=StartDrawing(CanvasOutput(#Canvas))

DrawImage(#PB_Canvas_Image, 0, 0 ,#Window_Width,#Window_Height)

x = Round(#AxeX + (#rayon) * Sin(Radian(90)),#PB_Round_Nearest)
y = Round(#AxeY + (#rayon)  * Cos(Radian(90)),#PB_Round_Nearest)
Ligne(DC,#AxeX ,#AxeY ,x ,y,1,3,#Red)

StopDrawing()

Repeat
  EventID = WaitWindowEvent() 
Until EventID = #PB_Event_CloseWindow 

Dernière modification par kernadec le ven. 19/oct./2012 6:48, modifié 1 fois.
Avatar de l’utilisateur
falsam
Messages : 7324
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Soucis CanvasGadget et API lignes pointillées.

Message par falsam »

Bonsoir kernadec. Dans ta procédure Ligne, Il manque la couleur d’arrière plan de ta ligne.

Code : Tout sélectionner

SetBkColor_(DC, Backcolor)
J'ai modifié les paramètres de ta procédure.
j'ai aussi commenté cette ligne qui ne sert à rien dans cet exemple en tout cas.

Code : Tout sélectionner

;DrawImage(#PB_Canvas_Image, 0, 0 ,#Window_Width,#Window_Height)
Le code complet.

Code : Tout sélectionner

#Window         = 0
#Canvas         = 1
#Window_Width   = 800 
#Window_Height  = 600 
#AxeX           = #Window_Width / 2
#AxeY           = #Window_Height / 2
#rayon          = 195


Procedure Ligne(DC,x1,y1,x,y,Width,style,color, backcolor) 
  ;#PS_SOLID style=0:#PS_DASH style=1:#PS_DOT style=2:#PS_DASHDOT style=3:#PS_DASHDOTDOT style=4
  
  SetBkColor_(DC, Backcolor)
  
  pen=CreatePen_(style, Width, color)  ; 
  
  hPenOld=SelectObject_(DC,pen) 
  ;nDrawMode=SetROP2_(DC,0)              ;#R2_MASKPEN  #R2_COPYPEN   Etc..  de 0 à 15
  MoveToEx_(DC,x1,y1,0):LineTo_(DC,x,y) 
  ;SetROP2_(DC,nDrawMode)
  DeleteObject_(pen) 
  DeleteObject_(hPenOld) 
EndProcedure 

OpenWindow(#Window, 0, 0, #Window_Width,#Window_Height, "PureBasic ", #WS_SYSMENU)
CanvasGadget(#Canvas, 0, 0,#Window_Width,#Window_Height,#PB_Canvas_ClipMouse)
StartDrawing(CanvasOutput(#Canvas))
;Box(0,0,GadgetWidth(1),GadgetHeight(1),RGB(255,255,255))
Box(0,0,GadgetWidth(1),GadgetHeight(1), RGB(70,70,70))
StopDrawing()

DC=StartDrawing(CanvasOutput(#Canvas))
DrawingMode(#PB_2DDrawing_XOr)

;DrawImage(#PB_Canvas_Image, 0, 0 ,#Window_Width,#Window_Height)

x = Round(#AxeX + (#rayon) * Sin(Radian(90)),#PB_Round_Nearest)
y = Round(#AxeY + (#rayon)  * Cos(Radian(90)),#PB_Round_Nearest)

Ligne(DC,#AxeX ,#AxeY ,x ,y, 1, 3, #Red, RGB(70,70,70))


StopDrawing()

Repeat
  EventID = WaitWindowEvent() 
Until EventID = #PB_Event_CloseWindow 
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
kernadec
Messages : 1606
Inscription : ven. 25/avr./2008 11:14

Re: Soucis CanvasGadget et API lignes pointillées.

Message par kernadec »

bonjour

merci Falsam

Pour la commande setbkcolor_,je suis passé a coté :?
pour les lignes en trop, c'est vrai merci :wink:
c'est juste après avoir bricolé plusieurs solutions,
J' étais complétement dégue et n'ai pas posté un code minimum, :oops:
encore merci

cordialement
Répondre