Esempio n. 1
0
    def draw(self):
        r = ui.Rect(*self.bounds).inset(1, 1)
        s = ui.Path.oval(*r)
        s.line_width = 2

        ui.set_color('silver')
        s.fill()
        ui.set_color('black')
        s.stroke()

        ui.set_color('white')
        r = ui.Rect(*self.bounds).inset(3, 3)
        s = ui.Path.oval(*r)
        s.line_width = 1
        s.stroke()
        if self.selected:
            ui.set_color('red')
            ui.set_shadow('black', 0, 0, 15)
            r = ui.Rect(*self.bounds).inset(18, 18)
            s = ui.Path.oval(*r)
            s.fill()
        else:
            ui.set_color('darkgray')
            ui.set_shadow('black', 0, 0, 15)
            r = ui.Rect(*self.bounds).inset(18, 18)
            s = ui.Path.oval(*r)
            s.fill()
Esempio n. 2
0
	def draw(self):
	
		'1'
		#Setup path of window shape
		path = ui.Path.rect(0, 0, self.width-10, self.height-10)
		
		#Draw background
		ui.set_color((0.95,0.95,0.95,0.5))
		path.fill()
		
		
		'2'
		#Setup mask by creating image
		from PIL import ImageDraw
		i = Image.new('RGBA',(520,290), (255,255,255,0))
		draw = ImageDraw.Draw(i)
		draw.rectangle((self.width-10, 0, self.width, self.height),fill=(0,0,0,255))
		draw.rectangle((0, self.height-10, self.width, self.height),fill=(0,0,0,255))
		
		#Convert to UI, apply the mask, and draw shadow!
		i = pil_to_ui(i)
		i.clip_to_mask()
		ui.set_color((1,1,1,1))
		ui.set_shadow("black",-2,-2,10)
		path.fill()
Esempio n. 3
0
	def draw(self):
		
		'1'
		#Setup path of window shape
		path = ui.Path.rect(0, 0, self.width-10, self.height-10)
		
		#Draw background
		ui.set_color((0.95,0.95,0.95,0.5))
		path.fill()
		

		'2'
		#Setup mask by creating image
		from PIL import ImageDraw
		i = Image.new('RGBA',(520,290), (255,255,255,0))
		draw = ImageDraw.Draw(i)
		draw.rectangle((self.width-10, 0, self.width, self.height),fill=(0,0,0,255))
		draw.rectangle((0, self.height-10, self.width, self.height),fill=(0,0,0,255))
		
		#Convert to UI, apply the mask, and draw shadow!
		i = pil_to_ui(i)
		i.clip_to_mask()
		ui.set_color((1,1,1,1))
		ui.set_shadow("black",-2,-2,10)
		path.fill()
Esempio n. 4
0
 def draw_face(self, diameter, border, font_size):
     with ui.ImageContext(diameter, diameter) as ctx:
         ui.set_color('white')
         circle = ui.Path.oval(border / 2, border / 2, diameter - border,
                               diameter - border)
         circle.line_width = border - 1
         circle.fill()
         ui.set_color('silver')
         with ui.GState():
             ui.set_shadow((0, 0, 0, 0.35), 0, 1, 5.0)
             circle.stroke()
         angle = (-pi / 2) + (pi * 2) / 12.0
         for i in range(1, 13):
             number = str(i)
             x = diameter / 2 + cos(angle) * (diameter / 2 -
                                              font_size * 1.2)
             y = diameter / 2 + sin(angle) * (diameter / 2 -
                                              font_size * 1.2)
             font = ('HelveticaNeue-UltraLight', font_size)
             w, h = ui.measure_string(number, font=font)
             rect = (x - 50, y - h / 2, 100, h)
             ui.draw_string(number,
                            rect=rect,
                            font=font,
                            alignment=ui.ALIGN_CENTER)
             angle += (pi * 2.0) / 12.0
         return ctx.get_image()
Esempio n. 5
0
 def draw(self):
     # Set drawing attributes
     ui.set_color(self._color)
     ui.set_shadow(*self._shadow)
     # Calculations
     scale_x = self.width / self._pathsize[0]
     scale_y = self.height / self._pathsize[0]
     # Scale the path
     new_path = ui2.path_helpers.scale_path(self._path, (scale_x, scale_y))
     new_path.fill()
Esempio n. 6
0
	def draw(self):
		self.buttonsize = int(self.height/16)
		self.startx=int((self.width/2-self.height/2))
		
		buttonsize=self.buttonsize
		for x in range(16):
			for y in range(16):
				frame=(self.startx+x*buttonsize,y*buttonsize,buttonsize,buttonsize)
				p=ui.Path.rect(*frame)
				ui.set_color(self.load[x,y])
				p.fill()
		
		path=self.Djk2UI(self.pathCalc())
		
		ui.set_color((0,0,1))
		ui.set_shadow((0,0,0),2,2,5)
		path.stroke()
Esempio n. 7
0
    def draw(self):
        r = min(self.width, self.height) / 2 * 0.9

        circle = ui.Path.oval(0, 0, r * 2, r * 2)
        circle.line_width = 6

        shadow = ('black', 0, 0, 15)
        ui.set_shadow(*shadow)
        ui.set_color('silver')
        #self.face = ShapeNode(circle, 'white', 'silver', shadow=shadow)
        circle.fill()
        circle.stroke()

        for i in range(12):
            label = LabelNode(str(i + 1),
                              font=('HelveticaNeue-UltraLight', 0.2 * r))
            label.color = 'black'
            a = 2 * pi * (i + 1) / 12.0
            #label.position = sin(a)*(r*0.85), cos(a)*(r*0.85)
            label.position = sin(a) * (r * 0.85), cos(a) * (r * 0.85)
            #print(label.position)
            ui.draw_string(str(i + 1),
                           rect=(r + label.position[0], r + label.position[1],
                                 0, 0),
                           font=('<system>', 18),
                           color='black',
                           alignment=ui.ALIGN_CENTER,
                           line_break_mode=ui.LB_WORD_WRAP)

        #self.hands = []
        #hand_attrs = [(r*0.6, 8, 'black'), (r*0.9, 8, 'black'), (r*0.9, 4, 'red')]
        #self.hands = [(r*0.6, 8, 'black'), (r*0.9, 8, 'black'), (r*0.9, 4, 'red')]
        t = datetime.now()
        tick = -2 * pi / 60.0
        seconds = t.second + t.microsecond / 1000000.0
        minutes = t.minute + seconds / 60.0
        hours = (t.hour % 12) + minutes / 60.0
        self.hands[0] = 5 * tick * hours
        self.hands[1] = tick * minutes
        self.hands[2] = tick * seconds
        #print(type(self.hands))
        for l, w, color in self.hands:
            #shape = ShapeNode(ui.Path.rounded_rect(0, 0, w, l, w/2), color)
            shape = ui.Path.rounded_rect(0, 0, w, l, w / 2)
            #shape.anchor_point = (0.5, 0)
            shape.stroke()
Esempio n. 8
0
    def update_texture(self):
        if self._suspend_updates or not self.path:
            return

        if self.shadow:
            shadow_color = self.shadow[0]
            shadow_offset_x = self.shadow[1]
            shadow_offset_y = self.shadow[2]
            shadow_radius = self.shadow[3]
        else:
            shadow_offset_x = 0
            shadow_offset_y = 0
            shadow_radius = 0

        shadow_left = shadow_radius - shadow_offset_x
        shadow_right = shadow_radius + shadow_offset_x
        shadow_top = shadow_radius - shadow_offset_y
        shadow_bottom = shadow_radius + shadow_offset_y

        lw = self.path.line_width
        path_bounds = self.path.bounds
        w = max(
            1,
            math.ceil(path_bounds.w + abs(shadow_left) + abs(shadow_right)) +
            lw)
        h = max(
            1,
            math.ceil(path_bounds.h + abs(shadow_top) + abs(shadow_bottom)) +
            lw)

        with ui.ImageContext(w, h) as ctx:
            ui.concat_ctm(
                ui.Transform.translation(
                    lw / 2 + max(0, shadow_left) - path_bounds.x,
                    lw / 2 + max(0, shadow_top) - path_bounds.y))
            ui.set_color(self.fill_color)
            with ui.GState():
                if self.shadow:
                    ui.set_shadow(shadow_color, shadow_offset_x,
                                  shadow_offset_y, shadow_radius)
                self.path.fill()
            if self.path.line_width > 0:
                ui.set_color(self.stroke_color)
                self.path.stroke()
            img = ctx.get_image()
        self.texture = Texture(img)
Esempio n. 9
0
	def draw(self):
		self.buttonsize = int(self.height / CELLS_PER_ROW)
		self.startx = int(self.width / 2 - self.height / 2)

		buttonsize = self.buttonsize
		for x in range(CELLS_PER_ROW):
			for y in range(CELLS_PER_ROW):
				frame = (self.startx+x*buttonsize, y*buttonsize, buttonsize, buttonsize)
				p = ui.Path.rect(*frame)
				ui.set_color(self.load[x, y])
				p.fill()
		
		path=self.Djk2UI(self.pathCalc())
		
		ui.set_color('blue')
		ui.set_shadow('black', 2, 2, 5)
		path.stroke()
Esempio n. 10
0
    def draw_string(self):
        color = 'black'
        # uiのメソッドによるフォント描画
        with ui.GState():
            if self.is_enable_title is True:
                ui.set_shadow('gray', 1, 1, 0)
                ui.draw_string(self.string_A_D,
                               rect=(10, 10, 300, 20),
                               font=('HiraMinProN-W6', 20),
                               color=color)
                ui.draw_string(self.string_A_D_s,
                               rect=(10, 30, 300, 10),
                               font=('HiraMinProN-W6', 10),
                               color=color)
                ui.draw_string(self.string_C_D,
                               rect=(350, 10, 300, 20),
                               font=('HiraMinProN-W6', 20),
                               color=color)
                ui.draw_string(self.string_C_D_s,
                               rect=(350, 30, 300, 10),
                               font=('HiraMinProN-W6', 10),
                               color=color)
                ui.draw_string(self.string_T_D,
                               rect=(10, 150, 300, 20),
                               font=('HiraMinProN-W6', 20),
                               color=color)
                ui.draw_string(self.string_T_D_s,
                               rect=(10, 170, 300, 10),
                               font=('HiraMinProN-W6', 10),
                               color=color)
                ui.draw_string(self.string_E_D,
                               rect=(350, 135, 300, 20),
                               font=('HiraMinProN-W6', 20),
                               color=color)
                ui.draw_string(self.string_E_D_s,
                               rect=(350, 155, 300, 10),
                               font=('HiraMinProN-W6', 10),
                               color=color)

            for character in self.characters:
                if character.is_enable_name is True:
                    ui.draw_string(character.name_string,
                                   rect=(character.name_x, character.name_y,
                                         300, 15),
                                   font=('HiraMinProN-W6', 15),
                                   color=color)
Esempio n. 11
0
    def draw(self):
        self.buttonsize = int(self.height / 16)
        self.startx = int((self.width / 2 - self.height / 2))

        buttonsize = self.buttonsize
        for x in range(16):
            for y in range(16):
                frame = (self.startx + x * buttonsize, y * buttonsize,
                         buttonsize, buttonsize)
                p = ui.Path.rect(*frame)
                ui.set_color(self.load[x, y])
                p.fill()

        path = self.Djk2UI(self.pathCalc())

        ui.set_color((0, 0, 1))
        ui.set_shadow((0, 0, 0), 2, 2, 5)
        path.stroke()
Esempio n. 12
0
    def draw_text(self, **kwargs):
        if kwargs:
            self.do_kwargs(**kwargs)

        r = ui.Rect(*self.rect).inset(*self.margin).translate(*self.origin)

        my_center = r.center()
        font_size = self.font_size

        if not font_size:
            result = self.get_max_fontsize()
            r1 = ui.Rect(*result[1])
            font_size = result[0]
        else:
            w, h = ui.measure_string(self.text,
                                     max_width=0,
                                     font=(self.font_name, font_size),
                                     alignment=ui.ALIGN_CENTER,
                                     line_break_mode=ui.LB_TRUNCATE_TAIL)
            r1 = ui.Rect(0, 0, w, h)

        r1.center(my_center)
        with ui.GState():
            if self.rotate:
                '''
				help from @omz
				https://forum.omz-software.com/topic/3180/understanding-ui-transform-rotation
				'''
                ui.concat_ctm(ui.Transform.translation(*r1.center()))
                ui.concat_ctm(ui.Transform.rotation(math.radians(self.rotate)))
                ui.concat_ctm(ui.Transform.translation(*r1.center() * -1))

            if self.use_shadow:
                ui.set_shadow(*self.shadow_params)

            ui.draw_string(self.text,
                           rect=r1,
                           font=(self.font_name, font_size),
                           color=self.text_color,
                           alignment=ui.ALIGN_CENTER,
                           line_break_mode=ui.LB_TRUNCATE_TAIL)
Esempio n. 13
0
	def draw_face(self, diameter, border, font_size):
		with ui.ImageContext(diameter, diameter) as ctx:
			ui.set_color('white')
			circle = ui.Path.oval(border/2, border/2, diameter-border, diameter-border)
			circle.line_width = border-1
			circle.fill()
			ui.set_color('silver')
			with ui.GState():
				ui.set_shadow((0, 0, 0, 0.35), 0, 1, 5.0)
				circle.stroke()
			angle = (-pi/2) + (pi*2)/12.0
			for i in xrange(1, 13):
				number = str(i)
				x = diameter/2 + cos(angle) * (diameter/2 - font_size*1.2)
				y = diameter/2 + sin(angle) * (diameter/2 - font_size*1.2)
				font = ('HelveticaNeue-UltraLight', font_size)
				w, h = ui.measure_string(number, font=font)
				rect = (x-50, y-h/2, 100, h)
				ui.draw_string(number, rect=rect, font=font, alignment=ui.ALIGN_CENTER)
				angle += (pi*2.0)/12.0			
			return ctx.get_image()
Esempio n. 14
0
	def update_texture(self):
		if self._suspend_updates or not self.path:
			return
			
		if self.shadow:
			shadow_color = self.shadow[0]
			shadow_offset_x = self.shadow[1]
			shadow_offset_y = self.shadow[2]
			shadow_radius = self.shadow[3]
		else:
			shadow_offset_x = 0
			shadow_offset_y = 0
			shadow_radius = 0
			
		shadow_left = shadow_radius - shadow_offset_x
		shadow_right = shadow_radius + shadow_offset_x
		shadow_top = shadow_radius - shadow_offset_y
		shadow_bottom = shadow_radius + shadow_offset_y
		
		lw = self.path.line_width
		path_bounds = self.path.bounds
		w = max(1, math.ceil(path_bounds.w + abs(shadow_left) + abs(shadow_right)) + lw)
		h = max(1, math.ceil(path_bounds.h + abs(shadow_top) + abs(shadow_bottom)) + lw)
		
		with ui.ImageContext(w, h) as ctx:
			ui.concat_ctm(ui.Transform.translation(lw/2 + max(0, shadow_left) - path_bounds.x, lw/2 + max(0, shadow_top) - path_bounds.y))
			ui.set_color(self.fill_color)
			with ui.GState():
				if self.shadow:
					ui.set_shadow(shadow_color, shadow_offset_x, shadow_offset_y, shadow_radius)
				self.path.fill()
			if self.path.line_width > 0:
				ui.set_color(self.stroke_color)
				self.path.stroke()
			img = ctx.get_image()
		self.texture = Texture(img)
Esempio n. 15
0
	def draw(self):
		path = ui.Path.rect(0, 0, self.width-10,self.height-10)
		ui.set_color((0.9,0.9,0.9,1.0))
		ui.set_shadow("black",0,0,10)
		path.fill()
Esempio n. 16
0
    def draw(self):
        # 水面
        if not self.surface is None:
            surface = self.surface
            a_x, a_y, a_z = surface.corner_A()
            b_x, b_y, b_z = surface.corner_B()
            c_x, c_y, c_z = surface.corner_C()
            d_x, d_y, d_z = surface.corner_D()

            a_x, a_y = self.projection(a_x, a_y, a_z)
            b_x, b_y = self.projection(b_x, b_y, b_z)
            c_x, c_y = self.projection(c_x, c_y, c_z)
            d_x, d_y = self.projection(d_x, d_y, d_z)

            path_s = ui.Path()
            path_s.move_to(a_x, a_y)
            path_s.line_to(b_x, b_y)
            path_s.line_to(c_x, c_y)
            path_s.line_to(d_x, d_y)
            path_s.line_to(a_x, a_y)

            ui.set_color(surface.color)
            path_s.fill()

        # uiのメソッドによるフォント描画
        with ui.GState():
            ui.set_shadow('gray', 10, 10, 0)
            ui.draw_string(self.string_S,
                           rect=(130, 130, 300, 40),
                           font=('HiraMinProN-W6', 30),
                           color='black')
            ui.draw_string(self.string_D,
                           rect=(130, 290, 300, 40),
                           font=('HiraMinProN-W6', 30),
                           color='black')
            ui.draw_string(self.string_G,
                           rect=(130, 450, 300, 40),
                           font=('HiraMinProN-W6', 30),
                           color='black')

        # 文字を描画する
        for character in self.characters:
            # [[x,y,z,type,flag],[],...],[]
            contours = character.glyph(self.height)

            # フォントを描画する
            for points in contours:
                if len(points) < 1:
                    continue

                # 座標点、制御点を描画する
                # line,curve 黒塗り
                # control 白抜き
                if self.is_Fill is False:
                    self.draw_glyph_points(points)

                path = ui.Path()
                # 最初のglyph座標
                if points[0][4] is True:
                    p_x, p_y = self.projection(points[0][0], points[0][1],
                                               points[0][2])
                    path.move_to(p_x, p_y)
                else:
                    continue

                controls = []  # 制御点を格納する
                # 2番目以降のglyph座標
                for i in range(1, len(points)):
                    if points[i][4] is True:
                        self.draw_glyph(points[i], controls, path)

                # 最後のglyph座標
                self.draw_glyph(points[0], controls, path)

                ui.set_color('black')
                if self.is_Fill is True:
                    path.fill()
                else:
                    path.stroke()
Esempio n. 17
0
	def stroke(self):
		with ui.GState():
			ui.set_color(self.s_clr)
			ui.set_shadow('darkgray', .5, .5, 8)
			self.shape.line_width = self.line_width
			self.shape.stroke()
Esempio n. 18
0
# coding: utf-8

# https://forum.omz-software.com/topic/1942/drop-shadow-behind-ui-view

import ui

with ui.ImageContext(100, 100) as ctx:
	ui.set_shadow('blue', 5, 5, 2)
	with ui.GState():
		ui.concat_ctm(ui.Transform.rotation(0.78))
		ui.draw_string('    Rotated text')
	ui.draw_string('Not rotated')
	ctx.get_image().show()
	
#==============================

class shadowview(ui.View):
	def draw(self):
		path = ui.Path.rect(0, 0, self.width-10,self.height-10)
		ui.set_color((0.9,0.9,0.9,1.0))
		ui.set_shadow("black",0,0,10)
		path.fill()
		
#==============================

class shadowview(ui.View):
	'''A class for a ui.View that has a shadow behind it.
	
	This is accomplished by:
	1. Draw the background
	2. Redraw with a shadow, but set clipping so only the edge of the shadow