]> O.S.I.I.S - jp/crow.git/commitdiff
checkbox focusable handling, png image detection from magic
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 18 Mar 2025 03:48:24 +0000 (04:48 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 18 Mar 2025 03:48:24 +0000 (04:48 +0100)
Crow/src/Interface.cs
Crow/src/Widgets/CheckBox.cs
Crow/src/Widgets/Image.cs
Crow/src/Widgets/SaturationValueSelector.cs
Samples/common/ui/Interfaces/Experimental/SaturationValueSelector.crow [new file with mode: 0644]
Samples/common/ui/Interfaces/TemplatedControl/testCheckbox.crow

index a10ef1db3ed511dc2e33eaa8fbabf25496ccbd35..0b4491f5b038ead8b6b697e5bd356d0b0b6ca5ee 100644 (file)
@@ -531,7 +531,7 @@ namespace Crow
                                windows [window].OnKeyDown (new KeyEventArgs (key, scanCode, modifiers));
                };
                static CharDelegate HandleCharDelegate = (IntPtr window, CodePoint codepoint) => {
-                       Console.WriteLine ($"Char: cp:{codepoint.Value} -> '{codepoint}'");
+                       //Console.WriteLine ($"Char: cp:{codepoint.Value} -> '{codepoint}'");
                        windows [window].OnKeyPress (codepoint.ToChar());
                };
                static WindowSizeDelegate HandleWindowSizeDelegate = (IntPtr window, int Width, int Height) => {
@@ -1112,13 +1112,13 @@ namespace Crow
                /// </summary>
                public void Update(IContext ctx = null){
 
-                       CrowThread[] tmpThreads;
+                       /*CrowThread[] tmpThreads;
                        lock (CrowThreads) {
                                tmpThreads = new CrowThread[CrowThreads.Count];
                                Array.Copy (CrowThreads.ToArray (), tmpThreads, CrowThreads.Count);
                        }
                        for (int i = 0; i < tmpThreads.Length; i++)
-                               tmpThreads [i].CheckState ();
+                               tmpThreads [i].CheckState ();*/
 
                        if (lastMouseDownEvent != null) {
                                if (mouseRepeatTimer.ElapsedMilliseconds > DEVICE_REPEAT_INTERVAL) {
@@ -1935,7 +1935,7 @@ namespace Crow
                }
                void resetTooltip ()
                {
-                       lock (tooltipMutex) {
+                       lock (tooltipMutex) {//TODO:deadlock
                                if (tooltipVisible) {
                                        ToolTipContainer.LayoutChanged -= ToolTipContainer_LayoutChanged;
                                        ToolTipContainer.DataSource = null;
index a51ff18c1868a38c469c9bf01cfc1a260c2cb198..82db73272798407264f0faa10157eecf8cac2759 100644 (file)
@@ -45,8 +45,10 @@ namespace Crow
 
                public override void onMouseClick (object sender, MouseButtonEventArgs e)
                {
-                       IsChecked = !IsChecked;
-                       e.Handled = true;
+                       if (Focusable) {
+                               IsChecked = !IsChecked;
+                               e.Handled = true;
+                       }
                        base.onMouseClick (sender, e);
                }
        }
index b1a3a94fc2004c10e02e72fbeadd270ac750cd83..a6f559379fa5583b11e6a9061773f40c21fbbbc6 100644 (file)
@@ -25,6 +25,7 @@ namespace Crow
        /// </remarks>
        public class Image : Scalable
        {
+               static readonly byte[] pngMagic = new byte[] {0x89, 0x50 ,0x4e ,0x47 ,0x0d ,0x0a};
                Picture _pic;
                string _svgSub;
 
@@ -139,9 +140,7 @@ namespace Crow
                /// Initializes a new instance of the <see cref="Crow.Image"/> class from code
                /// </summary>
                /// <param name="iface">interface to bound to</param>
-               public Image (Interface iface) : base(iface)
-               {
-               }
+               public Image (Interface iface, string style = null) : base(iface, style) { }
                #endregion
 
                #region Image Loading
@@ -154,8 +153,27 @@ namespace Crow
                        if (getcontenttype.Wait(HTTP_DOWNLOAD_TIMEOUT_MS) && getcontenttype.IsCompletedSuccessfully) {
                                if (!getcontenttype.Result.Content.Headers.TryGetValues("content-Type", out IEnumerable<string> contents))
                                        return;
-                               string[] type = contents.FirstOrDefault().Split('/');                           
-                               if (!string.Equals(type[0], "image", StringComparison.Ordinal))
+                               string[] type = contents.FirstOrDefault().Split('/');
+                               if (string.Equals(contents.FirstOrDefault(), "application/octet-stream")) {
+                                       if (task.Wait(HTTP_DOWNLOAD_TIMEOUT_MS) && task.IsCompletedSuccessfully) {
+                                               MemoryStream dataCopy = new MemoryStream();
+                                               task.Result.CopyTo(dataCopy);
+                                               dataCopy.Position = 0;
+                                               Span<byte> magic = stackalloc byte[6];
+                                               dataCopy.Read(magic);
+                                               if (magic.SequenceEqual(pngMagic)) {
+                                                       dataCopy.Position = 0;
+                                                       pic = new BmpPicture(uri.AbsoluteUri);
+                                               } else
+                                                       return;
+                                               pic.LoadFromStream(IFace, dataCopy);
+                                               pic.Scaled = scaled;
+                                               pic.KeepProportions = keepProps;
+                                               lock(IFace.UpdateMutex)
+                                                       Picture = pic;
+                                       }
+                                       return;
+                               } else  if (!string.Equals(type[0], "image", StringComparison.Ordinal))
                                        return;
                                if (string.Equals(type[1], "svg", StringComparison.Ordinal))
                                        pic = new SvgPicture(uri.AbsoluteUri);
@@ -176,6 +194,8 @@ namespace Crow
                                        lock(IFace.UpdateMutex)
                                                Picture = pic;
                                }
+                       } else {
+                               Debug.WriteLine("image downloadThread: get content failed");
                        }
 
                }
index 69ff67b9e62a7a64f351751a00f18a57601fd7d1..8cd54d186ae4f877952f82b9236e32411b64c6e7 100644 (file)
@@ -49,6 +49,8 @@ namespace Crow
 
                        Rectangle r = ClientRectangle;
 
+                       gr.Operator = Operator.Over;
+
                        if (Foreground != null) {//TODO:test if null should be removed
                                Foreground.SetAsSource (IFace, gr, r);
                                CairoHelpers.CairoRectangle (gr, r, CornerRadius);
diff --git a/Samples/common/ui/Interfaces/Experimental/SaturationValueSelector.crow b/Samples/common/ui/Interfaces/Experimental/SaturationValueSelector.crow
new file mode 100644 (file)
index 0000000..24b626c
--- /dev/null
@@ -0,0 +1,15 @@
+<ColorPicker Height="Fit" Width="Fit">
+       <Template>
+               <VerticalStack >
+                       <HorizontalStack Height="Fit" Margin="0">
+                               <Label2 Text="{../svs.V}" Foreground="White"/>
+                               <Label2 Text="{../svs.S}" Foreground="White"/>
+                       </HorizontalStack>
+                       <HorizontalStack Height="200" Margin="0">
+                               <SaturationValueSelector Name="svs" V="10"  S="0"  Width="200" Height="200" Margin="0"
+Foreground="RebeccaPurple" Background="Transparent"/>
+                               <HueSelector Orientation="Vertical" Width="20" Margin="0"/> 
+                       </HorizontalStack>
+               </VerticalStack>
+       </Template>
+</ColorPicker>
\ No newline at end of file
index 6e627506124ae737b835ccf2c659f2d8dc648c12..9582994ff0f57f6c9dad1990cb767fb61c996059 100644 (file)
@@ -19,7 +19,7 @@
                        </HorizontalStack>
                </Template>
        </CheckBox>
-       <CheckBox Background="Jet" Height="30" Width="60"       
+       <CheckBox Background="Jet" Height="30" Width="60" IsChecked="{²BoolVal}"
                                                Checked="{sh.HorizontalAlignment=Right};{Background=SeaGreen}"
                                                Unchecked="{sh.HorizontalAlignment=Left};{Background=Jet}">
                <Template>
                        </Group>
                </Template>
        </CheckBox>
-       
+       <CheckBox Caption="Ok" Background="Transparent" Height="30" Width="30" IsChecked="{²BoolVal}" CornerRadius="10"
+                                               Checked="{Background=SeaGreen}"
+                                               Unchecked="{Background=Red}">
+               <Template>
+                       <Label2 Background="{./Background}" Text="{./Caption}" Margin="5" CornerRadius="{./CornerRadius}"/>
+               </Template>
+       </CheckBox>     
 </VerticalStack>