-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Allen Ray
committed
Jun 23, 2020
1 parent
48aa362
commit 3fcdd79
Showing
2 changed files
with
59 additions
and
24 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package pixelui | ||
|
||
import ( | ||
"image/color" | ||
"log" | ||
"unsafe" | ||
|
||
"github.com/faiface/pixel" | ||
) | ||
|
||
// loadFont parses the imgui font data and creates a pixel picture from it. | ||
func (ui *UI) loadFont() { | ||
f := ui.fonts.TextureDataAlpha8() | ||
pic := pixel.MakePictureData(pixel.R(0, 0, float64(f.Width), float64(f.Height))) | ||
|
||
for y := 0; y < f.Height; y++ { | ||
for x := 0; x < f.Width; x++ { | ||
i := y*f.Width + x | ||
ptr := (*uint8)(unsafe.Pointer(uintptr(f.Pixels) + uintptr(i))) | ||
pic.Pix[i] = color.RGBA{R: 0, G: 0, B: 0, A: *ptr} | ||
} | ||
} | ||
|
||
ui.fontAtlas = ui.win.MakePicture(pic) | ||
} | ||
|
||
// loadDefaultFont loads the imgui default font if the user wants it. | ||
func (ui *UI) loadDefaultFont() { | ||
ui.fonts.AddFontDefault() | ||
ui.loadFont() | ||
} | ||
|
||
// AddTTFFont loads the given font into imgui. | ||
func (ui *UI) AddTTFFont(path string, size float32) { | ||
ui.fonts.AddFontFromFileTTF(path, size) | ||
if err := ui.fonts.BuildWithFreeType(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
ui.loadFont() | ||
} |
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