WIMP: A Window Manager Program
Time limit1sMemory limit128 MB
Simulate a window manager over a 1024x1024 screen, tracking overlapping windows and handling click, drag, zoom, close, create, and redraw events.
- Level
Medium6 of 10
- Topics
- Simulation, Implementation, Geometry, Sorting
- Solved
- No attempts yet
Problem
A window manager takes care of creating, displaying, moving, and resizing a collection of windows in a graphical user interface. It also handles the input events (such as mouse clicks) related to those window-management tasks. In this problem you implement a simple WIndow Manager Program (WIMP).
The WIMP controls a screen of size 1024 × 1024 pixels, with the upper-left pixel at (0, 0). The x-coordinates run from 0 at the left edge to 1023 at the right edge, and the y-coordinates run from 0 at the top to 1023 at the bottom. All coordinates are integers. The user creates and manipulates rectangular windows by moving the mouse and clicking its button. A window is divided into 4 non-overlapping areas:
A window is always at least 51 × 26 so that all four areas are nonempty. Each window is given a unique integer identifier starting at 0 (the first window created has id 0, the second has id 1, and so on). Identifiers are never reused.
The WIMP accepts the following events:
The values x, y, l, t, r, and b are all nonnegative integers within the screen dimensions. A CR event always produces a properly formed window. Because windows can overlap, on a RE event they must be redrawn from back (least recently brought to the front) to front (most recently brought to the front) so that they appear correctly overlapped.
The WIMP must keep track of all windows even when some overlap. Its rules are:
- A newly created window is always completely visible (on top of all other windows).
- A DN event anywhere on the visible part of a window selects that window and puts it on top, making the entire window visible. A DN event that is not on the visible part of any window does not affect the currently selected window.
- Closing and zooming each require a DN event followed by an UP event in the appropriate box. There may be one or more AT events in between. The DN and UP must be in the same box, but not necessarily at the exact same location.
- Closing a window removes it from the screen.
- Zooming is a toggle: it either makes the window occupy the entire screen or returns it to its original size.
- A DN event in the motion bar lets the window be moved. The move ends with an UP event. The window moves the same distance and direction that the mouse moved between the DN and the UP.
- AT events while moving a window must output the window's current position. AT events at any other time output nothing.
- A window that occupies the full screen cannot be moved.
- A window may move partially off the visible screen.
- AT events may happen at any time.
Input
The input consists of one or more lines, each containing a single event. A ZZ event marks the end of the input. All events belong to the same session.
Output
For each user action, output the corresponding message. On a RE event, output the position of every window from back to front using the format shown below.