Changeset 8 for trunk/Platform/Base
- Timestamp:
- May 9, 2015, 1:32:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Platform/Base/UPlatformBase.pas
r7 r8 7 7 uses 8 8 Classes, SysUtils, UFileSystem, UKernel, syncobjs, UThreadEx, UMemory, 9 DateUtils ;9 DateUtils, UDevice, Contnrs, Graphics, Forms, UScreen; 10 10 11 11 type … … 42 42 end; 43 43 44 TReceiveEvent = procedure( Data: TMemory) of object;44 TReceiveEvent = procedure(Text: string) of object; 45 45 46 46 { TBaseSerialDevice } 47 47 48 TBaseSerialDevice = class(TDevice )48 TBaseSerialDevice = class(TDeviceSerial) 49 49 private 50 50 Lock: TCriticalSection; … … 53 53 constructor Create; override; 54 54 destructor Destroy; override; 55 procedure Service(Index: Integer; DataIn, DataOut: TMemory); override;55 procedure WriteText(Text: string); override; 56 56 property OnReceiveData: TReceiveEvent read FOnReceiveData write FOnReceiveData; 57 57 end; 58 58 59 { T BaseVideoDevice }60 61 T BaseVideoDevice = class(TDevice)59 { TDeviceVideoBase } 60 61 TDeviceVideoBase = class(TDeviceVideo) 62 62 private 63 FOnModeChanged: TNotifyEvent; 63 64 FOnRedraw: TNotifyEvent; 65 OnModeChanged: TNotifyEvent; 66 procedure DoRedraw; 64 67 public 65 68 VideoMemory: PByte; 66 69 VideoMemorySize: TPoint; 67 70 DPI: Integer; 68 constructor Create; override; 69 destructor Destroy; override; 70 procedure Service(Index: Integer; DataIn, DataOut: TMemory); override; 71 Canvas: TCanvas; 72 VideoMode: TVideoMode; 73 procedure SetMode(Mode: TVideoMode); override; 74 procedure GetSupportedModes(Modes: TObjectList); override; 75 function GetVideoMemory: PByte; override; 76 procedure VideoMemoryChange; override; 77 constructor Create; override; 78 destructor Destroy; override; 71 79 property OnRedraw: TNotifyEvent read FOnRedraw write FOnRedraw; 80 property OnModeChanged: TNotifyEvent read FOnModeChanged write FOnModeChanged; 72 81 end; 73 82 74 83 implementation 75 84 76 { TBaseVideoDevice } 77 78 constructor TBaseVideoDevice.Create; 85 { TDeviceVideoBase } 86 87 procedure TDeviceVideoBase.DoRedraw; 88 begin 89 90 end; 91 92 procedure TDeviceVideoBase.SetMode(Mode: TVideoMode); 93 begin 94 if (VideoMode.Size.X <> Mode.Size.X) or 95 (VideoMode.Size.Y <> Mode.Size.Y) or 96 (VideoMode.ColorFormat <> Mode.ColorFormat) then begin 97 VideoMode.Size := Mode.Size; 98 VideoMode.ColorFormat := Mode.ColorFormat; 99 if Assigned(FOnModeChanged) then 100 FOnModeChanged(Self); 101 end; 102 end; 103 104 procedure TDeviceVideoBase.GetSupportedModes(Modes: TObjectList); 105 var 106 NewMode: TVideoMode; 107 begin 108 Modes.Clear; 109 NewMode := TVideoMode.Create; 110 NewMode.Size := Point(320, 240); 111 NewMode.ColorFormat := cfRGBA8; 112 Modes.Add(NewMode); 113 NewMode := TVideoMode.Create; 114 NewMode.Size := Point(640, 480); 115 NewMode.ColorFormat := cfRGBA8; 116 Modes.Add(NewMode); 117 { NewMode := TVideoMode.Create; 118 NewMode.Size := Point(800, 600); 119 NewMode.ColorFormat := cfRGBA8; 120 Modes.Add(NewMode); 121 NewMode := TVideoMode.Create; 122 NewMode.Size := Point(1024, 768); 123 NewMode.ColorFormat := cfRGBA8; 124 Modes.Add(NewMode); 125 NewMode := TVideoMode.Create; 126 NewMode.Size := Point(1278, 1024); 127 NewMode.ColorFormat := cfRGBA8; 128 Modes.Add(NewMode); 129 NewMode := TVideoMode.Create; 130 NewMode.Size := Point(1920, 1080); 131 NewMode.ColorFormat := cfRGBA8; 132 Modes.Add(NewMode); 133 } 134 end; 135 136 function TDeviceVideoBase.GetVideoMemory: PByte; 137 begin 138 VideoMemory := GetMem(VideoMode.GetBytesPerImage); 139 FillDWord(VideoMemory^, VideoMode.GetBytesPerImage div 4, $ffffff); 140 Result := VideoMemory; 141 end; 142 143 procedure TDeviceVideoBase.VideoMemoryChange; 144 begin 145 if Assigned(FOnRedraw) then FOnRedraw(Self); 146 end; 147 148 constructor TDeviceVideoBase.Create; 79 149 begin 80 150 inherited Create; 81 end; 82 83 destructor TBaseVideoDevice.Destroy; 84 begin 85 inherited Destroy; 86 end; 87 88 procedure TBaseVideoDevice.Service(Index: Integer; DataIn, DataOut: TMemory); 89 begin 90 if Index = 0 then begin 91 // Redraw to screen 92 if Assigned(FOnRedraw) then 93 FOnRedraw(Self); 94 end else 95 if Index = 1 then begin 96 // Get video memory 97 VideoMemory := GetMem(VideoMemorySize.X * VideoMemorySize.Y * 4); 98 // DataOut^ := VideoMemory; 99 // DataOut^ := VideoMemory; 100 end else inherited; 151 VideoMode := TVideoMode.Create; 152 end; 153 154 destructor TDeviceVideoBase.Destroy; 155 begin 156 VideoMode.Free; 157 inherited Destroy; 101 158 end; 102 159 … … 116 173 end; 117 174 118 procedure TBaseSerialDevice.Service(Index: Integer; DataIn, DataOut: TMemory); 119 begin 120 if Index = 0 then begin 121 Lock.Acquire; 122 if Assigned(FOnReceiveData) then 123 FOnReceiveData(DataIn); 124 Lock.Release; 125 end else inherited; 175 procedure TBaseSerialDevice.WriteText(Text: string); 176 begin 177 Lock.Acquire; 178 if Assigned(FOnReceiveData) then 179 FOnReceiveData(Text); 180 Lock.Release; 126 181 end; 127 182
Note:
See TracChangeset
for help on using the changeset viewer.