-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add referee display layer #3337
Open
Lmh-java
wants to merge
30
commits into
UBC-Thunderbots:master
Choose a base branch
from
Lmh-java:minghao/referee-layer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
4d608ca
Add new layer
Lmh-java de95603
Update format
Lmh-java 07f17cb
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] b369777
Fix typo
Lmh-java 8f58631
Add ball placement vis?
Lmh-java 878112a
Migrate ball placement
Lmh-java 160d347
Add ball placement visuals
Lmh-java ef0a030
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] f39a399
Refactor code
Lmh-java 0d242ce
Fix refactor
Lmh-java db3f208
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 709db29
Rename methods
Lmh-java ecd314d
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] b7642cf
Merge branch 'master' into HEAD
Lmh-java 4f3d93c
replace auto with optional
Lmh-java 947428d
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 70ea39f
partially introduce constexpr
Lmh-java 63ff6ed
use cpp library calls
Lmh-java 494b833
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] f403762
nit
Lmh-java e08edd0
replace all font name with constant
Lmh-java 8b1a616
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 2daae4f
update flag logic
Lmh-java 207eae2
Merge branch 'minghao/referee-layer' of github.com:Lmh-java/Software …
Lmh-java 4f94227
update flag logic
Lmh-java 7368f8c
Merge branch 'master' into minghao/referee-layer
Lmh-java 7f097b0
Merge branch 'master' into minghao/referee-layer
Lmh-java afaf9a9
remove font name instance
Lmh-java 6b4fb32
fix
Lmh-java 1f91332
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from PyQt6.QtGui import QFont, QColor | ||
from pyqtgraph.opengl.GLGraphicsItem import GLGraphicsItem | ||
from pyqtgraph.Qt import QtCore, QtGui | ||
|
||
from typing import Optional | ||
|
||
from software.thunderscope.gl.graphics.gl_painter import GLPainter | ||
from software.thunderscope.constants import Colors, THUNDERSCOPE_UI_FONT_NAME | ||
|
||
|
||
class GLLabel(GLPainter): | ||
"""Displays a 2D text label on the viewport""" | ||
|
||
def __init__( | ||
self, | ||
parent_item: Optional[GLGraphicsItem] = None, | ||
font: QFont = QFont(THUNDERSCOPE_UI_FONT_NAME, 8), | ||
text_color: QColor = Colors.PRIMARY_TEXT_COLOR, | ||
offset: tuple[int, int] = (0, 0), | ||
text: str = "", | ||
) -> None: | ||
"""Initialize the GLLabel | ||
|
||
:param parent_item: The parent item of the graphic | ||
:param font: The font using to render the text | ||
:param text_color: The color for rendering the text. | ||
:param offset: The offset (x, y) from the viewport left and top edge | ||
to use when positioning the label. | ||
If x is negative then the x offset is |x| pixels from | ||
the viewport right edge. | ||
If y is negative then the y offset is |y| pixels from | ||
the viewport bottom edge. | ||
:param text: The optional title to display above the legend | ||
""" | ||
super().__init__(parent_item=parent_item) | ||
|
||
self.text_pen = QtGui.QPen(text_color) | ||
self.font = font | ||
self.offset = offset | ||
self.text = text | ||
|
||
self.add_draw_function(self.draw_label) | ||
|
||
def draw_label(self, painter: QtGui.QPainter, viewport_rect: QtCore.QRect) -> None: | ||
"""Draw the label | ||
:param painter: The QPainter to perform drawing operations with | ||
:param viewport_rect: The QRect indicating the viewport dimensions | ||
""" | ||
# calculate width and height of the label | ||
painter.setFont(self.font) | ||
bounds = painter.boundingRect( | ||
QtCore.QRectF(0, 0, 0, 0), | ||
QtCore.Qt.AlignmentFlag.AlignLeft | QtCore.Qt.AlignmentFlag.AlignVCenter, | ||
str(self.text), | ||
) | ||
|
||
width = round(bounds.width()) | ||
height = round(bounds.height()) | ||
|
||
# Determine x and y coordinates of the label | ||
if self.offset[0] < 0: | ||
x = viewport_rect.right() + self.offset[0] - width | ||
else: | ||
x = viewport_rect.left() + self.offset[0] | ||
if self.offset[1] < 0: | ||
y = viewport_rect.bottom() + self.offset[1] - height | ||
else: | ||
y = viewport_rect.top() + self.offset[1] | ||
|
||
if self.text: | ||
painter.drawText(QtCore.QPoint(x, y), self.text) | ||
|
||
def set_text(self, new_text: str) -> None: | ||
"""Update the text being displayed | ||
:param new_text: new text being displayed | ||
""" | ||
self.text = new_text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: is this necessary? feels like its a bit clearer to just require the offsets to be positive numbers always. from the perspective of someone using this method in the future, the sign flipping feels a bit roundabout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a huge deal tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol I followed the design of other components on the same level for consistency. But sure, I will clean this up to make it more understandable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some testing here, I found out that the easier way to place the label on the top right corner is just to keep this wired sign flipping, because it takes some code to fetch the width of the viewport before passing into this function. Instead, we can get viewport by whatever calls this function, so we probably need to use a negative sign to denote starting from the right side.