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): 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(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_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(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(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): # 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 on_draw(self): with gx_matrix: glMultMatrixf(self.transform_gl) self.draw() self.controls.dispatch_event('on_draw') # use stencil for container with gx_stencil: drawRectangle((0, 0), size=self.size) stencilUse() self.container.dispatch_event('on_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_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_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 _render_cover(self, index): # render the children on a fbo child = self.children[index] with self._fbo: self._fbo.clear() child.dispatch_event('on_draw') # pre-calculate y2 = self.center[1] - self.thumbnail_size[1] / 2. angle, x = self._get_cover_position(index, 0) # if a transition is in way, # use it to calculate angle/position from # current position and future position if self._transition != 0: i2 = index if self._transition > 0: i2 -= 1 elif self._transition < 0: i2 += 1 i2 = min(max(-1, i2), len(self.children)) angle2, x2 = self._get_cover_position(i2, self._transition) # do linear alpha if self._transition > 0: angle += self._transition * (angle2 - angle) x += self._transition * (x2 - x) else: angle -= self._transition * (angle2 - angle) x -= self._transition * (x2 - x) # calculate alpha coordinate # this is to make cover more darker on the farest side # and make brighter the current displayed cover a = 1. - .7 * (angle / 90.) alpha_coords = ((1, 1, 1, 0), (a, a, a, 0), (a, a, a, 0), (1, 1, 1, 0)) # draw ! glTranslatef(x, y2, 0) glRotatef(angle, 0, 1, 0) # draw the cover if self.cover_blend: set_color(1, blend=True) drawTexturedRectangle(texture=self._fbo.texture, size=self.thumbnail_size, color_coords=self._cover_blend_coords) else: set_color(1) drawTexturedRectangle(texture=self._fbo.texture, size=self.thumbnail_size, color_coords=alpha_coords) # now, for reflection, don't do matrix transformation # just invert texcoord + play with color old_texcoords = self._fbo.texture.tex_coords self._fbo.texture.flip_vertical() self._fbo.texture.tex_coords = list(self._fbo.texture.tex_coords) self._fbo.texture.tex_coords[1] = self.reflection_percent self._fbo.texture.tex_coords[3] = self.reflection_percent # draw reflection pos = (0, -self.thumbnail_size[1] * self.reflection_percent) size = (self.thumbnail_size[0], self.thumbnail_size[1] * self.reflection_percent) # activate blending with background ? if self.reflection_blend: set_color(*self.style['bg-color']) drawRectangle(pos=pos, size=size) set_color(1, 1, 1, blend=True) drawTexturedRectangle(texture=self._fbo.texture, pos=pos, size=size, color_coords=self._reflection_coords) # restore fbo tex_coords self._fbo.texture.tex_coords = old_texcoords # reset our position changes glRotatef(angle, 0, -1, 0) glTranslatef(-x, -y2, 0)
def _on_draw(): global _toggle_state if _toggle_state == '': return win = getWindow() # # Show HELP screen # if _toggle_state == 'help': # draw the usual window win.on_draw() # make background more black set_color(0, 0, 0, .8) drawRectangle(size=win.size) # prepare calculation w2 = win.width / 2. h2 = win.height / 2. k = {'font_size': 24} # draw help drawLabel('PyMT Keybinding', pos=(w2, win.height - 100), font_size=40) drawLabel('Press F1 to leave help', pos=(w2, win.height - 160), font_size=12) drawLabel('F1 - Show Help', pos=(w2, h2), **k) drawLabel('F2 - Show FPS (%s)' % str(win.show_fps), pos=(w2, h2 - 35), **k) drawLabel('F3 - Draw back gradient (%s)' % str(win.gradient), pos=(w2, h2 - 70), **k) drawLabel('F4 - Show Calibration screen', pos=(w2, h2 - 105), **k) drawLabel('F5 - Toggle fullscreen', pos=(w2, h2 - 140), **k) drawLabel('F6 - Show log', pos=(w2, h2 - 175), **k) return True # # Draw calibration screen # elif _toggle_state == 'calibration': step = 8 ratio = win.height / float(win.width) stepx = win.width / step stepy = win.height / int(step * ratio) # draw black background set_color(0, 0, 0) drawRectangle(size=win.size) # draw lines set_color(1, 1, 1) for x in xrange(0, win.width, stepx): drawLine((x, 0, x, win.height)) for y in xrange(0, win.height, stepy): drawLine((0, y, win.width, y)) # draw circles drawCircle(pos=(win.width / 2., win.height / 2.), radius=win.width / step, linewidth = 2.) drawCircle(pos=(win.width / 2., win.height / 2.), radius=(win.width / step) * 2, linewidth = 2.) drawCircle(pos=(win.width / 2., win.height / 2.), radius=(win.width / step) * 3, linewidth = 2.) return True # # Draw calibration screen 2 (colors) # elif _toggle_state == 'calibration2': # draw black background set_color(0, 0, 0) drawRectangle(size=win.size) # gray step = 25 stepx = (win.width - 100) / step stepy = stepx * 2 sizew = stepx * step sizeh = stepy * step w2 = win.width / 2. h2 = win.height / 2. for _x in xrange(step): x = w2 - sizew / 2. + _x * stepx drawLabel(chr(65+_x), pos=(x + stepx / 2., h2 + 190)) c = _x / float(step) # grey set_color(c, c, c) drawRectangle(pos=(x, h2 + 100), size=(stepx, stepy)) # red set_color(c, 0, 0) drawRectangle(pos=(x, h2 + 80 - stepy), size=(stepx, stepy)) # green set_color(0, c, 0) drawRectangle(pos=(x, h2 + 60 - stepy * 2), size=(stepx, stepy)) # blue set_color(0, 0, c) drawRectangle(pos=(x, h2 + 40 - stepy * 3), size=(stepx, stepy)) return True # # Draw log screen # elif _toggle_state == 'log': # draw the usual window win.on_draw() # make background more black set_color(0, 0, 0, .8) drawRectangle(size=win.size) # calculation w2 = win.width / 2. h2 = win.height / 2. k = {'font_size': 11, 'center': False} y = win.height - 20 y = h2 max = int((h2 / 20)) levels = { logging.DEBUG: ('DEBUG', (.4,.4,1)), logging.INFO: ('INFO', (.4,1,.4)), logging.WARNING: ('WARNING', (1,1,.4)), logging.ERROR: ('ERROR', (1,.4,.4)), logging.CRITICAL: ('CRITICAL', (1,.4,.4)), } # draw title drawLabel('PyMT logger', pos=(w2, win.height - 100), font_size=40) # draw logs for log in reversed(pymt_logger_history.history[:max]): levelname, color = levels[log.levelno] msg = log.message.split('\n')[0] x = 10 x += drawLabel('[', pos=(x, y), **k) x += drawLabel(levelname, pos=(x, y), color=color, **k) x += drawLabel(']', pos=(x, y), **k) drawLabel(msg, pos=(100, y), **k) y -= 20 return True
def stencil_push(self): stencilPush() # draw on stencil drawRectangle(pos=self.pos, size=self.size) # switch drawing to color buffer. stencilUse()
def _render_cover(self, index): # render the children on a fbo child = self.children[index] with self._fbo: self._fbo.clear() child.dispatch_event('on_draw') # pre-calculate y2 = self.center[1] - self.thumbnail_size[1] / 2. angle, x = self._get_cover_position(index, 0) # if a transition is in way, # use it to calculate angle/position from # current position and future position if self._transition != 0: i2 = index if self._transition > 0: i2 -= 1 elif self._transition < 0: i2 += 1 i2 = min(max(-1, i2), len(self.children)) angle2, x2 = self._get_cover_position(i2, self._transition) # do linear alpha if self._transition > 0: angle += self._transition * (angle2 - angle) x += self._transition * (x2 - x) else: angle -= self._transition * (angle2 - angle) x -= self._transition * (x2 - x) # calculate alpha coordinate # this is to make cover more darker on the farest side # and make brighter the current displayed cover a = 1. - .7 * (angle / 90.) alpha_coords = ( (1, 1, 1, 0), (a, a, a, 0), (a, a, a, 0), (1, 1, 1, 0)) # draw ! glTranslatef(x, y2, 0) glRotatef(angle, 0, 1, 0) # draw the cover if self.cover_blend: set_color(1, blend=True) drawTexturedRectangle( texture=self._fbo.texture, size=self.thumbnail_size, color_coords=self._cover_blend_coords) else: set_color(1) drawTexturedRectangle( texture=self._fbo.texture, size=self.thumbnail_size, color_coords=alpha_coords) # now, for reflection, don't do matrix transformation # just invert texcoord + play with color old_texcoords = self._fbo.texture.tex_coords self._fbo.texture.flip_vertical() self._fbo.texture.tex_coords = list(self._fbo.texture.tex_coords) self._fbo.texture.tex_coords[1] = self.reflection_percent self._fbo.texture.tex_coords[3] = self.reflection_percent # draw reflection pos = (0, -self.thumbnail_size[1] * self.reflection_percent) size = (self.thumbnail_size[0], self.thumbnail_size[1] * self.reflection_percent) # activate blending with background ? if self.reflection_blend: set_color(*self.style['bg-color']) drawRectangle(pos=pos, size=size) set_color(1, 1, 1, blend=True) drawTexturedRectangle( texture=self._fbo.texture, pos=pos, size=size, color_coords=self._reflection_coords) # restore fbo tex_coords self._fbo.texture.tex_coords = old_texcoords # reset our position changes glRotatef(angle, 0, -1, 0) glTranslatef(-x, -y2, 0)
def _on_draw(): global _toggle_state if _toggle_state == '': return win = getWindow() # # Show HELP screen # if _toggle_state == 'help': # draw the usual window win.on_draw() # make background more black set_color(0, 0, 0, .8) drawRectangle(size=win.size) # prepare calculation w2 = win.width / 2. h2 = win.height / 2. y = 0 k = {'font_size': 20} ydiff = 25 # draw help drawLabel('PyMT Keybinding', pos=(w2, win.height - 100), font_size=40) drawLabel('Press F1 to leave help', pos=(w2, win.height - 160), font_size=12) drawLabel('FPS is %.3f' % getClock().get_fps(), pos=(w2, win.height - 180), font_size=12) drawLabel('F1 - Show Help', pos=(w2, h2), **k) y += ydiff drawLabel('F2 - Show FPS (%s)' % str(win.show_fps), pos=(w2, h2 - y), **k) y += ydiff drawLabel('F3 - Show Cache state', pos=(w2, h2 - y), **k) y += ydiff drawLabel('F4 - Show Calibration screen', pos=(w2, h2 - y), **k) if _can_fullscreen(): y += ydiff drawLabel('F5 - Toggle fullscreen', pos=(w2, h2 - y), **k) y += ydiff drawLabel('F6 - Show log', pos=(w2, h2 - y), **k) y += ydiff drawLabel('F7 - Reload CSS', pos=(w2, h2 - y), **k) y += ydiff drawLabel('F8 - Show widget tree', pos=(w2, h2 - y), **k) y += ydiff drawLabel('F9 - Rotate the screen (%d)' % win.rotation, pos=(w2, h2 - y), **k) y += ydiff drawLabel('F12 - Screenshot', pos=(w2, h2 - y), **k) return True # # Draw cache state # elif _toggle_state == 'cachestat': # draw the usual window win.on_draw() # make background more black set_color(0, 0, 0, .8) drawRectangle(size=win.size) y = 0 for x in Cache._categories: y += 25 cat = Cache._categories[x] count = 0 usage = '-' limit = cat['limit'] timeout = cat['timeout'] try: count = len(Cache._objects[x]) except: pass try: usage = 100 * count / limit except: pass args = (x, usage, count, limit, timeout) drawLabel('%s: usage=%s%% count=%d limit=%s timeout=%s' % args, pos=(20, 20 + y), font_size=20, center=False, nocache=True) return True # # Draw calibration screen # elif _toggle_state == 'calibration': step = 8 ratio = win.height / float(win.width) stepx = win.width / step stepy = win.height / int(step * ratio) # draw black background set_color(0, 0, 0) drawRectangle(size=win.size) # draw lines set_color(1, 1, 1) for x in xrange(0, win.width, stepx): drawLine((x, 0, x, win.height)) for y in xrange(0, win.height, stepy): drawLine((0, y, win.width, y)) # draw circles drawCircle(pos=(win.width / 2., win.height / 2.), radius=win.width / step, linewidth = 2.) drawCircle(pos=(win.width / 2., win.height / 2.), radius=(win.width / step) * 2, linewidth = 2.) drawCircle(pos=(win.width / 2., win.height / 2.), radius=(win.width / step) * 3, linewidth = 2.) return True # # Draw calibration screen 2 (colors) # elif _toggle_state == 'calibration2': # draw black background set_color(0, 0, 0) drawRectangle(size=win.size) # gray step = 25 stepx = (win.width - 100) / step stepy = stepx * 2 sizew = stepx * step sizeh = stepy * step w2 = win.width / 2. h2 = win.height / 2. for _x in xrange(step): x = w2 - sizew / 2. + _x * stepx drawLabel(chr(65+_x), pos=(x + stepx / 2., h2 + 190)) c = _x / float(step) # grey set_color(c, c, c) drawRectangle(pos=(x, h2 + 100), size=(stepx, stepy)) # red set_color(c, 0, 0) drawRectangle(pos=(x, h2 + 80 - stepy), size=(stepx, stepy)) # green set_color(0, c, 0) drawRectangle(pos=(x, h2 + 60 - stepy * 2), size=(stepx, stepy)) # blue set_color(0, 0, c) drawRectangle(pos=(x, h2 + 40 - stepy * 3), size=(stepx, stepy)) return True # # Draw log screen # elif _toggle_state == 'log': # draw the usual window win.on_draw() # make background more black set_color(0, 0, 0, .8) drawRectangle(size=win.size) # calculation w2 = win.width / 2. h2 = win.height / 2. k = {'font_size': 11, 'center': False} y = win.height - 20 y = h2 max = int((h2 / 20)) levels = { logging.DEBUG: ('DEBUG', (.4,.4,1)), logging.INFO: ('INFO', (.4,1,.4)), logging.WARNING: ('WARNING', (1,1,.4)), logging.ERROR: ('ERROR', (1,.4,.4)), logging.CRITICAL: ('CRITICAL', (1,.4,.4)), } # draw title drawLabel('PyMT logger', pos=(w2, win.height - 100), font_size=40) # draw logs for log in reversed(pymt_logger_history.history[:max]): levelname, color = levels[log.levelno] msg = log.message.split('\n')[0] x = 10 s = drawLabel('[', pos=(x, y), **k) x += s[0] s = drawLabel(levelname, pos=(x, y), color=color, **k) x += s[0] s = drawLabel(']', pos=(x, y), **k) x += s[0] drawLabel(msg, pos=(100, y), **k) y -= 20 return True
def _on_draw(): global _toggle_state if _toggle_state == '': return win = getWindow() # # Show HELP screen # if _toggle_state == 'help': # draw the usual window win.on_draw() # make background more black set_color(0, 0, 0, .8) drawRectangle(size=win.size) # prepare calculation w2 = win.width / 2. h2 = win.height / 2. y = 0 k = {'font_size': 20} ydiff = 25 # draw help drawLabel('PyMT Keybinding', pos=(w2, win.height - 100), font_size=40) drawLabel('Press F1 to leave help', pos=(w2, win.height - 160), font_size=12) drawLabel('FPS is %.3f' % getClock().get_fps(), pos=(w2, win.height - 180), font_size=12) drawLabel('F1 - Show Help', pos=(w2, h2), **k) y += ydiff drawLabel('F2 - Show FPS (%s)' % str(win.show_fps), pos=(w2, h2 - y), **k) y += ydiff drawLabel('F3 - Show Cache state', pos=(w2, h2 - y), **k) y += ydiff drawLabel('F4 - Show Calibration screen', pos=(w2, h2 - y), **k) if _can_fullscreen(): y += ydiff drawLabel('F5 - Toggle fullscreen', pos=(w2, h2 - y), **k) y += ydiff drawLabel('F6 - Show log', pos=(w2, h2 - y), **k) y += ydiff drawLabel('F7 - Reload CSS', pos=(w2, h2 - y), **k) y += ydiff drawLabel('F8 - Show widget tree', pos=(w2, h2 - y), **k) y += ydiff drawLabel('F9 - Rotate the screen (%d)' % win.rotation, pos=(w2, h2 - y), **k) y += ydiff drawLabel('F12 - Screenshot', pos=(w2, h2 - y), **k) return True # # Draw cache state # elif _toggle_state == 'cachestat': # draw the usual window win.on_draw() # make background more black set_color(0, 0, 0, .8) drawRectangle(size=win.size) y = 0 for x in Cache._categories: y += 25 cat = Cache._categories[x] count = 0 usage = '-' limit = cat['limit'] timeout = cat['timeout'] try: count = len(Cache._objects[x]) except: pass try: usage = 100 * count / limit except: pass args = (x, usage, count, limit, timeout) drawLabel('%s: usage=%s%% count=%d limit=%s timeout=%s' % args, pos=(20, 20 + y), font_size=20, center=False, nocache=True) return True # # Draw calibration screen # elif _toggle_state == 'calibration': step = 8 ratio = win.height / float(win.width) stepx = win.width / step stepy = win.height / int(step * ratio) # draw black background set_color(0, 0, 0) drawRectangle(size=win.size) # draw lines set_color(1, 1, 1) for x in xrange(0, win.width, stepx): drawLine((x, 0, x, win.height)) for y in xrange(0, win.height, stepy): drawLine((0, y, win.width, y)) # draw circles drawCircle(pos=(win.width / 2., win.height / 2.), radius=win.width / step, linewidth=2.) drawCircle(pos=(win.width / 2., win.height / 2.), radius=(win.width / step) * 2, linewidth=2.) drawCircle(pos=(win.width / 2., win.height / 2.), radius=(win.width / step) * 3, linewidth=2.) return True # # Draw calibration screen 2 (colors) # elif _toggle_state == 'calibration2': # draw black background set_color(0, 0, 0) drawRectangle(size=win.size) # gray step = 25 stepx = (win.width - 100) / step stepy = stepx * 2 sizew = stepx * step sizeh = stepy * step w2 = win.width / 2. h2 = win.height / 2. for _x in xrange(step): x = w2 - sizew / 2. + _x * stepx drawLabel(chr(65 + _x), pos=(x + stepx / 2., h2 + 190)) c = _x / float(step) # grey set_color(c, c, c) drawRectangle(pos=(x, h2 + 100), size=(stepx, stepy)) # red set_color(c, 0, 0) drawRectangle(pos=(x, h2 + 80 - stepy), size=(stepx, stepy)) # green set_color(0, c, 0) drawRectangle(pos=(x, h2 + 60 - stepy * 2), size=(stepx, stepy)) # blue set_color(0, 0, c) drawRectangle(pos=(x, h2 + 40 - stepy * 3), size=(stepx, stepy)) return True # # Draw log screen # elif _toggle_state == 'log': # draw the usual window win.on_draw() # make background more black set_color(0, 0, 0, .8) drawRectangle(size=win.size) # calculation w2 = win.width / 2. h2 = win.height / 2. k = {'font_size': 11, 'center': False} y = win.height - 20 y = h2 max = int((h2 / 20)) levels = { logging.DEBUG: ('DEBUG', (.4, .4, 1)), logging.INFO: ('INFO', (.4, 1, .4)), logging.WARNING: ('WARNING', (1, 1, .4)), logging.ERROR: ('ERROR', (1, .4, .4)), logging.CRITICAL: ('CRITICAL', (1, .4, .4)), } # draw title drawLabel('PyMT logger', pos=(w2, win.height - 100), font_size=40) # draw logs for log in reversed(pymt_logger_history.history[:max]): levelname, color = levels[log.levelno] msg = log.message.split('\n')[0] x = 10 s = drawLabel('[', pos=(x, y), **k) x += s[0] s = drawLabel(levelname, pos=(x, y), color=color, **k) x += s[0] s = drawLabel(']', pos=(x, y), **k) x += s[0] drawLabel(msg, pos=(100, y), **k) y -= 20 return True
def draw_cursor(self, x, y): set_color(1, 0, 0, int(self.cursor_fade)) drawRectangle(size=(2, -self.line_height), pos=(x + self.cursor_offset(), y))