2011-07-06 10:29:20 +02:00
|
|
|
"""
|
|
|
|
Hello World Text Example
|
|
|
|
++++++++++++++++++++++++
|
2011-07-29 03:24:03 +02:00
|
|
|
|
2018-04-17 12:25:51 +02:00
|
|
|
Example of using the blf module. For this module to work we
|
2011-07-06 10:29:20 +02:00
|
|
|
need to use the OpenGL wrapper :class:`~bgl` as well.
|
|
|
|
"""
|
|
|
|
# import stand alone modules
|
|
|
|
import blf
|
2018-04-17 12:25:51 +02:00
|
|
|
import bpy
|
2011-07-06 10:29:20 +02:00
|
|
|
|
2018-04-17 12:25:51 +02:00
|
|
|
font_info = {
|
|
|
|
"font_id": 0,
|
|
|
|
"handler": None,
|
|
|
|
}
|
2011-07-29 03:24:03 +02:00
|
|
|
|
2018-06-26 19:41:37 +02:00
|
|
|
|
2011-07-06 10:29:20 +02:00
|
|
|
def init():
|
|
|
|
"""init function - runs once"""
|
2018-04-17 12:25:51 +02:00
|
|
|
import os
|
|
|
|
# Create a new font object, use external ttf file.
|
|
|
|
font_path = bpy.path.abspath('//Zeyada.ttf')
|
|
|
|
# Store the font indice - to use later.
|
|
|
|
if os.path.exists(font_path):
|
|
|
|
font_info["font_id"] = blf.load(font_path)
|
|
|
|
else:
|
|
|
|
# Default font.
|
|
|
|
font_info["font_id"] = 0
|
2011-07-06 10:29:20 +02:00
|
|
|
|
2011-07-29 03:24:03 +02:00
|
|
|
# set the font drawing routine to run every frame
|
2018-04-17 12:25:51 +02:00
|
|
|
font_info["handler"] = bpy.types.SpaceView3D.draw_handler_add(
|
|
|
|
draw_callback_px, (None, None), 'WINDOW', 'POST_PIXEL')
|
2011-07-29 03:24:03 +02:00
|
|
|
|
2011-07-06 10:29:20 +02:00
|
|
|
|
2018-04-17 12:25:51 +02:00
|
|
|
def draw_callback_px(self, context):
|
|
|
|
"""Draw on the viewports"""
|
2011-07-06 10:29:20 +02:00
|
|
|
# BLF drawing routine
|
2018-04-17 12:25:51 +02:00
|
|
|
font_id = font_info["font_id"]
|
|
|
|
blf.position(font_id, 2, 80, 0)
|
2023-05-23 04:02:10 +02:00
|
|
|
blf.size(font_id, 50.0)
|
2011-07-06 10:29:20 +02:00
|
|
|
blf.draw(font_id, "Hello World")
|
2018-04-17 12:25:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
init()
|