Procházet zdrojové kódy

* Remove some debug logs, click outside fresnel window removes focus, so keyboard can be used

Michaël Van Canneyt před 1 rokem
rodič
revize
168824bca8
1 změnil soubory, kde provedl 20 přidání a 3 odebrání
  1. 20 3
      src/pas2js/fresnel.pas2js.wasmapi.pp

+ 20 - 3
src/pas2js/fresnel.pas2js.wasmapi.pp

@@ -122,6 +122,7 @@ Type
     FTimerInterval: NativeInt;
     FLastTick: TDateTime;
     FKeyMap : TJSObject;
+    procedure DoGlobalClick(aEvent: TJSEvent);
     procedure DrawBaseLine(C: TJSCanvasRenderingContext2D; S: String; X, Y: Single);
     procedure SetCreateDefaultCanvas(AValue: Boolean);
     procedure SetFocusedCanvas(AValue: TCanvasReference);
@@ -366,7 +367,6 @@ procedure TCanvasReference.SetFillStyle(AValue: JSValue);
 begin
   if FFillStyle=AValue then Exit;
   FFillStyle:=AValue;
-  Writeln('---> Canvas: fill style ',FFillStyle);
   canvascontext.fillStyle:=FFillStyle;
 end;
 
@@ -587,6 +587,7 @@ begin
   Result:=True;
   TJSArray(API.FEvents).Push(MouseToEvent(evt,WASMSG_CLICK));
   SendEvent;
+  aEvent.cancelBubble:=True;
 end;
 
 function TCanvasReference.DoMouseDblClick(aEvent: TJSEvent): boolean;
@@ -623,11 +624,28 @@ begin
   InstallGLobalHandlers;
 end;
 
+procedure TWasmFresnelApi.DoGlobalClick(aEvent : TJSEvent);
+
+var
+  EL : TJSElement;
+
+begin
+  El:=aEvent.targetElement;
+  While Assigned(El) do
+    begin
+    if El.ClassList.contains('fresnel-window') then
+      exit;
+    El:=El.parentElement;
+    end;
+  FocusedCanvas:=Nil;
+end;
+
 procedure TWasmFresnelApi.InstallGlobalHandlers;
 begin
   // Attach to summary
   Document.Body.AddEventListener('keydown',@DoKeyDownEvent);
   Document.Body.AddEventListener('keyup',@DoKeyUpEvent);
+  Document.Body.AddEventListener('click',@DoGlobalClick);
 end;
 
 function TWasmFresnelApi.ImportName: String;
@@ -771,7 +789,7 @@ begin
   if lMap=Nil then
     lmap:=GetGlobalKeyMap;
   Result:=KeyNameToKeyCode(lMap,aKey);
-  Writeln('Mapped ',aKey,' to ',TJSJSON.StringIfy(Result));
+//  Writeln('Mapped ',aKey,' to ',TJSJSON.StringIfy(Result));
 end;
 
 class function TWasmFresnelApi.KeyNameToKeyCode(aMap : TJSObject; aKey: string): TKeyKind;
@@ -2025,7 +2043,6 @@ begin
   C:=GetCanvas(aID);
   if Assigned(C) then
     begin
-    Console.Log('Drawing rect, current fill style: ',C.fillStyle);
     C.FillRect(X,y,width,Height);
     Result:=ECANVAS_SUCCESS;
     end;