1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603 |
- # THIS FILE IS A PART OF VCStudio
- # PYTHON 3
- import os
- import datetime
- # GTK module ( Graphical interface
- import gi
- gi.require_version('Gtk', '3.0')
- from gi.repository import Gtk
- import cairo
- # Own modules
- from settings import settings
- from settings import talk
- from settings import fileformats
- from settings import oscalls
- # Studio
- from studio import story
- from studio import analytics
- from studio import studio_dialogs
- from studio import checklist
- # UI modules
- from UI import UI_testing
- from UI import UI_color
- from UI import UI_elements
- from UI import UI_math
- def node_dot(layer, win, x, y, direction="in", entry="end"):
-
- # This function will draw a dot to which various nodes are connected. And
- # from which connections going off.
-
- # This is a very alpha version of the dot thing
-
- raw_entry = entry
- if type(entry) == list:
- entry = entry[0]+":"+entry[1]
-
-
- if entry.startswith("scene:") or entry in ["start", "end"]:
- UI_color.set(layer, win, "node_script")
- elif entry.startswith("blend:"):
- UI_color.set(layer, win, "node_blendfile")
- else:
- UI_color.set(layer, win, "node_imagefile")
-
- UI_elements.roundrect(layer, win,
- x,
- y,
- 0,
- 0,
- 6)
-
- if int(win.current["mx"]) in range(int(x), int(x+12))\
- and int(win.current["my"]) in range(int(y), int(y+12)):
- UI_color.set(layer, win, "text_normal")
- UI_elements.roundrect(layer, win,
- x,
- y,
- 0,
- 0,
- 6,
- fill=False)
- layer.stroke()
-
- win.current["cursor"] = win.cursors["arrow"]
-
- # Start drawing the line
-
- if not win.previous["LMB"] and win.current["LMB"] and direction != "in":
-
- # Out point
-
- win.current["tool"] = "connect"
- win.current["draw_dot"] = raw_entry
-
- elif not win.previous["LMB"] and win.current["LMB"] and direction == "in" and win.current["tool"] != "connect":
-
- # Take out of the in point
- try:
- found = False
- win.current["tool"] = "connect"
- for arrow in win.story["arrows"]:
- if raw_entry == arrow[1]:
- win.current["draw_dot"] = arrow[0]#.copy()
- found = arrow
- break
- if found:
- win.story["arrows"].remove(found)
- else:
- win.current["draw_dot"] = "end"
- except:
- pass
-
- # Refrashing analytics
- story.save(win.project, win.story)
- win.analytics = analytics.load(win.project)
- analytics.save(win.project, win.analytics)
-
-
- # Connecting the line
-
- if win.current["tool"] == "connect" and direction == "in" and not win.current["LMB"]:
-
- # Connecting the scenes together
-
- if raw_entry[0] not in ["file", "blend"] and win.current["draw_dot"][0] not in ["file", "blend"]:
-
- new_arrow = [
- win.current["draw_dot"],
- raw_entry
- ]
-
- if new_arrow not in win.story["arrows"]:
- win.story["arrows"].append(new_arrow)
-
- # Copying images to places
-
- elif raw_entry[0] == "asset" and win.current["draw_dot"][0] == "file":
-
- new = oscalls.copy_file(
- win,
- win.current["draw_dot"][1],
- "dev"+raw_entry[1])
-
-
- win.story["links"].append([
- "file", new, [
- win.current["mx"]-win.story["camera"][0]-75,
- win.current["my"]-win.story["camera"][1]-75
- ],
- "" # Parent
- ])
-
- # Now let's select and move the thing
- win.story["selected"] = [["file", len(win.story["links"])-1]]
- win.current["tool"] = "grab"
- win.current["LMB"] = [win.current["mx"], win.current["my"], True]
-
- elif raw_entry[0] == "blend" and win.current["draw_dot"][0] == "blend":
-
- new = oscalls.copy_file(
- win,
- win.current["draw_dot"][1],
- "dev"+raw_entry[1])
-
-
- win.story["links"].append([
- "file", new, [
- win.current["mx"]-win.story["camera"][0]-75,
- win.current["my"]-win.story["camera"][1]-75
- ],
- "" # Parent
- ])
-
- # Now let's select and move the thing
- win.story["selected"] = [["file", len(win.story["links"])-1]]
- win.current["tool"] = "grab"
- win.current["LMB"] = [win.current["mx"], win.current["my"], True]
-
- UI_math.filter_arrows(win)
-
- # Refrashing analytics
- story.save(win.project, win.story)
- win.analytics = analytics.load(win.project)
- analytics.save(win.project, win.analytics)
-
- if direction != "in":
- win.out_dots[entry] = [x+6, y+6]
-
- elif entry.startswith("scene:") or entry in ["start", "end"]:
- for arrow in win.story["arrows"]:
- if raw_entry == arrow[1]:
-
- fr = arrow[0]
- if type(fr) == list:
- fr = fr[0]+":"+fr[1]
-
- try:
- UI_color.set(layer, win, "node_script")
- layer.move_to(
- win.out_dots[fr][0],
- win.out_dots[fr][1]
- )
- layer.line_to(x+6, y+6)
- layer.stroke()
-
- except:
- pass
-
- elif entry.startswith("asset:"):
- for link in win.story["links"]:
-
- if link[0] == "file":
- link = link[1]
- fr = "file:"+link
-
-
- if entry[entry.find(":")+1:] in link:
- try:
- UI_color.set(layer, win, "node_imagefile")
- layer.move_to(
- win.out_dots[fr][0],
- win.out_dots[fr][1]
- )
- layer.line_to(x+6, y+6)
- layer.stroke()
-
- except:
- pass
-
- elif entry.startswith("blend:"):
- for link in win.story["links"]:
-
- if link[0] == "file":
- link = link[1]
- fr = "blend:"+link
-
-
- if entry[entry.find(":")+1:]+"/" in link or entry[entry.find(":")+1:]+"." in link:
- try:
- UI_color.set(layer, win, "node_blendfile")
- layer.move_to(
- win.out_dots[fr][0],
- win.out_dots[fr][1]
- )
- layer.line_to(x+6, y+6)
- layer.stroke()
-
- except:
- pass
-
- def start_node(outlayer, win, x, y, width, height):
-
- # This function will draw a start node in the top left corner of the story
- # editor. This is where the story begins.
-
- # Making the layer
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
- layer = cairo.Context(surface)
-
-
- # Clip
- UI_elements.roundrect(layer, win,
- 0,
- 0,
- width,
- height,
- 10,
- fill=False)
- layer.clip()
-
- # Background
- UI_color.set(layer, win, "dark_overdrop")
- layer.rectangle(0,0,width, height)
- layer.fill()
-
- # top banner
-
- UI_color.set(layer, win, "node_badfile")
- layer.rectangle(0,0,width, 20)
- layer.fill()
-
- # Text saying START
- UI_color.set(layer, win, "text_normal")
- layer.set_font_size(15)
- layer.move_to(width/2-len(talk.text("Start"))*9/2,15)
- layer.show_text(talk.text("Start"))
-
-
-
- # Outputting the layer
- outlayer.set_source_surface(surface, x, y)
- outlayer.paint()
-
- # Dot
- node_dot(outlayer, win, x+width-7, y+height-12, direction="out", entry="start")
-
-
- def end_node(outlayer, win, x, y, width, height):
-
- # This function will draw a end node in the bottom right corner of the story
- # editor. This is where the story ends.
-
- # Making the layer
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
- layer = cairo.Context(surface)
-
-
- # Clip
- UI_elements.roundrect(layer, win,
- 0,
- 0,
- width,
- height,
- 10,
- fill=False)
- layer.clip()
-
- # Background
- UI_color.set(layer, win, "dark_overdrop")
- layer.rectangle(0,0,width, height)
- layer.fill()
-
- # top banner
-
- UI_color.set(layer, win, "node_badfile")
- layer.rectangle(0,0,width, 20)
- layer.fill()
-
- # Text saying END
- UI_color.set(layer, win, "text_normal")
- layer.set_font_size(15)
- layer.move_to(width/2-len(talk.text("End"))*9/2,15)
- layer.show_text(talk.text("End"))
-
- # Outputting the layer
- outlayer.set_source_surface(surface, x, y)
- outlayer.paint()
-
- # Dot
- node_dot(outlayer, win, x-2, y+height-12)
- def scene_node(outlayer, win, x, y, width, height, name="Unknown", fraction=0.0, shots=[]):
-
- # This function will draw scene nodes.
-
- entry = ['scene', name]
-
- width = max(width,20)
- height = max(height,20)
-
- doparent = True
-
- if int(x) in range(int(0-width), int(win.current["w"]))\
- and int(y) in range(int(0-height), int(win.current["h"])):
-
- # Making the layer
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
- layer = cairo.Context(surface)
- layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
-
-
- selected = False
-
- if win.url == "story_editor"\
- and int(win.current["mx"]) in range(50, int(win.current["w"]-50)) \
- and int(win.current["my"]) in range(50, int(win.current["h"]-30)):
-
- if win.current["LMB"] and entry in win.story["selected"]:
- if int(win.current["LMB"][0]) in range(int(x), int(x+width))\
- and int(win.current["LMB"][1]) in range(int(y), int(y+height))\
- and win.current["tool"] == "selection":
- win.current["tool"] = "grab"
- win.story["active"] = entry
-
- # Launching the item
- if int(win.current["mx"]) in range(int(x), int(x+width))\
- and int(win.current["my"]) in range(int(y), int(y+height)):
-
- win.current["cursor"] = win.cursors["hand"]
-
- if not win.current["LMB"] and win.previous["LMB"]\
- and entry in win.story["selected"]\
- and int(win.current["mx"]) == int(win.previous["LMB"][0])\
- and int(win.current["my"]) == int(win.previous["LMB"][1]):
-
- win.url = "script"
- win.cur = "/"+name
- win.current["tool"] = "selection"
-
- if win.current["LMB"] and win.current["tool"] == "selection":
-
- # If mouse over. But way more complex. Because we might select more then
- # 1 scene at ones.
-
- mx = win.current["mx"]
- my = win.current["my"]
- pmx = win.current["LMB"][0]
- pmy = win.current["LMB"][1]
-
- intersect = UI_math.rectangle_overlap(
- [mx, my, pmx-mx, pmy-my],
- [x,y,width, height])
-
- # Now let's make a higlight
- if intersect:
- selected = True
-
- elif win.previous["LMB"] and win.previous["tool"] == "selection":
-
- # If you released the mouse while selecting. Then do selecting. I guess.
- mx = win.previous["mx"]
- my = win.previous["my"]
- pmx = win.previous["LMB"][0]
- pmy = win.previous["LMB"][1]
-
- intersect = UI_math.rectangle_overlap(
- [mx, my, pmx-mx, pmy-my],
- [x,y,width, height])
-
- # Now let's make a selection
- if intersect:
-
- if entry not in win.story["selected"]:
- win.story["selected"].append(entry)
-
- if win.story["active"] not in win.story["selected"]:
- win.story["active"] = entry
-
-
-
-
-
- if entry in win.story["selected"]:
- selected = True
-
- if selected:
-
- if win.current["tool"] == "selection":
- UI_math.rectangle_surround(win, "selection",
- win.szone[0], win.szone[1],
- [x,y], [width, height]
- )
-
- # Now let's make the stratching thing do it's stratching. It's the
- # circle in the bottom, right corner of the selection.
-
- if win.current["tool"] == "scale" and win.current["LMB"] and win.previous["LMB"]:
-
-
- # let's get the points of the selection zone.
- zx = win.szone[0][0]
- zy = win.szone[0][1]
- zsx = win.previous["LMB"][0]
- zsy = win.previous["LMB"][1]
-
- if win.current["mx"] > zx and win.current["my"] > zy:
-
-
- # now let's get the motion fraction.
-
- mvx = (x - zx) / (zsx - zx)
- mvy = (y - zy) / (zsy - zy)
-
- svx = (win.current["mx"]- zx) / (win.previous["mx"]-zx)
- svy = (win.current["my"]- zy) / (win.previous["my"]-zy)
-
- # now let's apply these
-
- win.story["scenes"][name]["position"][0]\
- += (win.current["mx"] - win.previous["mx"])*mvx
-
- win.story["scenes"][name]["position"][1]\
- += (win.current["my"] - win.previous["my"])*mvy
-
- win.story["scenes"][name]["size"][0]\
- = max(win.story["scenes"][name]["size"][0] * svx, 40)
-
- win.story["scenes"][name]["size"][1]\
- = max(win.story["scenes"][name]["size"][1] * svy, 40)
-
-
-
- # Now let's do the simple grab tool.
-
- if win.current["tool"] == "grab":
-
- # If you press shift, You take things out of events
- if 65505 in win.current["keys"]:
- doparent = False
-
- try:
-
-
- if win.current["LMB"]:
- x += win.current["mx"] - win.current["LMB"][0]
- y += win.current["my"] - win.current["LMB"][1]
-
-
- elif win.previous["LMB"]:
- win.story["scenes"][name]["position"][0]\
- += win.previous["mx"] - win.previous["LMB"][0]
- win.story["scenes"][name]["position"][1]\
- += win.previous["my"] - win.previous["LMB"][1]
-
- x += win.previous["mx"] - win.previous["LMB"][0]
- y += win.previous["my"] - win.previous["LMB"][1]
-
- # Parent removing / assigning
-
- if not doparent:
- win.story["scenes"][name]["parent"] = ""
-
- elif not win.story["scenes"][name]["parent"]:
-
- for event in win.story["events"]:
-
- mx, my = win.story["events"][event]["position"]
- pmx, pmy = win.story["events"][event]["size"]
-
- if UI_math.rectangle_overlap(
- [mx, my, pmx, pmy],
- [x,y,width, height]):
-
- win.story["scenes"][name]["parent"] = event
- break
-
-
- elif win.current["tool"] != "connect":
- win.current["tool"] = "selection"
-
-
-
-
-
- except:
- raise()
-
- # The selected outline
-
- UI_color.set(outlayer, win, "progress_background")
-
- if win.story["active"] == entry:
- UI_color.set(outlayer, win, "text_normal")
- outlayer.set_line_width(4)
- UI_elements.roundrect(outlayer, win,
- x,
- y,
- width,
- height,
- 10,
- fill=False)
- outlayer.stroke()
- outlayer.set_line_width(2)
-
-
- # Clip
- UI_elements.roundrect(layer, win,
- 0,
- 0,
- width,
- height,
- 10,
- fill=False)
- layer.clip()
-
- # Tooltip
-
- if int(win.current["mx"]) in range(int(x), int(x+width))\
- and int(win.current["my"]) in range(int(y), int(y+height)):
- UI_elements.tooltip(win, name)
-
- # Background
- UI_color.set(layer, win, "dark_overdrop")
- layer.rectangle(0,0,width, height)
- layer.fill()
-
- # top banner
-
- UI_color.set(layer, win, "node_script")
- layer.rectangle(0,0,width, 20)
- layer.fill()
-
- # Text saying The name of the scene
- UI_color.set(layer, win, "text_normal")
- layer.set_font_size(15)
- layer.move_to(15,15)
- layer.show_text(name)
- text_height = 10
-
- # Fraction
- if fraction:
- text_height = 40
-
-
- UI_color.set(layer, win, "progress_background")
- UI_elements.roundrect(layer, win,
- 10,
- height-20,
- width-20,
- 0,
- 5)
- UI_color.set(layer, win, "progress_active")
- UI_elements.roundrect(layer, win,
- 10,
- height-20,
- (width-20)*fraction,
- 0,
- 5)
-
- # A bit of the scene itself if the size allows.
- if width > 100 and height > text_height:
- # Very simple text from the scene, nothing fancy
- alltext = ""
- for i in shots:
- for b in i[-1]:
- if b[0] == "frase":
- alltext = alltext + b[1][-1]+": "
- alltext = alltext + b[-1]
- alltext = alltext.replace("\n", " \n ")
- # Rendering it.
- fx = 15
- fy = 50
- for word in alltext.split(" "):
- if word == "\n" or len(word)*9 + fx > width:
- fy = fy + 20
- fx = 15
- if fy > height - text_height:
- break
-
- if word != "\n":
- UI_color.set(layer, win, "text_normal")
- layer.set_font_size(15)
- layer.move_to(fx,fy)
- layer.show_text(word)
- fx = fx + len(word)*9 + 10
-
-
- # Outputting the layer
- outlayer.set_source_surface(surface, x, y)
- outlayer.paint()
-
-
- # In case there is a parent event in the scene.
-
- if win.story["scenes"][name]["parent"] and doparent:
- parent = win.story["scenes"][name]["parent"]
- UI_math.rectangle_surround(win, parent,
- win.story["events"][parent]["position"],
- win.story["events"][parent]["size"],
- [x,y], [width, height]
- )
-
- # Dots
- node_dot(outlayer, win, x-5, y+25, entry=entry)
- node_dot(outlayer, win, x+width-7, y+25, direction="out",entry=entry)
- def event_node(outlayer, win, x, y, width, height, name="Unknown"):
-
- # This function draws events.
-
- x = x - 20
- y = y - 20
- width = width + 40
- height = height + 40
-
- entry = ['event', name]
-
-
- # Making sure the size is alright
- if width < 100:
- width = 100
- if height < 100:
- height = 100
-
- # Making the layer
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
- layer = cairo.Context(surface)
-
-
- # Clip
- UI_elements.roundrect(layer, win,
- 0,
- 0,
- width,
- height,
- 10,
- fill=False)
- layer.clip()
-
- # Background
- UI_color.set(layer, win, "dark_overdrop")
- layer.rectangle(0,0,width, height)
- layer.fill()
-
-
- # Here should be the event name thing. But I thought that it wasn't
- # important for a simple framing thing.
-
- # Outputting the layer
- outlayer.set_source_surface(surface, x, y)
- outlayer.paint()
-
- def link_node(outlayer, win, x, y, width=150, height=150, name="", num=0, linktype="file"):
-
- filetype = ""
-
- # This node will output links to files.
-
- if linktype == "asset":
- width += 50
- height += 80
-
- else:
- # Let's find out what type of file is it.
- for f in fileformats.images:
- if name.endswith(f):
- filetype = "image"
-
- if not filetype:
- for f in fileformats.videos:
- if name.endswith(f):
- filetype = "video"
-
- doparent = True
-
- if int(x) in range(int(0-width), int(win.current["w"]))\
- and int(y) in range(int(0-height), int(win.current["h"])):
-
-
-
- # Making the layer
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
- layer = cairo.Context(surface)
-
- entry = [linktype, num]
-
-
-
-
- selected = False
- if win.url == "story_editor"\
- and int(win.current["mx"]) in range(50, int(win.current["w"]-50)) \
- and int(win.current["my"]) in range(50, int(win.current["h"]-30)):
-
- if win.current["LMB"] and entry in win.story["selected"]:
- if int(win.current["LMB"][0]) in range(int(x), int(x+width))\
- and int(win.current["LMB"][1]) in range(int(y), int(y+height))\
- and win.current["tool"] == "selection":
-
-
-
- win.current["tool"] = "grab"
- win.story["active"] = entry
-
- # Launching the item
- if int(win.current["mx"]) in range(int(x), int(x+width))\
- and int(win.current["my"]) in range(int(y), int(y+height)):
-
- win.current["cursor"] = win.cursors["hand"]
-
- if not win.current["LMB"] and win.previous["LMB"]\
- and entry in win.story["selected"]\
- and int(win.current["mx"]) == int(win.previous["LMB"][0])\
- and int(win.current["my"]) == int(win.previous["LMB"][1]):
-
- if linktype == "file":
- oscalls.file_open(win, name)
-
- elif int(win.current["mx"]) > x+40: # This is a hack. But whatever.
- win.url = "assets"
- win.cur = name
- win.current["tool"] = "selection"
- win.previous["LMB"] = False
-
- if win.current["LMB"] and win.current["tool"] == "selection":
-
- # If mouse over. But way more complex. Because we might select more then
- # 1 scene at ones.
-
- mx = win.current["mx"]
- my = win.current["my"]
- pmx = win.current["LMB"][0]
- pmy = win.current["LMB"][1]
-
-
-
-
- intersect = UI_math.rectangle_overlap(
- [mx, my, pmx-mx, pmy-my],
- [x,y,width, height])
-
- # Now let's make a higlight
- if intersect:
- selected = True
-
- elif win.previous["LMB"] and win.previous["tool"] == "selection":
-
- # If you released the mouse while selecting. Then do selecting. I guess.
- mx = win.previous["mx"]
- my = win.previous["my"]
- pmx = win.previous["LMB"][0]
- pmy = win.previous["LMB"][1]
-
- intersect = UI_math.rectangle_overlap(
- [mx, my, pmx-mx, pmy-my],
- [x,y,width, height])
-
- # Now let's make a selection
- if intersect:
- if entry not in win.story["selected"]:
- win.story["selected"].append(entry)
- # Making it active.
- if win.story["active"] not in win.story["selected"]:
- win.story["active"] = entry
-
-
-
- if entry in win.story["selected"]:
- selected = True
-
- if selected:
-
- if win.current["tool"] == "selection":
- UI_math.rectangle_surround(win, "selection",
- win.szone[0], win.szone[1],
- [x,y], [width, height]
- )
-
- # Now let's make the stratching thing do it's stratching. It's the
- # circle in the bottom, right corner of the selection.
-
- if win.current["tool"] == "scale" and win.current["LMB"] and win.previous["LMB"]:
-
-
- # let's get the points of the selection zone.
- zx = win.szone[0][0]
- zy = win.szone[0][1]
- zsx = win.previous["LMB"][0]
- zsy = win.previous["LMB"][1]
-
- if win.current["mx"] > zx and win.current["my"] > zy:
-
-
- # now let's get the motion fraction.
-
- mvx = (x - zx) / (zsx - zx)
- mvy = (y - zy) / (zsy - zy)
-
- # now let's apply these
-
- win.story["links"][num][2][0]\
- += (win.current["mx"] - win.previous["mx"])*mvx
-
- win.story["links"][num][2][1]\
- += (win.current["my"] - win.previous["my"])*mvy
-
-
- if win.current["tool"] == "grab":
-
- # If you press shift, You take things out of events
- if 65505 in win.current["keys"]:
- doparent = False
-
- try:
- if win.current["LMB"]:
- x += win.current["mx"] - win.current["LMB"][0]
- y += win.current["my"] - win.current["LMB"][1]
-
-
- elif win.previous["LMB"]:
- win.story["links"][num][2][0]\
- += win.previous["mx"] - win.previous["LMB"][0]
- win.story["links"][num][2][1]\
- += win.previous["my"] - win.previous["LMB"][1]
-
- x += win.previous["mx"] - win.previous["LMB"][0]
- y += win.previous["my"] - win.previous["LMB"][1]
-
- # Parent removing / assigning
-
- if not doparent:
- win.story["links"][num][3] = ""
-
- elif not win.story["links"][num][3]:
-
- for event in win.story["events"]:
-
- mx, my = win.story["events"][event]["position"]
- pmx, pmy = win.story["events"][event]["size"]
-
- if UI_math.rectangle_overlap(
- [mx, my, pmx, pmy],
- [x,y,width, height]):
-
- win.story["links"][num][3] = event
- break
-
- elif win.current["tool"] != "connect":
- win.current["tool"] = "selection"
-
-
- except:
- raise()
-
- # The selected outline
-
- UI_color.set(outlayer, win, "progress_background")
-
- if win.story["active"] == entry:
- UI_color.set(outlayer, win, "text_normal")
- outlayer.set_line_width(4)
- UI_elements.roundrect(outlayer, win,
- x,
- y,
- width,
- height,
- 10,
- fill=False)
- outlayer.stroke()
- outlayer.set_line_width(2)
-
-
-
- # Clip
- UI_elements.roundrect(layer, win,
- 0,
- 0,
- width,
- height,
- 10,
- fill=False)
- layer.clip()
-
- # Background
- UI_color.set(layer, win, "dark_overdrop")
- layer.rectangle(0,0,width, height)
- layer.fill()
-
- if linktype == "asset":
-
- assettype = name[:name.rfind("/")].replace("/", "")
-
- if os.path.exists(win.project+"/dev"+name+"/renders/Preview.png"):
- UI_elements.image(layer, win,
- win.project+"/dev"+name+"/renders/Preview.png",
- 0, 0, width, height, cell="story_asset_previews")
- elif os.path.exists(win.project+"/dev"+name+"/renders/Preview.jpg"):
- UI_elements.image(layer, win,
- win.project+"/dev"+name+"/renders/Preview.jpg",
- 0, 0, width, height, cell="story_asset_previews")
-
- else:
- UI_elements.image(layer, win,
- "settings/themes/"+win.settings["Theme"]+"/icons/"+assettype+".png",
- width/2-20, height/2-20, 40, 40)
-
- # Here I want to add some buttons for accessing the various folder of
- # the asset. And also to link stuff into those folders using nodes.
-
- if int(win.current["mx"]) in range(int(x), int(x+width))\
- and int(win.current["my"]) in range(int(y), int(y+height)):
-
- # Darkening thing.
- UI_color.set(layer, win, "dark_overdrop")
- layer.rectangle(0,0,50, height)
- layer.fill()
-
- def after(win, var):
- if var:
- win.story["links"].append([
- "file", var, [
- win.current["mx"]-win.story["camera"][0]-75,
- win.current["my"]-win.story["camera"][1]-75
- ],
- ""
- ])
-
- # Now let's select and move the thing
- win.story["selected"] = [["file", len(win.story["links"])-1]]
- win.current["tool"] = "grab"
- win.current["LMB"] = [win.current["mx"], win.current["my"], True]
-
-
-
-
- # Blendfiles
- def do():
- studio_dialogs.file_select(win, name+"_blends", after, force=True,
- IMAGE=False, BLEND=True, VIDEO=False, FILE=False, CHR=True, VEH=True,
- LOC=True, OBJ=True, RND=False, FOLDER=False, SEARCH=name)
-
- UI_elements.roundrect(layer, win,
- 5,
- 25,
- 40,
- 40,
- 10,
- do,
- "blender",
- talk.text("blend_files_folder"),
- url="story_editor",
- offset=[x,y])
-
-
-
- # References
- def do():
- studio_dialogs.file_select(win, name+"_reference", after, force=True,
- IMAGE=True, BLEND=False, VIDEO=True, FILE=False, CHR=True, VEH=True,
- LOC=True, OBJ=True, RND=False, FOLDER=False, SEARCH=name+"/reference")
-
- UI_elements.roundrect(layer, win,
- 5,
- 75,
- 40,
- 40,
- 10,
- do,
- "idea",
- talk.text("reference_folder"),
- url="story_editor",
- offset=[x,y])
-
- # Textures
- def do():
- studio_dialogs.file_select(win, name+"_textures", after, force=True,
- IMAGE=True, BLEND=False, VIDEO=True, FILE=False, CHR=True, VEH=True,
- LOC=True, OBJ=True, RND=False, FOLDER=False, SEARCH=name+"/tex")
-
- UI_elements.roundrect(layer, win,
- 5,
- 125,
- 40,
- 40,
- 10,
- do,
- "texture",
- talk.text("tex_folder"),
- url="story_editor",
- offset=[x,y])
-
- # Renders
- def do():
- studio_dialogs.file_select(win, name+"_renders", after, force=True,
- IMAGE=True, BLEND=False, VIDEO=True, FILE=False, CHR=True, VEH=True,
- LOC=True, OBJ=True, RND=False, FOLDER=False, SEARCH=name+"/renders")
-
- UI_elements.roundrect(layer, win,
- 5,
- 175,
- 40,
- 40,
- 10,
- do,
- "render",
- talk.text("renders_folder"),
- url="story_editor",
- offset=[x,y])
-
- # Fraction
-
- fraction = story.get_asset_data(win, name)["fraction"]
-
- UI_color.set(layer, win, "progress_background")
- UI_elements.roundrect(layer, win,
- 65,
- height-20,
- width-85,
- 0,
- 5)
-
- UI_color.set(layer, win, "progress_active")
- UI_elements.roundrect(layer, win,
- 65,
- height-20,
- (width-85)*fraction,
- 0,
- 5)
- else:
-
- # Fraction
-
- fraction = story.get_asset_data(win, name)["fraction"]
-
- UI_color.set(layer, win, "progress_background")
- UI_elements.roundrect(layer, win,
- 10,
- height-20,
- width-20,
- 0,
- 5)
-
- UI_color.set(layer, win, "progress_active")
- UI_elements.roundrect(layer, win,
- 10,
- height-20,
- (width-20)*fraction,
- 0,
- 5)
-
- UI_color.set(layer, win, "node_asset")
-
- # Tooltip
-
- if int(win.current["mx"]) in range(int(x+40), int(x+width))\
- and int(win.current["my"]) in range(int(y), int(y+height)):
- UI_elements.tooltip(win, name)
-
- else:
-
-
- if os.path.exists(win.project+"/"+name):
- UI_elements.image(layer, win,
- win.project+"/"+name,
- 0, 0, width, height)
-
- else:
- UI_elements.image(layer, win,
- name,
- 0, 0, width, height)
-
- if name.endswith(".progress"):
-
- fraction = checklist.get_fraction(win, name)
-
- UI_color.set(layer, win, "progress_background")
- UI_elements.roundrect(layer, win,
- 10,
- height-20,
- width-20,
- 0,
- 5)
-
- UI_color.set(layer, win, "progress_active")
- UI_elements.roundrect(layer, win,
- 10,
- height-20,
- (width-20)*fraction,
- 0,
- 5)
-
- if name.endswith(".blend"):
- UI_color.set(layer, win, "node_blendfile")
- if "ast/" in name:
- UI_color.set(layer, win, "node_asset")
- elif filetype == "image":
- UI_color.set(layer, win, "node_imagefile")
-
- elif filetype == "video":
- UI_color.set(layer, win, "node_videofile")
-
- else:
- UI_color.set(layer, win, "node_script")
-
-
- # Tooltip
-
- if int(win.current["mx"]) in range(int(x), int(x+width))\
- and int(win.current["my"]) in range(int(y), int(y+height)):
- UI_elements.tooltip(win, name)
-
- # top banner
-
-
- layer.rectangle(0,0,width, 20)
- layer.fill()
-
- # Text saying The name of the event
- UI_color.set(layer, win, "text_normal")
- layer.set_font_size(15)
- layer.move_to(15,15)
- layer.show_text(name[name.rfind("/")+1:])
-
- # Outputting the layer
- outlayer.set_source_surface(surface, x, y)
- outlayer.paint()
-
- if linktype == "asset":
- node_dot(outlayer, win, x-6, y+25+14, entry=["blend", name])
- node_dot(outlayer, win, x-6, y+75+14, entry=["asset", name+"/reference"])
- node_dot(outlayer, win, x-6, y+125+14, entry=["asset", name+"/tex"])
- node_dot(outlayer, win, x-6, y+175+14, entry=["asset", name+"/renders"])
- else:
- if name.endswith(".blend"):
- node_dot(outlayer, win, x+width-6, y+120, entry=["blend", name], direction="out")
- elif filetype in ["image", "video"]:
- node_dot(outlayer, win, x+width-6, y+120, entry=["file", name], direction="out")
-
- else: # If not in the frame
- if linktype == "file":
- try:
- if name.endswith(".blend"):
- del win.out_dots["blend:"+name]
- else:
- del win.out_dots["file:"+name]
- except:
- pass
- # In case there is a parent event in the scene.
-
- if win.story["links"][num][3] and doparent:
- parent = win.story["links"][num][3]
- UI_math.rectangle_surround(win, parent,
- win.story["events"][parent]["position"],
- win.story["events"][parent]["size"],
- [x,y], [width, height]
- )
-
- def marker(outlayer, win, name ,x, y ):
- # This function will draw markers to the screen. They are like shortcuts in
- # a story editor space.
-
-
-
- if int(x) in range(int(60), int(win.current["w"]-100))\
- and int(y) in range(int(60), int(win.current["h"]-80)):
- width = 200
- height = 40
-
- inscreen = True
- else:
-
- x = min(max(x, 60), win.current["w"]-100)
- y = min(max(y, 60), win.current["h"]-80)
-
- width = 40
- height = 40
-
- inscreen = False
-
- # Making the layer
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
- layer = cairo.Context(surface)
-
- entry = ["marker", name]
-
- if inscreen:
-
- doparent = True
-
- selected = False
- if win.url == "story_editor"\
- and int(win.current["mx"]) in range(50, int(win.current["w"]-50)) \
- and int(win.current["my"]) in range(50, int(win.current["h"]-30)):
-
- if win.current["LMB"] and entry in win.story["selected"]:
- if int(win.current["LMB"][0]) in range(int(x), int(x+40))\
- and int(win.current["LMB"][1]) in range(int(y), int(y+height))\
- and win.current["tool"] == "selection":
-
-
-
- win.current["tool"] = "grab"
- win.story["active"] = entry
-
-
-
- if win.current["LMB"] and win.current["tool"] == "selection":
-
- # If mouse over. But way more complex. Because we might select more then
- # 1 scene at ones.
-
- mx = win.current["mx"]
- my = win.current["my"]
- pmx = win.current["LMB"][0]
- pmy = win.current["LMB"][1]
-
-
-
-
- intersect = UI_math.rectangle_overlap(
- [mx, my, pmx-mx, pmy-my],
- [x,y,width, height])
-
- # Now let's make a higlight
- if intersect:
- selected = True
-
- elif win.previous["LMB"] and win.previous["tool"] == "selection":
-
- # If you released the mouse while selecting. Then do selecting. I guess.
- mx = win.previous["mx"]
- my = win.previous["my"]
- pmx = win.previous["LMB"][0]
- pmy = win.previous["LMB"][1]
-
- intersect = UI_math.rectangle_overlap(
- [mx, my, pmx-mx, pmy-my],
- [x,y,width, height])
-
- # Now let's make a selection
- if intersect:
- if entry not in win.story["selected"]:
- win.story["selected"].append(entry)
- # Making it active.
- if win.story["active"] not in win.story["selected"]:
- win.story["active"] = entry
-
-
-
- if entry in win.story["selected"]:
- selected = True
-
- if selected:
-
- if win.current["tool"] == "selection":
- UI_math.rectangle_surround(win, "selection",
- win.szone[0], win.szone[1],
- [x,y], [width, height]
- )
-
- # Now let's make the stratching thing do it's stratching. It's the
- # circle in the bottom, right corner of the selection.
-
- if win.current["tool"] == "scale" and win.current["LMB"] and win.previous["LMB"]:
-
-
- # let's get the points of the selection zone.
- zx = win.szone[0][0]
- zy = win.szone[0][1]
- zsx = win.previous["LMB"][0]
- zsy = win.previous["LMB"][1]
-
- if win.current["mx"] > zx and win.current["my"] > zy:
-
-
- # now let's get the motion fraction.
-
- mvx = (x - zx) / (zsx - zx)
- mvy = (y - zy) / (zsy - zy)
-
- # now let's apply these
-
- win.story["markers"][name][0]\
- += (win.current["mx"] - win.previous["mx"])*mvx
-
- win.story["markers"][name][1]\
- += (win.current["my"] - win.previous["my"])*mvy
-
-
- if win.current["tool"] == "grab":
-
- # If you press shift, You take things out of events
- if 65505 in win.current["keys"]:
- doparent = False
-
- try:
- if win.current["LMB"]:
- x += win.current["mx"] - win.current["LMB"][0]
- y += win.current["my"] - win.current["LMB"][1]
-
-
- elif win.previous["LMB"]:
- win.story["markers"][name][0]\
- += win.previous["mx"] - win.previous["LMB"][0]
- win.story["markers"][name][1]\
- += win.previous["my"] - win.previous["LMB"][1]
-
- x += win.previous["mx"] - win.previous["LMB"][0]
- y += win.previous["my"] - win.previous["LMB"][1]
-
-
- # Parent removing / assigning
-
- if not doparent:
- win.story["markers"][name][2] = ""
-
- elif not win.story["markers"][name][2] :
-
- for event in win.story["events"]:
-
- mx, my = win.story["events"][event]["position"]
- pmx, pmy = win.story["events"][event]["size"]
-
- if UI_math.rectangle_overlap(
- [mx, my, pmx, pmy],
- [x,y,width, height]):
-
- win.story["markers"][name][2] = event
- print(event)
- break
-
-
- elif win.current["tool"] != "connect":
- win.current["tool"] = "selection"
-
-
- except:
- raise()
-
- # The selected outline
-
- UI_color.set(outlayer, win, "progress_background")
-
- if win.story["active"] == entry:
- UI_color.set(outlayer, win, "text_normal")
- outlayer.set_line_width(4)
- UI_elements.roundrect(outlayer, win,
- x,
- y,
- width,
- height,
- 10,
- fill=False)
- outlayer.stroke()
- outlayer.set_line_width(2)
-
-
-
- # Clip
- UI_elements.roundrect(layer, win,
- 0,
- 0,
- width,
- height,
- 10,
- fill=False)
- layer.clip()
-
- # Background
- UI_color.set(layer, win, "dark_overdrop")
- layer.rectangle(0,0,width, height)
- layer.fill()
-
- # Pin Icon
- UI_elements.image(layer, win,
- "settings/themes/"+win.settings["Theme"]+"/icons/pin.png",
- 0, 0, 40, 40)
-
-
-
- # Outputting the layer
- outlayer.set_source_surface(surface, x, y)
- outlayer.paint()
-
- if inscreen:
-
-
- # Text editor for the marker's name.
-
- UI_elements.text(outlayer, win, name+"_marker",
- x+40,
- y,
- width-40,
- 40,
- set_text=name)
-
- if name != win.text[name+"_marker"]["text"] and win.text[name+"_marker"]["text"]:
- def do():
-
-
- win.story["selected"] = []
- win.story["markers"][win.text[name+"_marker"]["text"]] = [
- x - win.story["camera"][0],
- y - win.story["camera"][1],
- win.story["markers"][name][2]
- ]
-
- win.textactive = ""
-
- del win.story["markers"][name]
-
- UI_elements.roundrect(outlayer, win,
- x+width-40,
- y,
- 40,
- 40,
- 10,
- button=do,
- icon="ok",
- tip=talk.text("checked"))
-
- if 65293 in win.current["keys"]:
- do()
-
- # In case there is a parent event in the scene.
-
- if win.story["markers"][name][2] and doparent:
- parent = win.story["markers"][name][2]
- UI_math.rectangle_surround(win, parent,
- win.story["events"][parent]["position"],
- win.story["events"][parent]["size"],
- [x,y], [width, height]
- )
-
- else:
-
- if win.textactive == name+"_marker":
- win.textactive = ""
-
- def do():
-
- nex = 0-win.story["markers"][name][0] + win.current["w"]/2
- ney = 0-win.story["markers"][name][1] + win.current["h"]/2
-
- UI_elements.animate("cameraX", win, win.story["camera"][0],nex, time=20, force=True)
- UI_elements.animate("cameraY", win, win.story["camera"][1],ney, time=20, force=True)
-
- UI_elements.roundrect(outlayer, win,
- x+width-40,
- y,
- 40,
- 40,
- 10,
- button=do,
- tip=name,
- fill=False)
- outlayer.stroke()
-
-
- def user(outlayer, win, name ,x, y, user):
- # This function will draw users from multiuser to the screen.
-
-
-
- if int(x) in range(int(60), int(win.current["w"]-100))\
- and int(y) in range(int(60), int(win.current["h"]-80)):
- width = 200
- height = 40
-
- inscreen = True
- else:
-
- x = min(max(x, 60), win.current["w"]-100)
- y = min(max(y, 60), win.current["h"]-80)
-
- width = 40
- height = 40
-
- inscreen = False
-
- # Making the layer
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
- layer = cairo.Context(surface)
-
- # Clip
- UI_elements.roundrect(layer, win,
- 0,
- 0,
- width,
- height,
- 10,
- fill=False)
- layer.clip()
-
- # Background
- UI_color.set(layer, win, "dark_overdrop")
- layer.rectangle(0,0,width, height)
- layer.fill()
-
- # Pin Icon
- UI_elements.image(layer, win,
- "settings/themes/"+win.settings["Theme"]+"/icons/user.png",
- 0, 0, 40, 40)
-
-
-
- # Outputting the layer
- outlayer.set_source_surface(surface, x, y)
- outlayer.paint()
-
- if inscreen:
-
-
- # Text editor for the marker's name.
-
- UI_elements.text(outlayer, win, name+"_user",
- x+40,
- y,
- width-40,
- 40,
- set_text=name,
- editable=False)
-
- else:
-
- # Going to the other user with 1 click
-
- def do():
-
- nex = win.multiuser["users"][user]["camera"][0]
- ney = win.multiuser["users"][user]["camera"][1]
-
- UI_elements.animate("cameraX", win, win.story["camera"][0],nex, time=20, force=True)
- UI_elements.animate("cameraY", win, win.story["camera"][1],ney, time=20, force=True)
-
- UI_elements.roundrect(outlayer, win,
- x+width-40,
- y,
- 40,
- 40,
- 10,
- button=do,
- tip=name,
- fill=False)
- outlayer.stroke()
-
|