MCPcopy Create free account
hub / github.com/WallBreaker2/op / Calculate

Function Calculate

libop/window/WindowLayout.cpp:226–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224}
225
226std::vector<Rect> Calculate(const std::vector<HWND> &windows, const Options &options) {
227 std::vector<LayoutSeed> seeds = BuildLayoutSeeds(windows, options);
228 std::vector<Rect> rects;
229 rects.reserve(seeds.size());
230 if (seeds.empty()) {
231 return rects;
232 }
233
234 int max_anchor_width = 0;
235 int max_anchor_height = 0;
236 for (const auto &seed : seeds) {
237 if (seed.anchor_width > max_anchor_width)
238 max_anchor_width = seed.anchor_width;
239 if (seed.anchor_height > max_anchor_height)
240 max_anchor_height = seed.anchor_height;
241 }
242
243 int current_x = options.start_x;
244 int current_y = options.start_y;
245
246 switch (options.type) {
247 case Type::Grid: {
248 const int columns = options.columns > 0 ? options.columns : 1;
249 for (size_t i = 0; i < seeds.size(); ++i) {
250 const int col = static_cast<int>(i) % columns;
251 const int row = static_cast<int>(i) / columns;
252 Rect rect = seeds[i].rect;
253 const int anchor_x = options.start_x + col * (max_anchor_width + options.gap_x);
254 const int anchor_y = options.start_y + row * (max_anchor_height + options.gap_y);
255
256 // 宫格使用统一单元格,避免原窗口大小不一致时互相重叠。
257 rect.x = anchor_x - seeds[i].anchor_offset_x;
258 rect.y = anchor_y - seeds[i].anchor_offset_y;
259 rects.push_back(rect);
260 }
261 break;
262 }
263
264 case Type::Diagonal: {
265 for (const auto &seed : seeds) {
266 Rect rect = seed.rect;
267 rect.x = current_x - seed.anchor_offset_x;
268 rect.y = current_y - seed.anchor_offset_y;
269 current_x += seed.anchor_width + options.gap_x;
270 current_y += seed.anchor_height + options.gap_y;
271 rects.push_back(rect);
272 }
273 break;
274 }
275 }
276
277 return rects;
278}
279
280long Apply(const std::vector<HWND> &windows, const std::vector<Rect> &rects, const Options &options) {
281 if (windows.empty() || windows.size() != rects.size()) {

Callers 1

LayoutFunction · 0.85

Calls 3

BuildLayoutSeedsFunction · 0.85
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected