Просмотр исходного кода

add: spectrum view to ray-dmx.py

micha 4 месяцев назад
Родитель
Сommit
67caf05299
1 измененных файлов с 67 добавлено и 59 удалено
  1. 67 59
      tkray/dmx.py

+ 67 - 59
tkray/dmx.py

@@ -1,13 +1,14 @@
 #from pyray import *
 import pyray 
 
-for i in dir(pyray):
-    if i.startswith("draw_"):
-        print(i)
+#for i in dir(pyray):
+#    if i.startswith("draw_"):
+#        print(i)
+
 #exit()
-pyray.ConfigFlags(pyray.FLAG_MSAA_4X_HINT) #|FLAG_WINDOW_RESIZABLE  )
+#pyray.ConfigFlags(pyray.FLAG_MSAA_4X_HINT) #|pyray.FLAG_WINDOW_RESIZABLE  )
 #pyray.ConfigFlags(pyray.FLAG_WINDOW_RESIZABLE  )
-pyray.ConfigFlags(pyray.FLAG_WINDOW_HIGHDPI )
+#pyray.ConfigFlags(pyray.FLAG_WINDOW_HIGHDPI )
 pyray.init_window(760, 450, "RAY-DMX")#,10,10,10,10)
 #pyray.TextureFilter(font10,1)
 
@@ -131,7 +132,7 @@ def draw_mouse_box(window,pos1,mouse=[None,None,None],color=[128,128,128],text=1
     global mouse_box_on_pos 
     global mouse_box_on 
 
-    if mouse[0]=="press":
+    if mouse[0]=="click":#"press":
         if mouse_box_on == 0:
             pos2 = pos1[:]
             mouse_box_on_pos = pos2
@@ -185,54 +186,36 @@ def check_area(pos,event_pos):
     if x and y:
         return 1
 
+spectrum = [[255,127]]*40
 def render_spectrum(cur,x,y):
-    xi=0
-    yi=0
-    grid_x = x #250
-    grid_y = y #60
-
-    for i,v in enumerate(range(20)):
-        # COL NUMBER -> 1 2... 20
-        x2 = grid_x+i*25#+xi
-        y2 = grid_y-20 #+yi
+    
+    pyray.draw_text_ex(font25,"SRC:{}".format(cur),[x-20,y-50], 25, 0,  pyray.VIOLET)
+            
+    txt="1 DMX"
+    pyray.draw_text_ex(font10,txt, [x,y-20], font_size, 0, [0,255,0,255]) #pyray.YELLOW)
+    txt="255"
+    pyray.draw_text_ex(font10,txt, [x+230,y-20], font_size, 0, [0,255,0,255]) #pyray.YELLOW)
+    txt="512 DMX"
+    pyray.draw_text_ex(font10,txt, [x+470,y-20], font_size, 0, [0,255,0,255]) #pyray.YELLOW)
 
-        txt=str(i+1)
-        pyray.draw_text_ex(font10,txt, [x2,y2], font_size, 0, [0,255,0,255]) #pyray.YELLOW)
-        i+=1
     DMX=mc.get(cur)
-    pyray.draw_text_ex(font25,"SRC:{}".format(cur),[grid_x-20,grid_y-50], 25, 0,  pyray.VIOLET)
+    spectrum.append(DMX)
+    if len(spectrum) > 40:
+        spectrum.pop(0)
+
+    for i,lines in enumerate(spectrum):
+        for j,pix in enumerate(lines):
+            if type(pix) is not int:
+                pix=0
+            if pix > 255:
+                pix=255
+            if pix < 0:
+                pix=0
+            c=[255,255,255,pix]
+            #pyray.draw_pixel(x+j,y+i*6,c)
+            pyray.draw_line(x+j,y+i*6,x+j,y+i*6-5,c)
 
-    for i,v in enumerate(DMX):
-        if v:
-            host_list[k][-1] +=1
-        txt = str(v)
-        x2 = grid_x+xi*25
-        y2 = grid_y+yi*15
-        try:
-            pyray.draw_rectangle(x2-2, y2-2,24,13,[255,255,255,int(v)])
-        except:
-            pyray.draw_rectangle(x2-2, y2-2,24,13,[255,2,2,255])
 
-        try:
-            int(v)
-        except:
-            v=0
-
-
-        if int(v) > 100:
-            pyray.draw_text_ex(font10,txt, [x2,y2], font_size, 0, pyray.BLACK)# pyray.VIOLET)
-        else:
-            pyray.draw_text_ex(font10,txt, [x2,y2], font_size, 0, pyray.GRAY)# pyray.VIOLET)
-        xi+=1
-
-        if xi % 20 == 0:
-            txt = str(int(yi*20)+1)
-            pyray.draw_text_ex(font10,txt, [grid_x-30,y2], font_size, 0, pyray.YELLOW)# pyray.VIOLET) # ROEW NR
-
-            xi = 0
-            yi += 1
-    txt = str(int(yi*20)+1)
-    pyray.draw_text_ex(font10,txt, [grid_x-30,y2], font_size, 0, pyray.YELLOW)# pyray.VIOLET) # ROEW NR
 def render_grid(cur,x,y):
     xi=0
     yi=0
@@ -270,7 +253,7 @@ def render_grid(cur,x,y):
         if int(v) > 100:
             pyray.draw_text_ex(font10,txt, [x2,y2], font_size, 0, pyray.BLACK)# pyray.VIOLET)
         else:
-            pyray.draw_text_ex(font10,txt, [x2,y2], font_size, 0, pyray.GREY)# pyray.VIOLET)
+            pyray.draw_text_ex(font10,txt, [x2,y2], font_size, 0, GREY)# pyray.VIOLET)
         xi+=1
 
         if xi % 20 == 0:
@@ -285,6 +268,12 @@ def render_grid(cur,x,y):
 buttons={} #[]
 cur = None
 history = []
+
+spectrum_btn=BUTTON(None,"SPECTRUM",[3,610,20,90])
+spectrum_btn.btn.btn1.color    = pyray.YELLOW # [127,127,127,255]
+spectrum_btn.btn.btn1.color_on = pyray.YELLOW # [127,127,127,255]
+
+add=0
 while not pyray.window_should_close():
     pyray.begin_drawing()
 
@@ -312,8 +301,11 @@ while not pyray.window_should_close():
 
         if cur is None:
             cur = k #k[3] #"xx123" # k
-        #render_grid(cur,250,50)
-        render_spectrum(cur,250,50)
+
+        if spectrum_btn.btn.btn1.val.get():
+            render_spectrum(cur,240,50)
+        else:
+            render_grid(cur,250,50)
 
         p=0
         for k,v in host_list.items():
@@ -324,14 +316,13 @@ while not pyray.window_should_close():
 
             key = txt.split(" ")[0]
             p+=22
-
             if key in buttons:
                 btn = buttons[key]
             else:
                 btn=BUTTON(None,txt,[y2,x2,20,190])
                 buttons[key] = btn
                 print("ADD",key,btn)
-            
+                add=1
             btn.btn.btn1.name = txt
             btn.btn.btn1.color_on = [255,255,0,255]
             btn.btn.btn1.val.set(0)
@@ -340,6 +331,9 @@ while not pyray.window_should_close():
                 #btn.btn.btn1.press() #val.set(255)
 
 
+        if add:
+            add=0
+            print()
         w=200
         h=50
 
@@ -361,15 +355,27 @@ while not pyray.window_should_close():
             if pyray.is_mouse_button_released(i):
                 ev = "release"
             if pyray.is_mouse_button_pressed(i):
-                ev = "press"
+                ev = "click" #"press"
             if ev and ev != mouse[i]:
                 mouse[i] = ev
                 mouse_change=1
 
         if mouse != mouse_old and mouse != [None,None,None]:
-            print(mouse)
+            #print(mouse)
             mouse_old = mouse[:]
 
+        spectrum_btn.event(old_x,old_y,mouse_old) #abtn.btn1.name = "SPECTRUM"
+        if check_area(spectrum_btn.btn.pos,[old_y,old_x]):#event_pos):
+            if "release" == mouse_old[0]:
+                print( spectrum_btn.btn.btn1.val.get(),mouse_old)
+                if spectrum_btn.btn.btn1.val.get():
+                    spectrum_btn.btn.btn1.val.set(0)
+                    spectrum_btn.btn.btn1.name = "SPECTRUM"
+                else:
+                    spectrum_btn.btn.btn1.val.set(255)
+                    spectrum_btn.btn.btn1.name = "DMX-GRID" 
+        spectrum_btn.draw()
+            
         for k,btn in buttons.items():
             btn.event(old_x,old_y,mouse_old)
             #if "press" == mouse_old[0]:
@@ -384,19 +390,21 @@ while not pyray.window_should_close():
             btn.draw()
             aapos = draw_mouse_box(None,[old_x,old_y],mouse_old,color=[128,128,128],text=1)
 
-
+        
         pyray.draw_text_ex(font20,"POS:{}:{}".format(int(m.x),int(m.y)),[10,34], 20, 0,  pyray.VIOLET)
 
         pyray.draw_rectangle(int(old_x-10),int(old_y-1),20,2,[255,0,255,255])
         pyray.draw_rectangle(int(old_x-1),int(old_y-10),2,20,[255,0,255,255])
 
         pyray.end_drawing()
-        time.sleep(1/10)
+        time.sleep(1/11)
 
         for i,v in enumerate(mouse_old):
             if v == "release":
                 mouse_old[i] = None
-        print(mouse_old)
+            if v == "click":
+                mouse_old[i] = "press"
+        #print(mouse_old)
         frame_count += 1
         if time.time()-start > 1:
             start = time.time()