def draw(self): # background set_color(*self.style['bg-color']) drawCSSRectangle(size=self.size, style=self.style) # content dynamic update with gx_matrix: glTranslatef(self.style['margin'][3], self.style['margin'][2], 0) # draw precalculated background self._current_cache['background'].draw() # draw active keys layer # +2 and -4 result of hard margin coded in _do_update (m = 3 * s) # we substract 1 cause of border (draw-border is activated.) set_color(*self.style['color-down']) for key, size in self._active_keys: x, y, w, h = size drawCSSRectangle(pos=(x+2, y+2), size=(w-4, h-4), style=self.style, prefix='key', state='down') # search the good scale for current precalculated keys layer if self._last_update_scale == self.scale: s = 1. / self.scale# / self._last_update_scale glScalef(s, s, s) else: s = 1. / self._last_update_scale glScalef(s, s, s) self._current_cache['keys'].draw()
def draw(self): w = self.get_parent_window() if not w: return self.size = w.size set_color(*self.style['bg-color']) drawCSSRectangle(size=self.size, style=self.style)
def on_popup_draw(self): self._xml.root.center = self.get_parent_window().center popup = self._xml.getById('popup') set_color(*self.style.get('bg-color-full')) drawCSSRectangle(pos=Vector(popup.pos) - (10, 10), size=Vector(popup.size) + (20, 20), style=self.style)
def draw(self): b = self.bordersize b2 = b * 2 set_color(*self.style['bg-color']) drawCSSRectangle((-b, -b), (self.width + b2, self.height + b2), style=self.style) super(MTVideo, self).draw()
def draw(self): px, py = self.style['padding'] px2, py2 = px / 2, py / 2 if self.orientation == 'vertical': pos = (self.x + px2, self.y + self.value_min * self.ratio + py2) size = (self.width - px, (self.value_max - self.value_min) * self.ratio - py) textposmin = (self.x + self.width, self.y + self.value_min * self.ratio) textposmax = (self.x + self.width, self.y + self.value_max * self.ratio) elif self.orientation == 'horizontal': pos = (self.x + self.value_min * self.ratio + px2, self.y + py2) size = ((self.value_max - self.value_min) * self.ratio - px, self.height - py) textposmin = (self.x + self.value_min * self.ratio, self.y + self.height) textposmax = (self.x + self.value_max * self.ratio, self.y + self.height) # draw outer rectangle set_color(*self.style.get('bg-color')) drawCSSRectangle(pos=self.pos, size=self.size, style=self.style) # draw inner rectangle set_color(*self.style.get('slider-color')) drawCSSRectangle(pos=pos, size=size, style=self.style, prefix='slider') if self.showtext and len(self.touchstarts): drawLabel(u'%.1f' % (self.value_min), pos=textposmin, font_size=self.style['font-size']) drawLabel(u'%.1f' % (self.value_max), pos=textposmax, font_size=self.style['font-size'])
def draw(self): super(MyScribbleWidget,self).draw() # set_color(1, 1, 1) d_txt = self.potential_deleted_text if d_txt: x = int(time.time()) % 2 if x == 0: b_col = d_txt.style['bg-color'] d_txt.style['bg-color'] = d_txt.style['border-color'] d_txt.style['border-color'] = b_col _del_list = [] for k in self.touch_positions.keys(): _points = self.touch_positions[k]['Cdata'] if not len(_points): _del_list.append(k) continue _colour = self.touch_positions[k]['Color'] if self.potential_deleted_lines == k: x = int(time.time()) % 2 if x == 0: _colour = DELETED_LINE else: self.touch_positions[k]['Color'] = RED set_color(*_colour) drawLine(_points) for k in _del_list: del self.touch_positions[k]
def draw(self): if self._texture: set_color(*self.color) drawTexturedRectangle(texture=self._texture, pos=self.pos, size=self.size) else: set_color(0, 0, 0) drawRectangle(pos=self.pos, size=self.size)
def draw_background(self): set_color(*self.style.get('bg-color')) state = 'active' is self._is_active_input or None drawCSSRectangle(pos=self.pos, size=self.size, style=self.style, state=state)
def draw(self): if not self.layout.visible: return set_color(*self.style.get('bg-color')) drawCSSRectangle(pos=self.layout.pos, size=self.layout.size, style=self.style)
def on_popup_draw(self): self._xml.root.center = self.get_parent_window().center popup = self._xml.getById('popup') set_color(*self.style.get('bg-color-full')) drawCSSRectangle( pos=Vector(popup.pos) - (10, 10), size=Vector(popup.size) + (20, 20), style=self.style)
def draw(self): if self.selected: set_color(1,0,0,0.3) drawRectangle(self.to_widget(*self.widget.pos), self.widget.size) set_color(1,.3,0) for c in self.child_layout.children: drawLine((self.node_btn.centerright,c.node_btn.centerleft), width=2)
def draw(self): '''Draw the current image camera''' if self._texture: set_color(*self.color) drawTexturedRectangle(self._texture, pos=self.pos, size=self.size) else: drawRectangle(pos=self.pos, size=self.size) drawLabel('No Camera :(', pos=(self.width/2, self.height/2))
def draw_cursor(self, x, y): '''Draw the cursor on the widget ''' if not int(self.cursor_fade): return set_color(*self.style.get('cursor-color')) drawRectangle(size=(2, -self.line_height), pos=(x + self.cursor_offset() - self._scroll_x, y))
def draw_background(self): if self.is_active_input: set_color(*self.style.get('bg-color')) drawCSSRectangle(pos=self.pos, size=self.size, style=self.style, state='active') else: set_color(*self.style.get('bg-color')) drawCSSRectangle(pos=self.pos, size=self.size, style=self.style)
def draw(self): if self.selected: set_color(1, 0, 0, 0.3) drawRectangle(self.to_widget(*self.widget.pos), self.widget.size) set_color(1, .3, 0) for c in self.child_layout.children: drawLine((self.node_btn.centerright, c.node_btn.centerleft), width=2)
def draw(self): if not self.dl.is_compiled(): with self.dl: set_color(*self.style['bg-color']) drawCSSRectangle(size=self.size, style=self.style) set_color(*self.current_color) drawRectangle(pos=(10, 220), size=(110, 60)) self.dl.draw()
def draw(self): # draw outer rectangle set_color(*self.style.get('bg-color')) drawCSSRectangle(pos=self.pos, size=self.size, style=self.style) # draw inner circle set_color(*self.style.get('slider-color')) pos_x = int((self._value_x - self.min_x) * (self.width - self.padding*2) / (self.max_x - self.min_x)) + self.x + self.padding pos_y = int((self._value_y - self.min_y) * (self.height - self.padding*2) / (self.max_y - self.min_y)) + self.y + self.padding drawCircle(pos=(pos_x, pos_y), radius=self.radius)
def draw(self): if self.selected: selected_color = self.style.get('selected-color', (0.4,) * 4) set_color(*selected_color) drawCSSRectangle(pos=self.pos, size=self.size, style=self.style) pos = int(self.x + self.width / 2.), int(self.y + 10) drawLabel(label=self.striptext(self.label_txt, 10), pos=pos) self.image.x = self.x + int(self.image.width / 2) - 5 self.image.y = self.y + int(self.image.height / 2) - 5 self.image.draw()
def draw(self): if self.selected: selected_color = self.style.get('selected-color', (0.4, ) * 4) set_color(*selected_color) drawCSSRectangle(pos=self.pos, size=self.size, style=self.style) pos = int(self.x + self.width / 2.), int(self.y + 10) drawLabel(label=self.striptext(self.label_txt, 10), pos=pos) self.image.x = self.x + int(self.image.width / 2) - 5 self.image.y = self.y + int(self.image.height / 2) - 5 self.image.draw()
def draw(self): # Draw background set_color(*self.style.get('bg-color')) drawRectangle(pos=self.pos, size=self.size) # Draw sliders set_color(*self.style.get('slider-color')) for slider in range(self._sliders): pos_x = self.x + slider * (float(self.width) / self._sliders) pos_y = self.y size_x = (float(self.width) / self._sliders) - self._spacing size_y = self.height * self.slider_values[slider] drawRectangle(pos = (pos_x, pos_y), size = (size_x, size_y))
def draw_tile(self, i, j): if self.matrix[i][j] == 0: set_color(*self.buttoncolor) if self.matrix[i][j]: set_color(*self.downcolor) with gx_matrix: glTranslatef(self.width / self._matrix_size[0] * i + self.x, self.height / self._matrix_size[1] * j + self.y, 0) s = (self.width / self._matrix_size[0] - self.border, self.height / self._matrix_size[1] - self.border) drawRectangle(size=s)
def draw(self): if self._is_active_input and self.keyboard_type == 'virtual': set_color(*self.style.get('bg-color')) kx, ky = self.keyboard.to_window(*self.keyboard.center) kx, ky = self.to_widget(kx, ky) drawLine([self.center[0], self.center[1], kx, ky]) if self.password: pw = '*' * len(self.label) old_label = self.label self.label = pw super(MTTextInput, self).draw() if self.password: self.label = old_label
def draw(self): ''' set_color(.509, .407, .403, .95) drawRoundedRectangle(size=self.size) set_color(.298, .184, .192, .95) drawRoundedRectangle(size=self.size, linewidth=2, style=GL_LINE_LOOP) ''' self.width = max(20, self.label.width) self.height = max(20,self.label.height) #set_color(.435, .749, .996) set_color(*self.style['bg-color']) drawRoundedRectangle(size=self.size) #set_color(.094, .572, .858) set_color(*self.style['border-color']) drawRoundedRectangle(size=self.size, linewidth=2, style=GL_LINE_LOOP)
def draw(self): pos = self.image.width, self.y # Max number of chars for this entry's label max_chars = 20 # Simple trick to get the maximum label width for the current font size self.width = getLabel('W'*max_chars, font_size=self.font_size).width if self.selected: selected_color = self.style.get('selected-color', (0.4,) * 4) set_color(*selected_color) drawCSSRectangle(pos=(0, self.y), size=self.size, style=self.style) kwargs = {'pos': pos, 'anchor_x': 'left', 'anchor_y': 'bottom', 'font_size':self.style['font-size'], 'color':self.style['color']} drawLabel(label=self.striptext(self.label_txt, max_chars), **kwargs ) self.image.pos = (0, self.y) self.image.draw()
def draw(self): # Background set_color(*self.style.get('bg-color')) drawCircle(self.pos, self.radius) # A good size for the hand, proportional to the size of the widget hd = self.radius / 10 # Draw center of the hand set_color(*self.style.get('vector-color')) drawCircle(self.pos, hd) # Rotate the triangle so its not skewed l = prot((self.pos[0] - hd, self.pos[1]), self.angle - 90, self.pos) h = prot((self.pos[0] + hd, self.pos[1]), self.angle - 90, self.pos) # Draw triable of the hand with gx_begin(GL_POLYGON): glVertex2f(*l) glVertex2f(*h) glVertex2f(self.vector[0], self.vector[1])
def draw(self): pos = self.image.width, self.y # Max number of chars for this entry's label max_chars = 20 # Simple trick to get the maximum label width for the current font size self.width = getLabel('W' * max_chars, font_size=self.font_size).width if self.selected: selected_color = self.style.get('selected-color', (0.4, ) * 4) set_color(*selected_color) drawCSSRectangle(pos=(0, self.y), size=self.size, style=self.style) drawLabel(label=self.striptext(self.label_txt, max_chars), pos=pos, anchor_x='left', anchor_y='bottom', font_size=self.style.get('font-size'), color=self.style.get('color')) self.image.pos = (0, self.y) self.image.draw()
def draw(self): # Background set_color(*self.style.get('bg-color')) drawCircle(self.pos, self.radius) # A good size for the hand, proportional to the size of the widget hd = self.radius / 10 # Draw center of the hand set_color(*self.style.get('vector-color')) drawCircle(self.pos, hd) # Rotate the triangle so its not skewed l = prot((self.pos[0] - hd, self.pos[1]), self.angle-90, self.pos) h = prot((self.pos[0] + hd, self.pos[1]), self.angle-90, self.pos) # Draw triable of the hand with gx_begin(GL_POLYGON): glVertex2f(*l) glVertex2f(*h) glVertex2f(self.vector[0], self.vector[1])
def draw(self): super(MTCircularSlider, self).draw() # faster calculation if we remove dot x, y = self.center p = 0, 0 r = self.radius t = self.thickness s = self.sweep_angle padding = self.padding with gx_matrix: set_color(*self.style.get('bg-color')) glTranslatef(x, y, 0) glRotatef(-self.rotation, 0, 0, 1) drawSemiCircle(p, r - t, r, 32, 1, 0, s) set_color(*self.style.get('slider-color')) drawSemiCircle(p, r - t + padding, r - padding, 32, 1, 0, self._slider_angle)
def draw(self): if not self.visible: return for objectID in self.objects: x, y, angle = self.objects[objectID] with gx_matrix: glTranslatef(x, y, 0.0) glRotatef(angle, 0.0, 0.0, 1.0) set_color(.5) drawCSSRectangle( pos=(-0.5 * self.width, -0.5 * self.height), size=(self.width, self.height), style=self.style ) set_color(*self.style['vector-color']) with gx_begin(GL_LINES): glVertex2f(0., 0.) glVertex2f(0., -0.5 * self.height)
def draw(self): # select color from number of touch if len(self._touches) == 0: set_color(*self.style.get('bg-color')) elif len(self._touches) == 1: set_color(*self.style.get('bg-color-move')) else: set_color(*self.style.get('bg-color-full')) # draw border scaled_border = self.get_scaled_border() self.update_controls() drawRoundedRectangle( pos=(-scaled_border, -scaled_border), size=(self.width+scaled_border*2, self.height+scaled_border*2), radius=15. / self.scale ) # draw control background control_width = self.btn_fullscreen.width + self.btn_close.width drawRoundedRectangle( pos=((self.width/2)-(scaled_border + control_width / 2), -scaled_border * 2), size=(scaled_border*2 + control_width, scaled_border), radius=15. / self.scale, corners=(True, True, False, False) )
def draw(self): # select color from number of touch if len(self._touches) == 0: set_color(*self.style.get('bg-color')) elif len(self._touches) == 1: set_color(*self.style.get('bg-color-move')) else: set_color(*self.style.get('bg-color-full')) # draw border scaled_border = self.get_scaled_border() self.update_controls() drawRoundedRectangle(pos=(-scaled_border, -scaled_border), size=(self.width + scaled_border * 2, self.height + scaled_border * 2), radius=15. / self.scale) # draw control background control_width = self.btn_fullscreen.width + self.btn_close.width drawRoundedRectangle( pos=((self.width / 2) - (scaled_border + control_width / 2), -scaled_border * 2), size=(scaled_border * 2 + control_width, scaled_border), radius=15. / self.scale, corners=(True, True, False, False))
def draw(self): # background set_color(*self.style.get('bg-color')) drawCSSRectangle(pos=self.pos, size=self.size, style=self.style) # draw children self.stencil_push() for w in self.children[:]: # internal update of children w.update() # optimization to draw only viewed children if self.do_y and (w.y + w.height < self.y or w.y > self.y + self.height): continue if self.do_x and (w.x + w.width < self.x or w.x > self.x + self.width): continue w.on_draw() self.stencil_pop() # draw widgets for w in self.widgets: w.dispatch_event('on_draw') # title bar if self.titletext is not None: set_color(*self.style.get('title-color')) w = 0 if self.searchable: x = 80 w += 80 else: x = 0 if self.deletable: w += 80 drawCSSRectangle(pos=(self.x + x, self.height + self.y - 40), size=(self.width - w, 40), prefix='title', style=self.style) self.title.x = self.width / 2 + self.x self.title.y = self.height - 20 + self.y self.title.draw() # scrollbar sb_size = self.style.get('scrollbar-size') if sb_size > 0: mtop, mright, mbottom, mleft = self.style.get('scrollbar-margin') if self.do_y: pos = [ self.x + self.width - mright - sb_size, self.y + mbottom ] size = [sb_size, self.height - mbottom - mtop] pos[1] += size[1] * self._scrollbar_index size[1] = size[1] * self._scrollbar_size elif self.do_x: pos = [self.x + mleft, self.y + self.height - mtop - sb_size] size = [self.width - mleft - mright, sb_size] pos[0] += size[0] * self._scrollbar_index size[0] = size[0] * self._scrollbar_size set_color(*self.style.get('scrollbar-color')) drawRectangle(pos=pos, size=size)
def draw(self): px, py = self.style['padding'] px2, py2 = px / 2., py / 2. diff = self.max - self.min if self.orientation == 'vertical': if diff == 0: length = 0 else: length = int((self._value - self.min) * \ (self.height - py) / diff) pos = self.x + px2, self.y + py2 size = self.width - px, length else: if diff == 0: length = 0 else: length = int((self._value - self.min) * \ (self.width - px) / diff) pos = self.x + px2, self.y + py2 size = length, self.height - py # draw outer rectangle set_color(*self.style.get('bg-color')) drawCSSRectangle(pos=self.pos, size=self.size, style=self.style) # draw inner rectangle if self.touchstarts: set_color(*self.style.get('slider-color-down')) else: set_color(*self.style.get('slider-color')) drawCSSRectangle(pos=pos, size=size, style=self.style, prefix='slider') if self.value_show: self.draw_value()
def draw_selection(self, label, line_num): '''Draw the current selection on the widget. ''' a, b = self._selection_from, self._selection_to if a > b: a, b = b, a s1c, s1r = self.get_cursor_from_index(a) s2c, s2r = self.get_cursor_from_index(b) if line_num < s1r or line_num > s2r: return x1 = label.x x2 = label.x + label.width y1 = label.y - self.line_height g = self.glyph_size if line_num == s1r: lines = self.lines[line_num] x1 += sum([g(x) for x in lines[:s1c]]) if line_num == s2r: lines = self.lines[line_num] x2 = label.x + sum([g(x) for x in lines[:s2c]]) set_color(*self.style.get('selection-color')) drawRectangle(pos=(x1, y1), size=(x2-x1, self.line_height))
def on_draw(self): # background set_color(*self.style['bg-color']) drawRectangle(pos=self.pos, size=self.size) if not len(self.children): return # draw left side for i in xrange(0, self._selection): self._render_cover(i) # draw right side in reverse order for i in xrange(len(self.children) - 1, self._selection, -1): self._render_cover(i) # draw cover self._render_cover(self._selection) # draw title ? if self.title_draw: child = self.children[self._selection] self._draw_title(child)
def on_draw(self): # background set_color(*self.style['bg-color']) drawRectangle(pos=self.pos, size=self.size) if not len(self.children): return # draw left side for i in xrange(0, self._selection): self._render_cover(i) # draw right side in reverse order for i in xrange(len(self.children) - 1, self._selection, - 1): self._render_cover(i) # draw cover self._render_cover(self._selection) # draw title ? if self.title_draw: child = self.children[self._selection] self._draw_title(child)
def draw(self): # background set_color(*self.style.get('bg-color')) drawCSSRectangle(pos=self.pos, size=self.size, style=self.style) # draw children self.stencil_push() for w in self.children[:]: # internal update of children w.update() # optimization to draw only viewed children if self.do_y and (w.y + w.height < self.y or w.y > self.y + self.height): continue if self.do_x and (w.x + w.width < self.x or w.x > self.x + self.width): continue w.on_draw() self.stencil_pop() # draw widgets for w in self.widgets: w.dispatch_event('on_draw') # title bar if self.titletext is not None: set_color(*self.style.get('title-color')) w = 0 if self.searchable: x = 80 w += 80 else: x = 0 if self.deletable: w += 80 drawCSSRectangle(pos=(self.x + x, self.height + self.y - 40), size=(self.width - w, 40), prefix='title', style=self.style) self.title.x = self.width/2 + self.x self.title.y = self.height - 20 + self.y self.title.draw() # scrollbar sb_size = self.style.get('scrollbar-size') if sb_size > 0: mtop, mright, mbottom, mleft = self.style.get('scrollbar-margin') if self.do_y: pos = [self.x + self.width - mright - sb_size, self.y + mbottom] size = [sb_size, self.height - mbottom - mtop] pos[1] += size[1] * self._scrollbar_index size[1] = size[1] * self._scrollbar_size if self.do_x: pos = [self.x + mleft, self.y + self.height - mtop - sb_size] size = [self.width - mleft - mright, sb_size] pos[0] += size[0] * self._scrollbar_index size[0] = size[0] * self._scrollbar_size set_color(*self.style.get('scrollbar-color')) drawRectangle(pos=pos, size=size)
def draw_transition(self, t): ''' Function is called each frame while switching screens and responsible for drawing transition state. t will go from -1.0 (previous screen), to 0 (rigth in middle), until 1.0 (last time called before giving new screen full controll) ''' set_color(*self.style['bg-color']) #from 1 to zero drawRectangle(pos=self.container.pos, size=self.container.size) r, g, b = self.style['bg-color'][0:3] if t < 0: if self.previous_screen is not None: self.previous_screen.dispatch_event('on_draw') set_color(r, g, b, 1+t) #from 1 to zero drawRectangle(pos=self.container.pos, size=self.container.size) else: if self.previous_screen is not None: self.screen.dispatch_event('on_draw') set_color(r, g, b, 1-t) #from 0 to one drawRectangle(pos=self.container.pos, size=self.container.size)
def draw_transition(self, t): ''' Function is called each frame while switching screens and responsible for drawing transition state. t will go from -1.0 (previous screen), to 0 (rigth in middle), until 1.0 (last time called before giving new screen full controll) ''' set_color(*self.style['bg-color']) #from 1 to zero drawRectangle(pos=self.container.pos, size=self.container.size) r, g, b = self.style['bg-color'][0:3] if t < 0: if self.previous_screen is not None: self.previous_screen.dispatch_event('on_draw') set_color(r, g, b, 1 + t) #from 1 to zero drawRectangle(pos=self.container.pos, size=self.container.size) else: if self.previous_screen is not None: self.screen.dispatch_event('on_draw') set_color(r, g, b, 1 - t) #from 0 to one drawRectangle(pos=self.container.pos, size=self.container.size)
def draw(self): set_color(*self.style['bg-color']) drawCSSRectangle(pos=(0, 0), size=(self.width, self.height), style=self.style)
def draw(self): set_color(*self.style['bg-color']) drawCSSRectangle(pos=self.pos, size=self.size, style=self.style) self.image.color = self.style['color'] super(MTButtonVideo, self).draw()
def _do_update(self, mode=None): # we absolutly want mode to update displaylist. if mode not in ('background', 'keys'): return # don't update background if it's already compiled if mode == 'background' and self._current_cache['background'].is_compiled(): return # calculate margin s = self.scale w, h = self.container_width, self.container_height if mode == 'background': s = 1. w, h = self.size mtop, mright, mbottom, mleft = map(lambda x: x * s, self.style['margin']) self.texsize = Vector(w - mleft - mright, h - mtop - mbottom) kx, ky = self.layout.SIZE self.keysize = Vector(self.texsize.x / kx, self.texsize.y / ky) m = 3 * s x, y = 0, self.texsize.y - self.keysize.y # update display list self._current_cache['usedlabel'] = [] with self._current_cache[mode]: # draw lines for index in xrange(1, ky + 1): line = self.layout.__getattribute__('%s_%d' % (self.mode, index)) # draw keys for key in line: displayed_str, internal_str, internal_action, scale = key kw = self.keysize.x * scale # don't display empty keys if displayed_str is not None: set_color(*self.style['key-color']) if mode == 'background': if internal_action is not None: set_color(*self.style['syskey-color']) drawCSSRectangle( pos=(x+m, y+m), size=(kw-m*2, self.keysize.y-m*2), style=self.style, prefix='key') elif mode == 'keys': font_size = int(14 * s) if font_size < 8: font_size = 8 color = self.style['color'] if internal_action is not None: color = self.style['color-syskey'] drawLabel(label=displayed_str, pos=(x + kw / 2., y + self.keysize.y / 2.), font_size=font_size, bold=False, font_name=self.style.get('font-name'), color=color) self._current_cache['usedlabel'].append(getLastLabel()) # advance X x += kw # advance Y y -= self.keysize.y x = 0 # update completed self._need_update = None
def draw(self): set_color(*self.style.get('bg-color')) drawCSSRectangle(pos=(0, 0), size=self.size, style=self.style)
def draw_background(self): '''Draw the background of the widget''' set_color(*self.style['bg-color']) drawCSSRectangle(pos=self.pos, size=self.size, style=self.style)