| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
import Numeric |
|---|
| 27 |
from OpenGL import GL |
|---|
| 28 |
|
|---|
| 29 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 30 |
#~ Definitions |
|---|
| 31 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 32 |
|
|---|
| 33 |
class ProgressBar(object): |
|---|
| 34 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 35 |
#~ Constants / Variables / Etc. |
|---|
| 36 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 37 |
|
|---|
| 38 |
NumericType = Numeric.Float16 |
|---|
| 39 |
StartColor = Numeric.array([.2, .2, .6, 0.8], NumericType) |
|---|
| 40 |
EndColor = Numeric.array([.3, .7, .3, 0.8], NumericType) |
|---|
| 41 |
OutlineColor = Numeric.array([1., 1., 1., 0.8], NumericType) |
|---|
| 42 |
|
|---|
| 43 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 44 |
#~ Public Methods |
|---|
| 45 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 46 |
|
|---|
| 47 |
def __init__(self, progress=0., pos0=(-0.9, -0.05), pos1=(0.9, 0.05), scaledim=(0.99, 0.8)): |
|---|
| 48 |
self.pos0 = Numeric.asarray(pos0, self.NumericType) |
|---|
| 49 |
self.pos1 = Numeric.asarray(pos1, self.NumericType) |
|---|
| 50 |
self.scaledim = Numeric.asarray(scaledim, self.NumericType) |
|---|
| 51 |
self.SetProgress(progress) |
|---|
| 52 |
|
|---|
| 53 |
def GetProgress(self, progress): |
|---|
| 54 |
return self.progress |
|---|
| 55 |
def SetProgress(self, progress): |
|---|
| 56 |
self.progress = progress |
|---|
| 57 |
|
|---|
| 58 |
def GLExecute(self, context): |
|---|
| 59 |
dim = self.pos1-self.pos0 |
|---|
| 60 |
x0, y0 = 0.5*(self.pos1+self.pos0-self.scaledim*dim) |
|---|
| 61 |
dx, dy = self.scaledim*dim |
|---|
| 62 |
dx *= self.progress |
|---|
| 63 |
self._DrawProgressBar((x0,y0), (x0+dx,y0+dy)) |
|---|
| 64 |
self._DrawOutline(self.pos0, self.pos1) |
|---|
| 65 |
|
|---|
| 66 |
def _DrawProgressBar(self, (x0, y0), (x1, y1)): |
|---|
| 67 |
color = (1.-self.progress)*self.StartColor + self.progress*self.EndColor |
|---|
| 68 |
GL.glColor4fv(color) |
|---|
| 69 |
GL.glRectf(x0, y0, x1, y1) |
|---|
| 70 |
|
|---|
| 71 |
def _DrawOutline(self, (x0, y0), (x1, y1)): |
|---|
| 72 |
GL.glColor4fv(self.OutlineColor) |
|---|
| 73 |
GL.glBegin(GL.GL_LINE_LOOP) |
|---|
| 74 |
GL.glVertex2f(x0,y0) |
|---|
| 75 |
GL.glVertex2f(x0,y1) |
|---|
| 76 |
GL.glVertex2f(x1,y1) |
|---|
| 77 |
GL.glVertex2f(x1,y0) |
|---|
| 78 |
GL.glEnd() |
|---|
| 79 |
|
|---|
| 80 |
class CenteredProgressBar(ProgressBar): |
|---|
| 81 |
def GLExecute(self, context): |
|---|
| 82 |
dim = self.pos1-self.pos0 |
|---|
| 83 |
cx, cy = 0.5*(self.pos1+self.pos0) |
|---|
| 84 |
dx, dy = 0.5*self.scaledim*dim |
|---|
| 85 |
dx *= self.progress |
|---|
| 86 |
self._DrawProgressBar((cx-dx,cy-dy),(cx+dx,cy+dy)) |
|---|
| 87 |
self._DrawOutline(self.pos0, self.pos1) |
|---|
| 88 |
|
|---|