Ejemplo n.º 1
0
    def __init__(self, rows=None, camera=None):
        Controller.__init__(self, camera) 

        self.rows = list([LayoutRow(r) if type(r) is list else r for r in rows or []])
        self._prepared = False 
        self._frames = None
        self.on_keyboard.append(self.keyboard_callback)
    def init(self):
        Controller.init(self)
        self.shaperenderer = ShapeRenderer(self.camera)
        self.shaperenderer.gl_init()
        self.first = True 
        self.frame_buffer = Framebuffer(self.camera, self.camera.screensize, record_mode=Framebuffer.RECORD_BLIT)
        self.frame_buffer.init()
        shape = Rectangle()
        texture = NumpyTexture(np.random.random_sample(4*10000).reshape(100,100,4))
        texture.gl_init()
        self.shaperenderer.draw_instance(ShapeInstance(shape, **{
            'size': (200,200),
            'position': (100,200), 
            'color': [0,0,0,1],
            'border': {
                'size': 10,
                'color': [1,0,0,1],
            },
            'texture': self.frame_buffer
        }))
        self.shaperenderer.draw_instance(ShapeInstance(shape, (200,200),(300,100), border={
            'size': 20,
            'color': [1,1,0,0.5],


        }))
Ejemplo n.º 3
0
    def camera_updated(self, camera):
        """
        updates cameras and modelview of axis and plotplane
        """
        self._update_xaxis()
        self._update_yaxis()
        self._update_measure_axis()
        self._update_plotframe_camera()
        self._update_graph_matricies()
        self._update_colorlegend()
        self._fntrenderer.set_camera(self.camera)
        self.render_graphs = True
        self.shaperenderer.update_camera()
        self._plotplane.size = self.plotframe_size
        if self.widget is not None and hasattr(self.widget, 'update_camera'):
            self.widget.update_camera()

        Controller.camera_updated(self, camera)
Ejemplo n.º 4
0
	def init(self):
		print('ich habe init gemacht')

		fancy_font = ImageFont.truetype (FONT_RESOURCES_DIR+"/cmunui.ttf", 30)
		
		self.font_renderer = FontRenderer(self.camera)
		self.font_renderer.init()

		text = Text("ich bin ein cooler font", fancy_font)
		
		abs_layout = AbsoluteLayout()
		abs_layout.add_text(text)

		self.font_renderer.layouts['abs'] = abs_layout



		Controller.init(self)
Ejemplo n.º 5
0
 def __init__(self):
     Controller.__init__(self)
     self._rendered = False
Ejemplo n.º 6
0
    def __init__(self,
        camera            = None,
        axis              = [2,2],
        origin            = [0,0],
        axis_units        = [1,1],
        xlabel            = None,
        ylabel            = None,
        title             = None,
        plotmode          = None,
        colorlegend      = None,
        axis_unit_symbols = [None,None],
        axis_subunits     = [4,4],
        color_scheme      = DEFAULT_COLORS,
        on_keyboard = (lambda s,a,p: None),
        graphs            = {},
        axis_measures     = [],
        render_axis = (True, True),
        plotplane_margin=[5, 10, 40, 5],
        plotplane_minsize=(100, 100),
        min_label_space=(0,0),
        widget = None,
        axis_density=(80,80),
    ):
        plot_info('Yo bro', 'plotter cant wait to plot for you')
        Controller.__init__(self, camera)

        if GlApplication.DEBUG:
            color_scheme = DEBUG_COLORS

        self.graphs               = graphs or OrderedDict()
        self.plot_camera          = None
        self.color_scheme         = color_scheme
        self.plotmode = plotmode
        self.widget = widget
        self.colorlegend = colorlegend
        self._on_keyboard = on_keyboard
        if type(plotmode) is str:
            if plotmode not in _PLOTMODE_ALIASES:
                raise ValueError('unkown plotmode "{}". Available aliases are: {}'.format(
                    plotmode, ', '.join(_PLOTMODE_ALIASES.keys())
                ))
            self.plotmode = _PLOTMODE_ALIASES[plotmode][0](
                *_PLOTMODE_ALIASES[plotmode][1],
                **_PLOTMODE_ALIASES[plotmode][2]
            )

        self._axis_measures = axis_measures

        self.on_state = Event()
        self.min_label_space = min_label_space
        self._axis_translation      = (10, 0)
        self._plotplane_margin      = plotplane_margin
        self._plot_plane_min_size   = plotplane_minsize
        self._axis                  = axis
        self._axis_units            = axis_units
        self.colorlegend_speed      = 0.01
        self._xlabel                = xlabel
        self._ylabel                = ylabel
        self._title                 = title
        self._title_font            = None
        self._xlabel_font           = None
        self._ylabel_font           = None
        self._axis_density = axis_density
        self._axis_subunits         = axis_subunits
        self._axis_unit_symbols     = axis_unit_symbols
        self._origin                = origin
        self._margin_changed        = False
        self._plotframe             = None
        self._xaxis                 = None
        self._yaxis                 = None
        self._colorlegend_axis      = None
        self._debug                 = False
        self._fontrenderer          = None
        self._render_axis           = render_axis
        self._axis_texts            = [[],[]]
        self._yboxwidths            = []
        # dstates
        self.render_graphs          = True
        self._graphs_initialized    = False
        self._has_rendered          = False
        self._state                 = 0
        self._select_area           = [0,0,0,0]
        self._select_area_rectangle = None
        self._colorlegend_frame     = None
        self._colorlegend           = None
        self._colorlegend_graph     = None
        self._colorlegend_texts = []

        self.xlabel_text = None
        self.ylabel_text = None
        self.title_text = None

        self._fntrenderer = FontRenderer2()
        self._fntlayout = AlignedLayout(self.camera)
        self.on_cursor.append(self.cursor_reload)
        self.on_keyboard.append(self.keyboard_callback)
        self.on_mouse.append(self.mouse_callback)
        self.on_pre_render.insert(0, self.pre_render)
        self.on_pre_render.insert(0, self.check_graphs)
        self.on_post_render.append(self.post_render)
        self.on_render.append(self.render)

        if self.widget is not None:
            self.widget.attach(self)
Ejemplo n.º 7
0
    def init(self):
        """
        initializes plot2d
        """
        self.shaperenderer = ShapeRenderer(self.camera)
        self.shaperenderer.shapes['default_rectangle'] = Rectangle()
        self.shaperenderer.gl_init()

        # setup axis
        self.init_labels()

        # setup plotplane
        plotframe = window.Framebuffer(
            camera      = self.camera,
            screensize  = self.plotframe_size,
            screen_mode = window.Framebuffer.SCREEN_MODE_STRECH,
            record_mode = self.plotmode.record_mode if self.plotmode is not None else window.Framebuffer.RECORD_CLEAR,
            clear_color = hex_to_rgba(self.color_scheme['plotplane-bgcolor']),
            multisampling = 8,
            blit_texture=True,
        )
        self._fntrenderer.set_camera(self.camera)
        self._fntrenderer.init()

        self._fntlayout.camera = self.camera
        if self.plotmode is not None:
            plotframe.record_program = self.plotmode.get_shader()

        plotframe.init()
        plotframe.modelview.set_position(self._plotplane_margin[3], self._plotplane_margin[0])
        plotframe.update_modelview()

        # setup plotplane camera
        plotframe.inner_camera.set_base_matrix(np.array([
            1, 0, 0, 0,
            0, -1, 0, 0,
            0, 0, 1, 0,
            0, 0, 0, 1,
        ], dtype=np.float32))
        plotframe.inner_camera.set_scaling(self._axis)
        plotframe.inner_camera.set_position(*self._origin)
        self._plotframe = plotframe




        # parent controller initialization
        Controller.init(self)
        self.state = self.STATE_IDLE

        self._select_area_rectangle = ShapeInstance('default_rectangle', **{
            'size': (0,0),
            'position': (0,0),
            'border': {
                'size': self.color_scheme['select-area-border-size'],
                'color': hex_to_rgba(self.color_scheme['select-area-border-color']),
            },
            'color': hex_to_rgba(self.color_scheme['select-area-bgcolor']),
        })

        self._plotplane = ShapeInstance('default_rectangle', **{
            'size': self.plotframe_size,
            'position': self.plotframe_position,
            'border': {
                'size': self.color_scheme['plotframe-border-size'],
                'color': hex_to_rgba(self.color_scheme['plotframe-border-color']),
            },
            'color': [0,0,0,0],
            'texture': self._plotframe
        })
        self.shaperenderer.draw_instance(self._plotplane)

        # setup axis
        if self._render_axis[0]:
            self._xaxis = axis.Scale(
                camera       = self.camera,
                scale_camera = self._plotframe.inner_camera,
                size         = self.get_xaxis_size(),
                unit         = self._axis_units[0],
                subunits     = self._axis_subunits[0],
                font         = None,
                axis         = axis.XAXIS,
                unit_symbol  = self._axis_unit_symbols[0],
                bgcolor      = hex_to_rgba(self.color_scheme['xaxis-bgcolor']),
                linecolor    = hex_to_rgba(self.color_scheme['xaxis-linecolor']),
                fontcolor    = hex_to_rgba(self.color_scheme['xaxis-fontcolor']),
            )
            self._xaxis.density = self._axis_density[0]

            self._xaxis.init()
            self._update_xaxis()

        if self._render_axis[1]:
            self._yaxis = axis.Scale(
                camera       = self.camera,
                scale_camera = self._plotframe.inner_camera,
                size         = self.get_yaxis_size(),
                unit         = self._axis_units[1],
                subunits     = self._axis_subunits[1],
                font         = None,
                axis         = axis.YAXIS,
                unit_symbol  = self._axis_unit_symbols[1],
                bgcolor      = hex_to_rgba(self.color_scheme['yaxis-bgcolor']),
                linecolor    = hex_to_rgba(self.color_scheme['yaxis-linecolor']),
                fontcolor    = hex_to_rgba(self.color_scheme['yaxis-fontcolor']),
            )
            self._yaxis.density = self._axis_density[1]
            self._yaxis.init()
            self._update_yaxis()
        self.init_colorlegend()
        self._plotplane.size = self.plotframe_size
        self._update_plotframe_camera()
        self._update_graph_matricies()
        glfwWindowHint(GLFW_SAMPLES, 4);
        glEnable(GL_MULTISAMPLE)

        if self.widget is not None:
            plot_info('Plotter2d', 'init widget...')
            self.widget.gl_init()

        plot_info('Plotter2d', 'inizialized!')
Ejemplo n.º 8
0
 def init(self):
     Controller.init(self)
     self.camera.on_change_matrix.append(self.rescale_camera)
     self.prepare()
Ejemplo n.º 9
0
	def __init__(self, camera=None):
		Controller.__init__(self, camera)