Recent

Author Topic: Analogue scissors windows  (Read 4913 times)

BIT

  • Full Member
  • ***
  • Posts: 158
Analogue scissors windows
« on: November 20, 2021, 11:17:11 am »
Hello!
I am trying to make an analog of windows scissors (Screenshot of part of the screen).
When drawing, Canvas.Rectangle is not transparent.
Because the form Form2.AlphaBlend: = 130;
The question is how to make Canvas.Brush transparent and the shape underneath?

Code: Pascal  [Select][+][-]
  1. var
  2.   Form2: TForm2;
  3.   AnchorX, AnchorY, CurX, CurY: integer;
  4.   Bounding: boolean;
  5.  
  6. implementation
  7.  
  8. uses Unit1;
  9.  
  10. {$R *.lfm}
  11.  
  12. { TForm2 }
  13.  
  14.  
  15.  
  16. procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton;
  17.   Shift: TShiftState; X, Y: integer);
  18. begin
  19.   Form1.Visible := False;
  20.  
  21.   AnchorX := X;
  22.   CurX := X;
  23.   AnchorY := Y;
  24.   CurY := Y;
  25.   Bounding := True;
  26.  
  27.   Form2.Canvas.Pen.Width := 2;
  28.   Form2.Canvas.Pen.Style := psSolid;
  29.   Form2.Canvas.Pen.Mode := pmNotXor;
  30.   Form2.Canvas.Pen.Color := clRed;
  31.  
  32.   Form2.Canvas.Brush.Style := bsSolid;
  33.   Form2.Canvas.Brush.Color := clBlack;
  34.  
  35.  
  36. end;
  37.  
  38. procedure TForm2.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: integer);
  39. begin
  40.   if Bounding then
  41.   begin
  42.     Form2.Canvas.Rectangle(AnchorX, AnchorY, CurX, CurY);
  43.     CurX := X;
  44.     CurY := Y;
  45.     Form2.Canvas.Rectangle(AnchorX, AnchorY, CurX, CurY);
  46.   end;
  47. end;
  48.  
  49. procedure TForm2.FormMouseUp(Sender: TObject; Button: TMouseButton;
  50.   Shift: TShiftState; X, Y: integer);
  51. begin
  52.  
  53.   if Bounding then
  54.   begin
  55.     Bounding := False;
  56.     Form2.Canvas.Pen.Mode := pmNot;
  57.     Form2.Canvas.Brush.Style := bsClear;
  58.     Form2.Canvas.Rectangle(AnchorX, AnchorY, CurX, CurY);
  59.     Form2.Repaint;
  60.     Form2.Visible := False;
  61.     Form1.ScreenM(AnchorX, AnchorY, CurX, CurY);
  62.   end;
  63.  
  64.   Form1.Visible := True;
  65.   Form1.Width := 600;
  66.   Form1.Height := 400;
  67. end;                                            
  68.  

korba812

  • Sr. Member
  • ****
  • Posts: 392
Re: Analogue scissors windows
« Reply #1 on: November 20, 2021, 12:42:01 pm »
Maybe take a screenshot before your semi-transparent form shows up and draw this part from the screenshot you took.

balazsszekely

  • Guest
Re: Analogue scissors windows
« Reply #2 on: November 20, 2021, 12:57:28 pm »
Hi BIT,

It's not exactly what you need, but it's very similar. The attached project contains a transparent resizable window. With a few small modifications, I believe you can achieve what are you after.
« Last Edit: November 20, 2021, 01:15:28 pm by GetMem »

balazsszekely

  • Guest
Re: Analogue scissors windows
« Reply #3 on: November 20, 2021, 01:14:55 pm »
The attached project is exactly what you need. I made it for another forum user a few years ago. Unfortunately I never had time to complete it, so it's far from perfect. IIRC it worked on Linux Mint too(not sure though).

PS: You need to install BGRABitmap.
« Last Edit: November 20, 2021, 01:30:39 pm by GetMem »

BIT

  • Full Member
  • ***
  • Posts: 158
Re: Analogue scissors windows
« Reply #4 on: November 20, 2021, 02:54:19 pm »
The attached project is exactly what you need. I made it for another forum user a few years ago. Unfortunately I never had time to complete it, so it's far from perfect. IIRC it worked on Linux Mint too(not sure though).

PS: You need to install BGRABitmap.
Your source works great!
But I would like to do as I intended)

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Analogue scissors windows
« Reply #5 on: November 20, 2021, 03:00:55 pm »
I don't seem to be able to detect the widget you are targeting because the transparent form seems to work here on a windows PC ?

 Are you on a different target and can not get the transparency of windows ?
The only true wisdom is knowing you know nothing

BIT

  • Full Member
  • ***
  • Posts: 158
Re: Analogue scissors windows
« Reply #6 on: November 20, 2021, 03:05:17 pm »
I don't seem to be able to detect the widget you are targeting because the transparent form seems to work here on a windows PC ?

 Are you on a different target and can not get the transparency of windows ?
Simply put, I want to make a hole in the form using Canvas.Brush.
I am using Windows 7.

BIT

  • Full Member
  • ***
  • Posts: 158
Re: Analogue scissors windows
« Reply #7 on: November 20, 2021, 03:09:38 pm »
I don't seem to be able to detect the widget you are targeting because the transparent form seems to work here on a windows PC ?

 Are you on a different target and can not get the transparency of windows ?
I want to do this.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Analogue scissors windows
« Reply #8 on: November 20, 2021, 03:19:10 pm »
Ah, ok.

 You need an exclusion rectangle in the canvas.

 With this, it will not draw where this rectangle region is or at least this is the theory.

 the canvas has a clip rectangle property and a region that can be used for things like this.

You must apply it to the canvas of the form.. Not sure how this is going to work out but I can experiment a bit over here to see.


EDIT
 Actually this reminds me of the project I have now where I made  Gripper using a TGraphicControl..
 
 It has the surface of the parent window and thus you receive the paint message where you can paint over just the surface where you would like.


Example of C code..

https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-use-clipping-with-a-region?view=netframeworkdesktop-4.8


« Last Edit: November 20, 2021, 03:25:42 pm by jamie »
The only true wisdom is knowing you know nothing

BIT

  • Full Member
  • ***
  • Posts: 158
Re: Analogue scissors windows
« Reply #9 on: November 20, 2021, 03:25:52 pm »
Ah, ok.

 You need an exclusion rectangle in the canvas.

 With this, it will not draw where this rectangle region is or at least this is the theory.

 the canvas has a clip rectangle property and a region that can be used for things like this.

You must apply it to the canvas of the form.. Not sure how this is going to work out but I can experiment a bit over here to see.


EDIT
 Actually this reminds me of the project I have now where I made  Gripper using a TGraphicControl..
 
 It has the surface of the parent window and thus you receive the paint message where you can paint over just the surface where you would like.


Example of C code..

https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-use-clipping-with-a-region?view=netframeworkdesktop-4.8
Here's a rough draft of the source.
If you take the time to look, it will be easier to understand what I want)
https://drive.google.com/file/d/1N6M5HrKWOMl71uK2aw-r5lnrm7CNerW4/view?usp=sharing

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Analogue scissors windows
« Reply #10 on: November 20, 2021, 03:37:52 pm »
Please use the published feature of lazarus which is in the project menu and drop the ZIp file here.

that will force us to recompile it locally and not include your EXE file.
The only true wisdom is knowing you know nothing

BIT

  • Full Member
  • ***
  • Posts: 158
Re: Analogue scissors windows
« Reply #11 on: November 20, 2021, 04:03:49 pm »
Please use the published feature of lazarus which is in the project menu and drop the ZIp file here.

that will force us to recompile it locally and not include your EXE file.
Found this menu item and attached the file))

balazsszekely

  • Guest
Re: Analogue scissors windows
« Reply #12 on: November 20, 2021, 05:09:53 pm »
@BIT
Quote
Your source works great!
But I would like to do as I intended)

OK. I redid the project the way you want. A few notes:
1. TBitmap is too slow for this, you will see a lot of flickers, so I switched to TBGRABitmap
2. The project supports multiple monitors
3. For now it's windows only
4. First build the project, then run outside the IDE, because savedialog is painfully slow with debugger
5. If you improve the project please give us some feedback. Thanks.


balazsszekely

  • Guest
Re: Analogue scissors windows
« Reply #13 on: November 20, 2021, 06:59:54 pm »
I made a few improvement + now the project is cross platform. Tested on Win10, Linux Mint 20.02. It works on macOS too, but instead of the form, you have to draw the bitmap to a TImage. If needed I can make the necessary adjustments for macOS.
« Last Edit: November 20, 2021, 08:02:14 pm by GetMem »

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Analogue scissors windows
« Reply #14 on: November 20, 2021, 07:38:38 pm »
I was under the impression that he wanted a ROUND clipping view port ?
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018