PowerToys/doc/devdocs/modules/screenruler.md
Gleb Khmyznikov 725535b760
Some checks failed
Spell checking / Check Spelling (push) Has been cancelled
Spell checking / Report (Push) (push) Has been cancelled
Spell checking / Report (PR) (push) Has been cancelled
Spell checking / Update PR (push) Has been cancelled
[DevDocs] More content and restructure (#40165)
## Summary of the Pull Request
Accumulated information from internal transition about the modules
development, and reworked it to be added in dev docs. Also the dev docs
intself was restructured to be more organized. New pages was
verified by transition team.

## PR Checklist
- [x] **Dev docs:** Added/updated

---------

Co-authored-by: Zhaopeng Wang (from Dev Box) <zhaopengwang@microsoft.com>
Co-authored-by: Hao Liu <liuhao3418@gmail.com>
Co-authored-by: Peiyao Zhao <105847726+zhaopy536@users.noreply.github.com>
Co-authored-by: Mengyuan <162882040+chenmy77@users.noreply.github.com>
Co-authored-by: zhaopeng wang <33367956+wang563681252@users.noreply.github.com>
Co-authored-by: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com>
2025-07-01 14:27:34 +02:00

3.8 KiB

Screen Ruler

Public overview - Microsoft Learn

All Issues
Bugs
Pull Requests

Overview

Screen Ruler (project name: MeasureTool or Measure 2) is a PowerToys module that allows users to measure pixel distances and detect color boundaries on the screen. The tool renders an overlay UI using DirectX and provides several measurement utilities.

Features

  • Bounce Utility: Measure a rectangular zone by dragging with a left click
  • Spacing Tool: Measure the length of a line with the same color with the same pixel value both horizontally and vertically
  • Horizontal Spacing: Measure the line with the same color in the horizontal direction
  • Vertical Spacing: Measure the line with the same color in the vertical direction

Architecture & Implementation

The Screen Ruler module consists of several components:

MeasureToolModuleInterface

  • Dllmain.cpp: Provides functionality to start and stop the Measure Tool process based on hotkey events, manage settings, and handle events.

MeasureToolUI

  • App.xaml.cs: Main entrance of the app. Initializes MeasureToolCore and activates a new main window.
  • MainWindow.xaml.cs: Sets properties and behaviors for the window, and handles user click interactions.
  • NativeMethods.cs: Interacts with the Windows API to manipulate window properties, such as positioning and sizing.
  • Settings.cs: Gets the default measure style from settings.

PowerToys.MeasureToolCore

  • PowerToys.MeasureToolCore: Handles initialization, state management, and starts the measure tool and bounds tool.
  • BGRATextureView.h: Manages and interacts with BGRA textures in a Direct3D 11 context.
  • Measurement.cpp: Defines a Measurement struct that represents a rectangular measurement area, including methods for converting and printing measurement details in various units.
  • Clipboard.cpp: Copies measurement data to the clipboard.
  • D2DState.cpp: Manages Direct2D rendering state and draws text boxes.
  • DxgiAPI.cpp: Creates and manages Direct3D and Direct2D devices.
  • EdgeDetection.cpp: Detects edges in a BGRA texture.
  • OverlayUI.cpp: Creates and manages overlay windows for tools like MeasureTool and BoundsTool.
  • BoundsToolOverlayUI.cpp: UI implementation for bounds feature. Handles mouse and touch events to draw measurement rectangles on the screen and display their pixels.
  • MeasureToolOverlayUI.cpp: UI implementation for measure feature. Draws measurement lines on the screen and displays their pixels.
  • ScreenCapturing.cpp: Continuously captures the screen, detects edges, and updates the measurement state for real-time drawing of measurement lines.
  • PerGlyphOpacityTextRender.cpp: Renders text with varying opacity on a Direct2D render target.

Building & Debugging

Building

  1. Open PowerToys.sln in Visual Studio
  2. In the Solutions Configuration drop-down menu, select Release or Debug
  3. From the Build menu, choose Build Solution
  4. The executable app for Screen Ruler is named PowerToys.MeasureToolUI.exe

Debugging

  1. Right-click the project MeasureToolUI and click 'Set as Startup Project'
  2. Right-click the project MeasureToolUI and click 'Debug'

Known Issues

There are several open bugs for the Screen Ruler module, most of which are related to crashing issues. These can be found in the PowerToys issues list.