Seite 2 von 2

Verfasst: 22.08.2006 22:13
von edel
schau dir mal folgenden Code an : (ACHTUNG : FALSCH)

Code: Alles auswählen

hwnd = OpenWindow(0,0,0,100,100,"")

CreateGadgetList(hwnd)
StringGadget(0,0,0,80,20,"")


Repeat
  
  event = WaitWindowEvent()
  
  SetGadgetText(0,"Fehler")
  
  ; If event = #PB_Event_Gadget
    ; If #PB_EventType_Change = EventType()
      ; Debug "FEHLER"
    ; EndIf
  ; EndIf
  
Until event = #WM_CLOSE
Mit WaitWindowEvent() wird die Schleife gestopt bis ein Event ankommt.
SetGadgetText veranlasst das Gadget aber auch ein Event abzusetzen.
Heisst also dein Programm bekommt immer Events und dann faengt es
froehlich mit flackern an.

Etwas abgespeckter Code

Verfasst: 22.08.2006 22:15
von GreyEnt
Hallo TS Soft.
Meinst Du die GadGets die ich für Kreis und Bogen verwende?

Code: Alles auswählen

;   PureXY CAD
;
;   geschrieben in PureBasic 4.00
;   Juni 2006
;   von Dieter Platzke
;   platzke@muenster.de
;
; ------------------------------------------------------------
;
Global pi.f
Global winkelgrad.f
Global quit.b
Global anzeigex1.l
Global anzeigey1.l
Global anzeigex2.l
Global anzeigey2.l
Global ladedatei$
Global aktivelement.l
Global mission.s


mission=""
pi=3.14159265
winkelgrad=pi/180
quit=0
anzeigex1.l=400
anzeigey1=300
anzeigex2.l=800
anzeigey2=600
gz.l=160    ;Zeile für freie gadgets
aobjekt.l=0 ;Aktuelles Objekt für Eigenschaftsfenster
farbe.l=0
cursorblau.l=0
cursorgruen.l=0
cursorrot.l=0
mcount=0
findencount.l=0

Structure bogen
  zentrumx.f
  zentrumy.f
  radius.f
  startwinkel.f
  endwinkel.f
EndStructure
Structure kreis
  zentrumx.f
  zentrumy.f
  radius.f
EndStructure
Structure linie
  startx.f
  starty.f
  endx.f
  endy.f
EndStructure
Structure punkt
  x.f
  y.f  
EndStructure
Structure dreieck
  startx.f
  starty.f
  liniec.f
  liniea.f
  linieb.f
EndStructure
Structure vieleck
  zentrumx.f
  zentrumy.f
  kantenzahl.w
  kantenlaenge.f
EndStructure
Structure elipse
  zentrumx.f
  zentrumy.f
  radius1.f
  radius2.f
EndStructure
Structure limiten ;ohne Funktion
limxmin.f
limxmax.f
limymin.f
limymax.f
EndStructure
Structure gummiband ;ohne Funktion
  x.f
  y.f  
EndStructure

Global NewList bo.bogen()
Global NewList kr.kreis()
Global NewList li.linie()
Global NewList pu.punkt()
Global NewList dr.dreieck()
Global NewList vi.vieleck()
Global NewList el.elipse()
Global NewList lim.limiten()
Global NewList gummiband.linie()
AddElement(li())
li()\startx=0
li()\starty=0
li()\endx=50
li()\endy=0

Procedure fegen()
StartDrawing(WindowOutput(0))
FrontColor(RGB(255,255,255))
Box(108,28,WindowWidth(0)-300,WindowHeight(0)-68)
FrontColor(RGB(212,208,200))
Box(109,29,WindowWidth(0)-302,WindowHeight(0)-70)
StopDrawing()
EndProcedure
Procedure bogenzeichnen()
winkel1.f=bo()\endwinkel-bo()\startwinkel
If bo()\startwinkel<bo()\endwinkel
bogenwinkel.f=winkel1       ; Der Bogenwinkel ist der Winkel zwischen Startwinkel und Endwinkel
Else
bogenwinkel.f=360+winkel1
EndIf
koordx1.f = bo()\zentrumx + anzeigex1 +Cos(winkelgrad*bo()\startwinkel)*bo()\radius
koordx2.f = koordx1
koordy1.f = -bo()\zentrumy + anzeigey1 -Sin(winkelgrad*bo()\startwinkel)*bo()\radius
koordy2.f = koordy1
a.f=bo()\startwinkel
While a<bo()\startwinkel+bogenwinkel
koordx1 = bo()\zentrumx + anzeigex1 +Cos(winkelgrad*a)*bo()\radius
koordy1 = -bo()\zentrumy + anzeigey1 -Sin(winkelgrad*a)*bo()\radius
LineXY(koordx1,koordy1,koordx2,koordy2)
koordx2 = koordx1
koordy2 = koordy1
a=a+1
Wend
EndProcedure
Procedure kreiszeichnen()
a.f = 0
  koordx1.l = kr()\zentrumx + anzeigex1 + Cos(winkelgrad*a)*kr()\radius
  koordx2.l = koordx1.l
  koordy1.l = -kr()\zentrumy + anzeigey1 + Sin(winkelgrad*a)*kr()\radius
  koordy2.l = koordy1.l
  Repeat
  koordx1 = kr()\zentrumx + anzeigex1 + Cos(winkelgrad*a)*kr()\radius
  koordy1 = -kr()\zentrumy + anzeigey1 + Sin(winkelgrad*a)*kr()\radius
  LineXY(koordx1,koordy1,koordx2,koordy2)
  koordx2.l = koordx1.l
  koordy2.l = koordy1.l
  a=a+1
  Until a>360
EndProcedure
Procedure liniezeichnen()
startx.f=li()\startx + anzeigex1
starty.f=anzeigey1 - li()\starty
endx.f=li()\endx + anzeigex1
endy.f=anzeigey1 - li()\endy
LineXY(startx,starty,endx,endy)
EndProcedure

OpenWindow(0, 20, 20, 800, 600,"Pure XY Editor", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget)

  CreateStatusBar(0, WindowID(0))
    AddStatusBarField(200)
    AddStatusBarField(200)
    AddStatusBarField(50)
    AddStatusBarField(50)
  
  StatusBarText(0, 0, "Area 1")
  StatusBarText(0, 1, "Area 2", #PB_StatusBar_BorderLess)
  StatusBarText(0, 2, "Area 3", #PB_StatusBar_Right | #PB_StatusBar_Raised)
  StatusBarText(0, 3, "Area 3", #PB_StatusBar_Right | #PB_StatusBar_Raised) 

  CreateToolBar(0, WindowID(0)) 
    ToolBarStandardButton(0,#PB_ToolBarIcon_New) 
    ToolBarStandardButton(1,#PB_ToolBarIcon_Open) 
    ToolBarStandardButton(2,#PB_ToolBarIcon_Save)
    ToolBarStandardButton(3,#PB_ToolBarIcon_Print)
    ToolBarStandardButton(4,#PB_ToolBarIcon_Find)
    ToolBarStandardButton(5,#PB_ToolBarIcon_Replace)
    ToolBarStandardButton(6,#PB_ToolBarIcon_Cut)
    ToolBarStandardButton(7,#PB_ToolBarIcon_Copy) 
    ToolBarStandardButton(8,#PB_ToolBarIcon_Paste) 
    ToolBarStandardButton(9,#PB_ToolBarIcon_Undo)
    ToolBarStandardButton(10,#PB_ToolBarIcon_Redo) 
    ToolBarStandardButton(11,#PB_ToolBarIcon_Delete)
    ToolBarStandardButton(12,#PB_ToolBarIcon_Properties)
    ToolBarStandardButton(13,#PB_ToolBarIcon_Help)
    
  CreateMenu(0, WindowID(0))
    MenuTitle("Datei")
    MenuItem(0,"Neu")
    MenuItem(1,"Öffnen")
    MenuItem(2,"Sichern")
    MenuBar()
    MenuItem(14,"Schließen")
    MenuTitle("Skizzieren")
    MenuItem(15,"Linie")
    MenuItem(16,"Kreis")  
    MenuTitle("?")
    MenuItem(17,"Info")
  
  CreateGadgetList(WindowID(0))
    ButtonGadget(1, 1, 25,106,25, "Neuzeichnen")
    ButtonGadget(2, 1, 50,106,25, "Programm beenden")
    ButtonGadget(3, 1, 75,106,25, "Neuer Bogen")
    ButtonGadget(16,1,100,106,25, "Neuer Kreis")
    ButtonGadget(17,1,125,106,25, "Neue Linie")
    TextGadget(100,WindowWidth(0)-140,10, 50, 19, "#")
      StringGadget(101,WindowWidth(0)-90 ,10, 80, 19,"#")
    TextGadget(102,WindowWidth(0)-140,30, 50, 19, "#")
      StringGadget(103,WindowWidth(0)-90 ,30, 80, 19,"#")
    TextGadget(104,WindowWidth(0)-140,50, 50, 19, "#")
      StringGadget(105,WindowWidth(0)-90 ,50, 80, 19,"#")
    TextGadget(106,WindowWidth(0)-140,70, 50, 19, "#")
      StringGadget(107,WindowWidth(0)-90 ,70, 80, 19,"#")
    TextGadget(108,WindowWidth(0)-140,90, 50, 19, "#")
      StringGadget(109,WindowWidth(0)-90 ,90, 80, 19,"#")
    TextGadget(110,WindowWidth(0)-140,110, 50, 19, "#")
      StringGadget(111,WindowWidth(0)-90 ,110, 80, 19,"#")
    TextGadget(112,WindowWidth(0)-140,130, 50, 19, "#")
      StringGadget(113,WindowWidth(0)-90 ,130, 80, 19,"#")
    TextGadget(114,WindowWidth(0)-140,150, 50, 19, "#")
      StringGadget(115,WindowWidth(0)-90 ,150, 80, 19,"#")
    TextGadget(116,WindowWidth(0)-140,170, 50, 19, "#")
      StringGadget(117,WindowWidth(0)-90 ,170, 80, 19,"#")
    TextGadget(118,WindowWidth(0)-140,190, 50, 19, "#")
      StringGadget(119,WindowWidth(0)-90 ,190, 80, 19,"#")
    
  AddKeyboardShortcut(0,#PB_Shortcut_Up, 20)    ;Tasten für PAN
  AddKeyboardShortcut(0,#PB_Shortcut_Down, 21)  ;     -||-
  AddKeyboardShortcut(0,#PB_Shortcut_Left, 22)  ;     -||-
  AddKeyboardShortcut(0,#PB_Shortcut_Right, 23) ;     -||-
  
  fegen()
  zbx1.l=109                ;Zeichenbereich festlegen
  zby1.l=29
  zbx2.l=WindowWidth(0)-195
  zby2.l=WindowHeight(0)-40
  Gosub SomeGraphics
  
Repeat
Ereignis = WaitWindowEvent()
  
Select Ereignis

Case #PB_Event_CloseWindow
quit = 1

Case #PB_Event_Gadget
 Select EventGadget()
  Case 1
  Gosub SomeGraphics
  Case 2
  quit = 1
  Case 3 ;Eingabe neuer Bogen
      CreateGadgetList(WindowID(0))
      StringGadget(5, 1, gz, 50, 19, "200")
      StringGadget(6, 1, gz+20, 50, 19, "200")
      StringGadget(7, 1, gz+40, 50, 19, "150")
      StringGadget(8, 1, gz+60, 50, 19, "0")
      StringGadget(9, 1, gz+80, 50, 19, "60")
      TextGadget(10, 55, gz, 50 , 19,"Zentr.X")
      TextGadget(11, 55, gz+20, 50 , 19,"Zentr.Y")
      TextGadget(12, 55, gz+40, 50 , 19,"Radius")
      TextGadget(13, 55, gz+60, 50 , 19,"S.Winkel")
      TextGadget(14, 55, gz+80, 50 , 19,"E.Winkel")
      ButtonGadget(15, 1, gz+100, 106, 25, " OK ")
  Case 15 ;ok neuer Bogen
      AddElement(bo())
      bo()\zentrumx = ValF(GetGadgetText(5))
      bo()\zentrumy = ValF(GetGadgetText(6))
      bo()\radius = ValF(GetGadgetText(7))
      bo()\startwinkel = ValF(GetGadgetText(8))
      bo()\endwinkel = ValF(GetGadgetText(9))
      For a.b=5 To 15
      FreeGadget(a)
      Next a
      Gosub SomeGraphics
  Case 16 ;Eingabe neuer Kreis
      CreateGadgetList(WindowID(0))
      StringGadget(5, 1, gz, 50, 19, "200")
      StringGadget(6, 1, gz+20, 50, 19, "200")
      StringGadget(7, 1, gz+40, 50, 19, "150")
      TextGadget(8, 55, gz, 50 , 19,"Zentr.X")
      TextGadget(9, 55, gz+20, 50 , 19,"Zentr.Y")
      TextGadget(10, 55, gz+40, 50 , 19,"Radius")
      ButtonGadget(11, 1, gz+60, 106, 25, " OK ")
  Case 11 ;ok neuer Kreis
      AddElement(kr())
      kr()\zentrumx = ValF(GetGadgetText(5))
      kr()\zentrumy = ValF(GetGadgetText(6))
      kr()\radius = ValF(GetGadgetText(7))
      For a.b=5 To 11
      FreeGadget(a)
      Next a
      Gosub SomeGraphics
  Case 17 ;Eingabe neue Linie
    mission="linie s"
    SetGadgetText(100,"Linie")
    SetGadgetText(101,Str(CountList(li())))
    SetGadgetText(102,"SX")
    SetGadgetText(104,"SY")
    
  Case 103

    
  EndSelect ;Ende Case #pb_event_gadget
  
 Case #PB_Event_Menu
 Select EventMenu()
    Case 0                  ; Elemente Löschen
    ClearList(bo())
    ClearList(kr())
    ClearList(li())
    fegen()
    SetWindowTitle(0,"VARICAD-"+"Neu")
    
    Case 1                  ; Fenster für Laden
 
    Case 2; Fenster für Sichern

    Case 20
    anzeigey1=anzeigey1-10
    fegen()
    Gosub somegraphics
    Case 21
    anzeigey1=anzeigey1+10
    fegen()
    Gosub somegraphics
    Case 22
    anzeigex1=anzeigex1-10
    fegen()
    Gosub somegraphics
    Case 23
    anzeigex1=anzeigex1+10
    fegen()
    Gosub somegraphics
       
    EndSelect ;Ende Event_Menu
    EndSelect ;Ende Ereignis
    
    StartDrawing(WindowOutput(0))
    cursorblau= Blue(Point(WindowMouseX(0),WindowMouseY(0)))
    cursorgruen=Green(Point(WindowMouseX(0),WindowMouseY(0)))
    cursorrot=Red(Point(WindowMouseX(0),WindowMouseY(0)))
    StopDrawing()
    koordx.l=WindowMouseX(0)-anzeigex1 : koordy.l=anzeigey1-WindowMouseY(0)
    StatusBarText(0,0,"X: "+Str(koordx)+"/ Y: "+Str(koordy))
    StatusBarText(0,1,Str(cursorrot)+" "+Str(cursorgruen)+" "+Str(cursorblau))
    StatusBarText(0,3,mission)
    
    If WindowMouseX(0)>zbx1 And WindowMouseX(0)<zbx2 And WindowMouseY(0)>zby1 And WindowMouseY(0)<zby2
    zb.s="ja"
    Else
    zb.s="nein"
    EndIf
    StatusBarText(0,2,"ZB="+zb)
    
    lk=GetAsyncKeyState_(#VK_LBUTTON) ;Linke Mausklickabfrage
    
    Select mission
    Case "linie e"
    gaendx.f = gnendx.f               ;Gummiband zeichnen
    gaendy.f = gnendy.f
    gnstartx.f = lnstartx.f + anzeigex1
    gnstarty.f = anzeigey1 - lnstarty.f
    gnendx.f = koordx + anzeigex1
    gnendy.f = anzeigey1 - koordy
      If gaendx <> gnendx Or gaendy <> gnendy
      fegen()
      Gosub SomeGraphics
      StartDrawing(WindowOutput(0))
      FrontColor(RGB(0,255,0))
      LineXY(gnstartx,gnstarty,gnendx,gnendy)
      FrontColor(RGB(0,0,0))
      StopDrawing()
      EndIf
    If lk And mcount=0
    LastElement(li())
    AddElement(li())
    li()\startx=lnstartx
    li()\starty=lnstarty
    li()\endx=koordx
    li()\endy=koordy
    StartDrawing(WindowOutput(0))
    FrontColor(RGB(0,0,255))
    liniezeichnen()
    StopDrawing()
    mission=""
    lk=0
    mcount=10
    EndIf
    
    Case "linie s"
    SetGadgetText(103,Str(koordx))
    SetGadgetText(105,Str(koordy))
    If lk And mcount=0
    lnstartx.f=koordx
    lnstarty.f=koordy
    mission="linie e"
    lk=0
    mcount=10
    EndIf
        
    EndSelect ;select mission
    
    
    If cursorrot <> 212 And mission="" And zb="ja" ;Block zum finden des ausgewählten Objektes
    SelectElement(li(), findencount)
    StartDrawing(WindowOutput(0))
    FrontColor(RGB(253,0,0))
    liniezeichnen()
    cursorrot=Red(Point(WindowMouseX(0),WindowMouseY(0)))
    If cursorrot = 253
    StopDrawing()
    Goto endblock
    Else
    FrontColor(RGB(0,0,0))
    liniezeichnen()
    EndIf
    StopDrawing()
    findencount=findencount+1
    If findencount> CountList(li())
    findencount=0
    EndIf
    EndIf
    endblock:
    
    If cursorrot <> 212 And mission="" And zb="ja"
    SetGadgetText(100,"Linie")
    SetGadgetText(101,Str(findencount))
    SetGadgetText(102,"SX")
    SetGadgetText(103,StrF(li()\startx))
    SetGadgetText(104,"SY")
    SetGadgetText(105,StrF(li()\starty))
    SetGadgetText(106,"EX")
    SetGadgetText(107,StrF(li()\endx))
    SetGadgetText(108,"EY")
    SetGadgetText(109,StrF(li()\endy))
    SetGadgetText(110,"Länge")
    SetGadgetText(111, StrF(Sqr( Pow(li()\startx-li()\endx,2)+Pow(li()\starty-li()\endy,2) )))
    deltax.f=li()\startx-li()\endx
    SetGadgetText(112,"deltaX")
    SetGadgetText(113,StrF(deltax))
    deltay.f=li()\starty-li()\endy
    SetGadgetText(114,"deltaY")
    SetGadgetText(115,StrF(deltay))
    steigung.f=deltay/deltax
    SetGadgetText(116,"Steigung")
    SetGadgetText(117,StrF(steigung))
    winkel.f=ATan(steigung)/winkelgrad
    SetGadgetText(118,"Winkel")
    SetGadgetText(119,StrF(winkel))
    EndIf

If mcount>0
mcount=mcount-1
EndIf
Until Ereignis = #PB_Event_CloseWindow Or quit=1  ; If the user has pressed on the close button

  
End   ; All the opened windows are closed automatically by PureBasic
;
; Some 2D graphics functions...
;

SomeGraphics:
  StartDrawing(WindowOutput(0))
  ForEach bo()
  bogenzeichnen()
  Next
  ForEach kr()
  kreiszeichnen()
  Next
  ForEach li()
  liniezeichnen()
  Next
  StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
Return ;Somegraphics
--------------
BBCode aktiviert -- bobobo
Das übrigens u.A. ist eine Option im Profil

Verfasst: 22.08.2006 22:22
von ts-soft
>> Meinst Du die GadGets die ich für Kreis und Bogen verwende?
Genau, erstelle die alle am anfang und dann bei Bedarf anzeigen oder ausblenden. Guck Dir auch in der Hilfe nochmal die Ereignisschleife an, da darf keine Abfrage weggelassen werden, siehe auch Posting von Edel

Neuer Test

Verfasst: 22.08.2006 22:31
von GreyEnt
Also den Code hab ich immer noch nicht richtig reingestellt. :(

Die Gadgets innerhalb des Loops hab ich entfernt. Daran hat es nicht gelegen.
dann werde ich mal weiter schauen.