Пример #1
0
    def __init__(
        self, parent, name, text="", font=None, pt_size=None, color=None, pos=[0, 0], sub_theme="", options=BGUI_DEFAULT
    ):
        """
        :param parent: the widget's parent
        :param name: the name of the widget
        :param text: the text to display (this can be changed later via the text property)
        :param font: the font to use
        :param pt_size: the point size of the text to draw (defaults to 30 if None)
        :param color: the color to use when rendering the font
        :param pos: a tuple containing the x and y position
        :param sub_theme: name of a sub_theme defined in the theme file (similar to CSS classes)
        :param options: various other options

        """
        Widget.__init__(self, parent, name, None, [0, 0], pos, sub_theme, options)

        if font:
            self.fontid = blf.load(font)
        else:
            font = self.theme["Font"]
            self.fontid = blf.load(font) if font else 0

        if pt_size:
            self.pt_size = pt_size
        else:
            self.pt_size = self.theme["Size"]

        if color:
            self.color = color
        else:
            self.color = self.theme["Color"]

        self.text = text
def init():
    """init function - runs once"""
    # create a new font object, use external ttf file
    font_path = logic.expandPath('//text/Big_Bottom_Cartoon_AD.ttf')
    italic_font_path = logic.expandPath('//text/Big_Bottom_Cartoon_Italic_AD.ttf')
    # store the font indice - to use later
    logic.font_id = blf.load(font_path)
    logic.font_id_italic = blf.load(italic_font_path)

    # set the font drawing routine to run every frame
    scene = logic.getCurrentScene()
    scene.post_draw = [write]
Пример #3
0
    def __init__(self,
                 parent,
                 name,
                 text="",
                 font=None,
                 pt_size=None,
                 color=None,
                 pos=[0, 0],
                 offset=[0, 0],
                 sub_theme='',
                 options=BGUI_NONE):
        """
		:param parent: the widget's parent
		:param name: the name of the widget
		:param text: the text to display (this can be changed later via the text property)
		:param font: the font to use
		:param pt_size: the point size of the text to draw (defaults to 30 if None)
		:param color: the color to use when rendering the font
		:param pos: a tuple containing the x and y position
		:param sub_theme: name of a sub_theme defined in the theme file (similar to CSS classes)
		:param options: various other options

		"""
        Widget.__init__(self, parent, name, [0, 0], pos, offset, sub_theme,
                        options)

        if font:
            path = os.path.join("ge", "themes", font)
            path = logic.expandPath("//" + path)
            self.fontid = blf.load(path)
            #self.fontid = blf.load(font)
        else:
            font = self.theme['Font']
            path = os.path.join("ge", "themes", font)
            path = logic.expandPath("//" + path)
            self.fontid = blf.load(path) if font else 0
            #self.fontid = blf.load(font) if font else 0

        if pt_size:
            self.pt_size = pt_size
        else:
            self.pt_size = self.theme['Size']

        if color:
            self.color = color
        else:
            self.color = self.theme['Color']

        self.text = text
        self.dimension = 0.0
Пример #4
0
def draw_text_custom(text,
                     x,
                     y,
                     font_file_path,
                     shadow_on,
                     align="LEFT",
                     size=12,
                     color=(1.0, 1.0, 1.0, 1.0)):
    font_path = font_file_path
    font_id = blf.load(font_path)
    font = font_id

    blf.size(font, size, int(dpi))
    glColor4f(*color)

    if shadow_on == "ON":
        blf.shadow(font, 5, 0.0, 0.0, 0.0, 1.0)

    if align == "LEFT":
        blf.position(font, x, y, 0)
    else:
        width, height = blf.dimensions(font, text)
        if align == "RIGHT":
            blf.position(font, x - width, y, 0)

    blf.draw(font, text)
Пример #5
0
def load_font(self):
    if self.font_id is not None:
        return
    try:
        self.font_id = blf.load(self.font_path)
    except:
        raise Exception
Пример #6
0
    def __init__(self):
        # NB: libcode param doesn't work
        self.shader = GPUShader(
            vertexcode=self.VERT_GLSL,
            fragcode=self.FRAG_GLSL,
            geocode=self.LIB_GLSL + self.GEOM_GLSL,
            defines=self.DEF_GLSL,
        )

        # Horrific prototype code to ensure bgl draws at drawing scales
        # https://blender.stackexchange.com/questions/16493/is-there-a-way-to-fit-the-viewport-to-the-current-field-of-view
        def is_landscape(render):
            return render.resolution_x > render.resolution_y

        def get_scale(camera):
            if camera.data.BIMCameraProperties.diagram_scale == "CUSTOM":
                human_scale, fraction = camera.data.BIMCameraProperties.custom_diagram_scale.split(
                    "|")
            else:
                human_scale, fraction = camera.data.BIMCameraProperties.diagram_scale.split(
                    "|")
            numerator, denominator = fraction.split("/")
            return float(numerator) / float(denominator)

        camera = bpy.context.scene.camera
        render = bpy.context.scene.render
        if is_landscape(render):
            camera_width_model = camera.data.ortho_scale
        else:
            camera_width_model = camera.data.ortho_scale / render.resolution_y * render.resolution_x
        self.camera_width_mm = get_scale(camera) * camera_width_model

        self.font_id = blf.load(
            os.path.join(bpy.context.scene.BIMProperties.data_dir, "fonts",
                         "OpenGost Type B TT.ttf"))
Пример #7
0
    def __init__(self, bounds=[0, 0, 100, 20], fontfile="", font_size=12):
        PControl.new.__init__(self, bounds)

        self.fid = blf.load(fontfile) if fontfile != "" else 0
        self.fontSize = font_size

        self._value = 0
        self._max = 100.0
        self._min = 0.0

        self.decimalPlaces = 0
        self.increment = 1

        self.addb = PButton.new(text="", fontfile=fontfile, text_align=1)
        self.decb = PButton.new(text="", fontfile=fontfile, text_align=1)

        _this = self

        def addf(s, d):
            _this.value += self.increment

        def decf(s, d):
            _this.value -= self.increment

        self.addb.on_mouse_click = addf
        self.decb.on_mouse_click = decf

        self.on_value_change = None

        self.backColor = default["text_background"]
Пример #8
0
    def invoke(self, context, event):

        #self._time = str(time.strftime('%X %x %Z'))

        # Clean lightmaps first?
        bpy.ops.tlm.clean_lightmaps()

        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

        args = (context, event)

        self._timer = context.window_manager.event_timer_add(
            0.1, window=context.window)
        context.window_manager.modal_handler_add(self)
        self._handle = bpy.types.SpaceView3D.draw_handler_add(
            self.draw_callback_px, args, 'WINDOW', 'POST_PIXEL')
        # print("Invoked..")

        return {'RUNNING_MODAL'}
Пример #9
0
    def __init__(self, bounds = None, rounded = False, with_name = False):

        """ constructor of morph class it can be called with no parameters or using the following keywords ->

        bounds : bounds set the bounds of the morph. It can be created using the Rect and Point  classes
        eg. morph = Morph( bounds = Rect(Point(0,0),Point(100,100)) will create a morph with weight and width of 100 pixels

        rounded : rounded is a boolean , if true will create a rounded morph

        with_name : This one set a name for the morph for easy access """

        super(Morph, self).__init__()
        if bounds: #PKHG>???28jun  and isinstance(bounds, Rectangle):
            self.bounds = bounds
        else:
            self.bounds = Rectangle(Point(0, 0), Point(100,60))
#PKHG test 3jul        self.color = (0.3, 0.3, 0.3, 1.0)
#sometimes working ???
        self.color = (1, 1, 1, 1)
        self.is_visible = True
        self.is_draggable = True
        self.fps = 0
        self.rounded = rounded
        # self.last_time = pygame.time.get_ticks()
        self.with_name = with_name
        self.path_to_local_fonts  = self.get_local_font_path()
        self.default_font = self.path_to_local_fonts + "/verdana.ttf"
        self.font_id = blf.load(self.default_font)
        self.my_name_size = 0
        self.texture_path = bpy.utils.script_paths()[0] + \
                          "/addons/Ephestos/data/images/".replace("/",path_sep)
        self.world = None
        self.texture = None
        self.is_textured = False
Пример #10
0
 def __init__(self, bounds=[0, 0, 100, 20], fontfile="", font_size=12):
     PControl.new.__init__(self, bounds)
     
     self.fid = blf.load(fontfile) if fontfile != "" else 0
     self.fontSize = font_size
     
     self._value = 0
     self._max = 100.0
     self._min = 0.0
     
     self.decimalPlaces = 0
     self.increment = 1
     
     self.addb = PButton.new(text="", fontfile=fontfile, text_align=1)
     self.decb = PButton.new(text="", fontfile=fontfile, text_align=1)
     
     _this = self
     def addf(s, d):
         _this.value += self.increment
     def decf(s, d):
         _this.value -= self.increment
     self.addb.on_mouse_click = addf
     self.decb.on_mouse_click = decf
 
     self.on_value_change = None
     
     self.backColor = default["text_background"]
Пример #11
0
def font_id_get(self):
    U = bpy.context.user_preferences
    path = U.system.font_path_ui
    if path:
        i = blf.load(path)
        if i != -1:
            return i
    return 0
Пример #12
0
def font_id_get(self):
    U = bpy.context.user_preferences
    path = U.system.font_path_ui
    if path:
        i = blf.load(path)
        if i != -1:
            return i
    return 0
Пример #13
0
    def __init__(self, parent):
        super(Splash, self).__init__(parent)
        utils_path = os.path.join(os.path.dirname(blender_cave.__file__), '..', 'utils')
        font_path = os.path.join(utils_path, 'font.ttf')
        self._font_id = blf.load(font_path)
        self._ecg_values = [2.2115759e+00, 1.9184524e+00, 1.6262298e+00, 1.3363817e+00, 1.0457467e+00, 8.7953729e-01,
                            8.0215353e-01, 7.2426229e-01, 6.5531316e-01, 7.2484014e-01, 8.0165860e-01, 8.7841227e-01,
                            8.9891580e-01, 8.9938683e-01, 9.0013088e-01, 9.0042507e-01, 8.9932180e-01, 9.4631408e-01,
                            1.0210519e+00, 1.0902796e+00, 1.1501810e+00, 1.1975850e+00, 1.2304606e+00, 1.2475264e+00,
                            1.2478137e+00, 1.2309090e+00, 1.1975449e+00, 1.1497013e+00, 1.0900498e+00, 1.0214188e+00,
                            9.4676607e-01, 8.9919702e-01, 8.9986325e-01, 8.9991225e-01, 8.9988388e-01, 8.9977460e-01,
                            8.9966892e-01, 8.9969241e-01, 8.9980904e-01, 8.9988400e-01, 9.0185543e-01, 9.2238531e-01,
                            9.3397361e-01, 9.3126973e-01, 9.1529574e-01, 8.9942898e-01, 8.9962413e-01, 8.9978944e-01,
                            8.9995322e-01, 8.9989238e-01, 8.9966710e-01, 8.9959321e-01, 8.9979372e-01, 8.9998970e-01,
                            8.9988168e-01, 8.9960574e-01, 8.9957540e-01, 8.9987410e-01, 9.0006866e-01, 8.9979595e-01,
                            8.9937733e-01, 8.9969153e-01, 9.1359251e-01, 9.9441355e-01, 1.0596300e+00, 1.1037278e+00,
                            1.1246771e+00, 1.1277361e+00, 1.1011566e+00, 1.0485388e+00, 9.7126260e-01, 8.9859989e-01,
                            8.9977939e-01, 9.0055926e-01, 8.9983003e-01, 8.9861560e-01, 8.9962911e-01, 9.4572544e-01,
                            1.2391061e+00, 1.5307464e+00, 1.8201066e+00, 2.1104914e+00, 2.4091746e+00, 2.3016856e+00]
        self._message = ''
        self._ecg_values_size = len(self._ecg_values)
        self._repeat = 10
        self._total_size = self._ecg_values_size * self._repeat
        self._extinction = 3.0

        self._official_splash = (bge.logic.getCurrentScene().name == "Blender Cave Splash Screen")

        if self._official_splash:
            return

        logo_path = os.path.join(utils_path, 'bc.ppm')
        file = open(logo_path, 'r')
        magic = file.readline().strip()
        if magic != 'P3':
            self.getLogger().warning('Cannot load Blender Cave Logo !')
            return
        comment = file.readline()
        format = file.readline().strip().split(' ')
        self.getLogger().debug('Blender Cave Logo size: ' + str(format))
        highest = float(file.readline())
        texture_buffer = []
        while 1:
            line = file.readline().strip()
            try:
                value = float(line)
            except ValueError:
                break
            texture_buffer.append(int(255 * (value / highest)))
        texture_buffer = Buffer(GL_BYTE, len(texture_buffer), texture_buffer)


        glEnable(GL_TEXTURE_2D)
        texture_id_buffer = Buffer(GL_INT,1)
        glGenTextures(1, texture_id_buffer)
        self._texture_id = texture_id_buffer[0]
        glBindTexture(GL_TEXTURE_2D, self._texture_id)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, int(format[0]), int(format[1]), 0, GL_RGB,GL_UNSIGNED_BYTE, texture_buffer)
        glDisable(GL_TEXTURE_2D)
Пример #14
0
def init():
    """init function - runs once"""
    # create a new font object
    font_path = logic.expandPath('//fonts/CabinSketch.ttf')
    logic.font_id = blf.load(font_path)

    # set the font drawing routine to run
    scene = logic.getCurrentScene()
    scene.post_draw = [draw_names]
Пример #15
0
    def __init__(self, parent, name, text="", font=None, pt_size=None, color=None,
                outline_color=None, outline_size=None, outline_smoothing=None,
                shadow=False, shadow_color=[0, 0, 0, 1], shadow_blur=5,
                pos=[0, 0], sub_theme='', options=BGUI_DEFAULT):
        """
        :param parent: the widget's parent
        :param name: the name of the widget
        :param text: the text to display (this can be changed later via the text property)
        :param font: the font to use
        :param pt_size: the point size of the text to draw (defaults to 30 if None)
        :param color: the color to use when rendering the font
        :param pos: a tuple containing the x and y position
        :param sub_theme: name of a sub_theme defined in the theme file (similar to CSS classes)
        :param options: various other options

        """
        Widget.__init__(self, parent, name, None, [0, 0], pos, sub_theme, options)

        if not font:
            font = self.theme['Font']

        if Theme.path != './' and font:
            font = path.join(Theme.path, font)

        self.fontid = blf.load(font) if font else 0

        if pt_size:
            self.pt_size = pt_size
        else:
            self.pt_size = self.theme['Size']


        if color:
            self.color = color
        else:
            self.color = self.theme['Color']

        if outline_color:
            self.outline_color = color
        else:
            self.outline_color = self.theme['OutlineColor']

        if outline_size is not None:
            self.outline_size = outline_size
        else:
            self.outline_size = self.theme['OutlineSize']
        self.outline_size = int(self.outline_size)

        if outline_smoothing is not None:
            self.outline_smoothing = outline_smoothing
        else:
            self.outline_smoothing = self.theme['OutlineSmoothing']

        self.text = text
        self.shadow = shadow
        self.shadow_color = shadow_color
        self.shadow_blur = shadow_blur
Пример #16
0
def init():
    """init function - runs once"""
    # create a new font object, use external ttf file
    font_path = logic.expandPath('//Zeyada.ttf')
    # store the font indice - to use later
    logic.font_id = blf.load(font_path)

    # set the font drawing routine to run every frame
    scene = logic.getCurrentScene()
    scene.post_draw = [write]
Пример #17
0
    def test_font(self):
        print("test_font")
        import blf
        import addon_utils
#PKHG.e.g. paths()        check_contains(addon_utils,'addons')
        addon_path = addon_utils.paths()[0]
        local_font_path = addon_path +"/Ephestos/fonts"
        verdana = local_font_path + "/verdana.ttf"
        res = blf.load(verdana)
        self.assertNotEqual(res, -1)
Пример #18
0
def init():
    """init function - runs once"""
    # create a new font object, use external ttf file
    font_path = logic.expandPath('//fonts/impact.ttf')
    # store the font indice - to use later
    logic.font_id = blf.load(font_path)

    # set the font drawing routine to run every frame
    scene = logic.getCurrentScene()
    scene.post_draw = [write]
Пример #19
0
    def __init__(self, parent):
        super(Splash, self).__init__(parent)
        utils_path = os.path.join(BlenderVR_root, 'utils')
        font_path = os.path.join(utils_path, 'font.ttf')
        self._font_id = blf.load(font_path)
        self._ecg_values = ECG_VALUES
        self._message = ''
        self._ecg_values_size = len(self._ecg_values)
        self._repeat = 8
        self._total_size = self._ecg_values_size * self._repeat
        self._extinction = 3.0

        self._official_splash = (bge.logic.getCurrentScene().name ==
                                                "BlenderVR Splash Screen")

        if self._official_splash:
            return

        logo_path = os.path.join(utils_path, 'bvr-logo.ppm')
        logofile = open(logo_path, 'r')
        magic = logofile.readline().strip()
        if magic != 'P3': # check for plain ppm format
            self.logger.warning('Cannot load BlenderVR Logo (wrong .ppm format)')
            return
        comment = logofile.readline() # remove comment line (Gimp generated)
        assert comment    # avoid unused warning
        if not comment[0] == '#': # if generated file doesn't have this comment line (varies between e.g. Gimp and MagickImage)
            logoformat = comment
        else:
            logoformat = logofile.readline().strip().split(' ')
        highest = float(logofile.readline())
        texture_buffer = []
        while 1:
            line = logofile.readline().strip()
            try:
                value = [int(255 * (float(x) / highest)) for x in line.split(' ')]
            except ValueError:
                break
            texture_buffer.append(value)

        if type(texture_buffer[0]) is list:
            # from list of list to list (in line of values (per lines) scenario)
            texture_buffer = [item for sublist in texture_buffer for item in sublist]

        texture_buffer = Buffer(GL_BYTE, len(texture_buffer), texture_buffer)

        glEnable(GL_TEXTURE_2D)
        texture_id_buffer = Buffer(GL_INT, 1)
        glGenTextures(1, texture_id_buffer)
        self._texture_id = texture_id_buffer[0]
        glBindTexture(GL_TEXTURE_2D, self._texture_id)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, int(logoformat[0]),
                    int(logoformat[1]), 0, GL_RGB, GL_UNSIGNED_BYTE,
                    texture_buffer)
        glDisable(GL_TEXTURE_2D)
Пример #20
0
    def getFontID(self, font):
        if font is None or font.filepath == "<builtin>":
            self.raiseErrorMessage("BFont is not supported!")

        fontID = blf.load(font.filepath)

        if fontID == -1:
            self.raiseErrorMessage("Can't load font!")

        blf.size(fontID, 50, 72)
        return fontID
Пример #21
0
def init():
    # create a new font object, use external ttf file
    font_path = logic.expandPath('//assets/fonts/LiberationMono-Regular.ttf')
    # store the font indice - to use later
    logic.font_id = blf.load(font_path)

    # set the font drawing routine to run every frame
    scene = logic.getCurrentScene()
    scene.post_draw = [write]

    logic.text_buffer = []
Пример #22
0
    def font(self, v):
        if self._fontname == v:
            return

        self._fontname = v
        self._font = blf.load(self._fontname)

        if self._font < 0:
            self._font = 0

        self.queue_resize()
Пример #23
0
def init():
	# create a new font object, use external ttf file
	font_path = logic.expandPath('//assets/fonts/LiberationMono-Regular.ttf')
	# store the font indice - to use later
	logic.font_id = blf.load(font_path)

	# set the font drawing routine to run every frame
	scene = logic.getCurrentScene()
	scene.post_draw = [write]

	logic.text_buffer = []
Пример #24
0
	def __init__(self, parent, name, text="", font=None, pt_size=None, color=None,
				pos=[0, 0], offset=[0,0], sub_theme='', options=BGUI_NONE):
		"""
		:param parent: the widget's parent
		:param name: the name of the widget
		:param text: the text to display (this can be changed later via the text property)
		:param font: the font to use
		:param pt_size: the point size of the text to draw (defaults to 30 if None)
		:param color: the color to use when rendering the font
		:param pos: a tuple containing the x and y position
		:param sub_theme: name of a sub_theme defined in the theme file (similar to CSS classes)
		:param options: various other options

		"""
		Widget.__init__(self, parent, name, [0,0], pos, offset, sub_theme, options)

		if font:
			path = os.path.join("ge", "themes", font)
			path = logic.expandPath("//"+path)
			self.fontid = blf.load(path)
			#self.fontid = blf.load(font)
		else:
			font = self.theme['Font']
			path = os.path.join("ge", "themes", font)
			path = logic.expandPath("//"+path)
			self.fontid = blf.load(path) if font else 0
			#self.fontid = blf.load(font) if font else 0

		if pt_size:
			self.pt_size = pt_size
		else:
			self.pt_size = self.theme['Size']

		if color:
			self.color = color
		else:
			self.color = self.theme['Color']


		self.text = text
		self.dimension = 0.0
Пример #25
0
    def __init__(self, font, type, size):

        dir = '\\UI\\Fonts\\'
        font1 = 'EXO2.0-'
        font2 = 'bonn_'
        bold = 'Bold'
        extraBold = 'ExtraBold'
        regular = 'Regular'
        light = 'Light'
        format = ['.otf', '.ttf']

        self.font_info = {
            'font_id': None,
            'font_handler': None,
            'loaded_font': None
        }
        filepath = None
        if font == 'Exo':
            if type == 'Bold':
                filepath = parent[:-10] + dir + font1 + bold + format[0]
                self.font_info['loaded_font'] = filepath
            elif type == 'ExtraBold':
                filepath = parent[:-10] + dir + font1 + extraBold + format[0]
                self.font_info['loaded_font'] = filepath
            elif type == 'Regular':
                filepath = parent[:-10] + dir + font1 + regular + format[0]
                self.font_info['loaded_font'] = filepath
            elif type == 'Light':
                filepath = parent[:-10] + dir + font1 + light + format[0]
                self.font_info['loaded_font'] = filepath

        elif font == 'Bonn':
            if type == 'Bold':
                filepath = parent[:-10] + dir + font2 + bold + format[1]
            elif type == 'ExtraBold':
                print('This font does not have Extra Bold')
                filepath = None
            elif type == 'Regular':
                filepath = parent[:-10] + dir + font2 + regular + format[1]
            elif type == 'Light':
                filepath = parent[:-10] + dir + font2 + light + format[1]

        self.parent = Vector3([0, 0, 0])
        self.position = Vector3([0, 0, 0])
        self.pos_pus_parent = Vector3([
            self.parent.x + self.position.x,
            self.parent.y + self.position.y,
            self.parent.z + self.position.z,
        ])

        self.font_info['font_id'] = blf.load(filepath)
        blf.size(self.font_info['font_id'], size, 72)
        blf.enable(self.font_info['font_id'], 1)
Пример #26
0
 def __init__(self, bounds=[0, 0, 100, 20], text="", fontfile="", font_size=12, text_align=0, vertical_align=1, shadow=False):
     PControl.new.__init__(self, bounds)
     self._text = text
     self.textAlign = text_align
     self.verticalAlign = vertical_align
     self.fontSize = font_size
     
     self.fid = blf.load(fontfile) if fontfile != "" else 0
     
     self.margin = 0
     self.shadow = shadow
     
     self.drawSelection = False
Пример #27
0
 def __init__(self, bounds=[0, 0, 100, 100], fontname=""):
     PControl.new.__init__(self, bounds)        
     self.items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7"]        
     self._ibounds = {}    
     self.fid = blf.load(fontname) if fontname != "" else 0        
     self.itemHeight = 16
     
     self.on_selected = None
     self.on_draw_item = None
     
     self.backColor = default["text_background"]
     
     self._selected = -1
Пример #28
0
def init():
    """init function - runs once"""
    # create a new font object
    font_path = logic.expandPath('//fonts/Nunito.ttf')
    logic.font_id = blf.load(font_path)

    scene = logic.getCurrentScene()

    # object that contains the dynamic text
    logic.text = scene.objects["Scripts"]

    # set the font drawing routine to run   
    scene.post_draw=[write]
Пример #29
0
def load_fonts():
    ''' Load fonts '''
    loaded_fonts["main"] = {}

    fonts_path = get_fonts_path()

    # load fonts and create dictionary of Font Name : Font ID
    for font_name, font_filename in font_names.items():
        font_filepath = os.path.join(fonts_path, font_filename)
        font_id = blf.load(font_filepath)
        if font_id >= 0:
            loaded_fonts["main"][font_name] = font_id
        else:  # font not found or could not load? => use blender default font
            loaded_fonts["main"][font_name] = 0
Пример #30
0
	def configure( self, scene=0, resourcescene=0, verbose=True ):
	
		if self.configured:
			return
	
		self.verbose = verbose
		self.framecount = 0
		
		if scene is 0:
			scenes = bge.logic.getSceneList()
			for sc in scenes:
				if sc.name == "render":
					self.context = sc
					break
		else:
			self.context = scene
			
		if resourcescene is 0:
			scenes = bge.logic.getSceneList()
			for sc in scenes:
				if sc.name == "resources":
					self.resources = sc
					break
		else:
			self.resources = resourcescene
		
		if self.resources is 0 or self.context is 0:
			print( "UNABLE TO LOCATE SCENES!" )
			print( "Verify the scenes names (should be 'render' and 'resources')" )
			print( "Or pass the scene object in args to this method!" )
			print( "scenes:", bge.logic.getSceneList() )
			return
		
		self.configured = True
		self.defaultLineColor = self.rgb2vector( 255,0,0 )

		# setting default values in bge.render
		self.background( 255,255,255 )
		
		# not working in texture mode, wait a bug fix
		bge.render.disableMist()
		
		# loading default font
		font_path = bge.logic.expandPath('//ProcessingBGE/resources/TitilliumWeb-Regular.ttf')
		self.font_id = blf.load(font_path)

		if ( self.verbose ):
			print( "processing/blender inititalised" )
			print( "ready to rock!" )
    def configure(self, scene=0, resourcescene=0, verbose=True):

        if self.configured:
            return

        self.verbose = verbose
        self.framecount = 0

        if scene is 0:
            scenes = bge.logic.getSceneList()
            for sc in scenes:
                if sc.name == "render":
                    self.context = sc
                    break
        else:
            self.context = scene

        if resourcescene is 0:
            scenes = bge.logic.getSceneList()
            for sc in scenes:
                if sc.name == "resources":
                    self.resources = sc
                    break
        else:
            self.resources = resourcescene

        if self.resources is 0 or self.context is 0:
            print("UNABLE TO LOCATE SCENES!")
            print("Verify the scenes names (should be 'render' and 'resources')")
            print("Or pass the scene object in args to this method!")
            print("scenes:", bge.logic.getSceneList())
            return

        self.configured = True
        self.defaultLineColor = self.rgb2vector(255, 0, 0)

        # setting default values in bge.render
        self.background(255, 255, 255)

        # not working in texture mode, wait a bug fix
        bge.render.disableMist()

        # loading default font
        font_path = bge.logic.expandPath("//ProcessingBGE/resources/TitilliumWeb-Regular.ttf")
        self.font_id = blf.load(font_path)

        if self.verbose:
            print("processing/blender inititalised")
            print("ready to rock!")
Пример #32
0
def init():
    """init function - runs once"""
    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

    # set the font drawing routine to run every frame
    font_info["handler"] = bpy.types.SpaceView3D.draw_handler_add(
        draw_callback_px, (None, None), 'WINDOW', 'POST_PIXEL')
Пример #33
0
 def load(val):
     if val is None:
         fontid = FontManager._last_fontid
     elif type(val) is int:
         fontid = val
     elif val in FontManager._cache:
         fontid = FontManager._cache[val]
     else:
         # note: loading the same file multiple times is not a problem.
         #       blender is smart enough to cache
         fontid = blf.load(val)
         print('Loaded font "%s" as id %d' % (val, fontid))
         FontManager._cache[val] = fontid
     FontManager._last_fontid = fontid
     return fontid
Пример #34
0
 def load(val):
     if val is None:
         fontid = FontManager._last_fontid
     elif type(val) is int:
         fontid = val
     elif val in FontManager._cache:
         fontid = FontManager._cache[val]
     else:
         # note: loading the same file multiple times is not a problem.
         #       blender is smart enough to cache
         fontid = blf.load(val)
         print('Loaded font "%s" as id %d' % (val, fontid))
         FontManager._cache[val] = fontid
     FontManager._last_fontid = fontid
     return fontid
 def load(val, load_callback=None):
     if val is None:
         fontid = FontManager._last_fontid
     else:
         if val not in FontManager._cache:
             # note: loading the same file multiple times is not a problem.
             #       blender is smart enough to cache
             fontid = blf.load(val)
             print(f'Addon Common: Loaded font "{val}" as id {fontid}')
             FontManager._cache[val] = fontid
             FontManager._cache[fontid] = fontid
             if load_callback: load_callback(fontid)
         fontid = FontManager._cache[val]
     FontManager._last_fontid = fontid
     return fontid
Пример #36
0
    def __init__(self, bounds=[0, 0, 100, 100], fontname=""):
        PControl.new.__init__(self, bounds)
        self.items = [
            "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6",
            "Item 7"
        ]
        self._ibounds = {}
        self.fid = blf.load(fontname) if fontname != "" else 0
        self.itemHeight = 16

        self.on_selected = None
        self.on_draw_item = None

        self.backColor = default["text_background"]

        self._selected = -1
Пример #37
0
    def __init__(self, parent):
        super(Splash, self).__init__(parent)
        utils_path = os.path.join(BlenderVR_root, 'utils')
        font_path = os.path.join(utils_path, 'font.ttf')
        self._font_id = blf.load(font_path)
        self._ecg_values = ECG_VALUES
        self._message = ''
        self._ecg_values_size = len(self._ecg_values)
        self._repeat = 10
        self._total_size = self._ecg_values_size * self._repeat
        self._extinction = 3.0

        self._official_splash = (
            bge.logic.getCurrentScene().name == "BlenderVR Splash Screen")

        if self._official_splash:
            return

        logo_path = os.path.join(utils_path, 'bc.ppm')
        logofile = open(logo_path, 'r')
        magic = logofile.readline().strip()
        if magic != 'P3':
            self.logger.warning('Cannot load BlenderVR Logo !')
            return
        comment = logofile.readline()
        assert comment  # avoid unused warning
        logoformat = logofile.readline().strip().split(' ')
        highest = float(logofile.readline())
        texture_buffer = []
        while 1:
            line = logofile.readline().strip()
            try:
                value = float(line)
            except ValueError:
                break
            texture_buffer.append(int(255 * (value / highest)))
        texture_buffer = Buffer(GL_BYTE, len(texture_buffer), texture_buffer)

        glEnable(GL_TEXTURE_2D)
        texture_id_buffer = Buffer(GL_INT, 1)
        glGenTextures(1, texture_id_buffer)
        self._texture_id = texture_id_buffer[0]
        glBindTexture(GL_TEXTURE_2D, self._texture_id)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, int(logoformat[0]),
                     int(logoformat[1]), 0, GL_RGB, GL_UNSIGNED_BYTE,
                     texture_buffer)
        glDisable(GL_TEXTURE_2D)
Пример #38
0
    def __init__(self, parent):
        super(Splash, self).__init__(parent)
        utils_path = os.path.join(BlenderVR_root, 'utils')
        font_path = os.path.join(utils_path, 'font.ttf')
        self._font_id = blf.load(font_path)
        self._ecg_values = ECG_VALUES
        self._message = ''
        self._ecg_values_size = len(self._ecg_values)
        self._repeat = 10
        self._total_size = self._ecg_values_size * self._repeat
        self._extinction = 3.0

        self._official_splash = (bge.logic.getCurrentScene().name ==
                                                "BlenderVR Splash Screen")

        if self._official_splash:
            return

        logo_path = os.path.join(utils_path, 'bc.ppm')
        logofile = open(logo_path, 'r')
        magic = logofile.readline().strip()
        if magic != 'P3':
            self.logger.warning('Cannot load BlenderVR Logo !')
            return
        comment = logofile.readline()
        assert comment    # avoid unused warning
        logoformat = logofile.readline().strip().split(' ')
        highest = float(logofile.readline())
        texture_buffer = []
        while 1:
            line = logofile.readline().strip()
            try:
                value = float(line)
            except ValueError:
                break
            texture_buffer.append(int(255 * (value / highest)))
        texture_buffer = Buffer(GL_BYTE, len(texture_buffer), texture_buffer)

        glEnable(GL_TEXTURE_2D)
        texture_id_buffer = Buffer(GL_INT, 1)
        glGenTextures(1, texture_id_buffer)
        self._texture_id = texture_id_buffer[0]
        glBindTexture(GL_TEXTURE_2D, self._texture_id)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, int(logoformat[0]),
                    int(logoformat[1]), 0, GL_RGB, GL_UNSIGNED_BYTE,
                    texture_buffer)
        glDisable(GL_TEXTURE_2D)
Пример #39
0
def init(cont):
    """init function - runs once"""
    global active_camera, game_timer, bamboo_counter, panda, level
    scene = logic.getCurrentScene()
    active_camera = cont.owner
    bamboo_counter = scene.objects["bambou_counter"]
    panda = scene.objects["Panda"]
    level = logic.globalDict["level"]
    # create a new font object, use external ttf file
    font_path = logic.expandPath('//text/Big_Bottom_Cartoon_AD.ttf')
    # store the font indice - to use later
    logic.font_id = blf.load(font_path)

    # set the font drawing routine to run every frame
    scene.post_draw = [write]
    # initialize the timer at the start of the scene
    active_camera["Timer"] = game_timer
Пример #40
0
def text_init(loc, rot):
    import os
    global fonting
    global handle
    font_path = bpy.path.abspath('//Zeyada.ttf')

    if os.path.exists(font_path):
        font_info["font_id"] = blf.load(font_path)
    else:
        font_info["font_id"] = 1

    loc_2d = bpy_extras.view3d_utils.location_3d_to_region_2d(bpy.context.region, bpy.context.space_data.region_3d, loc)

    handle = bpy.types.SpaceView3D.draw_handler_add(
        draw_callback_px, (None, None, loc_2d, rot), 'WINDOW', 'POST_PIXEL'
    )
    fonting = True
Пример #41
0
    def configure(self, verbose=True):

        global pbgeversion

        if self.configured:
            return

        self.verbose = verbose
        self.framecount = 0

        self.scene = bge.logic.getCurrentScene()
        self.root = bge.logic.getCurrentController().owner
        self.template_cube = 0
        self.template_cylinder = 0
        self.template_empty = 0
        self.template_plane = 0
        self.template_sphere = 0
        self.template_spot = 0
        self.template_2D_circle = 0
        self.template_2D_square = 0
        self.template_2D_triangle = 0
        self.templates = {}
        self.generatedObjects = {}
        self.locateTemplates()

        self.configured = True

        # lines and text colors
        self.lcolor = self.rgb2vector(255, 0, 0)
        self.tcolor = self.rgb2vector(255, 255, 255)
        self.tsize = 50

        # setting default values in bge.render
        self.background(255, 255, 255)

        # not working in texture mode, wait a bug fix
        bge.render.disableMist()

        # loading default font
        font_path = bge.logic.expandPath(
            '//ProcessingBGE/resources/TitilliumWeb-Regular.ttf')
        self.font = blf.load(font_path)

        if (self.verbose):
            print("processingBGE", pbgeversion, "started & ready to rock!")
Пример #42
0
	def configure( self, verbose=True ):
		
		global pbgeversion
		
		if self.configured:
			return
	
		self.verbose = verbose
		self.framecount = 0
		
		self.scene = bge.logic.getCurrentScene()
		self.root =  bge.logic.getCurrentController().owner
		self.template_cube = 0
		self.template_cylinder = 0
		self.template_empty = 0
		self.template_plane = 0
		self.template_sphere = 0
		self.template_spot = 0
		self.template_2D_circle = 0
		self.template_2D_square = 0
		self.template_2D_triangle = 0
		self.templates = {}
		self.generatedObjects = {}
		self.locateTemplates()

		self.configured = True

		# lines and text colors
		self.lcolor = self.rgb2vector( 255,0,0 )
		self.tcolor = self.rgb2vector( 255,255,255 )
		self.tsize = 50

		# setting default values in bge.render
		self.background( 255,255,255 )
		
		# not working in texture mode, wait a bug fix
		bge.render.disableMist()
		
		# loading default font
		font_path = bge.logic.expandPath('//ProcessingBGE/resources/TitilliumWeb-Regular.ttf')
		self.font = blf.load(font_path)

		if ( self.verbose ):
			print( "processingBGE", pbgeversion, "started & ready to rock!" )
Пример #43
0
def draw_text_custom(text, x, y, font_file_path, shadow_on, align="LEFT", size=12, color=(1.0, 1.0, 1.0, 1.0)):
    font_path = font_file_path
    font_id = blf.load(font_path)
    font = font_id

    blf.size(font, size, int(dpi))
    glColor4f(*color)

    if shadow_on == "ON":
        blf.shadow(font, 5, 0.0, 0.0, 0.0, 1.0)

    if align == "LEFT":
        blf.position(font, x, y, 0)
    else:
        width, height = blf.dimensions(font, text)
        if align == "RIGHT":
            blf.position(font, x - width, y, 0)

    blf.draw(font, text)
Пример #44
0
 def __init__(
     self,
     text,
     fontname="arialbd.ttf",
     fontsize=24,
     bold=False,
     italic=False,
     alignment="left",
     # PKHG.INFO a real Text needs a max_with > 0 !!!
     max_width=200,
 ):
     #### PKHG idea to make scrolling easy?
     """
     max_nr_of_lines >= 1
     show lines from startline >= 0
     show_nr_of_lines
     show_upto = min(startline + show_nr_of_lines, max_nr_of_lines)
     ==> range(startline,show_upto,1)
     problem, if because of width lines were added?!
     """
     super(Text, self).__init__()
     tmp = addon_utils.paths()[0] + "/Ephestos/fonts/" + fontname
     self.font = blf.load(tmp)
     blf.size(self.font, fontsize, 72)  # DPI = 72 !!
     self.background_color = [0, 0, 0, 1]
     # PKHG.??? if a of background_color  not 1 strange things can happen
     # 4jul12 show about use input move about =>strange behavior
     self.text = text
     self.words = []
     self.lines = []
     self.fontname = fontname
     self.fontsize = fontsize
     self.bold = bold
     self.italic = italic
     self.alignment = alignment
     self.max_width = max(20, min(max_width, 800))
     #        self.color = (.0, 1.0, 1.0, 1.0) #PKHG 7jul12 white forced in draw
     self.max_line_width = 0
     self.adjust_text(text)
Пример #45
0
    def __init__(self, font, toggle_key=None):
        """Console constructor

		Arguments:
			font - path to font file
			toggle_key - keycode to enable/disable console"""
        global SCROLLBACK, WRAP
        self.toggle_key = toggle_key

        self.active = False

        # GUI
        view_buf = Buffer(GL_INT, 4)
        glGetIntegerv(GL_VIEWPORT, view_buf)
        view = view_buf.to_list()

        self.text_size = [None] * 2

        self.text_fontid = blf.load(font) if font else 0
        blf.size(self.text_fontid, 14, 72)
        self.text_size[0], self.text_size[1] = blf.dimensions(
            self.text_fontid, "W")
        self._text = ''

        SCROLLBACK = int(SCROLLBACK / (2 * self.text_size[1]))
        WRAP = int(WRAP / (self.text_size[0]))

        # Console
        self.namespace = default_namespace()
        self.console = InteractiveConsole(self.namespace)
        self.cursor = 0
        self.edit_text = ''
        self.scrollback = []
        self.history = ['']
        self.is_multiline = False

        message = """Interactive Console"""
        self.add_scrollback(message)
Пример #46
0
    def execute(self, context):
        #print("Do Exec")
        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

        # set the font drawing routine to run every frame
        #font_info["handler"] = bpy.types.SpaceView3D.draw_handler_add(self.draw_callback_px, (None, None), 'WINDOW', 'POST_PIXEL')

        context.window_manager.modal_handler_add(self)
        self._updating = False
        self._timer = context.window_manager.event_timer_add(
            time_step=0.5, window=context.window)
        args = (context, None)
        self._handle = bpy.types.SpaceView3D.draw_handler_add(
            self.draw_callback_px, args, 'WINDOW', 'POST_PIXEL')
        return {'RUNNING_MODAL'}
Пример #47
0
    def __init__(self, target=None,
                 action='nop', #PKHG.??? was None
                 label='trigger',
                 fontname="verdana.ttf",
                 fontsize=10,
                 bold=False,
                 italic=False):
        #PKHG>??? once and for all that font stuff?
        super(Trigger, self).__init__()
        import  addon_utils
        path_to_local_fonts  = addon_utils.paths()[0] + "/Ephestos/fonts"
        font = path_to_local_fonts + "/" + fontname
        font_id = blf.load(font)
        blf.size(font_id, 16, 72) #pKHG needed to adjust text with!
        dims_x,dims_y = blf.dimensions(font_id, label)
#        self.my_name_size = dims_x 
#        mylabel_width = int(dims_x) + 75
#        bounds = Rectangle(Point(0,0),Point(mylabel_width, int(dims_y) + 20))
#        super(Trigger, self).__init__(bounds = bounds)
        
        self.set_width(int(dims_x) + 2)
        self.set_height(int(dims_y) + 15)   #PKHG old: 20)
        self.name = label
        self.action = action
Пример #48
0
	def font(self, font):
		font_path = logic.expandPath('//gui/font/' + font + '.ttf')
		if font not in Label._fontname_id: Label._fontname_id[font] = blf.load(font_path)
Пример #49
0
	def __init__(self, path=None):
		self.id = 0 if path is None else blf.load(path)
		self.size = 14.0
		self.shadowed = True
		self.shadow_offset = [0, -1]
Пример #50
0
	def load(self, filename):
		return blf.load(filename)
def initializeExternalFontId():
    font_file = r"C:\Users\tonton\Downloads\JetBrainsMono-1.0.3\JetBrainsMono-1.0.3\ttf\JetBrainsMono-Regular.ttf"
    print("Font Loaded : " + font_file)  #debug
    font_info["font_id"] = blf.load(font_file)
Пример #52
0
    def __init__(self, parent):
        super(Splash, self).__init__(parent)
        utils_path = "/".join((BlenderVR_root, 'utils'))
        font_path = "/".join((utils_path, 'font.ttf'))
        self._font_id = blf.load(font_path)
        self._ecg_values = ECG_VALUES
        self._message = ''
        self._ecg_values_size = len(self._ecg_values)
        self._repeat = 8
        self._total_size = self._ecg_values_size * self._repeat
        self._extinction = 3.0

        self._official_splash = (
            bge.logic.getCurrentScene().name == "BlenderVR Splash Screen")

        if self._official_splash:
            return

        logo_path = "/".join((utils_path, 'bvr-logo.ppm'))
        logofile = open(logo_path, 'r')
        magic = logofile.readline().strip()
        if magic != 'P3':  # check for plain ppm format
            self.logger.warning(
                'Cannot load BlenderVR Logo (wrong .ppm format)')
            return
        comment = logofile.readline()  # remove comment line (Gimp generated)
        assert comment  # avoid unused warning
        if not comment[
                0] == '#':  # if generated file doesn't have this comment line (varies between e.g. Gimp and MagickImage)
            logoformat = comment
        else:
            logoformat = logofile.readline().strip().split(' ')
        highest = float(logofile.readline())
        texture_buffer = []
        while 1:
            line = logofile.readline().strip()
            try:
                value = [
                    int(255 * (float(x) / highest)) for x in line.split(' ')
                ]
            except ValueError:
                break
            texture_buffer.append(value)

        if type(texture_buffer[0]) is list:
            # from list of list to list (in line of values (per lines) scenario)
            texture_buffer = [
                item for sublist in texture_buffer for item in sublist
            ]

        texture_buffer = Buffer(GL_BYTE, len(texture_buffer), texture_buffer)

        glEnable(GL_TEXTURE_2D)
        texture_id_buffer = Buffer(GL_INT, 1)
        glGenTextures(1, texture_id_buffer)
        self._texture_id = texture_id_buffer[0]
        glBindTexture(GL_TEXTURE_2D, self._texture_id)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, int(logoformat[0]),
                     int(logoformat[1]), 0, GL_RGB, GL_UNSIGNED_BYTE,
                     texture_buffer)
        glDisable(GL_TEXTURE_2D)
Пример #53
0
def init(controller):
    font_path = bge.logic.expandPath('//fonts/DejaVuSans.ttf')
    bge.logic.font_id = blf.load(font_path)
    scene = bge.logic.getCurrentScene()
    scene.post_draw = [write]
Пример #54
0
 def load(self, filename):
     return blf.load(filename)
Пример #55
0
 def __init__(self, fileName=None):
     self.id = blf.load(fileName) if fileName is not None else 0
     self.size = 18.0