Package eu.svjatoslav.sixth.e3d.gui
Class RenderingContext
java.lang.Object
eu.svjatoslav.sixth.e3d.gui.RenderingContext
Contains all state needed to render a single frame: the pixel buffer, graphics context,
screen dimensions, and mouse event tracking.
A new RenderingContext is created whenever the view panel is resized.
During rendering, shapes use this context to:
- Access the raw pixel array (
pixels) for direct pixel manipulation - Access the
Graphics2Dcontext (graphics) for Java2D drawing - Read screen dimensions (
width,height) and thecenterCoordinatefor coordinate projection - Use the
projectionScalefactor for perspective projection
The context also manages mouse interaction detection: as shapes are painted back-to-front, each shape can report itself as the object under the mouse cursor. After painting completes, the topmost shape receives the mouse event.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intTheBufferedImagepixel format used for the rendering buffer (4-byte ABGR).final Point2DCenter of the screen in screen space (pixels).intNumber of frame that is currently being rendered.final Graphics2DJava2D graphics context for drawing text, anti-aliased shapes, and other high-level graphics operations onto the render buffer.final intHeight of the rendering area in pixels.final byte[]Pixels of the rendering area.final doubleScale factor for perspective projection, derived from screen width.final intWidth of the rendering area in pixels. -
Constructor Summary
ConstructorsConstructorDescriptionRenderingContext(int width, int height) Creates a new rendering context with the specified pixel dimensions. -
Method Summary
Modifier and TypeMethodDescriptionReturns the pending mouse event for this frame, ornullif none.booleanvoidResets per-frame state in preparation for rendering a new frame.voidsetCurrentObjectUnderMouseCursor(MouseInteractionController currentObjectUnderMouseCursor) Called when given object was detected under mouse cursor, while processingmouseEvent.voidsetMouseEvent(MouseEvent mouseEvent) Sets the mouse event to be processed during this frame's rendering.
-
Field Details
-
bufferedImageType
public static final int bufferedImageTypeTheBufferedImagepixel format used for the rendering buffer (4-byte ABGR).- See Also:
-
graphics
Java2D graphics context for drawing text, anti-aliased shapes, and other high-level graphics operations onto the render buffer. -
pixels
public final byte[] pixelsPixels of the rendering area. Each pixel is represented by 4 bytes: alpha, blue, green, red. -
width
public final int widthWidth of the rendering area in pixels. -
height
public final int heightHeight of the rendering area in pixels. -
centerCoordinate
Center of the screen in screen space (pixels). This is the point where (0,0) coordinate of the world space is rendered. -
projectionScale
public final double projectionScaleScale factor for perspective projection, derived from screen width. Used to convert normalized device coordinates to screen pixels. -
frameNumber
public int frameNumberNumber of frame that is currently being rendered. Every frame has its own number.
-
-
Constructor Details
-
RenderingContext
public RenderingContext(int width, int height) Creates a new rendering context with the specified pixel dimensions.Initializes the offscreen image buffer, extracts the raw pixel byte array, and configures anti-aliasing on the Graphics2D context.
- Parameters:
width- the rendering area width in pixelsheight- the rendering area height in pixels
-
-
Method Details
-
prepareForNewFrameRendering
public void prepareForNewFrameRendering()Resets per-frame state in preparation for rendering a new frame. Clears the mouse event and the current object under the mouse cursor. -
getMouseEvent
Returns the pending mouse event for this frame, ornullif none.- Returns:
- the mouse event to process, or
null
-
setMouseEvent
Sets the mouse event to be processed during this frame's rendering.- Parameters:
mouseEvent- the mouse event with position and button information
-
setCurrentObjectUnderMouseCursor
public void setCurrentObjectUnderMouseCursor(MouseInteractionController currentObjectUnderMouseCursor) Called when given object was detected under mouse cursor, while processingmouseEvent. Because objects are rendered back to front. The last method caller will set the top-most object, if there are multiple objects under mouse cursor. -
handlePossibleComponentMouseEvent
public boolean handlePossibleComponentMouseEvent()- Returns:
trueif view update is needed as a consequence of this mouse event.
-