Seite 1 von 1

Abfrage von Klick auf Combobox

Verfasst: 24.05.2012 11:58
von Velindos
Hallo Leute,
habe leidiges Problem bei meiner Rotstiftkorrektur. Wenn ich auf Linienstärke drücke, dann habe ich zwar die Stärke, aber gleich auch einen Punkt in meinen ImageGadget.
Hab versucht den Klick abzufangen, gelingt mir aber nicht, vieleicht kennt einer dieses Problem?

Code: Alles auswählen

;-Constantes
Enumeration
  #Window
  #RotstiftImage
  #RotstiftLinienfarbe
  #Rotstiftstaerke
  #Rotstifttext
  #RingButtonContainer_x
  #RotstiftSpeichern
EndEnumeration

;-Fonts
Enumeration
  #Font_Bildtext
  #Font_ComboLinienstaerke
EndEnumeration

UsePNGImageDecoder()
UsePNGImageEncoder()

;Globlae Images
Global RotstiftStatusOn = 1
Global RotstiftShowLine.i, Start.Point
Global Rotstift_Ringbutton
Global Rotstift_Y_GadgetOffset = 43
Global Rotstift_X_GadgetOffset = 9
Global Rotstift_Color.l
Global Rotstift_Linienstaerke
Global Rotstift_Disaeble

;Image
Enumeration
  #RotstiftBild
  #RotstiftBildVorlage
  #LoadImage
  #Ringbutton
  #Editor_ImageFC
EndEnumeration

Rotstift_Ringbutton=CatchImage(#Ringbutton,?RingbuttonImage)
CreateImage(#Editor_ImageFC,25,25)


DataSection
  RingbuttonImage:
  IncludeBinary "D:\Pure@Store\DESIGN_PROFI_STANDARD\Ringbutton.png"
EndDataSection

Procedure RotstiftThickLineXY(X1.i, Y1.i, X2.i, Y2.i, Thickness.i, Rotstift_Color.i)
  Protected Length.i = Sqr((X2-X1)*(X2-X1)+(Y2-Y1)*(Y2-Y1))
  Protected I, DeltaX.i, DeltaY.i
  If Length = 0
    Circle(X1, Y1, Thickness/2, Rotstift_Color)
  Else
    For I = 0 To Length
      DeltaX = (X2-X1)*I/Length
      DeltaY = (Y2-Y1)*I/Length
      Circle(X1+DeltaX, Y1+DeltaY, Thickness/2, Rotstift_Color)
    Next
  EndIf
EndProcedure

OpenWindow(#Window, 0, 0, 637, 706, "Fenster", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ButtonImageGadget (#RotstiftLinienfarbe, 0,0,30,30 , ImageID(#Editor_ImageFC))
ComboBoxGadget(#Rotstiftstaerke, 31, 2, 62, 30)
SetGadgetFont(#Rotstiftstaerke, LoadFont(#Font_ComboLinienstaerke, "Arial", 13, #PB_Font_Bold|#PB_Font_HighQuality))
ButtonGadget(#Rotstifttext,95,0,30,30, "T")
SetGadgetFont(#Rotstifttext, LoadFont(#Font_Bildtext, "Arial", 16, #PB_Font_Bold|#PB_Font_HighQuality))
ButtonImageGadget(#RingButtonContainer_x, 126, 0, 477, 30,Rotstift_Ringbutton )
ButtonGadget(#RotstiftSpeichern, 605,0,30,30, "S")

ImageGadget(#RotstiftImage,  9, 43, 650, 650,0)
DisableGadget(#RotstiftImage,1)

For RotstiftCount = 1 To 40
  AddGadgetItem(#Rotstiftstaerke, -1, "  "+Str(RotstiftCount))
  SetGadgetItemData(#Rotstiftstaerke, CountGadgetItems(#Rotstiftstaerke)-1, RotstiftCount)
Next
SetGadgetState(#Rotstiftstaerke,4)

RotstiftStatusOn = 1

If RotstiftStatusOn = 1
  CreateImage(#RotstiftBildVorlage, 512, 512)
StartDrawing(ImageOutput(#RotstiftBildVorlage))
 Box(0,0,512,512,RGB(255, 215, 0))
  StopDrawing()
ResizeImage (#RotstiftBildVorlage,650,650 ,#PB_ImagePlugin_PNG)

CopyImage(#RotstiftBildVorlage,#RotstiftBild)
SetGadgetState(#RotstiftImage, ImageID(#RotstiftBild))
EndIf

Repeat
  
  Event = WaitWindowEvent()
  Debug event
  
  Select EventGadget()  
      ; Rotstift
    Case #RotstiftLinienfarbe
      If RotstiftStatusOn = 1
      Rotstift_Color=ColorRequester()
      StartDrawing(ImageOutput(#Editor_ImageFC))
      Box(0,0,ImageWidth(#Editor_ImageFC),ImageHeight(#Editor_ImageFC), Rotstift_Color)
      StopDrawing()
      SetGadgetAttribute(#RotstiftLinienfarbe , #PB_Button_Image , ImageID(#Editor_ImageFC))
      RotstiftShowLine = #False
      Rotstift_Disaeble = #True
    EndIf
    
    
    
    Case #Rotstifttext
      Rotstift_Disaeble = #True
          Debug Rotstift_Disaeble

      ; Rotstift speichern
    Case #RotstiftSpeichern
      If RotstiftStatusOn = 1
      SaveImage(#RotstiftBildVorlage, "D:\TestImage.png", #PB_ImagePlugin_PNG)
    EndIf
  EndSelect
  
  Select Event
      
    Case #PB_Event_CloseWindow
      End
      
        Case #Rotstiftstaerke
    Select EventType()
      Case #PB_EventType_LeftClick
        Debug "Linksklick"
        Rotstift_Disaeble = #True
        Debug Rotstift_Disaeble
    EndSelect

      
    Case #WM_RBUTTONDOWN
      Debug Rotstift_Disaeble
      Rotstift_Disaeble = #False
      If RotstiftStatusOn = 1
      RotstiftDeleter = #True
      RotstiftShowLine = #False
      RotstiftStart_X = WindowMouseX(#Window)-Rotstift_X_GadgetOffset
      RotstiftStart_Y = WindowMouseY(#Window)-Rotstift_Y_GadgetOffset
    EndIf
    
            

  Case #WM_LBUTTONDOWN
      If RotstiftStatusOn = 1
        RotstiftShowLine = #True
        RotstiftStart_X = WindowMouseX(#Window)-Rotstift_X_GadgetOffset
        RotstiftStart_Y = WindowMouseY(#Window)-Rotstift_Y_GadgetOffset
      EndIf
    
    
    
  Case #WM_MOUSEMOVE
         If Rotstift_Disaeble = #False

      If RotstiftStatusOn = 1
      If RotstiftShowLine
        StartDrawing(ImageOutput(#RotstiftBild))
        DrawImage(ImageID(#RotstiftBildVorlage), 0, 0)
        Rotstift_Linienstaerke= Val(GetGadgetText(#Rotstiftstaerke))
        ;LineXY(WindowMouseX(#Window)-Rotstift_X_GadgetOffset, WindowMouseY(#Window)-Rotstift_Y_GadgetOffset, RotstiftStart_X, RotstiftStart_Y, Rotstift_Color)
        RotstiftThickLineXY(WindowMouseX(#Window)-Rotstift_X_GadgetOffset, WindowMouseY(#Window)-Rotstift_Y_GadgetOffset, RotstiftStart_X, RotstiftStart_Y, Rotstift_Linienstaerke, Rotstift_Color)
        StopDrawing()
        SetGadgetState(#RotstiftImage,ImageID(#RotstiftBild))
      EndIf
      If RotstiftDeleter
        StartDrawing(ImageOutput(#RotstiftBild))
        DrawImage(ImageID(#RotstiftBildVorlage), 0, 0)
        Circle(WindowMouseX(#Window)-Rotstift_X_GadgetOffset, WindowMouseY(#Window)-Rotstift_Y_GadgetOffset, 10, RGB(255, 215, 0))
        StopDrawing()
        SetGadgetState(#RotstiftImage,ImageID(#RotstiftBild))
        CopyImage(#RotstiftBild,#RotstiftBildVorlage)
      EndIf
    EndIf
  EndIf
  
Case #WM_LBUTTONUP
       If Rotstift_Disaeble = #False

      If RotstiftStatusOn = 1
      RotstiftShowLine = #False
      StartDrawing(ImageOutput(#RotstiftBildVorlage))
      Rotstift_Linienstaerke= Val(GetGadgetText(#Rotstiftstaerke))
      ;LineXY(WindowMouseX(#Window)-Rotstift_X_GadgetOffset,WindowMouseY(#Window)-Rotstift_Y_GadgetOffset, RotstiftStart_X, RotstiftStart_Y, Rotstift_Color)
      RotstiftThickLineXY(WindowMouseX(#Window)-Rotstift_X_GadgetOffset, WindowMouseY(#Window)-Rotstift_Y_GadgetOffset, RotstiftStart_X, RotstiftStart_Y, Rotstift_Linienstaerke, Rotstift_Color)
      StopDrawing()
      SetGadgetState(#RotstiftImage,ImageID(#RotstiftBildVorlage))
    EndIf
    EndIf
    
  Case #WM_RBUTTONUP
      If RotstiftStatusOn = 1
      RotstiftDeleter = #False
    EndIf
    
EndSelect
  
ForEver

;ColorRequester()
;Farbe = RGB(Rot, Grün, Blau)
Gruss ... Velindos

Re: Abfrage von Klick auf Combobox

Verfasst: 24.05.2012 17:13
von Velindos
Hallo, habe hier einmal das Problem isoliert und der Klick reagiert nicht left noch right?

Code: Alles auswählen

If OpenWindow(0, 0, 0, 270, 140, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ComboBoxGadget(0, 10, 10, 250, 100, #PB_ComboBox_Editable)
  AddGadgetItem(0, -1, "ComboBox editable...")
  ComboBoxGadget(1, 10, 40, 250, 100)
  For a = 1 To 5 : AddGadgetItem(1, -1,"ComboBox item " + Str(a)) : Next a
  SetGadgetState(1, 2) 
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0, 1
            ;If EventType() = #PB_EventType_RightClick
              If EventType() = #PB_EventType_LeftClick
                Debug "Eintrag wurde geändert"
              EndIf
          EndSelect
      EndSelect
    ForEver
  EndIf
Gruss ... Velindos

Re: Abfrage von Klick auf Combobox

Verfasst: 24.05.2012 18:27
von ts-soft
Ich würde Dir raten, mal öfter in die Hilfe zu schauen :wink:
http://www.purebasic.com/german/documen ... adget.html
Hilfe hat geschrieben:ComboBoxGadget() unterstützt die folgenden Ereignisse, welche von EventType() gemeldet werden:

#PB_EventType_Change : Die aktuelle Auswahl des Textes im Eingabefeld hat sich geändert.
#PB_EventType_Focus : Das Eingabefeld hat den Tastatur-Fokus erhalten (nur bei editierbarer ComboBox).
#PB_EventType_LostFocus: Das Eingabefeld hat den Tastatur-Fokus verloren (nur bei editierbarer ComboBox).

Re: Abfrage von Klick auf Combobox

Verfasst: 24.05.2012 20:01
von Velindos
Hallo ts-soft,
danke für deinen Rat, habe ich gemacht, funkt nicht.

Wenn ich #PB_EventType_Focus und dann auf Bild gehe bleibt der Focus drauf, guckj mal!

Geht nur weg wenn ich auf zweite Combo drücke!

Code: Alles auswählen

#Combowindow=0
#ComboBoxGadget1=0
#ComboBoxGadget2=1
#ComboBoxGadget3=2

CreateImage(0,20,20)

If OpenWindow(#Combowindow, 0, 0, 270, 240, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ComboBoxGadget(#ComboBoxGadget1, 10, 10, 250, 20, #PB_ComboBox_Editable)
  AddGadgetItem(#ComboBoxGadget1, -1, "ComboBox editable...")
   For a = 1 To 5 : AddGadgetItem(#ComboBoxGadget1, -1,"ComboBox item " + Str(a)) : Next a
  SetGadgetState(#ComboBoxGadget1, 0)    ; wir setzen (beginnend bei 0) den dritten Eintrag als aktiven
 
  
  
  ComboBoxGadget(#ComboBoxGadget2, 40, 40, 250, 20)
  For a = 1 To 5 : AddGadgetItem(#ComboBoxGadget2, -1,"ComboBox item " + Str(a)) : Next a
  SetGadgetState(#ComboBoxGadget2, 2)    ; wir setzen (beginnend bei 0) den dritten Eintrag als aktiven
  
  ImageGadget(#ComboBoxGadget3,21,80,20,20,ImageID(0))
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #ComboBoxGadget1, #ComboBoxGadget2
            ;If EventType() = #PB_EventType_LeftClick
            ;If EventType() = #PB_EventType_RightButtonDown
            ;If EventType() = #PB_EventType_RightClick
            If EventType() =  #PB_EventType_Focus
              Debug "Eintrag wurde geändert"
           EndIf
       EndSelect
    EndSelect
  ForEver
EndIf
Gruss .. Velindos

PS.: In die Hilfe schauen, was hilfts wenn man nichts vesteht! Da braucht man das Forum, allen sei DANK!

Re: Abfrage von Klick auf Combobox

Verfasst: 24.05.2012 20:31
von ts-soft
Das mit dem Fokus und dem ImageGadget scheint mir ein Bug zu sein, ansonsten funktioniert alles, wie es auch
in der Hilfe steht.

Re: Abfrage von Klick auf Combobox

Verfasst: 24.05.2012 20:49
von Danilo
Velindos hat geschrieben:Hallo ts-soft,
danke für deinen Rat, habe ich gemacht, funkt nicht.

Wenn ich #PB_EventType_Focus und dann auf Bild gehe bleibt der Focus drauf, guckj mal!

Geht nur weg wenn ich auf zweite Combo drücke!
Das ImageGadget hat keinen Focus, siehst Du wenn Du TAB drückst.

Warum nimmst Du nicht #PB_EventType_Change?

Code: Alles auswählen

#Combowindow=0
#ComboBoxGadget1=0
#ComboBoxGadget2=1
#ComboBoxGadget3=2

CreateImage(0,20,20)

If OpenWindow(#Combowindow, 0, 0, 270, 240, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ComboBoxGadget(#ComboBoxGadget1, 10, 10, 250, 20, #PB_ComboBox_Editable)
  AddGadgetItem(#ComboBoxGadget1, -1, "ComboBox editable...")
   For a = 1 To 5 : AddGadgetItem(#ComboBoxGadget1, -1,"ComboBox item " + Str(a)) : Next a
  SetGadgetState(#ComboBoxGadget1, 0)    ; wir setzen (beginnend bei 0) den dritten Eintrag als aktiven
 
  
  
  ComboBoxGadget(#ComboBoxGadget2, 40, 40, 250, 20)
  For a = 1 To 5 : AddGadgetItem(#ComboBoxGadget2, -1,"ComboBox item " + Str(a)) : Next a
  SetGadgetState(#ComboBoxGadget2, 2)    ; wir setzen (beginnend bei 0) den dritten Eintrag als aktiven
  
  ImageGadget(#ComboBoxGadget3,21,80,20,20,ImageID(0))
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #ComboBoxGadget1, #ComboBoxGadget2
            If EventType() =  #PB_EventType_Change
              Debug "Eintrag wurde geändert"
           EndIf
       EndSelect
    EndSelect
  ForEver
EndIf

Re: Abfrage von Klick auf Combobox

Verfasst: 24.05.2012 20:59
von ts-soft
>> Das ImageGadget hat keinen Focus, siehst Du wenn Du TAB drückst.
Ahja, da sitzt das problem, gar nicht richtig drüber nachgedacht, werde langsam alt :mrgreen: