-
-
Notifications
You must be signed in to change notification settings - Fork 230
Generalize Tooltip Rendering into one function, Also add 9 slice drawing function #3276
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
Merged
IntegratedQuantum
merged 16 commits into
PixelGuys:master
from
SpellDigger:tooltip_render
Jul 5, 2026
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bf36f09
Make it work
SpellDigger 385854a
Cubyz Formatter
SpellDigger bf91a02
forgot mutpos exist
SpellDigger 464c064
forgor
SpellDigger da5cf3f
Rename tooltip.zig to Tooltip.zig (why didnt this change)
SpellDigger 7e4f8ed
update tooltip background
SpellDigger 34c729d
Made Tooltip lowercase (its not a type or a component)
SpellDigger e887ee8
Rename Tooltip.zig to tooltip.zig
SpellDigger e3e902f
Reduce unecessary variables in bound9SliceImage
SpellDigger c00b0eb
Merge branch 'tooltip_render' of https://github.com/SpellDigger/Cubyz…
SpellDigger 6b12ed6
Merge branch 'PixelGuys:master' into tooltip_render
SpellDigger 4dd6279
"Small" Modifications to tooltip rendering
SpellDigger 79b72fa
merge repeating if statement
SpellDigger 1fd0df1
quantum changes 2
SpellDigger 7d62c4e
fixed adjustment not considering existing position
SpellDigger ea4b4bc
Quantum Suggestions
SpellDigger 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,64 @@ | ||
| const std = @import("std"); | ||
|
|
||
| const main = @import("main"); | ||
| const graphics = main.graphics; | ||
| const draw = graphics.draw; | ||
| const Texture = graphics.Texture; | ||
| const vec = main.vec; | ||
| const Vec2f = vec.Vec2f; | ||
| const Vec4f = vec.Vec4f; | ||
| const gui = main.gui; | ||
| const GuiComponent = gui.GuiComponent; | ||
|
|
||
| var tooltipTexture: Texture = undefined; | ||
| var cornerSize: Vec2f = undefined; | ||
|
|
||
| const fontSize: f32 = 16; | ||
| const offsetFromMouse: f32 = 4; | ||
|
|
||
| pub fn globalInit() void { | ||
| tooltipTexture = Texture.initFromFile("assets/cubyz/ui/tooltip_background.png"); | ||
| cornerSize = (@as(Vec2f, @floatFromInt(tooltipTexture.size())) - Vec2f{1, 1})/Vec2f{2, 2}; | ||
| } | ||
|
|
||
| pub fn globalDeinit() void { | ||
| tooltipTexture.deinit(); | ||
| } | ||
|
|
||
| pub fn render(guiComponent: *GuiComponent, pos: Vec2f) void { | ||
| const size = guiComponent.size() + Vec2f{cornerSize[0]*2, cornerSize[1]*2}; | ||
| tooltipTexture.bindTo(0); | ||
|
|
||
| const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale)); | ||
| var renderPos = pos + Vec2f{offsetFromMouse, 0}; | ||
| if (renderPos[0] + size[0] > windowSize[0]) { | ||
| renderPos = pos - Vec2f{size[0] + cornerSize[0]*2, 0}; | ||
| } | ||
|
IntegratedQuantum marked this conversation as resolved.
|
||
| renderPos = @max(Vec2f{0, 0}, renderPos); | ||
| if (renderPos[1] + size[1] > windowSize[1]) { | ||
| renderPos[1] += windowSize[1] - (renderPos[1] + size[1]); | ||
| } | ||
|
|
||
| draw.bound9SliceImage(renderPos, size, @floatFromInt(tooltipTexture.size()), cornerSize, 1); | ||
|
|
||
| const adjustment = renderPos - guiComponent.pos() + Vec2f{cornerSize[0], cornerSize[1]}; | ||
| const oldTranslation = draw.setTranslation(adjustment); | ||
| defer draw.restoreTranslation(oldTranslation); | ||
| const oldClip = draw.setClip(guiComponent.size()); | ||
| defer draw.restoreClip(oldClip); | ||
| guiComponent.render(guiComponent.pos()); | ||
| } | ||
|
|
||
| pub fn renderFromText(text: []const u8, pos: Vec2f) void { | ||
| var label = GuiComponent.Label.init(Vec2f{0, 0}, 300, text, .left); | ||
| defer label.deinit(); | ||
| var size = label.text.calculateLineBreaks(fontSize, 300); | ||
| size[0] = 0; | ||
| for (label.text.lineBreaks.items) |lineBreak| { | ||
| size[0] = @max(size[0], lineBreak.width); | ||
| } | ||
| label.size = size; | ||
|
|
||
| var component = label.toComponent(); | ||
| render(&component, pos); | ||
| } | ||
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.
Why is this slightly transparent? I cannot see through it at all.
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.
honestly i dont know myself i just made it like that cuz it looks nicer, i can make it non transparent or more transparent if you like, i can see through it just fine but maybe its cuz of my monitor settings
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.
I would suggest to just make it opaque.