Skip to content

Commit

Permalink
Fix some linting
Browse files Browse the repository at this point in the history
  • Loading branch information
eruvanos committed Nov 19, 2024
1 parent 46fd0bf commit 976e6b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion arcade/gui/widgets/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from arcade.gui.widgets import UIWidget
from arcade.gui.widgets.layout import UIAnchorLayout
from arcade.text import FontNameOrNames
from arcade.types import Color, LBWH, RGBA255, RGBOrA255
from arcade.types import LBWH, RGBA255, Color, RGBOrA255


class UILabel(UIWidget):
Expand Down
40 changes: 18 additions & 22 deletions arcade/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import annotations

from ctypes import c_int, c_ubyte
from pathlib import Path
from typing import Any, Union

Expand All @@ -18,7 +19,7 @@
__all__ = ["load_font", "Text", "create_text_sprite", "draw_text"]


class ArcadeTextLayoutGroup(pyglet.text.layout.TextLayoutGroup):
class _ArcadeTextLayoutGroup(pyglet.text.layout.TextLayoutGroup):
"""Create a text layout rendering group.
Overrides pyglet blending handling to allow for additive blending.
Expand All @@ -29,45 +30,40 @@ class ArcadeTextLayoutGroup(pyglet.text.layout.TextLayoutGroup):
_prev_blend_func: tuple[int, int, int, int]

def set_state(self) -> None:
import pyglet.gl as gl
from ctypes import c_int, c_ubyte

self.program.use()
self.program["scissor"] = False

gl.glActiveTexture(gl.GL_TEXTURE0)
gl.glBindTexture(self.texture.target, self.texture.id)
pyglet.gl.glActiveTexture(pyglet.gl.GL_TEXTURE0)
pyglet.gl.glBindTexture(self.texture.target, self.texture.id)

blend = c_ubyte()
gl.glGetBooleanv(gl.GL_BLEND, blend)
pyglet.gl.glGetBooleanv(pyglet.gl.GL_BLEND, blend)
self._prev_blend = bool(blend.value)

src_rgb = c_int()
dst_rgb = c_int()
src_alpha = c_int()
dst_alpha = c_int()
gl.glGetIntegerv(gl.GL_BLEND_SRC_RGB, src_rgb)
gl.glGetIntegerv(gl.GL_BLEND_DST_RGB, dst_rgb)
gl.glGetIntegerv(gl.GL_BLEND_SRC_ALPHA, src_alpha)
gl.glGetIntegerv(gl.GL_BLEND_DST_ALPHA, dst_alpha)
pyglet.gl.glGetIntegerv(pyglet.gl.GL_BLEND_SRC_RGB, src_rgb)
pyglet.gl.glGetIntegerv(pyglet.gl.GL_BLEND_DST_RGB, dst_rgb)
pyglet.gl.glGetIntegerv(pyglet.gl.GL_BLEND_SRC_ALPHA, src_alpha)
pyglet.gl.glGetIntegerv(pyglet.gl.GL_BLEND_DST_ALPHA, dst_alpha)

self._prev_blend_func = (src_rgb.value, dst_rgb.value, src_alpha.value, dst_alpha.value)

gl.glEnable(gl.GL_BLEND)
gl.glBlendFuncSeparate(
gl.GL_SRC_ALPHA,
gl.GL_ONE_MINUS_SRC_ALPHA,
gl.GL_ONE,
gl.GL_ONE,
pyglet.gl.glEnable(pyglet.gl.GL_BLEND)
pyglet.gl.glBlendFuncSeparate(
pyglet.gl.GL_SRC_ALPHA,
pyglet.gl.GL_ONE_MINUS_SRC_ALPHA,
pyglet.gl.GL_ONE,
pyglet.gl.GL_ONE,
)

def unset_state(self) -> None:
import pyglet.gl as gl

if not self._prev_blend:
gl.glDisable(gl.GL_BLEND)
pyglet.gl.glDisable(pyglet.gl.GL_BLEND)

gl.glBlendFuncSeparate(
pyglet.gl.glBlendFuncSeparate(
self._prev_blend_func[0],
self._prev_blend_func[1],
self._prev_blend_func[2],
Expand All @@ -76,7 +72,7 @@ def unset_state(self) -> None:
self.program.stop()


pyglet.text.layout.TextLayout.group_class = ArcadeTextLayoutGroup
pyglet.text.layout.TextLayout.group_class = _ArcadeTextLayoutGroup


def load_font(path: str | Path) -> None:
Expand Down

0 comments on commit 976e6b8

Please sign in to comment.