Welcome to mirror list, hosted at ThFree Co, Russian Federation.

uvpaint.py « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 357c2d94aed67e6bff7ac593e59f5fc3963db295 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
#!BPY

""" Registration info for Blender menus: <- these words are ignored
Name: 'UVpainter'
Blender: 232
Group: 'UV'
Tip: 'Use vertex paint color value to fill uvmapping'
"""

__author__ = "Jean-Michel Soler (jms)"
__url__ = ("blender", "elysiun",
"Script's homepage, http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_uvpainting.htm",
"Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender")
__version__ = "0.8 08/2005"

__bpydoc__ = """\
This script "paints" uv-mappings with the model's vertex colors.

Usage:

With this script you can export uv-maps filled with vertex colors to TARGA
(.tga) images.  To use it the mesh must have proper uv coordinates assigned
in UV Face Select Mode.  And to fill the projected faces with color, the mesh
can also have material(s) and vertex colors painted on it.

The script has a GUI with a preview of the results and options like drawing
lines or not, defining size, etc.  You can paint vertex colors in the mesh and
see the uv-map updated in the script's window.

Notes:<br>
    Material's rgb color is also used to fill the uv-map;<br>
    If there are no vertex colors or texture faces in the mesh and you press
the "Make" VColors button in the edit mesh buttons win, the current light setup
is saved as vertex colors for the model;<br>
    Check the script's homepage for example images.

Short keys  Documentation

KEYS 
M : dipslay GUI Menu
D : Set/Unset Documentation
S : Save current window content
       in a tga file
Q or ESC : Exit
T : Set/Unset Transparency
L : Set/Unset lines
E : Set/Unset outline
B : Set lines color to Black 
W : Set lines color to white
ARROW   : displace model on 
         UP/DOWN/LEFT/RIGHT side
PADPLUS : increase ZOOM 
PADMINUS   : decrease  ZOOM 	
HOME    : cancel display modifs

Mouse button
RIGHTMOUSE : same as  arrows
	
"""

# $Id$
#
#----------------------------------------------
# uvpainter script (c) 04/2004  jean-michel soler
# http://jmsoler.free.fr/util/blenderfile/py/UVpaint05.zip
# this script is released under GPL licence
# for the Blender 2.33 scripts distribution
#----------------------------------------------
# Official page :
# http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_uvpainting.htm
# Communicate problems and errors on:
# http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender 
#----------------------------------------------
# Page officielle :
#   http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_uvpainting.htm
# Communiquer les problemes et erreurs sur:
#   http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
#--------------------------------------------- 
# ce script est proposé sous licence GPL pour etre associe
# a la distribution de Blender 2.33 et suivant
# --------------------------------------------------------------------------
# this script is released under GPL licence
# for the Blender 2.33 scripts package
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Script copyright (C) 2003, 2004: Jean-Michel Soler 
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------

import Blender
from Blender.Draw import *
from Blender.BGL import *
from Blender.NMesh import *

try:
  import nt
  os=nt
except:
   import posix
   os=posix

def exist(path):
       try:
        pth=os.stat(Blender.sys.dirname(path))  
       except:
        return 0
       return 1 

loc0= Blender.Get ("filename").replace('\\','/')
loc0=loc0[:loc0.rfind('/')]
	
loc2=loc0+'/'+'test00.tga' 


mouse_x,mouse_y=0,0
mouse_xr=1
mouse_yr=1
POS=[0,0]
ANC=[0,0]
XY=[0,0]
size=[]
sel=0
X,Y=0,0
TRANSP,EMPTY,DOCU=0,0,0
MENU, SAVE =1,0

glCr=glRasterPos2d
glCl3=glColor3f
glCl4=glColor4f
glRct=glRectf

LC=1.0

xlimit=0
selmatlist=[]
LIM=[0.0,0.0,0.0,0.0]
NOLIM=1
if not NOLIM : LIM=[-1.0,1.0,-1.0,1.0]

TR=0.8

def Doc(size):
    S0,S1=40,50
	
    a=[S0,size[3]-S1, .8,.8,.8]
    b=[S0*7,size[3]-S1, .8,0.8,0.8]
    c=[S0*7,size[3]-S1*7, 0.8,0.8,0.8]
    d=[S0,size[3]-S1*7, 0.8,0.8,0.8]
    Tcarre(a,b,c,d,0.8)
    Lcarre(a,b,c,d,0.0)
    DOC=[' ',
'Documentation',
' ',
'KEYS ',
'M : dipslay GUI Menu',
'D : Set/Unset Documentation',
'S : Save current window content',
'       in a tga file',	
'Q or ESC : Exit',
'T : Set/Unset Transparency',
'L : Set/Unset lines',	
'E : Set/Unset outline',
'B : Set lines color to Black ',
'W : Set lines color to white',
'ARROW   : displace model on ',
'         UP/DOWN/LEFT/RIGHT side' 	,
'PADPLUS : increase ZOOM ',
'PADMINUS   : decrease  ZOOM ',	
'HOME    : cancel display modifs',
' ',
'Mouse button',	
'RIGHTMOUSE : same as  arrows',
]
    glColor3f(0.0,0.0,0.0)
    for D in DOC :
      glRasterPos2f(S0+8, size[3]-S1-13*DOC.index(D))
      Text(D)

def Ttriangle(a,b,c):
  glBegin(GL_TRIANGLES);
  glColor4f(a[2],a[3],a[4],TR)
  glVertex2f(a[0],a[1]);
  glColor4f(b[2],b[3],b[4],TR)
  glVertex2f(b[0],b[1]);
  glColor4f(c[2],c[3],c[4],TR)
  glVertex2f(c[0],c[1]);
  glEnd();

def Ftriangle(a,b,c):
  glBegin(GL_TRIANGLES);
  glColor3f(a[2],a[3],a[4])
  glVertex2f(a[0],a[1]);
  glColor3f(b[2],b[3],b[4])
  glVertex2f(b[0],b[1]);
  glColor3f(c[2],c[3],c[4])
  glVertex2f(c[0],c[1]);
  glEnd();

def Ltriangle(a,b,c,LC=0.5):
  TL=[a,b,c,a] 	
  for v in [0,1,2] :
    glBegin(GL_LINES);
    glColor4f(LC,LC,LC,TR+0.2)
    glVertex2f(TL[v][0],TL[v][1]);
    glVertex2f(TL[v+1][0],TL[v+1][1]);
    glEnd();


def Tcarre(a,b,c,d,LC=1.0):
    Ttriangle(a,b,c)
    Ttriangle(a,c,d)

def Fcarre(a,b,c,d,LC=1.0):
    Ftriangle(a,b,c)
    Ftriangle(a,c,d)

def Lcarre(a,b,c,d,LC=0.5):
  TL=[a,b,c,d,a] 	
  for v in [0,1,2,3] :
    glBegin(GL_LINES);
    glColor4f(LC,LC,LC,TR+0.2)
    glVertex2f(TL[v][0],TL[v][1]);
    glVertex2f(TL[v+1][0],TL[v+1][1]);
    glEnd();

   
def transface(f,x,y,u=0.0, v=0.0):
    global xlimit, LIM  
    global mouse_xr,sel, ANC, X,Y
    global mouse_yr, POS, XY,size
    global mouse_x,  mouse_y

    mouse_x=mouse_xr-size[0]
    mouse_y=mouse_yr-size[1]

    if sel==1:
      POS=[mouse_x-ANC[0],mouse_y-ANC[1]]
    u,v=POS

    a=[0,0,0.0, 0.0,0.0,0.0]
    b=[0,0,0.0, 0.0,0.0,0.0]
    c=[0,0,0.0, 0.0,0.0,0.0]
    d=[0,0,0.0, 0.0,0.0,0.0]

    if len(f.v)>=3:
        a[0]=int((f.uv[0][0]-LIM[1])*x+u)
        a[1]=int((f.uv[0][1]-LIM[3])*y+v)

        if a[0]>xlimit:
               xlimit=a[0]

        a[2]=f.col[0].r/255.0
        a[3]=f.col[0].g/255.0
        a[4]=f.col[0].b/255.0

        c[0]=int((f.uv[2][0]-LIM[1])*x+u)
        c[1]=int((f.uv[2][1]-LIM[3])*y+v)

        if c[0]>xlimit:
               xlimit=c[0]

        c[2]=f.col[2].r/255.0
        c[3]=f.col[2].g/255.0
        c[4]=f.col[2].b/255.0

     
        b[0]=int((f.uv[1][0]-LIM[1])*x+u)
        b[1]=int((f.uv[1][1]-LIM[3])*y+v)

        if b[0]>xlimit:
               xlimit=b[0]

        b[2]=f.col[1].r/255.0
        b[3]=f.col[1].g/255.0
        b[4]=f.col[1].b/255.0


    if  len(f.v)==4:     
        d[0]=int((f.uv[3][0]-LIM[1])*x+u)
        d[1]=int((f.uv[3][1]-LIM[3])*y+v)

        if d[0]>xlimit:
               xlimit=d[0]

        d[2]=f.col[3].r/255.0
        d[3]=f.col[3].g/255.0
        d[4]=f.col[3].b/255.0
    else:
        d=0


    #print a,b,c
    return a,b,c,d


def extract_faces(me,MENU):
    global  TMATList, selmatlist 
    if MENU==2:
       listf=[]
       for f in me.faces:
          if f.mat in selmatlist:
              listf.append(f)
       return listf

def affiche_mesh(ME,x,y):
    global LINE,xlimit,MMENU,XLIMIT,xwin,xlimit,LC
    global LIM, EMPTY,TRANSP
    if not NOLIM : LIM=[-1.0,1.0,-1.0,1.0]
	
    if ME.getType()=='Mesh':
       me=ME.getData()
       if MMENU.val==1:
          se=me.faces
       elif MMENU.val==3:
          se=[s for s in me.faces if s in me.getSelectedFaces() or s.sel]
       elif MMENU.val==2:
           se=extract_faces(me,2) 
       if not NOLIM : 
         for s in se:
           for u in s.uv:
	            if u[0] >LIM[0] : LIM[0]=u[0]
	            if u[0] <LIM[1] : LIM[1]=u[0]
	            if u[1] >LIM[2] : LIM[2]=u[1]
	            if u[1] <LIM[3] : LIM[3]=u[1]		          		
       xlimit=0
       for f in se:
         a,b,c,d=transface(f,x,y)
         if not EMPTY and not TRANSP: 
           if len(f.v)==4:
               Ftriangle(a,b,c)
               Ftriangle(a,c,d)
           elif len(f.v)==3:
               Ftriangle(a,b,c)
         elif not EMPTY : 
           if len(f.v)==4:
               Ttriangle(a,b,c)
               Ttriangle(a,c,d)
           elif len(f.v)==3:
               Ttriangle(a,b,c)

       if LINE.val==1 or EMPTY:
         for f in se:
           a,b,c,d=transface(f,x,y)
           if len(f.v)==4:
              Lcarre(a,b,c,d,LC)
           elif len(f.v)==3:
              Ltriangle(a,b,c,LC)
         if XLIMIT.val==0:
            Lcarre([1,1],[1,y-2],[xlimit+2,y-2],[xlimit+2,1]) 
         else:
            Lcarre([1,1],[1,y-2],[xwin-2,y-2],[xwin-2,1]) 
        
def write_tgafile(loc2,bitmap,width,height,profondeur): 

                  f=open(loc2,'wb') 
                  Origine_en_haut_a_gauche=32 
                  Origine_en_bas_a_gauche=0 
                  Data_Type_2=2 
                  RVB=profondeur*8 
                  RVBA=32 
                  entete0=[] 
                  for t in range(18): 
                    entete0.append(chr(0)) 

                  entete0[2]=chr(Data_Type_2) 
                  entete0[13]=chr(width/256) 
                  entete0[12]=chr(width % 256) 
                  entete0[15]=chr(height/256) 
                  entete0[14]=chr(height % 256) 
                  entete0[16]=chr(RVB) 
                  entete0[17]=chr(Origine_en_bas_a_gauche) 

                  #Origine_en_haut_a_gauche 

                  for t in entete0: 
                    f.write(t) 

                  for t in bitmap:

                    for c in [2,1,0,3]:
                        #print t[c]%256      
                        f.write(chr(t[c]*2)) 
                  f.close() 


def save(x0,y0,dx,dy):
    global SAVE
    im = Buffer(GL_BYTE,[dx*(dy+1),4])
    glReadPixels(x0,y0,dx,dy,GL_RGBA, GL_BYTE,im); 
    print len(im), dx*dy, dx, dy, len(im)/dy    
    write_tgafile(loc2,im,dx,dy+1,4)
    SAVE=0
    Blender.Redraw()

def DOCMat_list(TMATList,ME):
    me=Blender.NMesh.GetRaw(ME.getData().name) 
    if len(me.materials)!=0: 
                n=0 
                for mat in me.materials:
                    TMATList[1][n][0]=mat.R
                    TMATList[1][n][1]=mat.G
                    TMATList[1][n][2]=mat.B
                    n+=1
                TMATList[0]=n
    else:
              TMATList[0]=0
    return TMATList

def SELMat_list():
      global TMATList,selmatlist
      Me=Blender.Object.GetSelected()
      if Me!=[]:
         if Me[0].getType()=='Mesh':   
            TMATList=DOCMat_list(TMATList,Me[0])
            selmatlist=[]
            for TMat in TMATList[2]:
               if TMat.val==1.0:
                  selmatlist.append(TMATList[2].index(TMat))  
            ERROR=0
         else:
            ERROR=1
            TextERROR='Selected Object is not a mesh.'  
      else:
          ERROR=1
          TextERROR='No Selected Object.'  
      
def DOCBONEMENU(TBONEMENU):
    pass

# ----------
# uvpaint1
# ----------
NSIZE=Create(1.0)
# ----------
# uvpaint2
# ----------
LINE=Create(0)
# ----------
# uvpaint3
# ----------
TEXT=Create(loc2)
# ----------
# uvpaint4
# ----------
TMENU="MODE MENU %t|All %x1|Material %x2|Selected %x3"
# ----------
# uvpaint4
# ----------
# coming soon : "|vertex group %x4", perhaps in uvpainter v0.5
LCOLOR= Create(64)
SAVE=0

MMENU=Create(3)
TDOCMat = Create(0)
# ----------
TMATList= [0,[],[]] 
for t in range(16):
    TMATList[1].append([0.0,0.0,0.0])
    TMATList[2].append(Create(0))
# ----------
TDOCMat = Create(1)
# ----------
TBONEMENU= Create(1) 
# ----------

XLIMIT=Create(0)

y=0
x=0
x0=0
y0=0
xwin=0

n0=32

def draw():
    global NSIZE,LINE,x0,y0,y,x,TEXT,MMENU,TDOCMat
    global XLIMIT,selmatlist,xwin, LCOLOR, SAVE
    global mouse_xr,sel, ANC, X,Y, TRANSP, DOCU
    global mouse_yr, POS, XY,size, TRANSP,EMPTY
    global MENU, SAVE

    size=Buffer(GL_FLOAT, 4)
    glGetFloatv(GL_SCISSOR_BOX, size)
    size=[int(s) for s in size ]
    
    n0=32
    x0=size[0]
    y0=size[1]
    
    x=size[2]
    y=size[3]
   
    xwin=x
    ywin=y
   

    glClear(GL_COLOR_BUFFER_BIT)
    glShadeModel(GL_SMOOTH)
    #transparence  
    if TRANSP : 
       glEnable(GL_BLEND)
       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    SelecMESH=Blender.Object.GetSelected()
    if SelecMESH!=[] and SelecMESH[0].getType()=='Mesh':
       affiche_mesh(SelecMESH[0],int(y*NSIZE.val),int(y*NSIZE.val-2))

    if MENU:
        glColor3f(0.0,0.0,0.0)
        glRectf(4,size[3],555,size[3]-32 )
        glColor3f(1.0,1.0,1.0)
       
        glRasterPos2f(8, size[3]-13)
        Text("uvpainter v0.8")
         
        glRasterPos2f(8, size[3]-28)
        Text("Jm Soler, 08/2005")

        Button("ReDraw"      ,16 ,290-118+61 ,size[3]-30  ,60 ,13)
        Button("Exit"        ,1  ,250-122+63 ,size[3]-30  ,38 ,13)
        Button("Save"        ,6  ,250-16+61  ,size[3]-30  ,40 ,13)

        NSIZE= Slider("Sc:",4   ,290-118+61  ,size[3]-15 , 102, 13, NSIZE.val, 0.1,5.0,0,"SIZE.")
        LINE=Toggle("line",   5   ,250-122+63   ,size[3]-15 , 38, 13, LINE.val, "Draw lines")

        glRasterPos2f(250-130  ,size[3]-13,)
        Text("Mode")

        LCOLOR=Number("", 50, 250-77,size[3]-15,18,13,LCOLOR.val,1,64,'Line color, 64-lighter, 1-darker.')

        MMENU= Menu(TMENU    ,2  ,250-130, size[3]-30, 63, 13, MMENU.val, "MODE menu.")

        if MMENU.val==1 or MMENU.val==3:
           glRasterPos2f( 250-16+61+42+80,size[3]-13)
           if XLIMIT.val:
                  xl=xwin
           else:
                  xl=xlimit

           Text("x :"+"%d"%(xl+2))  

           glRasterPos2f(250-16+61+42+65*2,size[3]-13)
           Text("y :"+"%d"%(y-n0+1))  

           TEXT=String("to:",   7   , 278+61  ,size[3]-28 , 213, 13, TEXT.val, 256, "Draw lines")
           if XLIMIT.val==1:
              limit='winlimit'
           else:
              limit='maxXlimit'
           XLIMIT=Toggle(limit, 9   , 250-16+61+42   ,size[3]-15 , 60, 13, XLIMIT.val, "to save picture from x max uv limit, or x window max limit")

        if MMENU.val==2:
           TDOCMat=Toggle("doc"     ,24,250-130+35  ,size[3]-13 , 28, 13, TDOCMat.val)   
           if TDOCMat.val==1:
                 SELMat_list()  
                 for t in range(TMATList[0]):
                     glCl3(TMATList[1][t][0],
                           TMATList[1][t][1],
                           TMATList[1][t][2]) 
                     glRct((293-16+61)+t*20,
                           size[3]-13,
                           (293-16+61)+t*20+20,
                           size[3]-30,)
                     TMATList[2][t]=Toggle("%s"%t , 32+t ,(293-16+61)+t*20  ,size[3]-13  ,20 , 13,TMATList[2][t].val)

    #else:
	#    save()

    if DOCU:
         Doc(size)
		
def event(evt, val):  
    global mouse_x, x, mouse_y, y, LC
    global LCOLOR, DOCU, MENU, SAVE
    global mouse_xr,sel, ANC, X,Y ,NSIZE
    global mouse_yr, POS, XY,size, TRANSP,EMPTY

    if (evt== QKEY or evt== ESCKEY and not val): 
      Exit()
    elif (evt== TKEY and not val): 
       TRANSP=abs(TRANSP-1)
    elif (evt== EKEY and not val): 
       EMPTY=abs(EMPTY-1)
    elif (evt== MKEY and not val): 
       MENU=abs(MENU-1)
    elif (evt== SKEY and not val): 
       SAVE=abs(MENU-1)
    elif (evt== WKEY and not val): 
       LC=1.0
       LCOLOR.val=64
    elif (evt== BKEY and not val): 
       LC=0.0
       LCOLOR.val=1	
    elif (evt==LEFTARROWKEY and not val) :
         POS[0]-=10
    elif (evt==RIGHTARROWKEY and not val) :
         POS[0]+=10
    elif (evt==UPARROWKEY and not val) :
         POS[1]+=10
    elif (evt==DOWNARROWKEY and not val) :
         POS[1]-=10
    elif (evt==PADMINUS and not val) :
         NSIZE.val-=0.1
    elif (evt==PADPLUSKEY and not val) :
         NSIZE.val+=0.1
    elif (evt==LKEY and not val) :
	     LINE.val=abs(LINE.val-1)
    elif (evt==HOMEKEY and not val) :
         NSIZE.val=1.0
         POS=[0,0]
    elif (evt==DKEY and not val) :
	     DOCU=abs(DOCU-1)          
    elif (evt == MOUSEX): mouse_xr = val
    elif (evt == MOUSEY): mouse_yr = val
	
    elif (evt == RIGHTMOUSE and val):
        if (sel==0 ) :
           ANC=[(mouse_xr-size[0])-POS[0],(mouse_yr-size[1])-POS[1]]
           sel=1        
    elif (evt == RIGHTMOUSE and not val):
        sel=0
        ANC=0,0
    Redraw(1)
   

def bevent(evt):
    global LINE,NSIZE,n0,x0,y0,y,TEXT, loc2
    global TMATList, selmatlist, TDOCMat,XLIMIT
    global xlimit,LCOLOR,LC,SAVE

    if   (evt== 1):
        Exit()

    elif   (evt== 16):
         pass

    elif   (evt== 4):
       ng=NSIZE.val

    elif   (evt== 6):
       if XLIMIT.val==1:
        xi=xwin
        save(x0,y0,xi+2,int(y-n0))
       else:
        xi=xlimit
        save(x0,y0,xi+2,int(y*NSIZE.val)-n0)

    elif (evt== 7):
       if exist(TEXT.val):
            loc2=TEXT.val
       else:
            TEXT.val=loc2
 
    elif (evt== 24) or (evt in [32,33,34,35,36,37,38,39,40,41,42,43,44]):
       SELMat_list()

    elif  (evt== 50):
       LC=float(LCOLOR.val)/64.0


    Blender.Redraw()

Register(draw, event, bevent)