From: Michael H. <mh...@us...> - 2001-01-02 21:46:24
|
Update of /cvsroot/pythianproject/Prototypes/GUISystem In directory usw-pr-cvs1:/tmp/cvs-serv18544/GUISystem Modified Files: StartupForm.pas vglClasses.pas vglStdCtrls.pas Log Message: added drag'n'drop -mike Index: StartupForm.pas =================================================================== RCS file: /cvsroot/pythianproject/Prototypes/GUISystem/StartupForm.pas,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** StartupForm.pas 2000/12/22 20:06:40 1.11 --- StartupForm.pas 2001/01/02 21:46:20 1.12 *************** *** 19,23 **** { Private declarations } c:TvglComponent; ! Image1:TvglImage; Button :TvglButton; Panel1:TvglPanel; --- 19,23 ---- { Private declarations } c:TvglComponent; ! Image1:TvglDraggableImage; Button :TvglButton; Panel1:TvglPanel; *************** *** 28,34 **** cc: TvglComponent; Edit1:TvglEdit; - ClipTestP1,ClipTestP2,ClipTestP3,ClipTestP4 :TvglPanel; SLE :TvglSingleLineEdit; Elapsed,FirstTime:Cardinal; public --- 28,35 ---- cc: TvglComponent; Edit1:TvglEdit; SLE :TvglSingleLineEdit; + DragBox :TvglDragBox; + Elapsed,FirstTime:Cardinal; public *************** *** 78,82 **** Elapsed := timeGetTime - FirstTime; // elapsed time from beginning - GLForm.Run InterfaceManager.Update(Elapsed); ! InterfaceManager.DrawAll; end; --- 79,83 ---- Elapsed := timeGetTime - FirstTime; // elapsed time from beginning - GLForm.Run InterfaceManager.Update(Elapsed); ! InterfaceManager.DrawAll; end; *************** *** 188,192 **** c.Width := 50; c.Height := 50; ! Image1 := TvglImage.Create('Image1',InterfaceManager.Desktop); Image1.LoadImage('olog.png'); Image1.Bounds := Rect(500,20,0,0); --- 189,193 ---- c.Width := 50; c.Height := 50; ! Image1 := TvglDraggableImage.Create('Image1',InterfaceManager.Desktop); Image1.LoadImage('olog.png'); Image1.Bounds := Rect(500,20,0,0); *************** *** 210,227 **** Button.HasHotkey := True; - { // now for clipping test panels - ClipTestP1 := TvglPanel.Create('ClipTest1',InterfaceManager.Desktop); - ClipTestp1.Color := clRed; - ClipTestp1.Bounds := Rect(270,290,580,450); - ClipTestP4 := TvglPanel.Create('ClipTest4',ClipTestP1); - ClipTestP4.Textured := true; - ClipTestP4.Bounds := Rect(80,80,150,150); - ClipTestP2 := TvglPanel.Create('ClipTest2',ClipTestP1); - ClipTestP2.Color := clBlue; - ClipTestP2.Bounds := Rect(10,10,100,100); - ClipTestP3 := TvglPanel.Create('ClipTest3',ClipTestP2); - ClipTestP3.Color := clGreen; - ClipTestP3.Bounds := Rect(-60,-60,60,60); } - Label1 := TvglTextBox.Create('Label1',InterfaceManager.Desktop); Label1.Top := 192; --- 211,214 ---- *************** *** 263,266 **** --- 250,256 ---- SLE := TvglSingleLineEdit.Create('SLE1',InterfaceManager.Desktop); SLE.Bounds := Rect(20,300,220,400); + + DragBox := TvglDragBox.Create('DragBox1',InterfaceManager.Desktop); + DragBox.Bounds := Rect(500,400,550,450); InterfaceManager.SetNewFocus(LB); Index: vglClasses.pas =================================================================== RCS file: /cvsroot/pythianproject/Prototypes/GUISystem/vglClasses.pas,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** vglClasses.pas 2001/01/01 19:07:21 1.9 --- vglClasses.pas 2001/01/02 21:46:20 1.10 *************** *** 194,197 **** --- 194,198 ---- FBounds: TRect; // this is relative to the owner FCanvas: TglCanvas; + FTotalAlpha :Single; // global alpha filter. should be added to any alpha drawing ops FChildren :TvglObjList; FManager :TvglInterfaceManager; *************** *** 225,229 **** procedure CacheEnd; dynamic ; procedure CacheInit; dynamic; ! procedure CacheFinalize; dynamic; procedure DrawSelf(where:TRect); virtual; // where is screen relative, bounds is parent relative --- 226,230 ---- procedure CacheEnd; dynamic ; procedure CacheInit; dynamic; ! procedure CacheFinalize; dynamic; procedure DrawSelf(where:TRect); virtual; // where is screen relative, bounds is parent relative *************** *** 275,278 **** --- 276,280 ---- property Focused: Boolean read GetFocused write SetFocused; property Focusable: Boolean read FFocusable; + property TotalAlpha :Single read FTotalAlpha write FTotalAlpha; property Owner :TvglComponent read FOwner write SetOwner; property Canvas :TGLCanvas read FCanvas write FCanvas; *************** *** 286,289 **** --- 288,294 ---- destructor Destroy; override ; // destroying an object also destroys its children + procedure MoveTo(x,y:integer); + procedure MoveBy(x,y:integer); + { child management } function AddChild(child:TvglComponent):integer; // connects object to this object as child, returns index in list *************** *** 334,337 **** --- 339,365 ---- end; + { Drag objects can be descended from this to allow ghost drags and movement drags } + TvglDragObject = class + DragOrigin :TPoint; + CurPoint :TPoint; + constructor Create(aDragOrigin:TPoint); + procedure StartDrag; virtual ; + procedure EndDrag; virtual ; + procedure Move(amountX,amountY:integer); virtual ; + end; + + TVGLDragBroadcastEvent = procedure(amountX,amountY:integer) of object; + + TvglDragBroadcasterObject = class(TvglDragObject) + OnDrag :TVGLDragBroadcastEvent; + procedure Move(amountX,amountY:integer); override ; + end; + + // copy drags are redrawn in their correct pos by the interface manager + TvglDragCopyObject = class(TvglDragObject) + CopyComponent :TvglComponent; + constructor Create(aDragOrigin:TPoint; aCopyComponent:TvglComponent); + end; + { Desktop component, basic container that displays a wallpaper and child components (all components are children of the desktop) } *************** *** 381,384 **** --- 409,419 ---- end; + TvglDraggableImage = class(TvglImage) + protected + FDragObj :TvglDragCopyObject; + procedure DoOnMouseDown(mb, X,Y:integer); override ; + procedure DoOnMouseUp(mb, X,Y:integer); override ; + end; + TvglMouseCursor = class(TvglComponent) protected *************** *** 391,394 **** --- 426,443 ---- end; + // test component + TvglDragBox = class(TvglComponent) + protected + FDragObj :TvglDragBroadcasterObject; + Color :TColor; + function GetComponentType:string; override ; + procedure DoOnMouseDown(mb, X,Y:integer); override ; + procedure DoOnMouseUp(mb, X,Y:integer); override ; + procedure DragHandler(amountX,amountY:integer); + public + constructor Create(aName:string; aOwner:TvglComponent); + procedure DrawSelf(where:TRect); override ; + end; + { ********************************************************************** } { Interface Manager } *************** *** 417,420 **** --- 466,471 ---- FLastFocused: TvglComponent; FOnFocusChange: TNotifyEvent; + FDragObjects :TList; + LastDragPos :TPoint; // these are used to generate onMouseEntry, onMouseExit events NewMouseList, OldMouseList, TempMouseList :TvglObjList; *************** *** 429,432 **** --- 480,486 ---- function DoCreateDesktop: TvglDesktop; virtual; function GetKBMod(KeyData: Integer): TVGLKBModifiers; + + procedure UpdateDragObjects(newPos:TPoint); + procedure OverlayDragCopyObjects; public property Focused: TvglComponent read FFocusedComponent; *************** *** 438,441 **** --- 492,496 ---- property WinHandle :HWND read FWinHandle write FWinHandle; property DefaultTextured :boolean read FDefaultTextured write FDefaultTextured; + property DragObjects :TList read FDragObjects; constructor Create(aWinHandle:HWND; aScreenBounds:TRect); overload; *************** *** 453,456 **** --- 508,515 ---- procedure SetNewFocus(C: TvglComponent); + // dragging + procedure StartDrag(dragObj:TvglDragObject); // begins a new drag operation with the object specified + procedure EndDrag(dragObj:TvglDragObject); // guess + // events - called by host environment procedure MouseDown(Button:byte; X,Y:integer); virtual; *************** *** 459,463 **** function KeyDown(KeyCode, KeyData: Integer): Boolean; virtual; // used the key? function KeyUp(KeyCode, KeyData: Integer): Boolean; virtual; - published property OnCreateDesktop: TCreateDesktopEvent read FOnCreateDesktop write SetOnCreateDesktop; --- 518,521 ---- *************** *** 500,503 **** --- 558,562 ---- FClickGetReady := false; FSavedMouseDown := nil; + FTotalAlpha := 1.0; FCached := false; FCacheInvalid := true; *************** *** 1034,1037 **** --- 1093,1116 ---- end; + procedure TvglComponent.MoveTo(x, y: integer); + var w,h:integer; + begin + w := Width; h := Height; + FBounds.Left := x; + FBounds.Top := y; + Width := w; Height := h; + end; + + procedure TvglComponent.MoveBy(x, y: integer); + var w,h:integer; + begin + w := Width; h := Height; + FBounds.Left := FBounds.Left + x; + FBounds.Top := FBounds.Top + y; + Width := w; Height := h; + end; + + + { TvglObjList } *************** *** 1060,1063 **** --- 1139,1143 ---- WinHandle := aWinHandle; DefaultTextured := true; + FDragObjects := TList.Create; FLeft := 0; FTop := 0; *************** *** 1078,1081 **** --- 1158,1191 ---- end; + procedure TvglInterfaceManager.EndDrag(dragObj: TvglDragObject); + begin + dragObj.EndDrag; + if FDragObjects.IndexOf(DragObj) <> -1 then + FDragObjects.Delete(FDragObjects.IndexOf(DragObj)); + end; + + procedure TvglInterfaceManager.StartDrag(dragObj: TvglDragObject); + begin + FDragObjects.Add(dragObj); + dragObj.StartDrag; + end; + + procedure TvglInterfaceManager.UpdateDragObjects(newPos:TPoint); + var + i:integer; + dx,dy:integer; + begin + // tell all drag objects about new move + for i := 0 to FDragObjects.Count-1 do + // work out difference + with TvglDragObject(FDragObjects[i]) do + begin + dX := newPos.x - CurPoint.x; + dY := newPos.Y - CurPoint.y; + Move(dX,dY); + CurPoint := newPos; + end; + end; + function TvglInterfaceManager.DoCreateDesktop: TvglDesktop; begin *************** *** 1109,1112 **** --- 1219,1223 ---- OldMouseList.Free; TempMouseList.Free; + FDragObjects.Free; inherited; end; *************** *** 1117,1120 **** --- 1228,1232 ---- Canvas.InitMatrix; FDesktop.Draw; + OverlayDragCopyObjects; FMouseCursor.Draw; end; *************** *** 1172,1177 **** t:integer; begin - // update the cursor - // send event Desktop.DoOnMouseMove(X, Y); --- 1284,1287 ---- *************** *** 1214,1217 **** --- 1324,1330 ---- CopyList(NewMouseList,OldMouseList); // done! + + // do drag ops + UpdateDragObjects(Point(X,Y)); end; *************** *** 1291,1299 **** inherited DrawSelf(where); if Textured then ! Canvas.TileBitmapSubRect(FitRectToRect(where,Canvas.ClipRect),VGL_SKINRECT_BACKGROUND,FTexture) ! else begin Canvas.CurrentColor := FColor; Canvas.Solid := true; ! Canvas.FillAlpha := 0.5; Canvas.Rectangle(where.Left,where.Top,where.Right,where.Bottom); Canvas.Solid := false; --- 1404,1414 ---- inherited DrawSelf(where); if Textured then ! begin ! Canvas.ImageAlpha := TotalAlpha; ! Canvas.TileBitmapSubRect(FitRectToRect(where,Canvas.ClipRect),VGL_SKINRECT_BACKGROUND,FTexture); ! end else begin Canvas.CurrentColor := FColor; Canvas.Solid := true; ! Canvas.FillAlpha := TotalAlpha - 0.5; Canvas.Rectangle(where.Left,where.Top,where.Right,where.Bottom); Canvas.Solid := false; *************** *** 1335,1338 **** --- 1450,1454 ---- begin inherited DrawSelf(where); + Canvas.ImageAlpha := TotalAlpha; Canvas.DrawBitmap(where.Left,where.Top,FImage); end; *************** *** 1389,1392 **** --- 1505,1509 ---- begin inherited DrawSelf(where); + Canvas.ImageAlpha := 1.0; Canvas.DrawBitmapSubRect(where.Left,where.Top,VGL_SKINRECT_MOUSECURSOR,FImage); end; *************** *** 1474,1477 **** --- 1591,1725 ---- r := rect(where.left+3,where.top,where.right-2,where.top+3); FCanvas.TileBitmapSubRect(r,VGL_SKINRECT_BORDER1_TOP,FImage); + end; + + { TvglDragObject } + + constructor TvglDragObject.Create(aDragOrigin: TPoint); + begin + inherited Create; + DragOrigin := aDragOrigin; + CurPoint := DragOrigin; + end; + + procedure TvglDragObject.EndDrag; + begin + // abstract + end; + + procedure TvglDragObject.Move(amountX, amountY: integer); + begin + CurPoint.X := CurPoint.X + amountX; + CurPoint.Y := CurPoint.Y + amountY; + end; + + procedure TvglDragObject.StartDrag; + begin + // abstract + end; + + { TvglDragBroadcasterObject } + + procedure TvglDragBroadcasterObject.Move(amountX, amountY: integer); + begin + inherited Move(amountX,amountY); + // call event handler + if assigned(OnDrag) then OnDrag(amountX,amountY); + end; + + + + { TvglDragBox } + + constructor TvglDragBox.Create(aName: string; aOwner: TvglComponent); + begin + inherited Create(aName,aOwner); + Color := clBlue; + end; + + procedure TvglDragBox.DoOnMouseDown(mb, X, Y: integer); + begin + // start the drag op + inherited DoOnMouseDown(mb,x,y); + + if assigned(FDragObj) then raise Exception.Create('TvglDragBox.doOnMouseDown: cannot drag more than once at a time!'); + FDragObj := TvglDragBroadcasterObject.Create(Point(X,Y)); + FDragObj.OnDrag := DragHandler; + Manager.StartDrag(FDragObj); + Color := clRed; + end; + + procedure TvglDragBox.DoOnMouseUp(mb, X, Y: integer); + begin + inherited DoOnMouseUp(mb,x,y); + + Manager.EndDrag(FDragObj); + FDragObj.Free; FDragObj := nil; + Color := clBlue; + end; + + procedure TvglDragBox.DragHandler(amountX,amountY:integer); + begin + MoveBy(amountX,amountY); + end; + + procedure TvglDragBox.DrawSelf(where: TRect); + begin + Canvas.CurrentColor := Color; + Canvas.Rectangle(where); + Canvas.Solid := false; + Canvas.FillAlpha := TotalAlpha - 0.5; + Canvas.Solid := true; + Canvas.Rectangle(where); + end; + + function TvglDragBox.GetComponentType: string; + begin + result := 'DragBox'; + end; + + { TvglDragCopyObject } + + constructor TvglDragCopyObject.Create(aDragOrigin: TPoint; + aCopyComponent: TvglComponent); + begin + inherited Create(aDragOrigin); + CopyComponent := aCopyComponent; + end; + + { TvglDraggableImage } + + procedure TvglDraggableImage.DoOnMouseDown(mb, X, Y: integer); + begin + inherited; + if assigned(FDragObj) then FDragObj.Free; + FDragObj := TvglDragCopyObject.Create(Point(x,y),self); + Manager.StartDrag(FDragObj); + end; + + procedure TvglDraggableImage.DoOnMouseUp(mb, X, Y: integer); + begin + inherited; + Manager.EndDrag(FDragObj); + FDragObj.Free; FDragObj := nil; + end; + + procedure TvglInterfaceManager.OverlayDragCopyObjects; + var + i:integer; + b:TRect; + a:single; + begin + for i := 0 to FDragObjects.Count-1 do + if TObject(FDragObjects[i]) is TvglDragCopyObject then + with TvglDragCopyObject(FDragObjects[i]) do + begin + b := CopyComponent.Bounds; + CopyComponent.MoveTo(CurPoint.X - (DragOrigin.X - CopyComponent.Bounds.Left),CurPoint.Y - (DragOrigin.Y - CopyComponent.Bounds.Top)); + a := CopyComponent.TotalAlpha; + CopyComponent.TotalAlpha:= 0.5; + CopyComponent.Draw; + CopyComponent.TotalAlpha := a; + CopyComponent.Bounds := b; + end; end; Index: vglStdCtrls.pas =================================================================== RCS file: /cvsroot/pythianproject/Prototypes/GUISystem/vglStdCtrls.pas,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** vglStdCtrls.pas 2001/01/01 19:26:11 1.8 --- vglStdCtrls.pas 2001/01/02 21:46:20 1.9 *************** *** 527,539 **** if Kind = sbHorizontal then begin ! FCanvas.DrawBitmapSubRect(tempr.Left,tempr.Top,VGL_SKINRECT_SCROLLBUTTON_RIGHT,FImage); ! FCanvas.SetClipping(FOwner.ChildClipRect); ! //FCanvas.Rectangle(tempr.Left, tempr.Top, tempr.Right, tempr.Bottom); tempr := GetMaxBtnRect(where); ! FCanvas.DrawBitmapSubRect(tempr.Left,tempr.Top,VGL_SKINRECT_SCROLLBUTTON_LEFT,FImage); ! FCanvas.SetClipping(FOwner.ChildClipRect); ! //FCanvas.Rectangle(tempr.Left, tempr.Top, tempr.Right, tempr.Bottom); end else if Kind = sbVertical then begin FCanvas.DrawBitmapSubRect(tempr.Left,tempr.Top,VGL_SKINRECT_SCROLLBUTTON_UP,FImage); FCanvas.SetClipping(FOwner.ChildClipRect); --- 527,539 ---- if Kind = sbHorizontal then begin ! Canvas.ImageAlpha := TotalAlpha; ! Canvas.DrawBitmapSubRect(tempr.Left,tempr.Top,VGL_SKINRECT_SCROLLBUTTON_RIGHT,FImage); ! Canvas.SetClipping(FOwner.ChildClipRect); tempr := GetMaxBtnRect(where); ! Canvas.DrawBitmapSubRect(tempr.Left,tempr.Top,VGL_SKINRECT_SCROLLBUTTON_LEFT,FImage); ! Canvas.SetClipping(FOwner.ChildClipRect); end else if Kind = sbVertical then begin + Canvas.ImageAlpha := TotalAlpha; FCanvas.DrawBitmapSubRect(tempr.Left,tempr.Top,VGL_SKINRECT_SCROLLBUTTON_UP,FImage); FCanvas.SetClipping(FOwner.ChildClipRect); *************** *** 550,554 **** FCanvas.Solid := True; FCanvas.CurrentColor := FColor; ! FCanvas.FillAlpha := FPageAlpha; tempr := GetBodyRect(where); FCanvas.Rectangle(tempr.Left, tempr.Top, tempr.Right, tempr.Bottom); --- 550,554 ---- FCanvas.Solid := True; FCanvas.CurrentColor := FColor; ! FCanvas.FillAlpha := FPageAlpha - (1-TotalAlpha); tempr := GetBodyRect(where); FCanvas.Rectangle(tempr.Left, tempr.Top, tempr.Right, tempr.Bottom); *************** *** 559,566 **** FCanvas.Solid := True; FCanvas.CurrentColor := clNavy; ! FCanvas.FillAlpha := 0.5; tempr := GetPageRect(where); FCanvas.Rectangle(tempr.Left, tempr.Top, tempr.Right, tempr.Bottom); ! FCanvas.Solid := False; FCanvas.FillAlpha := 1.0; FCanvas.Rectangle(tempr.Left, tempr.Top+1, tempr.Right-1, tempr.Bottom); if FHighLightPaging and FMouseOver then --- 559,566 ---- FCanvas.Solid := True; FCanvas.CurrentColor := clNavy; ! FCanvas.FillAlpha := TotalAlpha - 0.5; tempr := GetPageRect(where); FCanvas.Rectangle(tempr.Left, tempr.Top, tempr.Right, tempr.Bottom); ! FCanvas.Solid := False; FCanvas.FillAlpha := TotalAlpha; FCanvas.Rectangle(tempr.Left, tempr.Top+1, tempr.Right-1, tempr.Bottom); if FHighLightPaging and FMouseOver then *************** *** 577,581 **** end; FCanvas.CurrentColor := clBlack; ! FCanvas.FillAlpha := 1; FCanvas.Rectangle(HP.Left, HP.Top, HP.Right, HP.Bottom); end; --- 577,581 ---- end; FCanvas.CurrentColor := clBlack; ! FCanvas.FillAlpha := TotalAlpha; FCanvas.Rectangle(HP.Left, HP.Top, HP.Right, HP.Bottom); end; *************** *** 902,906 **** begin FCanvas.CurrentColor := FColor; ! FCanvas.FillAlpha := 1 - Translucency; FCanvas.Solid := True; FCanvas.Rectangle(where.Left, where.Top, where.Right, where.Bottom); --- 902,906 ---- begin FCanvas.CurrentColor := FColor; ! FCanvas.FillAlpha := TotalAlpha - Translucency; FCanvas.Solid := True; FCanvas.Rectangle(where.Left, where.Top, where.Right, where.Bottom); *************** *** 909,912 **** --- 909,913 ---- // border code here // background + FCanvas.Imagealpha := TotalAlpha; FCanvas.TileBitmapSubRect(where,VGL_SKINRECT_BACKGROUND,FImage); Manager.DrawBorder(where,FImage); *************** *** 928,932 **** begin FCanvas.CurrentColor := FSelBgColor; ! FCanvas.FillAlpha := 1 - FSelBgTranslulency; FCanvas.Solid := True; FCanvas.Rectangle(DC.Left, DC.Top, DC.Right, DC.Bottom); --- 929,933 ---- begin FCanvas.CurrentColor := FSelBgColor; ! FCanvas.FillAlpha := TotalAlpha - FSelBgTranslulency; FCanvas.Solid := True; FCanvas.Rectangle(DC.Left, DC.Top, DC.Right, DC.Bottom); *************** *** 983,986 **** --- 984,988 ---- begin inherited; + FScrollBar.TotalAlpha := TotalAlpha; DrawClient(where); DrawItems(where); *************** *** 1364,1367 **** --- 1366,1370 ---- SkinRect := GetCheckMarkSkinRect; MarkRect := GetCheckMarkBounds(where); + Canvas.Imagealpha := TotalALpha; Canvas.DrawBitmapSubRect(MarkRect.Left, MarkRect.Top, SkinRect, FImage); if FCaptionText.Text <> '' then *************** *** 1493,1496 **** --- 1496,1500 ---- begin inherited DrawSelf(where); + Canvas.ImageAlpha := TotalAlpha; case FButtonState of vglbsUp: FImage.Intensity := 255; |