|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2025 Patrick Ziegler and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License 2.0 which is available at |
| 6 | + * https://www.eclipse.org/legal/epl-2.0. |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * Patrick Ziegler - initial API and implementation |
| 12 | + *******************************************************************************/ |
| 13 | +package org.eclipse.wb.internal.os.linux; |
| 14 | + |
| 15 | +import java.lang.foreign.Arena; |
| 16 | +import java.lang.foreign.MemoryLayout; |
| 17 | +import java.lang.foreign.MemorySegment; |
| 18 | +import java.lang.foreign.StructLayout; |
| 19 | +import java.lang.foreign.ValueLayout; |
| 20 | + |
| 21 | +/** |
| 22 | + * A GdkRectangle data type for representing rectangles. |
| 23 | + * |
| 24 | + * GdkRectangle is identical to cairo_rectangle_t. Together with Cairo’s |
| 25 | + * cairo_region_t data type, these are the central types for representing sets |
| 26 | + * of pixels. |
| 27 | + * |
| 28 | + * The intersection of two rectangles can be computed with |
| 29 | + * gdk_rectangle_intersect(); to find the union of two rectangles use |
| 30 | + * gdk_rectangle_union(). |
| 31 | + * |
| 32 | + * The cairo_region_t type provided by Cairo is usually used for managing |
| 33 | + * non-rectangular clipping of graphical operations. |
| 34 | + * |
| 35 | + * The Graphene library has a number of other data types for regions and volumes |
| 36 | + * in 2D and 3D. |
| 37 | + */ |
| 38 | +public sealed class GdkRectangle permits GtkAllocation { |
| 39 | + private static final StructLayout LAYOUT = MemoryLayout.structLayout( // |
| 40 | + ValueLayout.JAVA_INT.withName("x"), // |
| 41 | + ValueLayout.JAVA_INT.withName("y"), // |
| 42 | + ValueLayout.JAVA_INT.withName("width"), // |
| 43 | + ValueLayout.JAVA_INT.withName("height")); |
| 44 | + |
| 45 | + private final MemorySegment segment; |
| 46 | + |
| 47 | + public GdkRectangle(Arena arena) { |
| 48 | + segment = arena.allocate(LAYOUT); |
| 49 | + } |
| 50 | + |
| 51 | + public final int x() { |
| 52 | + return segment.get(ValueLayout.JAVA_INT, 0); |
| 53 | + } |
| 54 | + |
| 55 | + public final int y() { |
| 56 | + return segment.get(ValueLayout.JAVA_INT, 4); |
| 57 | + } |
| 58 | + |
| 59 | + public final int width() { |
| 60 | + return segment.get(ValueLayout.JAVA_INT, 8); |
| 61 | + } |
| 62 | + |
| 63 | + public final int height() { |
| 64 | + return segment.get(ValueLayout.JAVA_INT, 12); |
| 65 | + } |
| 66 | + |
| 67 | + public final MemorySegment segment() { |
| 68 | + return segment; |
| 69 | + } |
| 70 | +} |
0 commit comments