├── .gitattributes
├── .gitignore
├── COPYING
├── LICENSE
├── Makefile
├── Makefile.win64
├── README.md
├── Resource.h
├── SourceCodePro-Bold.ttf
├── StrLit.ttf
├── engine.cpp
├── engine.h
├── examples
├── bfs-shortest-path.txt
├── boltzmann.txt
├── edgeslopes.txt
├── petersen.txt
└── sandpile.txt
├── export.cpp
├── export.h
├── fonts.cpp
├── fonts.h
├── graphicdepictions.sln
├── graphicdepictions.vcxproj
├── graphicdepictions.vcxproj.filters
├── graphics.cpp
├── graphics.h
├── imgui
├── LICENSE
├── imconfig.h
├── imgui.cpp
├── imgui.h
├── imgui_demo.cpp
├── imgui_draw.cpp
├── imgui_freetype.cpp
├── imgui_freetype.h
├── imgui_impl_glfw.cpp
├── imgui_impl_glfw.h
├── imgui_internal.h
├── stb_rect_pack.h
├── stb_textedit.h
└── stb_truetype.h
├── libbz2-1.dll
├── libfreetype-6.dll
├── libgcc_s_seh-1.dll
├── libpng16-16.dll
├── libstdc++-6.dll
├── libv8.dll
├── libwinpthread-1.dll
├── packages.config
├── pthread.h
├── sched.h
├── screenshots
├── boltzmann.png
├── gd-0.4-features.png
├── gd-discrete-cube.png
├── gd-erdoes-renyi.png
└── sandpile.gif
├── scripts
├── 0.js
├── 1.js
├── 2.js
├── 3.js
├── 4.js
├── 5.js
├── 6.js
├── 7.js
└── 8.js
├── semaphore.h
├── serialise.js
├── singletons.cpp
├── singletons.h
├── space.cpp
├── space.h
├── state.cpp
├── stdafx.cpp
├── stdafx.h
├── texpool.cpp
├── texpool.h
├── texture.cpp
├── texture.h
├── v8
├── v8-debug.h
├── v8-preparser.h
├── v8-profiler.h
├── v8-testing.h
├── v8.h
└── v8stdint.h
├── win32window.cpp
├── win32window.h
├── window.cpp
├── window.h
└── zlib1.dll
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | [Xx]64/
19 | [Xx]86/
20 | [Bb]uild/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 |
85 | # Visual Studio profiler
86 | *.psess
87 | *.vsp
88 | *.vspx
89 | *.sap
90 |
91 | # TFS 2012 Local Workspace
92 | $tf/
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 | *.DotSettings.user
101 |
102 | # JustCode is a .NET coding add-in
103 | .JustCode
104 |
105 | # TeamCity is a build add-in
106 | _TeamCity*
107 |
108 | # DotCover is a Code Coverage Tool
109 | *.dotCover
110 |
111 | # NCrunch
112 | _NCrunch_*
113 | .*crunch*.local.xml
114 | nCrunchTemp_*
115 |
116 | # MightyMoose
117 | *.mm.*
118 | AutoTest.Net/
119 |
120 | # Web workbench (sass)
121 | .sass-cache/
122 |
123 | # Installshield output folder
124 | [Ee]xpress/
125 |
126 | # DocProject is a documentation generator add-in
127 | DocProject/buildhelp/
128 | DocProject/Help/*.HxT
129 | DocProject/Help/*.HxC
130 | DocProject/Help/*.hhc
131 | DocProject/Help/*.hhk
132 | DocProject/Help/*.hhp
133 | DocProject/Help/Html2
134 | DocProject/Help/html
135 |
136 | # Click-Once directory
137 | publish/
138 |
139 | # Publish Web Output
140 | *.[Pp]ublish.xml
141 | *.azurePubxml
142 |
143 | # TODO: Un-comment the next line if you do not want to checkin
144 | # your web deploy settings because they may include unencrypted
145 | # passwords
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # NuGet Packages
150 | *.nupkg
151 | # The packages folder can be ignored because of Package Restore
152 | **/packages/*
153 | # except build/, which is used as an MSBuild target.
154 | !**/packages/build/
155 | # Uncomment if necessary however generally it will be regenerated when needed
156 | #!**/packages/repositories.config
157 | # NuGet v3's project.json files produces more ignoreable files
158 | *.nuget.props
159 | *.nuget.targets
160 |
161 | # Microsoft Azure Build Output
162 | csx/
163 | *.build.csdef
164 |
165 | # Microsoft Azure Emulator
166 | ecf/
167 | rcf/
168 |
169 | # Windows Store app package directory
170 | AppPackages/
171 | BundleArtifacts/
172 |
173 | # Visual Studio cache files
174 | # files ending in .cache can be ignored
175 | *.[Cc]ache
176 | # but keep track of directories ending in .cache
177 | !*.[Cc]ache/
178 |
179 | # Others
180 | ClientBin/
181 | [Ss]tyle[Cc]op.*
182 | ~$*
183 | *~
184 | *.dbmdl
185 | *.dbproj.schemaview
186 | *.pfx
187 | *.publishsettings
188 | node_modules/
189 | orleans.codegen.cs
190 |
191 | # RIA/Silverlight projects
192 | Generated_Code/
193 |
194 | # Backup & report files from converting an old project file
195 | # to a newer Visual Studio version. Backup files are not needed,
196 | # because we have git ;-)
197 | _UpgradeReport_Files/
198 | Backup*/
199 | UpgradeLog*.XML
200 | UpgradeLog*.htm
201 |
202 | # SQL Server files
203 | *.mdf
204 | *.ldf
205 |
206 | # Business Intelligence projects
207 | *.rdl.data
208 | *.bim.layout
209 | *.bim_*.settings
210 |
211 | # Microsoft Fakes
212 | FakesAssemblies/
213 |
214 | # GhostDoc plugin setting file
215 | *.GhostDoc.xml
216 |
217 | # Node.js Tools for Visual Studio
218 | .ntvs_analysis.dat
219 |
220 | # Visual Studio 6 build log
221 | *.plg
222 |
223 | # Visual Studio 6 workspace options file
224 | *.opt
225 |
226 | # Visual Studio LightSwitch build output
227 | **/*.HTMLClient/GeneratedArtifacts
228 | **/*.DesktopClient/GeneratedArtifacts
229 | **/*.DesktopClient/ModelManifest.xml
230 | **/*.Server/GeneratedArtifacts
231 | **/*.Server/ModelManifest.xml
232 | _Pvt_Extensions
233 |
234 | # LightSwitch generated files
235 | GeneratedArtifacts/
236 | ModelManifest.xml
237 |
238 | # Paket dependency manager
239 | .paket/paket.exe
240 |
241 | # FAKE - F# Make
242 | .fake/
243 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | The main part of the project is made available under the terms of the
2 | GNU General Public License, Version 3 (see LICENSE for details).
3 |
4 | Based on dear imgui, which is Copyright (c) 2014-2015 Omar Cornut and ImGui contributors
5 | and made available under a separate permissive license (see imgui/LICENSE).
6 |
7 | Includes the String Literal font, which is Copyright (c) 2005 David P. Kovalchik
8 | and free for non-commercial use.
9 |
10 | Includes the V8 JavaScript engine, which is Copyright 2012, the V8 project authors.
11 | See v8/v8.h for license details.
12 |
13 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | #------------------------------------------------------------------------------#
2 | # This makefile was generated by 'cbp2make' tool rev.147 #
3 | #------------------------------------------------------------------------------#
4 |
5 |
6 | WORKDIR = `pwd`
7 |
8 | CC = gcc
9 | CXX = g++
10 | AR = ar
11 | LD = g++
12 | WINDRES = windres
13 |
14 | INC =
15 | CFLAGS = -std=c++14 -I/usr/include/freetype2
16 | RESINC =
17 | LIBDIR =
18 | LIB = -lXrender -lX11 -lGL -lv8
19 | LDFLAGS =
20 |
21 | INC_DEBUG_LINUX = $(INC)
22 | CFLAGS_DEBUG_LINUX = $(CFLAGS) -std=c++14 -pg -g -W -O0 -I/usr/include/freetype2 -D_DEBUG -D_WINDOWS
23 | RESINC_DEBUG_LINUX = $(RESINC)
24 | RCFLAGS_DEBUG_LINUX = $(RCFLAGS)
25 | LIBDIR_DEBUG_LINUX = $(LIBDIR)
26 | LIB_DEBUG_LINUX = $(LIB) -lfreetype -lpthread -lGL -lGLU
27 | LDFLAGS_DEBUG_LINUX = $(LDFLAGS) -pg
28 | OBJDIR_DEBUG_LINUX = Debug
29 | DEP_DEBUG_LINUX =
30 | OUT_DEBUG_LINUX = Debug/gdepictions
31 |
32 | INC_RELEASE_LINUX = $(INC)
33 | CFLAGS_RELEASE_LINUX = $(CFLAGS) -std=c++14 -g -W -I/usr/include/freetype2 -DNDEBUG -D_WINDOWS
34 | RESINC_RELEASE_LINUX = $(RESINC)
35 | RCFLAGS_RELEASE_LINUX = $(RCFLAGS)
36 | LIBDIR_RELEASE_LINUX = $(LIBDIR)
37 | LIB_RELEASE_LINUX = $(LIB) -lGL -lGLU -lpthread -lfreetype
38 | LDFLAGS_RELEASE_LINUX = $(LDFLAGS)
39 | OBJDIR_RELEASE_LINUX = Release
40 | DEP_RELEASE_LINUX =
41 | OUT_RELEASE_LINUX = Release/gdepictions
42 |
43 | OBJ_DEBUG_LINUX = $(OBJDIR_DEBUG_LINUX)/state.o $(OBJDIR_DEBUG_LINUX)/singletons.o $(OBJDIR_DEBUG_LINUX)/space.o $(OBJDIR_DEBUG_LINUX)/stdafx.o $(OBJDIR_DEBUG_LINUX)/texpool.o $(OBJDIR_DEBUG_LINUX)/texture.o $(OBJDIR_DEBUG_LINUX)/window.o $(OBJDIR_DEBUG_LINUX)/engine.o $(OBJDIR_DEBUG_LINUX)/export.o $(OBJDIR_DEBUG_LINUX)/fonts.o $(OBJDIR_DEBUG_LINUX)/graphics.o $(OBJDIR_DEBUG_LINUX)/imgui/imgui.o $(OBJDIR_DEBUG_LINUX)/imgui/imgui_demo.o $(OBJDIR_DEBUG_LINUX)/imgui/imgui_draw.o $(OBJDIR_DEBUG_LINUX)/imgui/imgui_freetype.o $(OBJDIR_DEBUG_LINUX)/imgui/imgui_impl_glfw.o
44 |
45 | OBJ_RELEASE_LINUX = $(OBJDIR_RELEASE_LINUX)/state.o $(OBJDIR_RELEASE_LINUX)/singletons.o $(OBJDIR_RELEASE_LINUX)/space.o $(OBJDIR_RELEASE_LINUX)/stdafx.o $(OBJDIR_RELEASE_LINUX)/texpool.o $(OBJDIR_RELEASE_LINUX)/texture.o $(OBJDIR_RELEASE_LINUX)/window.o $(OBJDIR_RELEASE_LINUX)/engine.o $(OBJDIR_RELEASE_LINUX)/export.o $(OBJDIR_RELEASE_LINUX)/fonts.o $(OBJDIR_RELEASE_LINUX)/graphics.o $(OBJDIR_RELEASE_LINUX)/imgui/imgui.o $(OBJDIR_RELEASE_LINUX)/imgui/imgui_demo.o $(OBJDIR_RELEASE_LINUX)/imgui/imgui_draw.o $(OBJDIR_RELEASE_LINUX)/imgui/imgui_freetype.o $(OBJDIR_RELEASE_LINUX)/imgui/imgui_impl_glfw.o
46 |
47 | all: debug_linux release_linux
48 |
49 | clean: clean_debug_linux clean_release_linux
50 |
51 | before_debug_linux:
52 | test -d Debug || mkdir -p Debug
53 | test -d $(OBJDIR_DEBUG_LINUX) || mkdir -p $(OBJDIR_DEBUG_LINUX)
54 | test -d $(OBJDIR_DEBUG_LINUX)/imgui || mkdir -p $(OBJDIR_DEBUG_LINUX)/imgui
55 |
56 | after_debug_linux:
57 |
58 | debug_linux: before_debug_linux out_debug_linux after_debug_linux
59 |
60 | out_debug_linux: before_debug_linux $(OBJ_DEBUG_LINUX) $(DEP_DEBUG_LINUX)
61 | $(LD) $(LIBDIR_DEBUG_LINUX) -o $(OUT_DEBUG_LINUX) $(OBJ_DEBUG_LINUX) $(LDFLAGS_DEBUG_LINUX) $(LIB_DEBUG_LINUX)
62 |
63 | $(OBJDIR_DEBUG_LINUX)/state.o: state.cpp
64 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c state.cpp -o $(OBJDIR_DEBUG_LINUX)/state.o
65 |
66 | $(OBJDIR_DEBUG_LINUX)/singletons.o: singletons.cpp
67 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c singletons.cpp -o $(OBJDIR_DEBUG_LINUX)/singletons.o
68 |
69 | $(OBJDIR_DEBUG_LINUX)/space.o: space.cpp
70 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c space.cpp -o $(OBJDIR_DEBUG_LINUX)/space.o
71 |
72 | $(OBJDIR_DEBUG_LINUX)/stdafx.o: stdafx.cpp
73 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c stdafx.cpp -o $(OBJDIR_DEBUG_LINUX)/stdafx.o
74 |
75 | $(OBJDIR_DEBUG_LINUX)/texpool.o: texpool.cpp
76 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c texpool.cpp -o $(OBJDIR_DEBUG_LINUX)/texpool.o
77 |
78 | $(OBJDIR_DEBUG_LINUX)/texture.o: texture.cpp
79 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c texture.cpp -o $(OBJDIR_DEBUG_LINUX)/texture.o
80 |
81 | $(OBJDIR_DEBUG_LINUX)/window.o: window.cpp
82 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c window.cpp -o $(OBJDIR_DEBUG_LINUX)/window.o
83 |
84 | $(OBJDIR_DEBUG_LINUX)/engine.o: engine.cpp
85 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c engine.cpp -o $(OBJDIR_DEBUG_LINUX)/engine.o
86 |
87 | $(OBJDIR_DEBUG_LINUX)/export.o: export.cpp
88 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c export.cpp -o $(OBJDIR_DEBUG_LINUX)/export.o
89 |
90 | $(OBJDIR_DEBUG_LINUX)/fonts.o: fonts.cpp
91 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c fonts.cpp -o $(OBJDIR_DEBUG_LINUX)/fonts.o
92 |
93 | $(OBJDIR_DEBUG_LINUX)/graphics.o: graphics.cpp
94 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c graphics.cpp -o $(OBJDIR_DEBUG_LINUX)/graphics.o
95 |
96 | $(OBJDIR_DEBUG_LINUX)/imgui/imgui.o: imgui/imgui.cpp
97 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c imgui/imgui.cpp -o $(OBJDIR_DEBUG_LINUX)/imgui/imgui.o
98 |
99 | $(OBJDIR_DEBUG_LINUX)/imgui/imgui_demo.o: imgui/imgui_demo.cpp
100 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c imgui/imgui_demo.cpp -o $(OBJDIR_DEBUG_LINUX)/imgui/imgui_demo.o
101 |
102 | $(OBJDIR_DEBUG_LINUX)/imgui/imgui_draw.o: imgui/imgui_draw.cpp
103 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c imgui/imgui_draw.cpp -o $(OBJDIR_DEBUG_LINUX)/imgui/imgui_draw.o
104 |
105 | $(OBJDIR_DEBUG_LINUX)/imgui/imgui_freetype.o: imgui/imgui_freetype.cpp
106 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c imgui/imgui_freetype.cpp -o $(OBJDIR_DEBUG_LINUX)/imgui/imgui_freetype.o
107 |
108 | $(OBJDIR_DEBUG_LINUX)/imgui/imgui_impl_glfw.o: imgui/imgui_impl_glfw.cpp
109 | $(CXX) $(CFLAGS_DEBUG_LINUX) $(INC_DEBUG_LINUX) -c imgui/imgui_impl_glfw.cpp -o $(OBJDIR_DEBUG_LINUX)/imgui/imgui_impl_glfw.o
110 |
111 | clean_debug_linux:
112 | rm -f $(OBJ_DEBUG_LINUX) $(OUT_DEBUG_LINUX)
113 | rm -rf Debug
114 | rm -rf $(OBJDIR_DEBUG_LINUX)
115 | rm -rf $(OBJDIR_DEBUG_LINUX)/imgui
116 |
117 | before_release_linux:
118 | test -d Release || mkdir -p Release
119 | test -d $(OBJDIR_RELEASE_LINUX) || mkdir -p $(OBJDIR_RELEASE_LINUX)
120 | test -d $(OBJDIR_RELEASE_LINUX)/imgui || mkdir -p $(OBJDIR_RELEASE_LINUX)/imgui
121 |
122 | after_release_linux:
123 |
124 | release_linux: before_release_linux out_release_linux after_release_linux
125 |
126 | out_release_linux: before_release_linux $(OBJ_RELEASE_LINUX) $(DEP_RELEASE_LINUX)
127 | $(LD) $(LIBDIR_RELEASE_LINUX) -o $(OUT_RELEASE_LINUX) $(OBJ_RELEASE_LINUX) $(LDFLAGS_RELEASE_LINUX) $(LIB_RELEASE_LINUX)
128 |
129 | $(OBJDIR_RELEASE_LINUX)/state.o: state.cpp
130 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c state.cpp -o $(OBJDIR_RELEASE_LINUX)/state.o
131 |
132 | $(OBJDIR_RELEASE_LINUX)/singletons.o: singletons.cpp
133 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c singletons.cpp -o $(OBJDIR_RELEASE_LINUX)/singletons.o
134 |
135 | $(OBJDIR_RELEASE_LINUX)/space.o: space.cpp
136 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c space.cpp -o $(OBJDIR_RELEASE_LINUX)/space.o
137 |
138 | $(OBJDIR_RELEASE_LINUX)/stdafx.o: stdafx.cpp
139 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c stdafx.cpp -o $(OBJDIR_RELEASE_LINUX)/stdafx.o
140 |
141 | $(OBJDIR_RELEASE_LINUX)/texpool.o: texpool.cpp
142 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c texpool.cpp -o $(OBJDIR_RELEASE_LINUX)/texpool.o
143 |
144 | $(OBJDIR_RELEASE_LINUX)/texture.o: texture.cpp
145 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c texture.cpp -o $(OBJDIR_RELEASE_LINUX)/texture.o
146 |
147 | $(OBJDIR_RELEASE_LINUX)/window.o: window.cpp
148 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c window.cpp -o $(OBJDIR_RELEASE_LINUX)/window.o
149 |
150 | $(OBJDIR_RELEASE_LINUX)/engine.o: engine.cpp
151 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c engine.cpp -o $(OBJDIR_RELEASE_LINUX)/engine.o
152 |
153 | $(OBJDIR_RELEASE_LINUX)/export.o: export.cpp
154 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c export.cpp -o $(OBJDIR_RELEASE_LINUX)/export.o
155 |
156 | $(OBJDIR_RELEASE_LINUX)/fonts.o: fonts.cpp
157 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c fonts.cpp -o $(OBJDIR_RELEASE_LINUX)/fonts.o
158 |
159 | $(OBJDIR_RELEASE_LINUX)/graphics.o: graphics.cpp
160 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c graphics.cpp -o $(OBJDIR_RELEASE_LINUX)/graphics.o
161 |
162 | $(OBJDIR_RELEASE_LINUX)/imgui/imgui.o: imgui/imgui.cpp
163 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c imgui/imgui.cpp -o $(OBJDIR_RELEASE_LINUX)/imgui/imgui.o
164 |
165 | $(OBJDIR_RELEASE_LINUX)/imgui/imgui_demo.o: imgui/imgui_demo.cpp
166 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c imgui/imgui_demo.cpp -o $(OBJDIR_RELEASE_LINUX)/imgui/imgui_demo.o
167 |
168 | $(OBJDIR_RELEASE_LINUX)/imgui/imgui_draw.o: imgui/imgui_draw.cpp
169 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c imgui/imgui_draw.cpp -o $(OBJDIR_RELEASE_LINUX)/imgui/imgui_draw.o
170 |
171 | $(OBJDIR_RELEASE_LINUX)/imgui/imgui_freetype.o: imgui/imgui_freetype.cpp
172 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c imgui/imgui_freetype.cpp -o $(OBJDIR_RELEASE_LINUX)/imgui/imgui_freetype.o
173 |
174 | $(OBJDIR_RELEASE_LINUX)/imgui/imgui_impl_glfw.o: imgui/imgui_impl_glfw.cpp
175 | $(CXX) $(CFLAGS_RELEASE_LINUX) $(INC_RELEASE_LINUX) -c imgui/imgui_impl_glfw.cpp -o $(OBJDIR_RELEASE_LINUX)/imgui/imgui_impl_glfw.o
176 |
177 | clean_release_linux:
178 | rm -f $(OBJ_RELEASE_LINUX) $(OUT_RELEASE_LINUX)
179 | rm -rf Release
180 | rm -rf $(OBJDIR_RELEASE_LINUX)
181 | rm -rf $(OBJDIR_RELEASE_LINUX)/imgui
182 |
183 | .PHONY: before_debug_linux after_debug_linux clean_debug_linux before_release_linux after_release_linux clean_release_linux
184 |
185 |
--------------------------------------------------------------------------------
/Makefile.win64:
--------------------------------------------------------------------------------
1 | #------------------------------------------------------------------------------#
2 | # This makefile was generated by 'cbp2make' tool rev.147 #
3 | #------------------------------------------------------------------------------#
4 |
5 |
6 | WORKDIR = `pwd`
7 |
8 | CC = x86_64-w64-mingw32-gcc
9 | CXX = x86_64-w64-mingw32-g++
10 | AR = x86_64-w64-mingw32-ar
11 | LD = x86_64-w64-mingw32-g++
12 | WINDRES = windres
13 |
14 | INC = -I/usr/i686-w64-mingw32/include
15 | CFLAGS = -std=c++14 -I/usr/include/freetype2
16 | RESINC =
17 | LIBDIR =
18 | LIB = -lpthread libfreetype-6.dll libv8.dll -lopengl32 -lglu32 -lgdi32 -lcomdlg32
19 | LDFLAGS = -Wl,--enable-stdcall-fixup
20 |
21 | INC_DEBUG_WIN32 = $(INC)
22 | CFLAGS_DEBUG_WIN32 = $(CFLAGS) -std=c++14 -pg -g -W -O0 -I/usr/include/freetype2 -Iv8/ -D_DEBUG -D_WINDOWS -DWIN32
23 | RESINC_DEBUG_WIN32 = $(RESINC)
24 | RCFLAGS_DEBUG_WIN32 = $(RCFLAGS)
25 | LIBDIR_DEBUG_WIN32 = $(LIBDIR)
26 | LIB_DEBUG_WIN32 = $(LIB) libfreetype.a
27 | LDFLAGS_DEBUG_WIN32 = $(LDFLAGS) -pg
28 | OBJDIR_DEBUG_WIN32 = Debug.win
29 | DEP_DEBUG_WIN32 =
30 | OUT_DEBUG_WIN32 = Debug.win/gdepictions.exe
31 |
32 | INC_RELEASE_WIN32 = $(INC)
33 | CFLAGS_RELEASE_WIN32 = $(CFLAGS) -std=c++14 -g -W -O2 -I/usr/include/freetype2 -Iv8/ -DNDEBUG -D_WINDOWS -DWIN32
34 | RESINC_RELEASE_WIN32 = $(RESINC)
35 | RCFLAGS_RELEASE_WIN32 = $(RCFLAGS)
36 | LIBDIR_RELEASE_WIN32 = $(LIBDIR)
37 | LIB_RELEASE_WIN32 = $(LIB) libfreetype.a
38 | LDFLAGS_RELEASE_WIN32 = $(LDFLAGS)
39 | OBJDIR_RELEASE_WIN32 = Release.win
40 | DEP_RELEASE_WIN32 =
41 | OUT_RELEASE_WIN32 = Release.win/gdepictions.exe
42 |
43 | OBJ_DEBUG_WIN32 = $(OBJDIR_DEBUG_WIN32)/state.o $(OBJDIR_DEBUG_WIN32)/singletons.o $(OBJDIR_DEBUG_WIN32)/space.o $(OBJDIR_DEBUG_WIN32)/stdafx.o $(OBJDIR_DEBUG_WIN32)/texpool.o $(OBJDIR_DEBUG_WIN32)/texture.o $(OBJDIR_DEBUG_WIN32)/win32window.o $(OBJDIR_DEBUG_WIN32)/engine.o $(OBJDIR_DEBUG_WIN32)/export.o $(OBJDIR_DEBUG_WIN32)/fonts.o $(OBJDIR_DEBUG_WIN32)/graphics.o $(OBJDIR_DEBUG_WIN32)/imgui/imgui.o $(OBJDIR_DEBUG_WIN32)/imgui/imgui_demo.o $(OBJDIR_DEBUG_WIN32)/imgui/imgui_draw.o $(OBJDIR_DEBUG_WIN32)/imgui/imgui_freetype.o $(OBJDIR_DEBUG_WIN32)/imgui/imgui_impl_glfw.o
44 |
45 | OBJ_RELEASE_WIN32 = $(OBJDIR_RELEASE_WIN32)/state.o $(OBJDIR_RELEASE_WIN32)/singletons.o $(OBJDIR_RELEASE_WIN32)/space.o $(OBJDIR_RELEASE_WIN32)/stdafx.o $(OBJDIR_RELEASE_WIN32)/texpool.o $(OBJDIR_RELEASE_WIN32)/texture.o $(OBJDIR_RELEASE_WIN32)/win32window.o $(OBJDIR_RELEASE_WIN32)/engine.o $(OBJDIR_RELEASE_WIN32)/export.o $(OBJDIR_RELEASE_WIN32)/fonts.o $(OBJDIR_RELEASE_WIN32)/graphics.o $(OBJDIR_RELEASE_WIN32)/imgui/imgui.o $(OBJDIR_RELEASE_WIN32)/imgui/imgui_demo.o $(OBJDIR_RELEASE_WIN32)/imgui/imgui_draw.o $(OBJDIR_RELEASE_WIN32)/imgui/imgui_freetype.o $(OBJDIR_RELEASE_WIN32)/imgui/imgui_impl_glfw.o
46 |
47 | all: debug_win32 release_win32
48 |
49 | clean: clean_debug_win32 clean_release_win32
50 |
51 | before_debug_win32:
52 | test -d Debug.win || mkdir -p Debug.win
53 | test -d $(OBJDIR_DEBUG_WIN32) || mkdir -p $(OBJDIR_DEBUG_WIN32)
54 | test -d $(OBJDIR_DEBUG_WIN32)/imgui || mkdir -p $(OBJDIR_DEBUG_WIN32)/imgui
55 |
56 | after_debug_win32:
57 |
58 | debug_win32: before_debug_win32 out_debug_win32 after_debug_win32
59 |
60 | out_debug_win32: before_debug_win32 $(OBJ_DEBUG_WIN32) $(DEP_DEBUG_WIN32)
61 | $(LD) $(LIBDIR_DEBUG_WIN32) -o $(OUT_DEBUG_WIN32) $(OBJ_DEBUG_WIN32) $(LDFLAGS_DEBUG_WIN32) $(LIB_DEBUG_WIN32)
62 |
63 | $(OBJDIR_DEBUG_WIN32)/state.o: state.cpp
64 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c state.cpp -o $(OBJDIR_DEBUG_WIN32)/state.o
65 |
66 | $(OBJDIR_DEBUG_WIN32)/singletons.o: singletons.cpp
67 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c singletons.cpp -o $(OBJDIR_DEBUG_WIN32)/singletons.o
68 |
69 | $(OBJDIR_DEBUG_WIN32)/space.o: space.cpp
70 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c space.cpp -o $(OBJDIR_DEBUG_WIN32)/space.o
71 |
72 | $(OBJDIR_DEBUG_WIN32)/stdafx.o: stdafx.cpp
73 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c stdafx.cpp -o $(OBJDIR_DEBUG_WIN32)/stdafx.o
74 |
75 | $(OBJDIR_DEBUG_WIN32)/texpool.o: texpool.cpp
76 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c texpool.cpp -o $(OBJDIR_DEBUG_WIN32)/texpool.o
77 |
78 | $(OBJDIR_DEBUG_WIN32)/texture.o: texture.cpp
79 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c texture.cpp -o $(OBJDIR_DEBUG_WIN32)/texture.o
80 |
81 | $(OBJDIR_DEBUG_WIN32)/win32window.o: win32window.cpp
82 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c win32window.cpp -o $(OBJDIR_DEBUG_WIN32)/win32window.o
83 |
84 | $(OBJDIR_DEBUG_WIN32)/engine.o: engine.cpp
85 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c engine.cpp -o $(OBJDIR_DEBUG_WIN32)/engine.o
86 |
87 | $(OBJDIR_DEBUG_WIN32)/export.o: export.cpp
88 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c export.cpp -o $(OBJDIR_DEBUG_WIN32)/export.o
89 |
90 | $(OBJDIR_DEBUG_WIN32)/fonts.o: fonts.cpp
91 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c fonts.cpp -o $(OBJDIR_DEBUG_WIN32)/fonts.o
92 |
93 | $(OBJDIR_DEBUG_WIN32)/graphics.o: graphics.cpp
94 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c graphics.cpp -o $(OBJDIR_DEBUG_WIN32)/graphics.o
95 |
96 | $(OBJDIR_DEBUG_WIN32)/imgui/imgui.o: imgui/imgui.cpp
97 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c imgui/imgui.cpp -o $(OBJDIR_DEBUG_WIN32)/imgui/imgui.o
98 |
99 | $(OBJDIR_DEBUG_WIN32)/imgui/imgui_demo.o: imgui/imgui_demo.cpp
100 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c imgui/imgui_demo.cpp -o $(OBJDIR_DEBUG_WIN32)/imgui/imgui_demo.o
101 |
102 | $(OBJDIR_DEBUG_WIN32)/imgui/imgui_draw.o: imgui/imgui_draw.cpp
103 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c imgui/imgui_draw.cpp -o $(OBJDIR_DEBUG_WIN32)/imgui/imgui_draw.o
104 |
105 | $(OBJDIR_DEBUG_WIN32)/imgui/imgui_freetype.o: imgui/imgui_freetype.cpp
106 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c imgui/imgui_freetype.cpp -o $(OBJDIR_DEBUG_WIN32)/imgui/imgui_freetype.o
107 |
108 | $(OBJDIR_DEBUG_WIN32)/imgui/imgui_impl_glfw.o: imgui/imgui_impl_glfw.cpp
109 | $(CXX) $(CFLAGS_DEBUG_WIN32) $(INC_DEBUG_WIN32) -c imgui/imgui_impl_glfw.cpp -o $(OBJDIR_DEBUG_WIN32)/imgui/imgui_impl_glfw.o
110 |
111 | clean_debug_win32:
112 | rm -f $(OBJ_DEBUG_WIN32) $(OUT_DEBUG_WIN32)
113 | rm -rf Debug.win
114 | rm -rf $(OBJDIR_DEBUG_WIN32)
115 | rm -rf $(OBJDIR_DEBUG_WIN32)/imgui
116 |
117 | before_release_win32:
118 | test -d Release.win || mkdir -p Release.win
119 | test -d $(OBJDIR_RELEASE_WIN32) || mkdir -p $(OBJDIR_RELEASE_WIN32)
120 | test -d $(OBJDIR_RELEASE_WIN32)/imgui || mkdir -p $(OBJDIR_RELEASE_WIN32)/imgui
121 |
122 | after_release_win32:
123 |
124 | release_win32: before_release_win32 out_release_win32 after_release_win32
125 |
126 | out_release_win32: before_release_win32 $(OBJ_RELEASE_WIN32) $(DEP_RELEASE_WIN32)
127 | $(LD) $(LIBDIR_RELEASE_WIN32) -o $(OUT_RELEASE_WIN32) $(OBJ_RELEASE_WIN32) $(LDFLAGS_RELEASE_WIN32) $(LIB_RELEASE_WIN32)
128 |
129 | $(OBJDIR_RELEASE_WIN32)/state.o: state.cpp
130 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c state.cpp -o $(OBJDIR_RELEASE_WIN32)/state.o
131 |
132 | $(OBJDIR_RELEASE_WIN32)/singletons.o: singletons.cpp
133 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c singletons.cpp -o $(OBJDIR_RELEASE_WIN32)/singletons.o
134 |
135 | $(OBJDIR_RELEASE_WIN32)/space.o: space.cpp
136 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c space.cpp -o $(OBJDIR_RELEASE_WIN32)/space.o
137 |
138 | $(OBJDIR_RELEASE_WIN32)/stdafx.o: stdafx.cpp
139 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c stdafx.cpp -o $(OBJDIR_RELEASE_WIN32)/stdafx.o
140 |
141 | $(OBJDIR_RELEASE_WIN32)/texpool.o: texpool.cpp
142 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c texpool.cpp -o $(OBJDIR_RELEASE_WIN32)/texpool.o
143 |
144 | $(OBJDIR_RELEASE_WIN32)/texture.o: texture.cpp
145 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c texture.cpp -o $(OBJDIR_RELEASE_WIN32)/texture.o
146 |
147 | $(OBJDIR_RELEASE_WIN32)/win32window.o: win32window.cpp
148 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c win32window.cpp -o $(OBJDIR_RELEASE_WIN32)/win32window.o
149 |
150 | $(OBJDIR_RELEASE_WIN32)/engine.o: engine.cpp
151 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c engine.cpp -o $(OBJDIR_RELEASE_WIN32)/engine.o
152 |
153 | $(OBJDIR_RELEASE_WIN32)/export.o: export.cpp
154 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c export.cpp -o $(OBJDIR_RELEASE_WIN32)/export.o
155 |
156 | $(OBJDIR_RELEASE_WIN32)/fonts.o: fonts.cpp
157 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c fonts.cpp -o $(OBJDIR_RELEASE_WIN32)/fonts.o
158 |
159 | $(OBJDIR_RELEASE_WIN32)/graphics.o: graphics.cpp
160 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c graphics.cpp -o $(OBJDIR_RELEASE_WIN32)/graphics.o
161 |
162 | $(OBJDIR_RELEASE_WIN32)/imgui/imgui.o: imgui/imgui.cpp
163 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c imgui/imgui.cpp -o $(OBJDIR_RELEASE_WIN32)/imgui/imgui.o
164 |
165 | $(OBJDIR_RELEASE_WIN32)/imgui/imgui_demo.o: imgui/imgui_demo.cpp
166 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c imgui/imgui_demo.cpp -o $(OBJDIR_RELEASE_WIN32)/imgui/imgui_demo.o
167 |
168 | $(OBJDIR_RELEASE_WIN32)/imgui/imgui_draw.o: imgui/imgui_draw.cpp
169 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c imgui/imgui_draw.cpp -o $(OBJDIR_RELEASE_WIN32)/imgui/imgui_draw.o
170 |
171 | $(OBJDIR_RELEASE_WIN32)/imgui/imgui_freetype.o: imgui/imgui_freetype.cpp
172 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c imgui/imgui_freetype.cpp -o $(OBJDIR_RELEASE_WIN32)/imgui/imgui_freetype.o
173 |
174 | $(OBJDIR_RELEASE_WIN32)/imgui/imgui_impl_glfw.o: imgui/imgui_impl_glfw.cpp
175 | $(CXX) $(CFLAGS_RELEASE_WIN32) $(INC_RELEASE_WIN32) -c imgui/imgui_impl_glfw.cpp -o $(OBJDIR_RELEASE_WIN32)/imgui/imgui_impl_glfw.o
176 |
177 | clean_release_win32:
178 | rm -f $(OBJ_RELEASE_WIN32) $(OUT_RELEASE_WIN32)
179 | rm -rf Release.win
180 | rm -rf $(OBJDIR_RELEASE_WIN32)
181 | rm -rf $(OBJDIR_RELEASE_WIN32)/imgui
182 |
183 | .PHONY: before_debug_win32 after_debug_win32 clean_debug_win32 before_release_win32 after_release_win32 clean_release_win32
184 |
185 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | graphic depictions
2 | ==================
3 |
4 | This program is a graphical workbench for creating and manipulating graphs and running JavaScript on them to automate a variety of calculations.
5 |
6 | Possible applications include typesetting graphs for academic papers and presentations (it exports to [TikZ](https://en.wikipedia.org/wiki/PGF/TikZ)), looking for counterexamples to conjectures and testing graph algorithms.
7 |
8 | You are looking at an early release, and a lot of features and polish are still missing. I am grateful for any bug reports, pull requests, feature suggestions and other feedback.
9 |
10 |
11 |
12 |
13 |
14 | How to install
15 | --------------
16 |
17 | The easiest way to use this program is to pull one of the binary builds (version 0.4.1 of 2018-03-20):
18 |
19 | * [Linux x86_64](http://twilightro.kafuka.org/%7Eblackhole89/files/gdepictions-0.4.tar.gz)
20 | * [Windows x86_64](http://twilightro.kafuka.org/%7Eblackhole89/files/gdepictions-0.4-win64.zip)
21 |
22 | Once you have unpacked the relevant package, switch into the directory contained and run the binary (`./gdepictions` in a Linux shell, or `gdepictions.exe` on Windows).
23 |
24 | On Linux, you additionally require
25 | * a version of libv8 (>= 3.14.5 or thereabouts, as found in the Debian and Ubuntu repositories as `libv8-3.14.5`)
26 | * `zenity` for save/load dialogs.
27 | The Windows build includes the required DLLs.
28 |
29 | You may also try to compile it yourself, which may involve some effort. In fact, natively creating a Windows binary of the old version of V8 that graphic depictions is based on turned out to be so painful that I gave up and cross-compiled everything using mingw-w64. If you are not discouraged, consult the "How to compile from source" section further below.
30 |
31 | How to use
32 | ----------
33 |
34 | The program uses a [Blender](https://www.blender.org/)-inspired modal keyboard-and-mouse interface. Most actions are performed by pressing some key or key combination to _initiate_ an action at the mouse position. When more input is necessary (e.g. a second endpoint for a new edge, or the other corner of a box selection), the action can be completed by moving the mouse and either committing the results by clicking or cancelling by pressing Escape. The state in which no complex action is awaiting more input shall be referred to as _neutral mode_.
35 |
36 | ### Editing the graph
37 |
38 | The following list of examples doubles as an outline of basic workflow:
39 |
40 | * `V` to create a selected vertex at the current cursor position.
41 | * `C` to connect all selected vertices with edges.
42 | * `E` to initiate an edge at the vertex closest to the mouse cursor. A dangling edge will be drawn from the vertex to the mouse cursor to indicate that an edge is currently being added. Once another vertex is clicked, the interface returns to neutral mode and an edge is added between the two vertices. Alternatively, pressing `E` again adds the edge and initiates a new edge at the target vertex.
43 | * `B` initiates a selection box at the current location of the mouse pointer. When the left mouse button is clicked, all vertices in a square region between where `B` was pressed and the mouse was clicked are selected.
44 | * `A` unselects all vertices when vertices are selected, and selects all vertices when none are selected.
45 | * A left mouse button click in neutral mode selects the vertex closest to the mouse cursor. If `Shift` is held, the vertex is instead added to the current selection.
46 | * A right mouse button click in neutral mode opens the context menu.
47 | * `D` deletes all edges between selected vertices.
48 | * `G` initiates moving of the currently selected vertices by moving the mouse pointer. Click the graph view with the left mouse button to place the vertices at their current location, or press `Esc` to cancel.
49 | * `X` extrudes the currently selected vertices, that is, it duplicates the subgraph induced by them and connects each new node to the respective old node that gave rise to it. Pressing `X` automatically initiates `G`o mode on the new vertices.
50 |
51 | ### Moving the camera
52 |
53 | The camera may be manipulated in a variety of ways.
54 |
55 | * To pan (slide) the graph, hold and drag the middle mouse button or mouse wheel, or alternatively use the arrow keys.
56 | * To zoom in and out, roll the mouse wheel up or down respectively.
57 | * When operating in 3D mode (Layout > Unlock 3D), hold and drag the right mouse button to rotate the view in space.
58 | * When a nonzero number of vertices is selected, press `M` to center the view on the selected vertices.
59 |
60 | ### Writing and running scripts
61 |
62 | A key feature of graphic depictions is the ability to run JavaScript programs on the graph. To create a script, press the `Add` button in the **Scripts** window, and click on the `New script` entry that is created in the list. A script can either be applied to each selected node (default) or the whole graph (disable the `on nodes` option in the script editor). A few example scripts are included with the distribution, and if you are already familiar with JavaScript, these may be the fastest way to familiarise yourself with the environment. The important basics are the following:
63 |
64 | * When running on nodes, the current node is made available locally as an object named `N`. This object can store arbitrary data, so for instance the script `N.v=3;` creates an attribute named `v` in every node that is selected when it is run and assigns the integer `3` to it. If the script `N.v = N.v * N.v;` is then run on a subset of those nodes, the nodes it will run on will have their attribute `v` set to `9`.
65 | * Nodes also have a special boolean attribute `selected` which is true iff the node in question is currently selected.
66 | * If `N` is a node object, then `gamma(N)` is the array of nodes in the node's neighbourhood, that is, all nodes connected to it, not including itself. This set can be iterated over as follows:
67 | ```javascript
68 | gamma(N).forEach(function (M) {
69 | M.selected = true;
70 | });
71 | ```
72 | This script adds all nodes that are adjacent to `N` to the current selection.
73 | * If `N` is a node object, then `delta(N)` is an array of edges on the node's boundary, that is, all edges incident to it. This set can be iterated over as follows:
74 | ```javascript
75 | delta(N).forEach(function (E) {
76 | // Get other end.
77 | // + forces comparison of underlying nodes rather than references.
78 | var M;
79 | if(E.n1 ==+ N)
80 | M = E.n2;
81 | else
82 | M = E.n1;
83 |
84 | // label edges incident to N with difference in v going out of N
85 | E.label = M.v - N.v;
86 | });
87 | ```
88 | * The set of all nodes is always made available as an array in global scope as `nodes()`. So the action of a script "on nodes" can be emulated with a script "on graphs" as follows:
89 | ```javascript
90 | nodes().forEach(function (N) {
91 | if(N.selected) {
92 | // script here
93 | }
94 | });
95 | ```
96 | Likewise, the set of all edges is made available as `edges()`.
97 | * New nodes and edges can be added by scripts using `addNode` and `addEdge`. When adding nodes, the position in 2D or 3D space needs to be specified. For instance, the following script creates a new dangling vertex that is connected to each vertex in the selection next to the respective vertex:
98 | ```javascript
99 | M = addNode(N.pos.x+0.1, N.pos.y); // or addNode(N.pos.x+0.1, N.pos.y, N.pos.z)
100 | E = addEdge(M,N);
101 | ```
102 | * `getEdge(M,N)` returns a handle to the edge between `N` and `M` if there is one, and `undefined` otherwise.
103 | * Existing nodes and edges can be deleted with `delNode` and `delEdge` respectively. All references to a deleted node or edge in global scope are rendered undefined by this. However, it is the user's responsibility to ensure that local references and those stored in closures are disposed of properly.
104 | ```javascript
105 | addNode(0,0);
106 | addNode(0.1,0.1);
107 | E = addEdge(nodes()[0], nodes()[1]);
108 | var Elocal = E;
109 | delEdge(nodes()[0], nodes()[1]); // Also ok: delEdge(E);
110 | // E is now undefined
111 | // Elocal is now toxic sludge and should not be read
112 | delNode(nodes()[0]);
113 | ```
114 | * `print` and `println` can be used to print any single value to the console (opened with `Tab`), potentially creating a new line.
115 | * The display colour of a node `N` can be adjusted by calling `N.setColo(u)r`. By default, nodes are drawn white.
116 | ```javascript
117 | N = addNode(0,0); // add node at origin
118 | N.setColor(1.0,0.0,0.0); // make it red
119 | ```
120 | * In addition, all builtins of the ECMAScript 5 standard, e.g. `Math.sin`, are provided via V8.
121 |
122 | By default, scripts are saved with the graph you are editing. (File > Save) You can instead make a script global by right-clicking it in the script list and unchecking `Stored with graph`. You can also quickly enter scripts that will not be saved by
123 | * opening the **JavaScript console** with `Tab` (quit with `Esc`) or
124 | * right-clicking the graph view and selecting `Execute on selection...`.
125 |
126 | The **Data** subwindow allows you to inspect all global JavaScript variables and objects. Create them by assigning bare variables in scripts, e.g. `a=5;` (as opposed to `var a=5;`, or in the console.
127 |
128 | The **Node Appearance** subwindow contains a 3x3 matrix of input boxes which can be used to display the current values of vertex attributes next to the vertex in the graph view. For instance, if the previously-mentioned script `N.v=3;` was run on all nodes and `v` is entered into the second input box in the top line of the window, then a `3` will be rendered above every node. By right-clicking a field in the Node Appearance window, you can also adjust its display colour.
129 |
130 | Licensing
131 | ---------
132 |
133 | graphic depictions is made available under the terms of the GNU General Public License, Version 3. Parts of the program are also covered by different licenses; see the LICENSE file for details.
134 |
135 | How to compile from source
136 | --------------------------
137 |
138 | On Linux, you will require the development headers for:
139 |
140 | * V8 (`libv8-dev` >=3.14.5 or thereabouts, 4.x onwards will probably not work)
141 | * freetype2 (`libfreetype6-dev`)
142 | * OpenGL (`libgl1-mesa-dev` and `libglu1-mesa-dev`)
143 |
144 | If you have these and a sufficiently recent version of G++ installed, simply running the included Makefile should work.
145 |
146 | For Windows builds, I strongly recommend compiling with MinGW-w64 (g++-mingw-w64-x86-64 and its dependencies on Debianesque systems). If you are happy with reusing the included binary DLLs, this may be as simple as running `make -f Makefile.win64` in the program root. You can procure binaries and build scripts for the fairly standard dependencies such as zlib and freetype from Fedora's repositories, but compiling libv8.dll is a bit of an adventure and would probably require more than the length of this document to explain. I am grateful that its license frees me from the obligation to do so, but may expand upon this section later.
147 |
148 | I expect the only significant obstacle to compiling from MSVC++ to be V8, too; while the 3.x libv8 sources include some provisions for a Microsoft build environment, they seem to be based on several assumptions about standard compliancy and state of the platform headers that no longer hold true for more recent versions.
149 |
150 | Known issues
151 | ------------
152 |
153 | * Drawing lots of node labels can be slow on some platforms. Generally, the "separate texture for each glyph" approach my font implementation (`fonts.cpp`) uses seems to be much slower than imgui's font atlas + texture coordinates one; I will eventually switch over to it.
154 | * In the Windows binary build, TikZ export fails to correctly compute node label colours. This is a complete and utter mystery to me at the moment.
155 |
156 | Future plans
157 | ------------
158 |
159 | ### 0.5
160 |
161 | * Make graphs first-class objects, and allow a session/file to contain multiple graphs. (This should come with functions to extract induced subgraphs, merge graphs, find embeddings etc.)
162 | * Introduce bindings for a linear algebra library such as Armadillo to enable spectral graph theory work.
163 |
164 | ### ?
165 |
166 | * Multiple viewports
167 |
168 | Changelog
169 | ---------
170 |
171 | ### 0.4.2 (WIP)
172 |
173 | * Quality-of-life improvements:
174 | * highlight selected edges
175 | * camera position clamping and wrapping
176 | * better grid snapping
177 |
178 | ### 0.4.1
179 |
180 | * Fixed a number of memory leaks.
181 | * Added Restricted Boltzmann Machine example.
182 |
183 | ### 0.4
184 |
185 | * Nodes and edges can now store arbitrary JavaScript data.
186 | * Likewise, all global variables created by JS get stored with the graph.
187 | * Global variables can now be inspected in the user interface.
188 | * Adding a javascript console, accessible with `Tab`.
189 | * Adding builtin functions `print` and `println`.
190 | * Bump file format version.
191 |
192 | ### 0.3
193 |
194 | * Added support for manipulating the colour of nodes (N.setColour(float,float,float)) from scripts.
195 |
196 | ### 0.2.1
197 |
198 | * Made X11 keyboard support more portable.
199 |
200 | ### 0.2
201 |
202 | * Added basic support for edge data. At the moment, the "edge look" is hardcoded to display the field named "label" only.
203 | * Switched the node label font to a more legible one, and replaced shadows with outlines.
204 | * Fixed "Execute on selected..." doing nothing.
205 | * Added rudimentary editor for JS node properties in context menu.
206 | * Bump file format version.
207 |
208 | ### 0.1
209 |
210 | * Initial release.
211 |
--------------------------------------------------------------------------------
/Resource.h:
--------------------------------------------------------------------------------
1 | /*
2 | * graphic depictions, a visual workbench for graphs
3 | *
4 | * Copyright (C) 2016 Matvey Soloviev
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | //{{NO_DEPENDENCIES}}
21 | // Microsoft Visual C++ generated include file.
22 | // Used by space.rc
23 | //
24 |
25 | #define IDS_APP_TITLE 103
26 |
27 | #define IDR_MAINFRAME 128
28 | #define IDD_SPACE_DIALOG 102
29 | #define IDD_ABOUTBOX 103
30 | #define IDM_ABOUT 104
31 | #define IDM_EXIT 105
32 | #define IDI_SPACE 107
33 | #define IDI_SMALL 108
34 | #define IDC_SPACE 109
35 | #define IDC_MYICON 2
36 | #define IDC_STATIC -1
37 | // Next default values for new objects
38 | //
39 | #ifdef APSTUDIO_INVOKED
40 | #ifndef APSTUDIO_READONLY_SYMBOLS
41 |
42 | #define _APS_NO_MFC 130
43 | #define _APS_NEXT_RESOURCE_VALUE 129
44 | #define _APS_NEXT_COMMAND_VALUE 32771
45 | #define _APS_NEXT_CONTROL_VALUE 1000
46 | #define _APS_NEXT_SYMED_VALUE 110
47 | #endif
48 | #endif
49 |
--------------------------------------------------------------------------------
/SourceCodePro-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blackhole89/graphicdepictions/364800154c8393060e29952a437ef1500430c52c/SourceCodePro-Bold.ttf
--------------------------------------------------------------------------------
/StrLit.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blackhole89/graphicdepictions/364800154c8393060e29952a437ef1500430c52c/StrLit.ttf
--------------------------------------------------------------------------------
/engine.h:
--------------------------------------------------------------------------------
1 | /*
2 | * graphic depictions, a visual workbench for graphs
3 | *
4 | * Copyright (C) 2016-2018 Matvey Soloviev
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef _ENGINE_H_
21 | #define _ENGINE_H_
22 |
23 | #ifndef WIN32
24 | #include
25 | #else
26 | #include
27 | #include
28 | #endif
29 | #include "stdafx.h"
30 |
31 | struct CSScript {
32 | std::string name;
33 | std::string code;
34 | bool onNodes;
35 | };
36 |
37 | enum {
38 | NO_GRAPH=1,
39 | NO_NODE,
40 | NO_EDGE,
41 | NO_NODESET,
42 | NO_EDGESET
43 | };
44 |
45 | class CSState {
46 | public:
47 | struct CSAttr {
48 | v8::Persistent j_data;
49 |
50 | /* deferred load */
51 | std::string st;
52 | static CSAttr FromStringDeferred(char *buf);
53 | void Compile();
54 |
55 | CSAttr(char *);
56 | CSAttr &operator=(CSAttr &&other);
57 | CSAttr &operator=(const CSAttr &other);
58 | CSAttr(const CSAttr &other);
59 | CSAttr();
60 | ~CSAttr();
61 |
62 | std::string PrettyPrint();
63 |
64 | std::string ToString();
65 | static CSAttr FromString(char *buf);
66 | double ArrayGet(int i); // hack for node colour
67 | };
68 | typedef std::map attrs;
69 |
70 | class CSNode;
71 | class CSEdge;
72 |
73 | struct CSEdge {
74 | attrs a;
75 |
76 | CSNode *n1, *n2;
77 |
78 | bool selected;
79 | };
80 |
81 | struct CSNode {
82 | attrs a;
83 |
84 | float pos[3];
85 |
86 | std::set adj;
87 | std::set adje;
88 |
89 | bool selected;
90 | };
91 |
92 | std::set nodes;
93 | std::set edges;
94 |
95 | /* for (de)serialisation */
96 | std::map nodes2id;
97 | std::map id2nodes;
98 | std::map edges2id;
99 | std::map id2edges;
100 |
101 | int nselected;
102 |
103 | /* script state */
104 | v8::Persistent v8ctx;
105 |
106 | std::vector scripts;
107 |
108 | #define NSELGROUPS 10
109 | std::set selgroups[NSELGROUPS];
110 |
111 | //std::map nodesbyname;
112 |
113 | /* basic stuff */
114 | CSNode* AddNode(float x, float y, float z);
115 | CSEdge* AddEdge(CSNode *n1, CSNode *n2);
116 |
117 | CSEdge* GetEdge(CSNode *n1, CSNode *n2);
118 |
119 | void DelNode(CSNode *n);
120 | void DelEdge(CSNode *n1, CSNode *n2);
121 | void DelEdge(CSEdge *e);
122 |
123 | /* medium stuff */
124 | void GrowSelection();
125 | void ShrinkSelection();
126 | void SelectConnected();
127 | void InvertSelection();
128 |
129 | void SaveSelectionGroup(int id);
130 | void LoadSelectionGroup(int id);
131 |
132 | void DuplicateSelection();
133 | void ExtrudeSelection();
134 |
135 | /* advanced stuff */
136 | void MkDiscreteCube(int dim);
137 | void MkGnp(int n, float p);
138 | void OrderFromSelection();
139 | bool RelaxationStep(float tlength);
140 | void RoundPositions(float gridsize);
141 |
142 | /* load/save */
143 | char last_filename[1024];
144 | void SaveAs();
145 | void Save();
146 | void Load();
147 | void Clear();
148 | };
149 |
150 | class CSEngine {
151 | friend class CSGraphics;
152 | friend class CSUI;
153 | public:
154 | CSMainWindow *wnd;
155 | CSGraphics graphics;
156 |
157 | public:
158 | CSState st;
159 |
160 | bool use_3d;
161 |
162 | enum {
163 | AC_NOTHING,
164 | AC_GO,
165 | AC_SCALE,
166 | AC_SELECT,
167 | AC_RELAX,
168 | AC_EDGE
169 | } action;
170 |
171 | v8::HandleScope v8hs;
172 | v8::Persistent global, node_templ, set_templ, edge_templ, edge_set_templ;
173 | v8::Persistent value_of_templ, native_rendition_templ, set_colour_templ, edge_foreach_templ;
174 |
175 | std::vector scripts;
176 | char err_buf[4096];
177 |
178 | void LoadScripts();
179 | void SaveScripts();
180 | void SaveScript(int id);
181 |
182 | std::deque recent;
183 | public:
184 | pthread_mutex_t loading_mutex;
185 | pthread_cond_t loading_cond;
186 |
187 | bool keys[256];
188 |
189 | long f1,f2,sf1,sf2,df1,df2,tdelta;
190 |
191 | /* script editor state */
192 | int editor_index;
193 | bool editor_local;
194 | char editor_tbuf[64];
195 | char editor_buf[4096];
196 | bool editor_is_pernode;
197 |
198 | /* popup terminal state */
199 | bool show_terminal;
200 | bool force_terminal_focus;
201 | std::vector term_backlog, term_results;
202 | int term_backlog_pos;
203 | char term_buf[4096];
204 |
205 | /* return true iff entry was not erased */
206 | bool ScriptListEntry(CSScript *s, int id, bool local);
207 |
208 | /* for property editor */
209 | void RenderNamedProperty(const char *name, v8::Handle val, bool show_builtins);
210 | void RenderObjectProps(v8::Handle obj, bool show_builtins);
211 | void RenderAttrs(CSState::attrs *a, bool show_builtins);
212 |
213 | void Init(CSMainWindow *wndw);
214 | void Run();
215 | void RunLogic();
216 |
217 | void Click(int btn, int x,int y);
218 |
219 | void StartDragging(int x0, int y0);
220 | void CancelDragging();
221 | void SetSelectionRect(int x0, int y0, int x1, int y1);
222 |
223 | /* closest vertex in screenspace, within rmax */
224 | CSState::CSNode* GetClosestVertex(int x, int y, float rmax);
225 |
226 | v8::Local FromJSON(char *json);
227 | std::string ToJSON(v8::Handle);
228 |
229 | void DeepWipe(void *ptr);
230 | void ImportToGlobal(v8::Handle);
231 |
232 | // bool CompileScript(const char *code,const char *name, v8::Handle &out);
233 | bool RunScriptForNode(CSState::CSNode *n, const char *code, const char *name);
234 | bool RunScriptForNodes(std::set ns, const char *code, const char *name);
235 | bool RunScript(const char *code, const char *name);
236 | std::string EvalScript(const char *code, const char *name);
237 |
238 | /* actions; eventually should pull everything out here */
239 | void AcEdge(float x, float y);
240 | };
241 |
242 | typedef struct {
243 | long x,y,z;
244 | } SPosition;
245 |
246 | #endif
247 |
--------------------------------------------------------------------------------
/examples/bfs-shortest-path.txt:
--------------------------------------------------------------------------------
1 | version 1
2 | 2D
3 | 10
4 | 0 0.05790787 -0.05437336 0.00000000 2
5 | "d"=i999
6 | "dprev"=i16
7 | 0 0.00427867 -0.13473158 0.00000000 2
8 | "d"=i999
9 | "dprev"=i16
10 | 0 -0.00928365 0.05038917 0.00000000 2
11 | "d"=i999
12 | "dprev"=i14
13 | 0 -0.13907549 -0.14413996 0.00000000 2
14 | "d"=i999
15 | "dprev"=i18
16 | 0 0.05533705 -0.00344836 0.00000000 2
17 | "d"=i999
18 | "dprev"=i20
19 | 0 0.08825375 0.14498915 0.00000000 2
20 | "d"=i0
21 | "dprev"=i0
22 | 0 -0.13333380 0.02316415 0.00000000 2
23 | "d"=i999
24 | "dprev"=i16
25 | 0 -0.03132962 0.10386828 0.00000000 2
26 | "d"=i999
27 | "dprev"=i11
28 | 0 -0.07419213 0.00143083 0.00000000 2
29 | "d"=i999
30 | "dprev"=i14
31 | 1 0.10643733 0.05139336 0.00000000 2
32 | "d"=i999
33 | "dprev"=i12
34 | 21
35 | 1 3 1 "label"=i6
36 | 1 8 1 "label"=i1
37 | 0 9 1 "label"=i2
38 | 0 1 1 "label"=i5
39 | 2 4 1 "label"=i10
40 | 2 5 1 "label"=i14
41 | 2 7 1 "label"=i2
42 | 2 8 1 "label"=i1
43 | 2 9 1 "label"=i10
44 | 2 1 1 "label"=i9
45 | 2 0 1 "label"=i14
46 | 6 3 1 "label"=i4
47 | 7 5 1 "label"=i10
48 | 7 6 1 "label"=i6
49 | 8 3 1 "label"=i14
50 | 8 6 1 "label"=i10
51 | 8 7 1 "label"=i12
52 | 9 4 1 "label"=i4
53 | 9 7 1 "label"=i8
54 | 1 4 1 "label"=i12
55 | 4 8 1 "label"=i1
56 | 10
57 | 0
58 | 0
59 | 0
60 | 0
61 | 0
62 | 0
63 | 0
64 | 0
65 | 0
66 | 0
67 | 2
68 | 193 byte graph script propagate
69 | nodes().forEach(function (N) {
70 | N.dprev = N.d;
71 | });
72 |
73 | nodes().forEach(function (N) {
74 | gamma(N).forEach(function (M) {
75 | if(M.d>N.dprev+getEdge(N,M).label) M.d=N.dprev+getEdge(N,M).label;
76 | });
77 | });
78 | 116 byte graph script reset and randomise
79 | nodes().forEach(function (N) {
80 | if(N.d>0) N.d = 999;
81 | });
82 |
83 | edges().forEach(function (E) {
84 | E.label = 1+rand()%15;
85 | });
86 |
--------------------------------------------------------------------------------
/examples/boltzmann.txt:
--------------------------------------------------------------------------------
1 | version 2
2 | 2D
3 | 7
4 | 0 0.02000000 -0.00600000 0.00000000 9
5 | "b"=j17,4.039999999999958
6 | "clr"=j7,[1,1,1]
7 | "label"=j17,4.039999999999958
8 | "sample"=j217,function () {
9 | var N = this;
10 | var sum = N.b;
11 | gamma(N).forEach(function (M) {
12 | sum += M.v*getEdge(N,M).w;
13 | });
14 | var prob = 1.0/(1.0+Math.exp(-sum));
15 | N.v = ((rand()%1000000)<(prob*1000000))?1:0;
16 | N.show();
17 | }
18 | "show"=j85,function () {
19 | var N = this;
20 | N.label = N.b;
21 | N.setColour(1.0,1.0-N.v,1.0-N.v);
22 | }
23 | "update"=j71,function () {
24 | var N = this;
25 | N.b += epsilon*(N.vdata - N.vrecon);
26 | }
27 | "v"=j1,0
28 | "vdata"=j1,0
29 | "vrecon"=j1,0
30 | 0 0.00000000 -0.00000000 0.00000000 9
31 | "b"=j18,-4.049999999999958
32 | "clr"=j7,[1,0,0]
33 | "label"=j18,-4.049999999999958
34 | "sample"=j217,function () {
35 | var N = this;
36 | var sum = N.b;
37 | gamma(N).forEach(function (M) {
38 | sum += M.v*getEdge(N,M).w;
39 | });
40 | var prob = 1.0/(1.0+Math.exp(-sum));
41 | N.v = ((rand()%1000000)<(prob*1000000))?1:0;
42 | N.show();
43 | }
44 | "show"=j85,function () {
45 | var N = this;
46 | N.label = N.b;
47 | N.setColour(1.0,1.0-N.v,1.0-N.v);
48 | }
49 | "update"=j71,function () {
50 | var N = this;
51 | N.b += epsilon*(N.vdata - N.vrecon);
52 | }
53 | "v"=j1,1
54 | "vdata"=j1,1
55 | "vrecon"=j1,1
56 | 0 0.00000000 0.10000000 0.00000000 9
57 | "b"=j18,-1.330000000000001
58 | "clr"=j7,[1,0,0]
59 | "label"=j18,-1.330000000000001
60 | "sample"=j217,function () {
61 | var N = this;
62 | var sum = N.b;
63 | gamma(N).forEach(function (M) {
64 | sum += M.v*getEdge(N,M).w;
65 | });
66 | var prob = 1.0/(1.0+Math.exp(-sum));
67 | N.v = ((rand()%1000000)<(prob*1000000))?1:0;
68 | N.show();
69 | }
70 | "show"=j85,function () {
71 | var N = this;
72 | N.label = N.b;
73 | N.setColour(1.0,1.0-N.v,1.0-N.v);
74 | }
75 | "update"=j71,function () {
76 | var N = this;
77 | N.b += epsilon*(N.vdata - N.vrecon);
78 | }
79 | "v"=j1,1
80 | "vdata"=j1,1
81 | "vrecon"=j1,1
82 | 0 0.02000000 0.13000000 0.00000000 9
83 | "b"=j18,-1.420000000000001
84 | "clr"=j7,[1,0,0]
85 | "label"=j18,-1.420000000000001
86 | "sample"=j217,function () {
87 | var N = this;
88 | var sum = N.b;
89 | gamma(N).forEach(function (M) {
90 | sum += M.v*getEdge(N,M).w;
91 | });
92 | var prob = 1.0/(1.0+Math.exp(-sum));
93 | N.v = ((rand()%1000000)<(prob*1000000))?1:0;
94 | N.show();
95 | }
96 | "show"=j85,function () {
97 | var N = this;
98 | N.label = N.b;
99 | N.setColour(1.0,1.0-N.v,1.0-N.v);
100 | }
101 | "update"=j71,function () {
102 | var N = this;
103 | N.b += epsilon*(N.vdata - N.vrecon);
104 | }
105 | "v"=j1,1
106 | "vdata"=j1,1
107 | "vrecon"=j1,1
108 | 0 0.04000000 -0.01200000 0.00000000 9
109 | "b"=j18,-4.119999999999957
110 | "clr"=j7,[1,0,0]
111 | "label"=j18,-4.119999999999957
112 | "sample"=j217,function () {
113 | var N = this;
114 | var sum = N.b;
115 | gamma(N).forEach(function (M) {
116 | sum += M.v*getEdge(N,M).w;
117 | });
118 | var prob = 1.0/(1.0+Math.exp(-sum));
119 | N.v = ((rand()%1000000)<(prob*1000000))?1:0;
120 | N.show();
121 | }
122 | "show"=j85,function () {
123 | var N = this;
124 | N.label = N.b;
125 | N.setColour(1.0,1.0-N.v,1.0-N.v);
126 | }
127 | "update"=j71,function () {
128 | var N = this;
129 | N.b += epsilon*(N.vdata - N.vrecon);
130 | }
131 | "v"=j1,1
132 | "vdata"=j1,1
133 | "vrecon"=j1,1
134 | 0 0.08000000 -0.02400000 0.00000000 9
135 | "b"=j18,-4.019999999999959
136 | "clr"=j7,[1,0,0]
137 | "label"=j18,-4.019999999999959
138 | "sample"=j217,function () {
139 | var N = this;
140 | var sum = N.b;
141 | gamma(N).forEach(function (M) {
142 | sum += M.v*getEdge(N,M).w;
143 | });
144 | var prob = 1.0/(1.0+Math.exp(-sum));
145 | N.v = ((rand()%1000000)<(prob*1000000))?1:0;
146 | N.show();
147 | }
148 | "show"=j85,function () {
149 | var N = this;
150 | N.label = N.b;
151 | N.setColour(1.0,1.0-N.v,1.0-N.v);
152 | }
153 | "update"=j71,function () {
154 | var N = this;
155 | N.b += epsilon*(N.vdata - N.vrecon);
156 | }
157 | "v"=j1,1
158 | "vdata"=j1,1
159 | "vrecon"=j1,1
160 | 0 0.06000000 -0.01800000 0.00000000 9
161 | "b"=j17,4.049999999999958
162 | "clr"=j7,[1,1,1]
163 | "label"=j17,4.049999999999958
164 | "sample"=j217,function () {
165 | var N = this;
166 | var sum = N.b;
167 | gamma(N).forEach(function (M) {
168 | sum += M.v*getEdge(N,M).w;
169 | });
170 | var prob = 1.0/(1.0+Math.exp(-sum));
171 | N.v = ((rand()%1000000)<(prob*1000000))?1:0;
172 | N.show();
173 | }
174 | "show"=j85,function () {
175 | var N = this;
176 | N.label = N.b;
177 | N.setColour(1.0,1.0-N.v,1.0-N.v);
178 | }
179 | "update"=j71,function () {
180 | var N = this;
181 | N.b += epsilon*(N.vdata - N.vrecon);
182 | }
183 | "v"=j1,0
184 | "vdata"=j1,0
185 | "vrecon"=j1,0
186 | 10
187 | 6 3 4 "label"=j18,-4.844899999999941 "show"=j39,function () {
188 | this.label = this.w;
189 | } "update"=j112,function () {
190 | var E = this;
191 | E.w += epsilon*(E.n1.vdata*E.n2.vdata - E.n1.vrecon*E.n2.vrecon);
192 | E.show();
193 | } "w"=j18,-4.844899999999941
194 | 1 3 4 "label"=j17,4.517199999999948 "show"=j39,function () {
195 | this.label = this.w;
196 | } "update"=j112,function () {
197 | var E = this;
198 | E.w += epsilon*(E.n1.vdata*E.n2.vdata - E.n1.vrecon*E.n2.vrecon);
199 | E.show();
200 | } "w"=j17,4.517199999999948
201 | 5 2 4 "label"=j17,4.147299999999956 "show"=j39,function () {
202 | this.label = this.w;
203 | } "update"=j112,function () {
204 | var E = this;
205 | E.w += epsilon*(E.n1.vdata*E.n2.vdata - E.n1.vrecon*E.n2.vrecon);
206 | E.show();
207 | } "w"=j17,4.147299999999956
208 | 1 2 4 "label"=j17,4.164599999999956 "show"=j39,function () {
209 | this.label = this.w;
210 | } "update"=j112,function () {
211 | var E = this;
212 | E.w += epsilon*(E.n1.vdata*E.n2.vdata - E.n1.vrecon*E.n2.vrecon);
213 | E.show();
214 | } "w"=j17,4.164599999999956
215 | 6 2 4 "label"=j18,-4.295499999999953 "show"=j39,function () {
216 | this.label = this.w;
217 | } "update"=j112,function () {
218 | var E = this;
219 | E.w += epsilon*(E.n1.vdata*E.n2.vdata - E.n1.vrecon*E.n2.vrecon);
220 | E.show();
221 | } "w"=j18,-4.295499999999953
222 | 4 2 4 "label"=j17,4.148499999999956 "show"=j39,function () {
223 | this.label = this.w;
224 | } "update"=j112,function () {
225 | var E = this;
226 | E.w += epsilon*(E.n1.vdata*E.n2.vdata - E.n1.vrecon*E.n2.vrecon);
227 | E.show();
228 | } "w"=j17,4.148499999999956
229 | 5 3 4 "label"=j18,4.6220999999999455 "show"=j39,function () {
230 | this.label = this.w;
231 | } "update"=j112,function () {
232 | var E = this;
233 | E.w += epsilon*(E.n1.vdata*E.n2.vdata - E.n1.vrecon*E.n2.vrecon);
234 | E.show();
235 | } "w"=j18,4.6220999999999455
236 | 0 3 4 "label"=j18,-4.783699999999943 "show"=j39,function () {
237 | this.label = this.w;
238 | } "update"=j112,function () {
239 | var E = this;
240 | E.w += epsilon*(E.n1.vdata*E.n2.vdata - E.n1.vrecon*E.n2.vrecon);
241 | E.show();
242 | } "w"=j18,-4.783699999999943
243 | 0 2 4 "label"=j19,-4.2077999999999545 "show"=j39,function () {
244 | this.label = this.w;
245 | } "update"=j112,function () {
246 | var E = this;
247 | E.w += epsilon*(E.n1.vdata*E.n2.vdata - E.n1.vrecon*E.n2.vrecon);
248 | E.show();
249 | } "w"=j19,-4.2077999999999545
250 | 4 3 4 "label"=j17,4.701999999999944 "show"=j39,function () {
251 | this.label = this.w;
252 | } "update"=j112,function () {
253 | var E = this;
254 | E.w += epsilon*(E.n1.vdata*E.n2.vdata - E.n1.vrecon*E.n2.vrecon);
255 | E.show();
256 | } "w"=j17,4.701999999999944
257 | 10
258 | 0
259 | 0
260 | 0
261 | 0
262 | 0
263 | 0
264 | 0
265 | 0
266 | 0
267 | 0
268 | 1716
269 | {"epsilon":0.01,"load_functions":function () {
270 | nodes().forEach(function(N) {
271 | N.show = function() {
272 | var N = this;
273 | N.label = N.b;
274 | N.setColour(1.0,1.0-N.v,1.0-N.v);
275 | };
276 | N.sample = function() {
277 | var N = this;
278 | var sum = N.b;
279 | gamma(N).forEach(function (M) {
280 | sum += M.v*getEdge(N,M).w;
281 | });
282 | var prob = 1.0/(1.0+Math.exp(-sum));
283 | N.v = ((rand()%1000000)<(prob*1000000))?1:0;
284 | N.show();
285 | };
286 | N.update = function() {
287 | var N = this;
288 | N.b += epsilon*(N.vdata - N.vrecon);
289 | };
290 | });
291 | edges().forEach(function(E) {
292 | E.show = function() {
293 | this.label = this.w;
294 | };
295 | E.update = function() {
296 | var E = this;
297 | E.w += epsilon*(E.n1.vdata*E.n2.vdata - E.n1.vrecon*E.n2.vrecon);
298 | E.show();
299 | };
300 | });
301 | },"itoh":function () {
302 | hlayer.forEach(function(N) {
303 | N.sample();
304 | });
305 | },"htoi":function () {
306 | ilayer.forEach(function(N) {
307 | N.sample();
308 | });
309 | },"learn":function () {
310 | itoh();
311 | nodes().forEach(function(N) {
312 | N.vdata = N.v;
313 | });
314 | htoi();
315 | itoh();
316 | nodes().forEach(function(N) {
317 | N.vrecon = N.v;
318 | N.update();
319 | });
320 | edges().forEach(function(E) {
321 | E.update();
322 | });
323 | },"load":function (T) {
324 | for(var i=0;igamma(E.n2).length) {
49 | C = E.n1;
50 | O = E.n2;
51 | } else {
52 | C = E.n2;
53 | O = E.n1;
54 | }
55 | E.label = O.v - C.v;
56 | });
57 |
--------------------------------------------------------------------------------
/examples/petersen.txt:
--------------------------------------------------------------------------------
1 | 2D
2 | 10
3 | 0 -0.06000000 -0.02000000 0.00000000 0
4 | 0 -0.04000000 0.04000000 0.00000000 0
5 | 0 0.10000001 0.14000002 0.00000000 0
6 | 0 0.16000001 -0.06000000 0.00000000 0
7 | 0 0.00000000 -0.18000001 0.00000000 0
8 | 0 -0.16000001 -0.06000000 0.00000000 0
9 | 0 -0.10000001 0.14000002 0.00000000 0
10 | 0 0.06000000 -0.02000000 0.00000000 0
11 | 0 0.04000000 0.04000000 0.00000000 0
12 | 0 -0.00000000 -0.06000000 0.00000000 0
13 | 15
14 | 7 1
15 | 5 6
16 | 4 5
17 | 3 4
18 | 2 3
19 | 1 6
20 | 0 5
21 | 9 1
22 | 6 2
23 | 8 0
24 | 8 9
25 | 9 4
26 | 7 3
27 | 8 2
28 | 7 0
29 | 10
30 | 5 0 1 7 8 9
31 | 5 2 3 4 5 6
32 | 0
33 | 0
34 | 0
35 | 0
36 | 0
37 | 0
38 | 0
39 | 0
40 | 0
41 |
--------------------------------------------------------------------------------
/examples/sandpile.txt:
--------------------------------------------------------------------------------
1 | version 1
2 | 2D
3 | 17
4 | 1 -0.03645835 -0.00963542 0.00000000 2
5 | "clr"=F[0.75000000,0.75000000,0.75000000]
6 | "s"=i3
7 | 1 0.01197917 -0.03098959 0.00000000 2
8 | "clr"=F[0.50000000,0.50000000,0.50000000]
9 | "s"=i2
10 | 1 0.04166666 -0.00859375 0.00000000 2
11 | "clr"=F[1.00000000,1.00000000,1.00000000]
12 | "s"=i4
13 | 1 -0.01354167 0.04036459 0.00000000 2
14 | "clr"=F[0.25000000,0.25000000,0.25000000]
15 | "s"=i1
16 | 1 0.04218749 0.01223958 0.00000000 2
17 | "clr"=F[0.50000000,0.50000000,0.50000000]
18 | "s"=i2
19 | 0 -0.06730529 -0.07650107 0.00000000 2
20 | "clr"=F[0.00000000,0.00000000,0.00000000]
21 | "s"=i0
22 | 1 0.01250000 0.04140626 0.00000000 2
23 | "clr"=F[0.75000000,0.75000000,0.75000000]
24 | "s"=i3
25 | 1 -0.03645835 0.03984375 0.00000000 2
26 | "clr"=F[0.25000000,0.25000000,0.25000000]
27 | "s"=i1
28 | 1 0.04114582 -0.03151043 0.00000000 2
29 | "clr"=F[0.00000000,0.00000000,0.00000000]
30 | "s"=i0
31 | 1 0.04166666 0.04088542 0.00000000 2
32 | "clr"=F[4.50000000,4.50000000,4.50000000]
33 | "s"=i18
34 | 1 0.01302083 0.01276042 0.00000000 2
35 | "clr"=F[1.00000000,1.00000000,1.00000000]
36 | "s"=i4
37 | 1 -0.03593751 0.01119792 0.00000000 2
38 | "clr"=F[0.50000000,0.50000000,0.50000000]
39 | "s"=i2
40 | 1 -0.01302083 0.01171875 0.00000000 2
41 | "clr"=F[0.50000000,0.50000000,0.50000000]
42 | "s"=i2
43 | 1 -0.01354167 -0.00911459 0.00000000 2
44 | "clr"=F[1.00000000,1.00000000,1.00000000]
45 | "s"=i4
46 | 1 -0.03697918 -0.03255209 0.00000000 2
47 | "clr"=F[0.00000000,0.00000000,0.00000000]
48 | "s"=i0
49 | 1 -0.01406250 -0.03203126 0.00000000 2
50 | "clr"=F[0.75000000,0.75000000,0.75000000]
51 | "s"=i3
52 | 1 0.01250000 -0.00807292 0.00000000 2
53 | "clr"=F[0.25000000,0.25000000,0.25000000]
54 | "s"=i1
55 | 25
56 | 16 1 0
57 | 15 1 0
58 | 16 2 0
59 | 13 16 0
60 | 7 3 0
61 | 14 5 0
62 | 12 13 0
63 | 12 10 0
64 | 2 8 0
65 | 14 15 0
66 | 10 4 0
67 | 4 9 0
68 | 3 6 0
69 | 14 0 0
70 | 1 8 0
71 | 4 2 0
72 | 6 9 0
73 | 3 12 0
74 | 15 13 0
75 | 11 12 0
76 | 0 13 0
77 | 10 6 0
78 | 10 16 0
79 | 0 11 0
80 | 11 7 0
81 | 10
82 | 16 0 1 2 3 4 6 7 8 9 10 11 12 13 14 15 16
83 | 0
84 | 0
85 | 0
86 | 0
87 | 0
88 | 0
89 | 0
90 | 0
91 | 0
92 | 2
93 | 27 byte node script sandpile init
94 | N.s = 0;
95 | N.setColor(0,0,0);
96 | 183 byte node script sandpile fire
97 | if(N.s>=gamma(N).length) {
98 | N.s -= gamma(N).length;
99 | N.setColor(N.s*0.25,N.s*0.25,N.s*0.25);
100 | gamma(N).forEach(function (M) {
101 | M.s++;
102 | M.setColor(M.s*0.25,M.s*0.25,M.s*0.25);
103 | });
104 | }
105 |
--------------------------------------------------------------------------------
/export.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * graphic depictions, a visual workbench for graphs
3 | *
4 | * Copyright (C) 2016 Matvey Soloviev
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include "export.h"
21 |
22 | void RGBtoYUV( float r, float g, float b, float *y, float *u, float *v )
23 | {
24 | *y = 0.2126*r + 0.7152*g + 0.0722*b;
25 | *u = -0.09991*r - 0.33609*g + 0.436*b;
26 | *v = 0.615*r - 0.55861*g - 0.05639*b;
27 | }
28 |
29 | void YUVtoRGB( float *r, float *g, float *b, float y, float u, float v )
30 | {
31 | *r = y + 1.28033*v;
32 | *g = y - 0.21482*u - 0.38059*v;
33 | *b = y + 2.12798*u;
34 | }
35 |
36 | void ExportTikz(CSState *st, char *filename)
37 | {
38 | FILE *fl=fopen(filename,"w");
39 | if(!fl) return;
40 |
41 | fprintf(fl,"\\begin{tikzpicture}[x=800pt,y=800pt]\n");
42 |
43 | /* style preamble */
44 | fprintf(fl,"\\tikzstyle{n} = [fill=black, inner sep=2pt, circle,font=\\small]\n");
45 | fprintf(fl,"\\tikzstyle{nl} = [font=\\tiny]\n");
46 | fprintf(fl,"\\definecolor{clredge}{rgb}{%.2f,%.2f,%.2f}\n",s.e->graphics.config.edge[0],s.e->graphics.config.edge[1],s.e->graphics.config.edge[2]);
47 | fprintf(fl,"\\tikzstyle{e} = [draw=clredge]\n");
48 | fprintf(fl,"\\tikzstyle{el} = [color=clredge,font=\\tiny]\n");
49 |
50 | /* label styles */
51 | for(int y=0;y<3;++y) for(int x=0;x<3;++x) {
52 | float r,g,b,Y,U,V;
53 | r=::s.e->graphics.nodecol[y*3+x][0];
54 | g=::s.e->graphics.nodecol[y*3+x][1];
55 | b=::s.e->graphics.nodecol[y*3+x][2];
56 | RGBtoYUV(r,g,b,&Y,&U,&V);
57 | Y = 1.0f-Y;
58 | YUVtoRGB(&r,&g,&b,Y,U,V);
59 | /* make sure we are in [0.0,1.0] */
60 | float over = r; if(g>over) over=g; if(b>over) over=b;
61 | float under = r; if(g1.0f) adjust=1.0f-over;
64 | else if(under<0.0f) adjust=-under;
65 | else adjust=0.0f;
66 |
67 | fprintf(fl,"\\definecolor{clr%d%d}{rgb}{%.2f,%.2f,%.2f}\n",x,y,abs(r+adjust),abs(g+adjust),abs(b+adjust));
68 | }
69 |
70 | /* nodes */
71 | std::map nodes2id; int id=0;
72 | for(auto i=st->nodes.begin(); i!=st->nodes.end(); ++i) {
73 | float sx,sy;
74 | s.e->graphics.SpaceToScreen((*i)->pos[0],(*i)->pos[1],(*i)->pos[2],sx,sy);
75 | /* scale relative to window size */
76 | sx=(sx/s.wnd->w)-0.5f;
77 | sy=((sy+(s.wnd->w-s.wnd->h)/2)/s.wnd->w)-0.5f;
78 | /* flip y for tikz */
79 | sy*=-1;
80 |
81 | fprintf(fl,"\\coordinate (n%d) at (%.3f,%.3f) {};\n",id,sx,sy);
82 |
83 | nodes2id[*i]=id++;
84 | }
85 |
86 | /* edges */
87 | for(auto i=st->edges.begin(); i!=st->edges.end(); ++i) {
88 | if( (*i)->a.count( "label" ) ) {
89 | CSState::CSAttr *a = &(*i)->a["label"];
90 |
91 | fprintf(fl,"\\draw[e] (n%d) -- node[auto,midway,el] {$%s$} (n%d);\n",nodes2id[(*i)->n1],a->PrettyPrint().c_str(),nodes2id[(*i)->n2]);
92 | } else {
93 | fprintf(fl,"\\draw[e] (n%d) -- (n%d);\n",nodes2id[(*i)->n1],nodes2id[(*i)->n2]);
94 | }
95 | }
96 |
97 | /* node dots and labels */
98 | for(auto i=st->nodes.begin(); i!=st->nodes.end(); ++i) {
99 | fprintf(fl,"\\node[n] (dot) at (n%d) {};\n",nodes2id[*i]);
100 |
101 | char *anchors[3][3] = { {",anchor=south east",",anchor=south",",anchor=south west"} , {",anchor=east","",",anchor=west"}, {",anchor=north east", ",anchor=north", ",anchor=north west"}};
102 | for(int y=0;y<3;++y) for(int x=0;x<3;++x) {
103 | if( (*i)->a.count( s.e->graphics.nodelook[y*3+x] ) ) {
104 | CSState::CSAttr *a = &(*i)->a[s.e->graphics.nodelook[y*3+x]];
105 |
106 | fprintf(fl,"\\draw (n%d) node[color=clr%d%d,nl%s] {$%s$};\n", nodes2id[*i], x,y, anchors[y][x], a->PrettyPrint().c_str());
107 | }
108 | }
109 |
110 |
111 | }
112 |
113 | fprintf(fl,"\\end{tikzpicture}\n");
114 |
115 |
116 | fclose(fl);}
117 |
--------------------------------------------------------------------------------
/export.h:
--------------------------------------------------------------------------------
1 | /*
2 | * graphic depictions, a visual workbench for graphs
3 | *
4 | * Copyright (C) 2016 Matvey Soloviev
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef _EXPORT_H_
21 | #define _EXPORT_H_
22 |
23 | #include "stdafx.h"
24 |
25 | void ExportTikz(CSState *st, char *filename);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/fonts.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * graphic depictions, a visual workbench for graphs
3 | *
4 | * Copyright (C) 2016 Matvey Soloviev
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include "stdafx.h"
21 | #include "fonts.h"
22 |
23 | long utf8unpack(unsigned char *p,long *offs)
24 | {
25 | long l;
26 |
27 | if(*p & 0x80) {
28 | l=2;
29 | if(*p & 0x20) {
30 | l=3;
31 | if(*p & 0x10) {
32 | l=4;
33 | }
34 | }
35 | } else l=1;
36 |
37 | (*offs)+=(l-1);
38 |
39 | switch(l) {
40 | case 1: return *p;
41 | case 2: return (*p & ~0xE0)<<6|(*(p+1) & ~0xC0);
42 | case 3: return (*p & ~0xF0)<<12|(*(p+1) & ~0xC0)<<6|(*(p+2) & ~0xC0);
43 | case 4: return (*p & ~0xF8)<<18|(*(p+1) & ~0xC0)<<12|(*(p+2) & ~0xC0)<<6|(*(p+3) & ~0xC0);
44 | }
45 | }
46 |
47 | FT_Library CSFont::l=0;
48 |
49 | void CSFont::LoadFont(char *fn,int s,int aspace) {
50 | if(!l) FT_Init_FreeType(&l);
51 | FT_New_Face(l,fn,0,&f);
52 | FT_Set_Pixel_Sizes(f,0,s);
53 | size=s;
54 | asp=aspace;
55 | }
56 |
57 | void CSFont::Render(int tsx,const char* text,int num,float *outline_color)
58 | {
59 | int len=strlen(text);
60 | int error;
61 | int x=0,y=1 << (int)ceil((log((double)(2*size))/log(2.0f)));;
62 | GLuint tex;
63 | unsigned char *buf=new unsigned char[y*tsx*4];
64 | unsigned char *sbuf=new unsigned char[y*tsx*4];
65 |
66 | int nrow=0;
67 |
68 | glPushMatrix();
69 | glTranslatef(0,10-size,0);
70 | glPushMatrix(); // this instance will move with newlines
71 |
72 | for (int n=0;nglyph, FT_RENDER_MODE_NORMAL );
89 | if ( error ) continue;
90 | /* now, draw to our target surface */
91 | //memcpy(buf+(y+i-f->glyph->bitmap_top)*tsx*4+x*4,f->glyph->bitmap.buffer+f->glyph->bitmap.width
92 | memset(buf,0,y*tsx*4);
93 | memset(sbuf,0,y*tsx*4);
94 | for(int i=0;iglyph->bitmap.rows;++i) {
95 | for(int j=0;jglyph->bitmap.width;++j) {
96 | int base;
97 | int dy;
98 | base=(j+x+f->glyph->bitmap_left)*4+(dy=(i+size-f->glyph->bitmap_top))*4*tsx;
99 |
100 | buf[base+0]=0xFF;//((dy<(0.7*size/3)||dy>(2.5*size/3))?0xB0:0xFF);
101 | buf[base+1]=buf[base+0];
102 | buf[base+2]=0xFF;
103 | buf[base+3]=f->glyph->bitmap.buffer[j+i*f->glyph->bitmap.width];
104 | }
105 | }
106 | e.advx=(f->glyph->advance.x >> 6) + asp;
107 | glGenTextures(1,&e.tex);
108 |
109 | glBindTexture(GL_TEXTURE_2D, e.tex);
110 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
111 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
112 |
113 | glTexImage2D ( GL_TEXTURE_2D, 0,GL_RGBA, tsx, y, 0,GL_RGBA, GL_UNSIGNED_BYTE, buf);
114 |
115 | for(int i=0;i=tsx)) continue;
123 | if((ib<0) || (ib>=y)) continue;
124 |
125 | if( ((unsigned)buf[aj*4 + ib*4*tsx+3])>max3x3)
126 | max3x3 = (unsigned)buf[aj*4 + ib*4*tsx+3];
127 | }
128 | int base = j*4 + i*4*tsx;
129 |
130 | sbuf[base+0]=0xFF;
131 | sbuf[base+1]=0xFF;
132 | sbuf[base+2]=0xFF;
133 | sbuf[base+3]=max3x3;
134 | }
135 | }
136 |
137 | glGenTextures(1,&e.shadow);
138 |
139 | glBindTexture(GL_TEXTURE_2D, e.shadow);
140 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
141 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
142 |
143 | glTexImage2D ( GL_TEXTURE_2D, 0,GL_RGBA, tsx, y, 0,GL_RGBA, GL_UNSIGNED_BYTE, sbuf);
144 |
145 | gcache[glyph_index]=e;
146 | }
147 | glEnable(GL_TEXTURE_2D);
148 | glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
149 |
150 | //glPushAttrib(GL_CURRENT_BIT);
151 |
152 | float clr[4];
153 | glGetFloatv(GL_CURRENT_COLOR,clr);
154 | glColor4fv(outline_color);
155 | glBindTexture(GL_TEXTURE_2D, gcache[glyph_index].shadow);
156 | glBegin(GL_QUADS);
157 | glTexCoord2f(0,0); glVertex2f(0,0);
158 | glTexCoord2f(0,1); glVertex2f(0,y);
159 | glTexCoord2f(1,1); glVertex2f(tsx,y);
160 | glTexCoord2f(1,0); glVertex2f(tsx,0);
161 | glEnd();
162 | //glTranslatef(-1,-1,0);
163 | glColor4fv(clr);
164 | //glPopAttrib();
165 | glBindTexture(GL_TEXTURE_2D, gcache[glyph_index].tex);
166 | glBegin(GL_QUADS);
167 | glTexCoord2f(0,0); glVertex2f(0,0);
168 | glTexCoord2f(0,1); glVertex2f(0,y);
169 | glTexCoord2f(1,1); glVertex2f(tsx,y);
170 | glTexCoord2f(1,0); glVertex2f(tsx,0);
171 | glEnd();
172 |
173 | /* increment pen position */
174 | glTranslatef(gcache[glyph_index].advx,0,0);
175 | }
176 |
177 | glPopMatrix();
178 | glPopMatrix();
179 |
180 | delete [] buf;
181 | delete [] sbuf;
182 | }
183 |
184 | int CSFont::RenderSingle(char *buf,int shift,int posx,int posy,char **text)
185 | {
186 | int n=0,error;
187 | FT_UInt glyph_index; /* retrieve glyph index from character code */
188 | glyph_index = FT_Get_Char_Index( f, utf8unpack((unsigned char*)*text,(long*)&n) );
189 | (*text) += n+1;
190 | /* load glyph image into the slot (erase previous one) */
191 | error = FT_Load_Glyph( f, glyph_index, FT_LOAD_DEFAULT );
192 | if ( error ) return 0;
193 | /* convert to an anti-aliased bitmap */
194 | error = FT_Render_Glyph( f->glyph, FT_RENDER_MODE_NORMAL );
195 | if ( error ) return 0;
196 | /* now, draw to our target surface */
197 | for(int i=0;iglyph->bitmap.rows;++i) {
198 | for(int j=0;jglyph->bitmap.width;++j) {
199 | int base;
200 | int dy;
201 | base=(j+posx+f->glyph->bitmap_left)*4+(i+posy-f->glyph->bitmap_top)*4*shift;
202 | dy=i+size-f->glyph->bitmap_top;
203 | buf[base+0]=(dy<(1.7*size/3)||dy>(2.5*size/3))?0xB0:0xFF;
204 | buf[base+1]=buf[base+0];
205 | buf[base+2]=0xFF;
206 | buf[base+3]=f->glyph->bitmap.buffer[j+i*f->glyph->bitmap.width];
207 | }
208 | }
209 | /* increment pen position */
210 | return (f->glyph->advance.x >> 6) + asp;
211 | }
212 |
213 | void CSTextContainer::IncrementFrame()
214 | {
215 | if(!*ptr) return; //text over
216 | if(*ptr == '\001') return; //wait for confirmation;
217 | --timeout;
218 | while(!timeout && *ptr) {
219 | if(*ptr == '\n') {
220 | //newline.
221 | //xpos=0;
222 | //ypos+=ft->size+4;
223 | ++ptr;
224 | timeout=default_timeout;
225 | } else if(*ptr == '\002') {
226 | ++ptr;
227 | timeout=2;
228 | } else {
229 | int n=0;
230 | utf8unpack((unsigned char*)ptr,(long*)&n);
231 | ptr+=(n+1);
232 | timeout=default_timeout;
233 | //xpos+=ft->RenderSingle(buf,sx,xpos,ypos,&ptr);
234 | }
235 | }
236 | //glBindTexture(GL_TEXTURE_2D, texture);
237 |
238 | //glTexImage2D(GL_TEXTURE_2D,0, GL_RGBA, sx, sy, 0,GL_RGBA, GL_UNSIGNED_BYTE, buf);*/
239 | }
240 |
241 | void CSTextContainer::SendConfirm()
242 | {
243 | if(*ptr == '\001') ++ptr;
244 | }
245 |
246 | bool CSTextContainer::IsDone()
247 | {
248 | return !*ptr;
249 | }
250 |
251 | bool CSTextContainer::IsWaiting()
252 | {
253 | return (*ptr == '\001');
254 | }
255 |
256 | void CSTextContainer::Render()
257 | {
258 | /*glEnable(GL_TEXTURE_2D);
259 | glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
260 | glBindTexture(GL_TEXTURE_2D, texture);
261 | glColor3f(0,0,0);
262 | glTranslatef(2,2,0);
263 | glBegin(GL_QUADS);
264 | glTexCoord2f(0,0); glVertex2f( 0, 0);
265 | glTexCoord2f(1,0); glVertex2f(sx, 0);
266 | glTexCoord2f(1,1); glVertex2f(sx,sy);
267 | glTexCoord2f(0,1); glVertex2f( 0,sy);
268 | glEnd();
269 | glTranslatef(-2,-2,0);
270 | glColor3f(1,1,1);
271 | glBegin(GL_QUADS);
272 | glTexCoord2f(0,0); glVertex2f( 0, 0);
273 | glTexCoord2f(1,0); glVertex2f(sx, 0);
274 | glTexCoord2f(1,1); glVertex2f(sx,sy);
275 | glTexCoord2f(0,1); glVertex2f( 0,sy);
276 | glEnd();
277 | */
278 | pthread_mutex_lock(&mutex);
279 | if(ft->size<16) ft->Render(16,txt,ptr-txt);
280 | else ft->Render(64,txt,ptr-txt);
281 | pthread_mutex_unlock(&mutex);
282 | }
283 |
284 | void CSTextContainer::AppendText(char *text)
285 | {
286 | pthread_mutex_lock(&mutex);
287 | timeout=1;
288 | memcpy(txt+strlen(txt),text,strlen(text)+1);
289 | pthread_mutex_unlock(&mutex);
290 | }
291 |
292 | void CSTextContainer::ReplaceText(char *text)
293 | {
294 | pthread_mutex_lock(&mutex);
295 | memcpy(txt,text,strlen(text)+1);
296 | ptr=txt;
297 | xpos=0; ypos=ft->size;
298 | timeout=1;
299 | memset(buf,0,sx*sy*4);
300 | pthread_mutex_unlock(&mutex);
301 | }
302 |
303 | void CSTextContainer::MaybeReplaceText(char *text)
304 | {
305 | if(!strcmp(txt,text)) return;
306 | pthread_mutex_lock(&mutex);
307 | memcpy(txt,text,strlen(text)+1);
308 | ptr=txt;
309 | xpos=0; ypos=ft->size;
310 | timeout=1;
311 | memset(buf,0,sx*sy*4);
312 | pthread_mutex_unlock(&mutex);
313 | }
314 |
315 | void CSTextContainer::Initialize(int sx_,int sy_,int bufs_,int spd,CSFont *font,bool usesnd)
316 | {
317 | //copy various data;
318 | sx=sx_;
319 | sy=sy_;
320 | bufs=bufs_;
321 | txt=new char[bufs];
322 | ptr=txt;
323 | *txt=0;
324 | buf=new char[sx*sy*4];
325 | memset(buf,0,sx*sy*4);
326 | ft=font;
327 | xpos=0; ypos=font->size;
328 | default_timeout=spd;
329 | timeout=1;
330 | snd=usesnd;
331 |
332 | #ifndef WIN32
333 | pthread_mutex_init(&mutex,NULL);
334 | #else
335 | mutex=PTHREAD_MUTEX_INITIALIZER;
336 | #endif
337 |
338 | glGenTextures(1,&texture);
339 |
340 | glBindTexture(GL_TEXTURE_2D, texture);
341 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
342 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
343 | }
344 |
--------------------------------------------------------------------------------
/fonts.h:
--------------------------------------------------------------------------------
1 | /*
2 | * graphic depictions, a visual workbench for graphs
3 | *
4 | * Copyright (C) 2016 Matvey Soloviev
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef _FONTS_H_
21 | #define _FONTS_H_
22 |
23 | #include
24 | #include
25 | #include