Users browsing this thread: 1 Guest(s)
Another UMC side-thread
#10
good news, my awesome brain came up with something Genki ^_^
Code:
class _SelectBox(_Widget):
    def __init__(this, X,Y,W,Na,Items,Def=0,Text='',priority=0):
        _Widget.__init__()
        this.widgets[Na] = this

        # names
        this.sbna='SelectBox%sQuad'%Na
        this.sbfna='SelectBox%sText'%Na
        this.sbbna='SelectBox%sButtonQuad'%Na
        this.sbbdna='SelectBox%sButtonDecal'%Na

        # priorities
        this.p2 = priority+2
        this.p3 = priority+3
        
        # minor pre-calculations
        this.X,this.Y,this.X2,this.Y2 = X,Y,X+W,Y+20.
        this.sy = this.Y2-this.Y
        this.hsy=this.sy*.5
        this.hsx2 = ((this.X2+15.)-this.X2)*.5
        
        this.info=[Def,Items[Def],False] # [selectionID, selectionItem, isOpen]
        this.hitdef.x=this.X; this.hitdef.y=this.Y
        this.hitdef.X=this.X2+15.; this.hitdef.Y=this.Y2

        this.add()
    
    def add(this):
        this.layer[0].stack[this.p2].AddQuad(this.sbna,[this.X,this.Y],[this.X2,this.Y],[this.X2,this.Y2],[this.X,this.Y2],(175,175,175,180))
        this.layer[0].stack[this.p2].AddString(this.sbfna,this.info[1],0.667,this.X+5.,this.Y+2.,None,None,(0,0,0,220))
        this.layer[0].stack[this.p2].AddQuad(this.sbbna,[this.X2,this.Y],[this.X2+15.,this.Y],[this.X2+15.,this.Y2],[this.X2,this.Y2],(95,95,95,180))
        this.layer[0].stack[this.p3].AddTri(this.sbbdna,[this.X2+5.,(this.Y+this.hsy)-2.],[(this.X2+15.)-5.,(this.Y+this.hsy)-2.],[this.X2+this.hsx2,(this.Y+this.hsy)+2.], (63,63,63,180))
        
    def update(this):
        if not this.layer[0].stack[this.p2].HasPrimitive(this.sbna): this.add() #TODO: get rid of this
            
        SB = this.layer[0].stack[this.p2].primitives[this.sbna]
        SBF = this.layer[0].stack[this.p2].strings[this.sbfna]
        SBB = this.layer[0].stack[this.p2].primitives[this.sbbna]
        SBBD = this.layer[0].stack[this.p3].primitives[this.sbbdna]
        
        #Positioning Verification
        if SB.Position([this.X,this.Y],[this.X2,this.Y],[this.X2,this.Y2],[this.X,this.Y2]):
            SBF.Position(this.X+5.,this.Y+2.,None,None)
            SBB.Position([this.X2,this.Y],[this.X2+15.,this.Y],[this.X2+15.,this.Y2],[this.X2,this.Y2])
            SBBD.Position([this.X2+5.,(this.Y+this.hsy)-2.],[(this.X2+15.)-5.,(this.Y+this.hsy)-2.],[this.X2+this.hsx2,(this.Y+this.hsy)+2.])
        
        #HitDef
        if this.hitdef.x!=this.X: this.hitdef.x=this.X; this.hitdef.X=this.X2+15.
        if this.hitdef.y!=this.Y: this.hitdef.y=this.Y; this.hitdef.Y=this.Y2
        
    def remove(this):
        this.hitdef.enabled=False
        this.layer[0].stack[this.p2].RemovePrimitive(this.sbna)
        this.layer[0].stack[this.p2].RemoveString(this.sbfna)
        this.layer[0].stack[this.p2].RemovePrimitive(this.sbbna)
        this.layer[0].stack[this.p3].RemovePrimitive(this.sbbdna)

    #TODO: event functions

it's far from finished, but should work better than before Smile

I'mma see if I can cut down on the CPU usage a bit more Wink
the draw-code is gonna be the hardest part here.
you see the parts with this.layer[0].stack[this.p2]
take a guess at what parses that.

the reason that's gonna be hard is because I'm already removing what's not drawn...
so the best I could possibly do is optimize.

one big area that needs alot of work is the update code, as that's about half the current CPU usage... heh

why CPU and not GPU if GPU is so much faster?
because I was a noob when I built the interface and followed tuts on GLUT and SDL...
so the interface currently CAN'T run on the GPU any more than it already is...

wait for 3.0 where I'll have shaders to hopefully pass the whole draw-code to the GPU Smile


btw, SDL sucks.
it clears the GL context on a video resize event, forcing you to have to rebuild it.
it also gimps your mouse usage, but luckily I've worked around that. Smile

what's better?
take a look into GLFW Wink
it's SDL+freeglut (no limitations)

I can't promise I'll have GLFW support on the next release of 3.0a, but I'll try for it. Wink


EDIT: btw, if anyone wants to watch me code the new GUI, it's actively sync'd from my compy here:
https://copy.com/vBWPp0VGzmk6dWuK
^ every Ctrl+S I make goes there, so you get the src fresh from my compy Smile

for the old GUI (which still works), you can find that here:
https://copy.com/p6N0xfn6oA3plh3O
good luck trying to understand it though Tongue

NOTE:
in UMC3.0 this will be a plugin, meaning it can be removed, and UMC will still run w/o it. Wink
WIDGETS.py won't work w/o GUI.py though which provides the widgets for UMC-scripts.
basically, that's what the CMD var in the import/export functions will be used for Smile
Reply
Thanked by:


Messages In This Thread
Another UMC side-thread - by Tcll - 12-13-2014, 01:18 AM
RE: Another UMC side-thread - by Tcll - 12-13-2014, 11:44 PM
RE: Another UMC side-thread - by Struggleton! - 12-13-2014, 11:44 PM
RE: Another UMC side-thread - by Tcll - 12-14-2014, 12:30 AM
RE: Another UMC side-thread - by Tcll - 12-15-2014, 09:56 PM
RE: Another UMC side-thread - by Tcll - 12-17-2014, 03:17 PM
RE: Another UMC side-thread - by puggsoy - 12-17-2014, 08:39 PM
RE: Another UMC side-thread - by Struggleton! - 12-17-2014, 09:15 PM
RE: Another UMC side-thread - by Tcll - 12-17-2014, 11:34 PM
RE: Another UMC side-thread - by Tcll - 12-18-2014, 01:55 AM
RE: Another UMC side-thread - by Tcll - 12-27-2014, 02:57 AM
RE: Another UMC side-thread - by Struggleton! - 12-29-2014, 12:37 AM
RE: Another UMC side-thread - by Tcll - 12-29-2014, 12:43 AM
RE: Another UMC side-thread - by Tcll - 01-01-2015, 01:59 PM
RE: Another UMC side-thread - by Tcll - 01-29-2015, 12:26 AM
RE: Another UMC side-thread - by Tcll - 01-30-2015, 01:22 AM
RE: Another UMC side-thread - by Tcll - 02-14-2015, 07:02 PM
RE: Another UMC side-thread - by Tcll - 02-15-2015, 03:37 PM
RE: Another UMC side-thread - by Tcll - 02-28-2015, 09:03 AM
RE: Another UMC side-thread - by Tcll - 03-10-2015, 09:11 AM
RE: Another UMC side-thread - by Tcll - 03-22-2015, 08:59 AM
RE: Another UMC side-thread - by Tcll - 03-31-2015, 12:54 AM
RE: Another UMC side-thread - by Tcll - 04-04-2015, 09:58 PM
RE: Another UMC side-thread - by Tcll - 04-11-2015, 09:23 AM
RE: Another UMC side-thread - by Tcll - 04-14-2015, 01:19 AM
RE: Another UMC side-thread - by Manki - 04-14-2015, 07:37 PM
RE: Another UMC side-thread - by Tcll - 04-14-2015, 08:54 PM
RE: Another UMC side-thread - by Tcll - 06-14-2015, 03:43 PM
RE: Another UMC side-thread - by Tcll - 06-18-2015, 09:20 AM
RE: Another UMC side-thread - by Tcll - 06-21-2015, 09:22 AM
RE: Another UMC side-thread - by Tcll - 07-09-2015, 01:27 PM
RE: Another UMC side-thread - by Tcll - 07-09-2015, 11:43 PM
RE: Another UMC side-thread - by Tcll - 08-10-2015, 10:26 PM

Forum Jump: