Verfasst: 21.07.2006 17:00
interessanter weise funzt es bei mir unter 3.94 sogar... o_O
aber du hast ja überhaupt keinen gummiband-effekt drin...
aber du hast ja überhaupt keinen gummiband-effekt drin...
Code: Alles auswählen
InitSprite()
InitKeyboard()
InitMouse()
InitSound()
OpenScreen(1280,1024,32, "CAD")
StartSpecialFX()
Dim Linie(1000,5)
;line(x,1) = xachse1
;line(x,2) = yachse1
;line(x,3) = xachse2
;line(x,4) = yachse2
;line(x,5) = art (ob ein kreis gezeichnet werden soll oder eine linie)
Global art.w
Global x.f
Global y.f
Global radius.f
Global bogen.f
bogen = 3.1415926 / 180
art = 1
;wenn art = 1 ist dann wird eine linie gezeichnet bei 2 ein kreis
;bogen ist die konstance, womit wir uns den obtimalen bogenmaß ausrechnen kannst
Repeat
ExamineKeyboard()
ExamineMouse()
If art > 2
art = 1
EndIf
If KeyboardPushed(#PB_Key_Escape)
esc = 1
EndIf
If MouseButton(1)
If druck2 = 0
If MouseX() > 1000
If MouseY() < 20
esc = 1
EndIf
If MouseY() < 40
If MouseY() > 20
art = art +1
EndIf
EndIf
If MouseY() > 40
If MouseY() < 60
anzahl = anzahl -1
If anzahl <0
anzahl = 0
EndIf
linie(anzahl,1) = 0
linie(anzahl,2) = 0
linie(anzahl,3) = 0
linie(anzahl,4) = 0
linie(anzahl,5) = 0
EndIf
EndIf
EndIf
EndIf
druck2 = 1
Else
druck2 = 0
EndIf
If MouseButton(1)
If druck1 = 0
x1 = MouseX()
y1 = MouseY()
EndIf
druck1 = 1
Else
If druck1 = 1
x2 = MouseX()
y2 = MouseY()
If x1 < 1000
If x2 < 1000
linie(anzahl,1) = x1
linie(anzahl,2) = y1
linie(anzahl,3) = x2
linie(anzahl,4) = y2
linie(anzahl,5) = art
anzahl = anzahl +1
x1 = 0
x2 = 0
y1 = 0
y2 = 0
EndIf
EndIf
EndIf
druck1 = 0
EndIf
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
FrontColor (150,150,150)
LineXY(1000,0,1000,1024)
LineXY(0,0,0,1024)
LineXY(0,0,1000,0)
LineXY(0,1024,1000,1024)
Locate(1010,0)
DrawText("Programm Beenden")
Locate(1010,20)
If art = 1
DrawText("Zu Kreis Wechseln")
EndIf
If art = 2
DrawText("Zu Linie Wechseln")
EndIf
Locate(1010,40)
DrawText("Letzten Teil Löschen")
FrontColor (255,0,0)
For i = 0 To 1000
If linie(i,5) > 0
If linie(i,5) = 1
LineXY(linie(i,1),linie(i,2),linie(i,3),linie(i,4))
EndIf
If linie(i,5) = 2
x = (linie(i,1) - linie(i,3))*(linie(i,1) - linie(i,3))
y = (linie(i,2) - linie(i,4))*(linie(i,2) - linie(i,4))
radius = Sqr(x+y)
For j = 1 To 361
sinx = Sin(j*bogen)*radius+linie(i,1)
cosy = Cos(j*bogen)*radius+linie(i,2)
If j > 1
LineXY(sinx,cosy,sinxalt,cosyalt)
EndIf
sinxalt = sinx
cosyalt = cosy
Next j
EndIf
EndIf
Next i
Box(MouseX(),MouseY(),10,10)
If x1 > 0
FrontColor(0,255,0)
LineXY(x1,y1,MouseX(),MouseY())
EndIf
StopDrawing()
FlipBuffers()
Until esc = 1
Code: Alles auswählen
InitSprite()
InitKeyboard()
InitMouse()
InitSound()
OpenScreen(1280,1024,32, "CAD")
StartSpecialFX()
Dim Linie(1000,5)
;line(x,1) = xachse1
;line(x,2) = yachse1
;line(x,3) = xachse2
;line(x,4) = yachse2
;line(x,5) = art (ob ein kreis gezeichnet werden soll oder eine linie)
Global art.w
Global x.f
Global y.f
Global radius.f
Global bogen.f
bogen = 3.1415926 / 180
art = 1
;wenn art = 1 ist dann wird eine linie gezeichnet bei 2 ein kreis
;bogen ist die konstance, womit wir uns den obtimalen bogenmaß ausrechnen kannst
Repeat
ExamineKeyboard()
ExamineMouse()
If art > 2
art = 1
EndIf
If KeyboardPushed(#PB_Key_Escape)
esc = 1
EndIf
If MouseButton(1)
If druck2 = 0
If MouseX() > 1000
If MouseY() < 20
esc = 1
EndIf
If MouseY() < 40
If MouseY() > 20
art = art +1
EndIf
EndIf
If MouseY() > 40
If MouseY() < 60
anzahl = anzahl -1
If anzahl <0
anzahl = 0
EndIf
linie(anzahl,1) = 0
linie(anzahl,2) = 0
linie(anzahl,3) = 0
linie(anzahl,4) = 0
linie(anzahl,5) = 0
EndIf
EndIf
EndIf
EndIf
druck2 = 1
Else
druck2 = 0
EndIf
If MouseButton(1)
If druck1 = 0
x1 = MouseX()
y1 = MouseY()
EndIf
druck1 = 1
Else
If druck1 = 1
x2 = MouseX()
y2 = MouseY()
If x1 < 1000
If x2 < 1000
linie(anzahl,1) = x1
linie(anzahl,2) = y1
linie(anzahl,3) = x2
linie(anzahl,4) = y2
linie(anzahl,5) = art
anzahl = anzahl +1
x1 = 0
x2 = 0
y1 = 0
y2 = 0
EndIf
EndIf
EndIf
druck1 = 0
EndIf
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
FrontColor (150,150,150)
LineXY(1000,0,1000,1024)
LineXY(0,0,0,1024)
LineXY(0,0,1000,0)
LineXY(0,1024,1000,1024)
Locate(1010,0)
DrawText("Programm Beenden")
Locate(1010,20)
If art = 1
DrawText("Zu Kreis Wechseln")
EndIf
If art = 2
DrawText("Zu Linie Wechseln")
EndIf
Locate(1010,40)
DrawText("Letzten Teil Löschen")
FrontColor (255,0,0)
For i = 0 To 1000
If linie(i,5) > 0
If linie(i,5) = 1
LineXY(linie(i,1),linie(i,2),linie(i,3),linie(i,4))
EndIf
If linie(i,5) = 2
x = (linie(i,1) - linie(i,3))*(linie(i,1) - linie(i,3))
y = (linie(i,2) - linie(i,4))*(linie(i,2) - linie(i,4))
radius = Sqr(x+y)
For j = 1 To 361
sinx = Sin(j*bogen)*radius+linie(i,1)
cosy = Cos(j*bogen)*radius+linie(i,2)
If j > 1
LineXY(sinx,cosy,sinxalt,cosyalt)
EndIf
sinxalt = sinx
cosyalt = cosy
Next j
EndIf
EndIf
Next i
If x1 > 1000
x1 = 0
EndIf
Box(MouseX(),MouseY(),10,10)
If x1 > 0
If art = 1
FrontColor(0,255,0)
LineXY(x1,y1,MouseX(),MouseY())
EndIf
If art = 2
FrontColor(0,255,0)
radius = Sqr((x1-MouseX())*(x1-MouseX())+(y1-MouseY())*(y1-MouseY()))
For j = 0 To 361
sinx = Sin(j * bogen) * radius + x1
cosy = Cos(j * bogen) * radius + y1
If j > 0
LineXY(sinx,cosy,sinxalt,cosyalt)
EndIf
sinxalt = sinx
cosyalt = cosy
Next j
EndIf
EndIf
StopDrawing()
FlipBuffers()
Until esc = 1
Code: Alles auswählen
;PB3.94 DEMO-TESTVERSION , aber weitere API's sind nicht mehr weiter angepasst worden:D
OpenLibrary(0,"user32.dll")
OpenLibrary(1,"gdi32.dll")
InitSprite()
Structure POINTAPI
x.l
y.l
EndStructure
#PS_SOLID = $0
#SM_CXSCREEN = $0
#SM_CYSCREEN = $1
WS_OVERLAPPED = $0
WS_CAPTION = $C00000
WS_SYSMENU = $80000
WS_THICKFRAME = $40000
WS_MINIMIZEBOX = $20000
WS_MAXIMIZEBOX = $10000
WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
#WM_LBUTTONDOWN = $201
#WM_LBUTTONUP = $202
Procedure.l GetDC(hwnd.l)
ProcedureReturn CallFunction(0,"GetDC",hwnd)
EndProcedure
;
Procedure.l CreatePen(nPenStyle.l, nWidth.l, crColor.l)
ProcedureReturn CallFunction(1,"CreatePen",nPenStyle, nWidth, crColor)
EndProcedure
;
Procedure.l SelectObject(hdc.l, hObject.l)
ProcedureReturn CallFunction(1,"SelectObject",hdc, hObject)
EndProcedure
;
Procedure.l MoveToEx(hdc.l, x.l, y.l,Point)
ProcedureReturn CallFunction(1,"MoveToEx",hdc, x, y, lpPoint.POINTAPI)
EndProcedure
;
Procedure.l LineTo(hdc.l, x.l, y.l,Point)
ProcedureReturn CallFunction(1,"LineTo",hdc, x, y)
EndProcedure
;
Procedure.l DeleteObject(hObject.l)
ProcedureReturn CallFunction(1,"DeleteObject",hObject)
EndProcedure
;
Procedure.l GetSystemMetrics(nIndex.l)
ProcedureReturn CallFunction(0,"GetSystemMetrics",nIndex)
EndProcedure
;
Procedure.w ScreenWidth ()
ProcedureReturn GetSystemMetrics_ (#SM_CXSCREEN)
EndProcedure
;
Procedure.w ScreenHeight ()
ProcedureReturn GetSystemMetrics_ (#SM_CYSCREEN)
EndProcedure
;
Procedure CopyWindow (fromWindow, x, y)
width = ScreenWidth ()
height = ScreenHeight ()
fromDC = GetWindowDC_ (fromWindow)
toDC = StartDrawing (ImageOutput ())
BitBlt_ (toDC, 0,-29, WindowWidth(), WindowHeight()+29, fromDC, x, y, #SRCCOPY)
StopDrawing ()
ReleaseDC_ (fromWindow, fromDC)
EndProcedure
;
Procedure Lin(x,y,x1,y1,Width,Color)
hDC=GetDC(WindowID(0))
pen=CreatePen(#PS_SOLID,Width,color)
hPenOld=SelectObject(hDC,pen)
MoveToEx(hDC,x,y,0):LineTo(hDC,x1,y1,0)
DeleteObject(pen)
DeleteObject(hPenOld)
EndProcedure
_X=GetSystemMetrics(#SM_CXSCREEN)-8 : _Y=GetSystemMetrics(#SM_CYSCREEN)-68
OpenWindow(0,0,0,_X,_Y,#PB_Window_SystemMenu,"")
Set=0
CreateImage (0, WindowWidth() ,WindowHeight() )
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_MoveWindow
StartDrawing (WindowOutput ())
DrawImage (ImageID (), 0, 0)
StopDrawing ()
Case #WM_LBUTTONDOWN
x1 = WindowMouseX()
y1 = WindowMouseY()
Set=1
Case #WM_LBUTTONUP
If Set=1
x2 = WindowMouseX()
y2 = WindowMouseY()
lin(x1,y1,x2,y2,2,RGB(255,0,0))
CopyWindow (WindowID(0),0,0)
Set=0
EndIf
EndSelect
Until event = #PB_Event_CloseWindow
CloseLibrary(0): CloseLibrary(1)
Code: Alles auswählen
;Hier der Source ohne Rattenschwanz für PB-Vollversion 3.94
;
Procedure.w ScreenWidth ()
ProcedureReturn GetSystemMetrics_ (#SM_CXSCREEN)
EndProcedure
;
Procedure.w ScreenHeight ()
ProcedureReturn GetSystemMetrics_ (#SM_CYSCREEN)
EndProcedure
;
Procedure CopyWindow (fromWindow, x, y)
width = ScreenWidth ()
height = ScreenHeight ()
fromDC = GetWindowDC_ (fromWindow)
toDC = StartDrawing (ImageOutput ())
BitBlt_ (toDC, 0,-49, WindowWidth(), WindowHeight()+49, fromDC, x, y, #SRCCOPY)
StopDrawing ()
ReleaseDC_ (fromWindow, fromDC)
EndProcedure
;
Procedure Lin(x,y,x1,y1,Width,Color)
hDC=GetDC_(WindowID(0))
pen=CreatePen_(#PS_SOLID,Width,color)
hPenOld=SelectObject_(hDC,pen)
MoveToEx_(hDC,x,y,0):LineTo_(hDC,x1,y1)
DeleteObject_(pen)
DeleteObject_(hPenOld)
EndProcedure
_X=GetSystemMetrics_(#SM_CXSCREEN)-8 : _Y=GetSystemMetrics_(#SM_CYSCREEN)-68
OpenWindow(0,0,0,_X,_Y,#PB_Window_SystemMenu,"")
If CreateMenu(0, WindowID())
MenuTitle("Einstellungen")
MenuItem( 1, "Linienstärke")
MenuItem( 2, "Linienfarbe")
CloseSubMenu()
MenuBar()
MenuItem( 3, "&Quit")
EndIf
CreateImage (0, WindowWidth() ,WindowHeight() )
CopyWindow (WindowID(0),0,0)
;
Set=0
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Menu
Select EventMenuID()
Case 1
Ld=Val(InputRequester("Strichstärke eingeben", "Bitte geben sie die Lininendicke ein","5"))
Case 2
Lf=Farbe = ColorRequester()
Case 3
End
EndSelect
Case #PB_Event_MoveWindow
StartDrawing (WindowOutput ())
DrawImage (ImageID (), -4, 0)
StopDrawing ()
Case #WM_LBUTTONDOWN
x1 = WindowMouseX()
y1 = WindowMouseY()
Set=1
Case #WM_LBUTTONUP
If Set=1
x2 = WindowMouseX()
y2 = WindowMouseY()
lin(x1,y1,x2,y2,Ld,Lf)
CopyWindow (WindowID(0),0,0)
Set=0
EndIf
EndSelect
Until event = #PB_Event_CloseWindow
Man hätte es z.B. in eine Procedure schreiben können.Case #PB_Event_MoveWindow
StartDrawing (WindowOutput ())
DrawImage (ImageID (), 0, 0)
StopDrawing ()
CreateImage (0, WindowWidth() ,WindowHeight() ) ; Erzeutg ein leeres Image mit der Imageid 0
CopyWindow (WindowID(0),0,0) ; kopiert das aktuelle Windows (leer) in das Image, was nachher zum redraw gebraucht wird.
Ich hoffe es ist einigermaßen verständlich.Case #WM_LBUTTONUP
If Set=1
x2 = WindowMouseX()
y2 = WindowMouseY()
lin(x1,y1,x2,y2,2,RGB(255,0,0))
CopyWindow (WindowID(0),0,0)
Set=0
EndIf