44import io .github .notenoughupdates .moulconfig .internal .NinePatchRenderer ;
55import juuxel .libninepatch .NinePatch ;
66import org .jetbrains .annotations .ApiStatus ;
7- import org .jetbrains .annotations .NotNull ;
87import org .jetbrains .annotations .Nullable ;
8+ import org .jspecify .annotations .NullMarked ;
99
1010import java .util .List ;
1111import java .util .function .Consumer ;
1212
1313@ ApiStatus .NonExtendable
14+ @ NullMarked
1415public interface RenderContext {
1516 void pushMatrix ();
1617
@@ -32,11 +33,15 @@ enum ScissorBehaviour {
3233 /**
3334 * draws more content that should be laid on top of other later render calls. the consumer will be invoked linearly, but with no guarantee for when.
3435 */
35- void drawOnTop (@ NotNull Layer layer , @ NotNull ScissorBehaviour escapeScissors , @ NotNull Consumer <@ NotNull RenderContext > later ); // TODO: assert well ordering of layers in all child classes
36+ void drawOnTop (Layer layer , ScissorBehaviour escapeScissors , Consumer <RenderContext > later ); // TODO: assert well ordering of layers in all child classes
3637
37- boolean isMouseButtonDown (int mouseButton );
38+ default boolean isMouseButtonDown (int mouseButton ) {
39+ return IMinecraft .INSTANCE .isMouseButtonDown (mouseButton );
40+ }
3841
39- boolean isKeyboardKeyDown (int keyboardKey );
42+ default boolean isKeyboardKeyDown (int keyboardKey ) {
43+ return IMinecraft .INSTANCE .isKeyboardKeyDown (keyboardKey );
44+ }
4045
4146 default boolean isShiftDown () {
4247 return isKeyboardKeyDown (KeyboardConstants .INSTANCE .getShiftLeft ()) || isKeyboardKeyDown (KeyboardConstants .INSTANCE .getShiftRight ());
@@ -64,7 +69,7 @@ default boolean isLogicalCtrlDown() {
6469 }
6570 }
6671
67- default void drawStringScaledMaxWidth (@ NotNull StructuredText text , @ NotNull IFontRenderer fontRenderer , int x , int y , boolean shadow , int width , int color ) {
72+ default void drawStringScaledMaxWidth (StructuredText text , IFontRenderer fontRenderer , int x , int y , boolean shadow , int width , int color ) {
6873 pushMatrix ();
6974 translate (x , y );
7075 float scale = Math .min (1F , Math .max (0.1F , width / (float ) fontRenderer .getStringWidth (text )));
@@ -74,8 +79,8 @@ default void drawStringScaledMaxWidth(@NotNull StructuredText text, @NotNull IFo
7479 }
7580
7681 default void drawStringCenteredScaledMaxWidth (
77- @ NotNull StructuredText text ,
78- @ NotNull IFontRenderer fr ,
82+ StructuredText text ,
83+ IFontRenderer fr ,
7984 float x , float y ,
8085 boolean shadow ,
8186 int length , int color
@@ -107,7 +112,29 @@ default void drawHorizontalLine(int y, int startX, int endX, int color) {
107112 drawColoredRect (startX , y , endX + 1 , y + 1 , color );
108113 }
109114
110- void drawColoredTriangles (int color , float ... coordinates );
115+ /**
116+ * Renders a list of triangles.
117+ * @param colour the color to render the triangles in
118+ * @param coordinates The coordinates of the triangles, encoded as 3 vertices consisting of 6 floats arranged as {@code [x0, y0, x1, y1, x2, y2]}
119+ */
120+ default void drawColoredTriangles (int colour , float ... coordinates ) {
121+ assert coordinates .length % 6 == 0 ;
122+ float [] newCoordinates = new float [coordinates .length / 3 * 4 ];
123+ for (int i = 0 ; i < coordinates .length / 6 ; i ++) {
124+ newCoordinates [i * 8 ] = coordinates [i * 6 ];
125+ newCoordinates [i * 8 + 1 ] = coordinates [i * 6 + 1 ];
126+ newCoordinates [i * 8 + 2 ] = coordinates [i * 6 + 2 ];
127+ newCoordinates [i * 8 + 3 ] = coordinates [i * 6 + 3 ];
128+ newCoordinates [i * 8 + 4 ] = coordinates [i * 6 + 4 ];
129+ newCoordinates [i * 8 + 5 ] = coordinates [i * 6 + 5 ];
130+ newCoordinates [i * 8 + 6 ] = coordinates [i * 6 + 4 ];
131+ newCoordinates [i * 8 + 7 ] = coordinates [i * 6 + 5 ];
132+ }
133+ drawColouredQuads (colour , newCoordinates );
134+ }
135+
136+ void drawColouredQuads (int colour , float ... coordinates );
137+
111138
112139 default void drawOpenCloseTriangle (boolean isOpen , float x , float y , float width , float height , int color ) {
113140 if (isOpen ) {
@@ -127,33 +154,33 @@ default void drawOpenCloseTriangle(boolean isOpen, float x, float y, float width
127154 }
128155 }
129156
130- void drawString (@ NotNull IFontRenderer fontRenderer , @ NotNull StructuredText text , int x , int y , int color , boolean shadow );
157+ void drawString (IFontRenderer fontRenderer , StructuredText text , int x , int y , int color , boolean shadow );
131158
132159 void drawColoredRect (float left , float top , float right , float bottom , int color );
133160
134161 void invertedRect (float left , float top , float right , float bottom , int additiveColor ); // TODO: worth a consideration (is this a stable API)???
135162
136- default void drawTexturedRect (@ NotNull MyResourceLocation texture , float x , float y , float width , float height ) {
163+ default void drawTexturedRect (MyResourceLocation texture , float x , float y , float width , float height ) {
137164 drawComplexTexture (texture , x , y , width , height , drawTextureBuilder -> {
138165 });
139166 }
140167
141- void drawTexturedTintedRect (@ NotNull MyResourceLocation texture ,
168+ void drawTexturedTintedRect (MyResourceLocation texture ,
142169 float x , float y , float width , float height ,
143170 float u1 , float v1 , float u2 , float v2 ,
144- int color , @ NotNull TextureFilter filter );
171+ int color , TextureFilter filter );
145172
146173 class DrawTextureBuilder {
147- @ NotNull MyResourceLocation texture ;
174+ MyResourceLocation texture ;
148175 float x ;
149176 float y ;
150177 float width ;
151178 float height ;
152179 float u1 = 0 , v1 = 0 , u2 = 1 , v2 = 1 ;
153180 int color = -1 ;
154- @ NotNull TextureFilter filter = TextureFilter .NEAREST ;
181+ TextureFilter filter = TextureFilter .NEAREST ;
155182
156- public DrawTextureBuilder (@ NotNull MyResourceLocation texture , float x , float y , float width , float height ) {
183+ public DrawTextureBuilder (MyResourceLocation texture , float x , float y , float width , float height ) {
157184 this .texture = texture ;
158185 this .x = x ;
159186 this .y = y ;
@@ -185,13 +212,13 @@ public void applyTo(RenderContext renderContext) {
185212 }
186213
187214
188- default void drawComplexTexture (@ NotNull MyResourceLocation texture , float x , float y , float width , float height , Consumer <DrawTextureBuilder > block ) {
215+ default void drawComplexTexture (MyResourceLocation texture , float x , float y , float width , float height , Consumer <DrawTextureBuilder > block ) {
189216 DrawTextureBuilder drawBuilder = new DrawTextureBuilder (texture , x , y , width , height );
190217 block .accept (drawBuilder );
191218 drawBuilder .applyTo (this );
192219 }
193220
194- default void drawNinePatch (@ NotNull NinePatch <@ NotNull MyResourceLocation > patch , float x , float y , int width , int height ) {
221+ default void drawNinePatch (NinePatch <MyResourceLocation > patch , float x , float y , int width , int height ) {
195222 pushMatrix ();
196223 translate (x , y );
197224 patch .draw (NinePatchRenderer .INSTANCE , this , width , height );
@@ -220,14 +247,17 @@ default void drawDarkRect(int x, int y, int width, int height) {
220247
221248 void assertNoScissors ();
222249
250+ /**
251+ * @deprecated this silently discards any errors in the scissor stack. use {@link #assertNoScissors()} to be sure about the current scissor stack instead.
252+ */
223253 @ Deprecated
224254 void clearScissor (); // TODO: this sort of escapes out of the current context.
225255
226- void renderItemStack (@ NotNull IItemStack itemStack , int x , int y , @ Nullable StructuredText overlayText );
256+ void renderItemStack (IItemStack itemStack , int x , int y , @ Nullable StructuredText overlayText );
227257
228- void drawTooltipNow (int x , int y , @ NotNull List <@ NotNull StructuredText > tooltipLines );
258+ void drawTooltipNow (int x , int y , List <StructuredText > tooltipLines );
229259
230- default void scheduleDrawTooltip (int x , int y , @ NotNull List <StructuredText > tooltipLines ) {
260+ default void scheduleDrawTooltip (int x , int y , List <StructuredText > tooltipLines ) {
231261 // TODO: should this do some form of conflict resolution?
232262 drawOnTop (Layer .TOOLTIP , ScissorBehaviour .ESCAPE , it -> it .drawTooltipNow (x , y , tooltipLines ));
233263 }
@@ -237,7 +267,7 @@ default void scheduleDrawTooltip(int x, int y, @NotNull List<StructuredText> too
237267 */
238268 void renderExtraLayers ();
239269
240- default @ NotNull IMinecraft getMinecraft () {
270+ default IMinecraft getMinecraft () {
241271 return IMinecraft .INSTANCE ;
242272 }
243273}
0 commit comments