merged in a few improvements from the older branch of roc
This commit is contained in:
parent
8efc87d502
commit
e74599be02
2 changed files with 118 additions and 3 deletions
|
@ -14,7 +14,7 @@ class datastorage(object):
|
||||||
|
|
||||||
|
|
||||||
class gameobj(object):
|
class gameobj(object):
|
||||||
def __init__(self, self.pos):
|
def __init__(self, pos):
|
||||||
self.pos = pos
|
self.pos = pos
|
||||||
self.roles = []
|
self.roles = []
|
||||||
self.effects = []
|
self.effects = []
|
||||||
|
@ -122,4 +122,4 @@ class billboard_role(role):
|
||||||
order = 3000
|
order = 3000
|
||||||
phases = (enums.phase.move,)
|
phases = (enums.phase.move,)
|
||||||
def update(self, owner, phase):
|
def update(self, owner, phase):
|
||||||
"we have no AI yet..."
|
"we have no AI yet..."
|
||||||
|
|
117
roc/widgets.py
117
roc/widgets.py
|
@ -1,9 +1,31 @@
|
||||||
|
import models
|
||||||
|
from OpenGL.GL import *
|
||||||
|
|
||||||
|
class Themer(object):
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def Button(self, pos, label, callback, xmin=None, ymin=None, xmax=None, ymax=None):
|
||||||
|
b = Button(pos, label, callback)
|
||||||
|
b.border = models.mgr.create('ui_button_edge')
|
||||||
|
b.corner = models.mgr.create('ui_button_corner')
|
||||||
|
b.background = models.mgr.create('ui_button_background')
|
||||||
|
b.font = models.mgr.fontlib["micross20"]
|
||||||
|
b.xmin = xmin
|
||||||
|
b.ymin = ymin
|
||||||
|
b.xmax = xmax
|
||||||
|
b.ymax = ymax
|
||||||
|
return b
|
||||||
|
|
||||||
|
theme = Themer()
|
||||||
|
|
||||||
class BaseWidget(object):
|
class BaseWidget(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def render(self):
|
||||||
|
pass
|
||||||
|
|
||||||
class InvisibleWidget(BaseWidget):
|
class InvisibleWidget(BaseWidget):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -11,11 +33,104 @@ class BoxWidget(BaseWidget):
|
||||||
def __init__(self, pos):
|
def __init__(self, pos):
|
||||||
self.pos = pos
|
self.pos = pos
|
||||||
self.border = None
|
self.border = None
|
||||||
|
self.corner = None
|
||||||
self.background = None
|
self.background = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Button(BoxWidget):
|
class Button(BoxWidget):
|
||||||
def __init__(self, pos, label, callback):
|
def __init__(self, pos, label, callback):
|
||||||
BoxWidget.__init__(self, pos)
|
BoxWidget.__init__(self, pos)
|
||||||
|
self.label = label
|
||||||
|
self.callback = callback
|
||||||
|
self.size = None
|
||||||
|
|
||||||
def
|
def get_size(self):
|
||||||
|
labelsize = self.font.size(self.label)
|
||||||
|
newx = labelsize[0]
|
||||||
|
newy = labelsize[1]
|
||||||
|
if self.xmax != None and self.xmax < labelsize[0]:
|
||||||
|
newx = self.xmax
|
||||||
|
if self.ymax != None and self.ymax < labelsize[1]:
|
||||||
|
newy = self.ymax
|
||||||
|
if self.xmin != None and self.xmin > labelsize[0]:
|
||||||
|
newx = self.xmax
|
||||||
|
if self.ymin != None and self.ymin > labelsize[1]:
|
||||||
|
newy = self.ymin
|
||||||
|
|
||||||
|
self.size = (newx, newy)
|
||||||
|
|
||||||
|
|
||||||
|
def render(self):
|
||||||
|
if self.size == None:
|
||||||
|
self.calc_size()
|
||||||
|
|
||||||
|
glPushMatrix()
|
||||||
|
glTranslatef(*self.pos)
|
||||||
|
|
||||||
|
# do corners first
|
||||||
|
glPushMatrix()
|
||||||
|
glRotatef(0.0, 0.0, 0.0, 1.0)
|
||||||
|
glTranslatef(-4.0, -4.0, 0.0)
|
||||||
|
self.corner.render()
|
||||||
|
glPopMatrix()
|
||||||
|
|
||||||
|
glPushMatrix()
|
||||||
|
glRotatef(90.0, 0.0, 0.0, 1.0)
|
||||||
|
glTranslatef(self.size[0], -4.0, 0.0)
|
||||||
|
self.corner.render()
|
||||||
|
glPopMatrix()
|
||||||
|
|
||||||
|
glPushMatrix()
|
||||||
|
glRotatef(180.0, 0.0, 0.0, 1.0)
|
||||||
|
glTranslatef(self.size[0], self.size[1], 0.0)
|
||||||
|
self.corner.render()
|
||||||
|
glPopMatrix()
|
||||||
|
|
||||||
|
glPushMatrix()
|
||||||
|
glRotatef(270.0, 0.0, 0.0, 1.0)
|
||||||
|
glTranslatef(-4.0, self.size[1], 0.0)
|
||||||
|
self.corner.render()
|
||||||
|
glPopMatrix()
|
||||||
|
|
||||||
|
# do border edges next
|
||||||
|
glPushMatrix()
|
||||||
|
glRotatef(0.0, 0.0, 0.0, 1.0)
|
||||||
|
glTranslatef(-4.0, 0.0, 0.0)
|
||||||
|
self.border.render()
|
||||||
|
glPopMatrix()
|
||||||
|
|
||||||
|
glPushMatrix()
|
||||||
|
glRotatef(90.0, 0.0, 0.0, 1.0)
|
||||||
|
glTranslatef(self.size[0], 0.0, 0.0)
|
||||||
|
self.border.render()
|
||||||
|
glPopMatrix()
|
||||||
|
|
||||||
|
glPushMatrix()
|
||||||
|
glRotatef(180.0, 0.0, 0.0, 1.0)
|
||||||
|
glTranslatef(self.size[0], self.size[1], 0.0)
|
||||||
|
self.border.render()
|
||||||
|
glPopMatrix()
|
||||||
|
|
||||||
|
glPushMatrix()
|
||||||
|
glRotatef(270.0, 0.0, 0.0, 1.0)
|
||||||
|
glTranslatef(-4.0, self.size[1], 0.0)
|
||||||
|
self.border.render()
|
||||||
|
glPopMatrix()
|
||||||
|
|
||||||
|
# last piece is the background
|
||||||
|
glPushMatrix()
|
||||||
|
glTranslatef(0.0, 0.0, 0.0)
|
||||||
|
self.background.render()
|
||||||
|
glPopMatrix()
|
||||||
|
|
||||||
|
# finally add the text
|
||||||
|
|
||||||
|
glPushMatrix()
|
||||||
|
glTranslatef(0.0, 0.0, 0.01)
|
||||||
|
self.background.render()
|
||||||
|
glPopMatrix()
|
||||||
|
|
||||||
|
self.font.render(self.label)
|
||||||
|
glPopMatrix()
|
||||||
|
|
Loading…
Add table
Reference in a new issue