Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import division
- import os, math
- from math import pi , tan, radians, sqrt
- import pyglet
- from pyglet.gl import *
- from pyglet.image.codecs import *
- class TextureEnableGroup(pyglet.graphics.Group):
- def set_state(self):
- glEnable(GL_TEXTURE_2D)
- def unset_state(self):
- glDisable(GL_TEXTURE_2D)
- texture_enable_group = TextureEnableGroup()
- class TextureBindGroup(pyglet.graphics.Group):
- def __init__(self, texture):
- super(TextureBindGroup, self).__init__(parent=texture_enable_group)
- texture.target = GL_TEXTURE_2D
- self.texture = texture
- def set_state(self):
- glBindTexture(GL_TEXTURE_2D, self.texture.id)
- # No unset_state method required.
- def __eq__(self, other):
- return (self.__class__ is other.__class__ and
- self.texture == other.__class__)
- class l_items_vectors:
- def __init__(self, x, y, z):
- self.x = x
- self.y = y
- self.z = z
- self.vectors = [x, y, z]
- class l_items(object):
- def __init__(self, name, execute,icon, cat_type, x, y, z, w, h , bc, tc, batch):
- self.name = name
- self.group = None
- self.execute = execute
- self.icon = icon
- self.cat_type = cat_type
- self.batch = batch
- self.x = float(x)
- self.y = float(y)
- self.z = float(0)
- self.w = float(w)
- self.h = float(h)
- self.box_verts = [self.x,self.y,self.z,self.x,self.y+self.h,self.z,self.x+self.w,self.y+self.h,self.z,self.x+self.w,self.y,self.z]
- self.box_verts2d = [self.x,self.y,self.x,self.y+self.h,self.x+self.w,self.y+self.h,self.x+self.w,self.y]
- self.box_icon = [self.x+(self.w/2)-32, self.y+16, self.x+(self.w/2)+32, self.y+16, self.x+(self.w/2)+32, self.y+80, self.x+(self.w/2)-32, self.y+80]
- self.lable_x = self.x
- self.lable_y = self.y
- self.lable_z = self.z
- self.color = (255, 255, 255, 255)
- self.box_color = bc
- self.highted = False
- #self.fimg = pyglet.image.load('texture.png')
- self.fimg = pyglet.image.Texture.create(512, 512, GL_RGBA)
- if self.icon:
- try:
- self.icon_image = pyglet.image.load(self.icon)
- #self.icon_image = pyglet.image.load(self.icon, decoder=PNGImageDecoder())
- except :
- try:
- self.icon_image = pyglet.image.load(self.icon, decoder=GdkPixbuf2ImageDecode())
- except :
- self.icon_image = pyglet.resource.image('no_icon.png')
- else:
- self.icon_image = pyglet.resource.image('no_icon.png')
- #itc = self.icon_image.get_texture()
- #gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
- #itc.width = 64
- #itc.height = 64
- #self.icon_image.width = 64
- #self.icon_image.height = 64
- iiw, iih = self.icon_image.width, self.icon_image.height
- self.fimg_tex = self.fimg.get_texture()
- print self.fimg
- #itc.blit_into(self.fimg_tex, 0, 0, 0)
- #self.icon_image.blit_to_texture(self.fimg_tex.target, 0, int(self.w/2 - iiw/2), 8, 8)
- #self.icon_image.blit_to_texture(self.fimg_tex.target, 0, 0, 8, 8)
- self.fimg_tex.width = 200
- self.fimg_tex.height = 80
- self.fimg = self.fimg.get_region(0, 0, int(self.w), int(self.h))
- self.fimg_tex = self.fimg_tex.get_transform(self, rotate=90)
- self.img_tex = self.icon_image.get_texture()
- self.img_tex.width = 64
- self.img_tex.height = 64
- self.img_tex = self.img_tex.get_region(0, 0, 64,64)
- #self.img_tex = self.img_tex.get_transform(self, rotate=90)
- #self.group = pyglet.sprite.SpriteGroup(self.fimg_tex,blend_src=GL_SRC_ALPHA, blend_dest=GL_ONE)
- self.group = TextureBindGroup(self.img_tex)
- self.text_group = pyglet.graphics.OrderedGroup(1)
- self.background_group = pyglet.graphics.OrderedGroup(0)
- self.draw_box()
- self.draw_title()
- def draw_box(self):
- #self.vertex_list = self.batch.add(4, pyglet.gl.GL_QUADS, None ,
- # ('v2f', self.box_verts2d),
- # ('c4f', self.box_color*4)
- # )
- self.vertex_list = self.batch.add(4, pyglet.gl.GL_QUADS,self.group ,
- #('c4f', self.box_color*4),
- ('v2f/static', self.box_icon),
- ('t3f/static', self.img_tex.tex_coords))
- self.vertex_list = self.batch.add(4, pyglet.gl.GL_QUADS, None ,
- ('v3f/static', self.box_verts),
- ('c4f/static', self.box_color*4)
- )
- def draw_title(self):
- if self.name:
- self.text_label = pyglet.text.Label(self.name, x=self.x+self.w//2, y=self.y+14,
- anchor_y='top',anchor_x='center' ,
- color=self.color, bold=True,
- font_name ='FreeSans', font_size = 8,
- batch = self.batch, group = self.text_group
- )
- def draw_icon(self):
- pass
- def get_xyz(self):
- return self.x, self.y, self.z
- def get_box_verts(self):
- return self.box_verts
- def draw_all(self):
- batch.draw()
- def update(self):
- self.box_verts = [self.x,self.y,self.z,self.x,self.y+self.h,self.z,self.x+self.w,self.y+self.h,self.z,self.x+self.w,self.y,self.z]
- self.box_verts2d = [self.x,self.y,self.x,self.y+self.h,self.x+self.w,self.y+self.h,self.x+self.w,self.y]
- self.vertex_list.vertices = self.box_verts
- self.vertex_list.colors = self.box_color*4
- class top_titles(object):
- def __init__(self, x, y , n , ww, wh, text, batch):
- self.x = x
- self.y = y
- self.wh = wh
- self.ww = ww
- self.text = text
- self.cx = (n/2)+self.x
- self.batch = batch
- self.label = pyglet.text.Label(self.text,
- font_name='FreeSans',
- font_size=24,
- x = self.cx, y= self.wh-(self.y /2),
- anchor_x='center', anchor_y='center', batch = self.batch)
- def update(self, x ):
- self.x = x
- self.label.x = self.x
- def get_center_x(self):
- return self.cx
Add Comment
Please, Sign In to add comment