1
2(********************************************************************)
3(*                                                                  *)
4(*  mirror.sd7    Mirror a rectangular screen area in a window.     *)
5(*  Copyright (C) 2021  Thomas Mertes                               *)
6(*                                                                  *)
7(*  This program is free software; you can redistribute it and/or   *)
8(*  modify it under the terms of the GNU General Public License as  *)
9(*  published by the Free Software Foundation; either version 2 of  *)
10(*  the License, or (at your option) any later version.             *)
11(*                                                                  *)
12(*  This program is distributed in the hope that it will be useful, *)
13(*  but WITHOUT ANY WARRANTY; without even the implied warranty of  *)
14(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *)
15(*  GNU General Public License for more details.                    *)
16(*                                                                  *)
17(*  You should have received a copy of the GNU General Public       *)
18(*  License along with this program; if not, write to the           *)
19(*  Free Software Foundation, Inc., 51 Franklin Street,             *)
20(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
21(*                                                                  *)
22(********************************************************************)
23
24
25$ include "seed7_05.s7i";
26  include "draw.s7i";
27  include "dialog.s7i";
28  include "time.s7i";
29  include "duration.s7i";
30
31
32const type: rectangularArea is new struct
33    var integer: topLeftX is 0;
34    var integer: topLeftY is 0;
35    var integer: bottomRightX is 0;
36    var integer: bottomRightY is 0;
37  end struct;
38
39
40const func rectangularArea: selectArea is func
41  result
42    var rectangularArea: area is rectangularArea.value;
43  local
44    var PRIMITIVE_WINDOW: screenPixmap is PRIMITIVE_WINDOW.value;
45    var PRIMITIVE_WINDOW: wholeScreen is PRIMITIVE_WINDOW.value;
46    var integer: oldBottomRightX is 0;
47    var integer: oldBottomRightY is 0;
48  begin
49    screenPixmap := capturePixmap(0, 0, screenWidth, screenHeight);
50    wholeScreen := openSubWindow(PRIMITIVE_WINDOW.value, 0, 0, screenWidth, screenHeight);
51    put(wholeScreen, 0, 0, screenPixmap);
52    if getc(KEYBOARD) = KEY_MOUSE1 then
53      area.topLeftX := pointerXPos(PRIMITIVE_WINDOW.value);
54      area.topLeftY := pointerYPos(PRIMITIVE_WINDOW.value);
55      point(wholeScreen, area.topLeftX, area.topLeftY, light_red);
56      oldBottomRightX := area.topLeftX;
57      oldBottomRightY := area.topLeftY;
58      repeat
59        area.bottomRightX := pointerXPos(PRIMITIVE_WINDOW.value);
60        area.bottomRightY := pointerYPos(PRIMITIVE_WINDOW.value);
61        if area.bottomRightX <> oldBottomRightX or area.bottomRightY <> oldBottomRightY then
62          if area.bottomRightX < area.topLeftX then
63            area.bottomRightX := area.topLeftX;
64          end if;
65          if area.bottomRightY < area.topLeftY then
66            area.bottomRightY := area.topLeftY;
67          end if;
68          copyArea(screenPixmap, wholeScreen, area.topLeftX, area.topLeftY,
69                   oldBottomRightX - area.topLeftX + 1, 1,
70                   area.topLeftX, area.topLeftY);
71          copyArea(screenPixmap, wholeScreen, area.topLeftX, area.topLeftY,
72                   1, oldBottomRightY - area.topLeftY + 1,
73                   area.topLeftX, area.topLeftY);
74          copyArea(screenPixmap, wholeScreen, area.topLeftX, oldBottomRightY,
75                   oldBottomRightX - area.topLeftX + 1, 1,
76                   area.topLeftX, oldBottomRightY);
77          copyArea(screenPixmap, wholeScreen, oldBottomRightX, area.topLeftY,
78                   1, oldBottomRightY - area.topLeftY + 1,
79                   oldBottomRightX, area.topLeftY);
80          lineTo(wholeScreen, area.topLeftX, area.topLeftY,
81                 area.topLeftX, area.bottomRightY, light_red);
82          lineTo(wholeScreen, area.topLeftX, area.topLeftY,
83                 area.bottomRightX, area.topLeftY, light_red);
84          lineTo(wholeScreen, area.topLeftX, area.bottomRightY,
85                 area.bottomRightX, area.bottomRightY, light_red);
86          lineTo(wholeScreen, area.bottomRightX, area.topLeftY,
87                 area.bottomRightX, area.bottomRightY, light_red);
88          oldBottomRightX := area.bottomRightX;
89          oldBottomRightY := area.bottomRightY;
90        end if;
91        wait(30000 . MICRO_SECONDS);
92      until not buttonPressed(KEYBOARD, KEY_MOUSE1);
93    end if;
94  end func;
95
96
97const proc: main is func
98  local
99    const integer: width is 1000;
100    const integer: height is 500;
101    var rectangularArea: area is rectangularArea.value;
102    var PRIMITIVE_WINDOW: pixmap is PRIMITIVE_WINDOW.value;
103  begin
104    KEYBOARD := GRAPH_KEYBOARD;
105    if isOkay("This program shows the content of a rectangular screen area in a mirror window.\n\
106              \To select the area move the mouse to the top left position of the area, press\n\
107              \the left mouse button and keep it pressed. Then move the mouse to the bottom\n\
108              \right position of the area. The area is shown in red. If you are satisfied with\n\
109              \with your selection release the left mouse button. After that the mirror window\n\
110              \will show up. The mirror window is updated every 30 milliseconds. To exit the\n\
111              \program just click on the mirror window. Are you ready to select the area?") then
112      flushGraphic;
113      # Wait until the message window has vanished.
114      wait(300000 . MICRO_SECONDS);
115      area := selectArea;
116      flushGraphic;
117      if area.topLeftX <> 0 or area.topLeftY <> 0 or area.bottomRightX <> 0 or area.bottomRightY <> 0 then
118        curr_win := PRIMITIVE_GRAPHIC_OPEN(250, 200,
119            area.bottomRightX - area.topLeftX + 1,
120            area.bottomRightY - area.topLeftY + 1, "mirror");
121        repeat
122          pixmap := capturePixmap(area.topLeftX, area.topLeftY,
123              area.bottomRightX - area.topLeftX + 1,
124              area.bottomRightY - area.topLeftY + 1);
125          put(curr_win, 0, 0, pixmap);
126          wait(30000 . MICRO_SECONDS);
127        until keypressed(KEYBOARD);
128      end if;
129    end if;
130  end func;
131