gml4win.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750
  1. /*
  2. * Copyright 2021
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * These are the four essential freedoms with GNU GPL software:
  18. * 1: freedom to run the program, for any purpose
  19. * 2: freedom to study how the program works, and change it to make it do what you wish
  20. * 3: freedom to redistribute copies to help your Free Software friends
  21. * 4: freedom to distribute copies of your modified versions to your Free Software friends
  22. * , ,
  23. * / \
  24. * ((__-^^-,-^^-__))
  25. * `-_---' `---_-'
  26. * `--|o` 'o|--'
  27. * \ ` /
  28. * ): :(
  29. * :o_o:
  30. * "-"
  31. */
  32. #include <stdio.h>
  33. #include <math.h>
  34. #include <windows.h>
  35. #include <commctrl.h>
  36. #include "main.h"
  37. #include "hier.h"
  38. #include "dpif.h"
  39. #include "pos.h"
  40. #include "gml_scanner.h"
  41. #include "gml_parser.h"
  42. #include "uniqstr.h"
  43. #include "uniqgraph.h"
  44. #include "uniqnode.h"
  45. #include "bubbling.h"
  46. #include "dot.tab.h"
  47. /* version string */
  48. #define HEADLINE L"gml4win version 2.0"
  49. /* icon number defined in gml4win.rc file */
  50. #define IDI_ICON1 101
  51. /* max line length in chars of a single text line in a node label */
  52. #define NODE_MAXCH (1024)
  53. /* font size at 100% scaling */
  54. #define FONTSZ 12 /* vertical size */
  55. #define FONTSZ2 (FONTSZ / 2) /* horizontal size */
  56. #define FONTNAME L"Sans"
  57. /* #define FONTNAME L"Times New Roman" */
  58. /* startup window x,y size */
  59. #define DEFAULT_WX 750
  60. #define DEFAULT_WY 650
  61. /* codes for file menu */
  62. #define IDM_FILE_OPEN_DOT 1
  63. #define IDM_FILE_OPEN_GML 2
  64. #define IDM_FILE_ABOUT 3
  65. #define IDM_FILE_QUIT 4
  66. /* sliders pos data */
  67. /* hor slider */
  68. #define HSL_X0 (30)
  69. #define HSL_Y0 (wysize-30)
  70. #define HSL_XS (wxsize-30-30)
  71. #define HSL_YS (30)
  72. /* left vertical slider */
  73. #define LSL_X0 (0)
  74. #define LSL_Y0 (0)
  75. #define LSL_XS (30)
  76. #define LSL_YS (wysize-30)
  77. /* right vertical slider */
  78. #define RSL_X0 (wxsize-30)
  79. #define RSL_Y0 (0)
  80. #define RSL_XS (30)
  81. #define RSL_YS (wysize-30)
  82. /* draw area */
  83. #define DRW_X0 (30)
  84. #define DRW_Y0 (0)
  85. #define DRW_XS (wxsize-30-30)
  86. #define DRW_YS (wysize-30)
  87. /* nr. of pixels hor. edge goes downwards */
  88. #define HEDGE_DY 10
  89. /* window (x,y) size */
  90. static int wxsize = 0;
  91. static int wysize = 0;
  92. /* draw window (x,y) size */
  93. static int drwxsize = 0;
  94. static int drwysize = 0;
  95. /* set if there is data to draw */
  96. static int validdata = 0;
  97. /* zoom scaling factor changed by zoom slider */
  98. static double zfactor = 1.0;
  99. /* x offset changed by x slider */
  100. static int vxmin = 0;
  101. /* y offset changed by y slider */
  102. static int vymin = 0;
  103. /* y size in pixels of the font */
  104. static int thefontsize = FONTSZ;
  105. static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  106. /* create sliders */
  107. static void createcontrols(HWND hwnd);
  108. static void addmenus(HWND hwnd);
  109. static void center(HWND hwnd);
  110. static void doopen(HWND hwnd, int what);
  111. static void updatesliders(void);
  112. static void drawit(HWND hwnd);
  113. static int scaleit(int pos);
  114. static HWND hTrackvl;
  115. static HWND hTrackvr;
  116. static HWND hTrackhor;
  117. static HWND mainhwnd;
  118. static HWND drw;
  119. static HDC hdc;
  120. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  121. {
  122. MSG msg;
  123. WNDCLASSW wc = { 0 };
  124. if (hInstance) {
  125. }
  126. if (hPrevInstance) {
  127. }
  128. if (lpCmdLine) {
  129. }
  130. if (nCmdShow) {
  131. }
  132. /* default icon defined using rc file */
  133. wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); /* or: IDI_APPLICATION */
  134. /* force redraw */
  135. wc.style = CS_HREDRAW | CS_VREDRAW;
  136. wc.lpszClassName = HEADLINE;
  137. wc.hInstance = hInstance;
  138. wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  139. wc.lpfnWndProc = WndProc;
  140. wc.hCursor = LoadCursor(0, IDC_ARROW);
  141. RegisterClassW(&wc);
  142. /* size of startup window */
  143. wxsize = DEFAULT_WX;
  144. wysize = DEFAULT_WY;
  145. /* start background color */
  146. bgcr = 0xdc;
  147. bgcg = 0xdc;
  148. bgcb = 0xdc;
  149. mainhwnd = CreateWindowW(wc.lpszClassName, HEADLINE,
  150. WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, wxsize, wysize, 0, 0, hInstance, 0);
  151. while (GetMessage(&msg, NULL, 0, 0)) {
  152. TranslateMessage(&msg);
  153. DispatchMessage(&msg);
  154. }
  155. return (int)msg.wParam;
  156. }
  157. static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  158. {
  159. RECT r;
  160. switch (msg) {
  161. case WM_CREATE:
  162. center(hwnd);
  163. createcontrols(hwnd);
  164. addmenus(hwnd);
  165. break;
  166. case WM_HSCROLL:
  167. updatesliders();
  168. break;
  169. case WM_VSCROLL:
  170. updatesliders();
  171. break;
  172. case WM_DESTROY:
  173. PostQuitMessage(0);
  174. break;
  175. case WM_PAINT:
  176. drawit(hwnd);
  177. break;
  178. /* window moved */
  179. case WM_MOVE:
  180. drawit(hwnd);
  181. break;
  182. case WM_SIZE:
  183. GetClientRect(hwnd, &r);
  184. wxsize = (int)r.right - (int)r.left;
  185. wysize = (int)r.bottom - (int)r.top;
  186. SetWindowPos(hTrackhor, NULL, HSL_X0, HSL_Y0, HSL_XS, HSL_YS, SWP_NOZORDER);
  187. SetWindowPos(hTrackvl, NULL, LSL_X0, LSL_Y0, LSL_XS, LSL_YS, SWP_NOZORDER);
  188. SetWindowPos(hTrackvr, NULL, RSL_X0, RSL_Y0, RSL_XS, RSL_YS, SWP_NOZORDER);
  189. SetWindowPos(drw, NULL, DRW_X0, DRW_Y0, DRW_XS, DRW_YS, SWP_NOZORDER);
  190. break;
  191. case WM_COMMAND:
  192. switch (LOWORD(wParam)) {
  193. case IDM_FILE_OPEN_DOT:
  194. doopen(hwnd, 0);
  195. break;
  196. case IDM_FILE_OPEN_GML:
  197. doopen(hwnd, 1);
  198. break;
  199. case IDM_FILE_ABOUT:
  200. MessageBoxW(NULL,
  201. L"gml4win is GNU GPL Free Software to copy, share or improve at https://gml4gtk.sourceforge.io",
  202. L"About gml4win", MB_OK);
  203. break;
  204. case IDM_FILE_QUIT:
  205. SendMessage(hwnd, WM_CLOSE, 0, 0);
  206. break;
  207. default:
  208. break;
  209. }
  210. break;
  211. case WM_NOTIFY:
  212. drawit(hwnd);
  213. break;
  214. default:
  215. break;
  216. }
  217. return DefWindowProcW(hwnd, msg, wParam, lParam);
  218. }
  219. /* center window on screen */
  220. static void center(HWND hwnd)
  221. {
  222. RECT rc = { 0 };
  223. int win_w = 0;
  224. int win_h = 0;
  225. int screen_w = 0;
  226. int screen_h = 0;
  227. GetWindowRect(hwnd, &rc);
  228. win_w = rc.right - rc.left;
  229. win_h = rc.bottom - rc.top;
  230. screen_w = GetSystemMetrics(SM_CXSCREEN);
  231. screen_h = GetSystemMetrics(SM_CYSCREEN);
  232. SetWindowPos(hwnd, HWND_TOP, (screen_w - win_w) / 2, (screen_h - win_h) / 2, 0, 0, SWP_NOSIZE);
  233. return;
  234. }
  235. static void createcontrols(HWND hwnd)
  236. {
  237. INITCOMMONCONTROLSEX icex;
  238. icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  239. icex.dwICC = ICC_LISTVIEW_CLASSES;
  240. InitCommonControlsEx(&icex);
  241. /* TBS_HORZ is horizontal, TBS_VERT is vertical slider */
  242. hTrackvl = CreateWindowW(TRACKBAR_CLASSW, L"Trackbar Controll",
  243. WS_CHILD | WS_VISIBLE | TBS_NOTICKS | TBS_VERT,
  244. LSL_X0, LSL_Y0, LSL_XS, LSL_YS, hwnd, (HMENU) 3, NULL, NULL);
  245. hTrackvr = CreateWindowW(TRACKBAR_CLASSW, L"Trackbar Controlr",
  246. WS_CHILD | WS_VISIBLE | TBS_NOTICKS | TBS_VERT,
  247. RSL_X0, RSL_Y0, RSL_XS, RSL_YS, hwnd, (HMENU) 3, NULL, NULL);
  248. hTrackhor = CreateWindowW(TRACKBAR_CLASSW, L"Trackbar Controlhor",
  249. WS_CHILD | WS_VISIBLE | TBS_NOTICKS | TBS_HORZ,
  250. HSL_X0, HSL_Y0, HSL_XS, HSL_YS, hwnd, (HMENU) 3, NULL, NULL);
  251. SendMessageW(hTrackvl, TBM_SETRANGE, TRUE, MAKELONG(0, 100));
  252. SendMessageW(hTrackvr, TBM_SETRANGE, TRUE, MAKELONG(0, 100));
  253. SendMessageW(hTrackhor, TBM_SETRANGE, TRUE, MAKELONG(0, 100));
  254. /* set zoom slider to 50, 1:1 scaling */
  255. SendMessageW(hTrackvl, TBM_SETPOS, TRUE, 50);
  256. SendMessageW(hTrackvr, TBM_SETPOS, TRUE, 0);
  257. SendMessageW(hTrackhor, TBM_SETPOS, TRUE, 0);
  258. /* draw window */
  259. drw = CreateWindowW(L"Static", L"0", WS_CHILD | WS_VISIBLE, DRW_X0, DRW_Y0, DRW_XS, DRW_YS, hwnd, (HMENU) 3, NULL, NULL);
  260. return;
  261. }
  262. /* one of the sliders moved */
  263. void updatesliders(void)
  264. {
  265. RECT area;
  266. LRESULT posvl = 0;
  267. LRESULT posvr = 0;
  268. LRESULT poshor = 0;
  269. double ph = 0.0;
  270. double pv = 0.0;
  271. double pz = 0.0;
  272. int val1 = 0;
  273. if (validdata == 0) {
  274. return;
  275. }
  276. posvl = SendMessageW(hTrackvl, TBM_GETPOS, 0, 0);
  277. posvr = SendMessageW(hTrackvr, TBM_GETPOS, 0, 0);
  278. poshor = SendMessageW(hTrackhor, TBM_GETPOS, 0, 0);
  279. if (0) {
  280. printf("left=%d right=%d hor=%d\n", (int)posvl, (int)posvr, (int)poshor);
  281. fflush(stdout);
  282. }
  283. /* set hor/vert values */
  284. ph = (double)poshor;
  285. ph = ph * maxx;
  286. ph = ph / 100;
  287. vxmin = (int)ph;
  288. pv = (double)posvr;
  289. pv = pv * maxy;
  290. pv = pv / 100;
  291. vymin = (int)pv;
  292. /* recalc zoom factor */
  293. pz = (double)posvl;
  294. pz = round(pz);
  295. val1 = (int)pz;
  296. zfactor = exp((double)(3 * (val1 - 50)) / (double)50);
  297. if (0) {
  298. printf("left=%d right=%d hor=%d vxmin=%d vymin=%d\n", (int)posvl, (int)posvr, (int)poshor, vxmin, vymin);
  299. fflush(stdout);
  300. }
  301. area.left = 0;
  302. area.top = 0;
  303. area.right = drwxsize;
  304. area.bottom = drwysize;
  305. InvalidateRect(drw, &area, FALSE);
  306. return;
  307. }
  308. /* set menu in menubar */
  309. static void addmenus(HWND hwnd)
  310. {
  311. HMENU hMenubar;
  312. HMENU hMenu;
  313. hMenubar = CreateMenu();
  314. hMenu = CreateMenu();
  315. AppendMenuW(hMenu, MF_STRING, IDM_FILE_OPEN_DOT, L"Open &DOT");
  316. AppendMenuW(hMenu, MF_STRING, IDM_FILE_OPEN_GML, L"Open &GML");
  317. AppendMenuW(hMenu, MF_STRING, IDM_FILE_ABOUT, L"&About");
  318. AppendMenuW(hMenu, MF_SEPARATOR, 0, NULL);
  319. AppendMenuW(hMenu, MF_STRING, IDM_FILE_QUIT, L"&Quit");
  320. AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR) hMenu, L"&File");
  321. SetMenu(hwnd, hMenubar);
  322. return;
  323. }
  324. /* clear all memory used by the graph data
  325. * if mode==0 clear all data
  326. * if mode==1 keep some data
  327. * used in a re-layout
  328. */
  329. static void do_clear_all(int mode)
  330. {
  331. /* no draw data */
  332. validdata = 0;
  333. if (mode == 0) {
  334. /* clear db with strings */
  335. clear_uniqstr();
  336. /* clear db with nodes */
  337. clear_uniqnode(NULL);
  338. /* clear db with graph pointers */
  339. clear_uniqgraph(NULL);
  340. }
  341. /* clear db with nodes */
  342. clear_uniqnode2(NULL);
  343. if (maingraph) {
  344. /* clear number of edges between level n and n+1 */
  345. clear_nume_r(maingraph);
  346. /* clear number of nodes at level */
  347. clear_nnl_r(maingraph);
  348. /* clear arrays in/out edges */
  349. clear_ioedges_r(maingraph);
  350. /* clear count of crossing edges at level */
  351. clear_numce_r(maingraph);
  352. /* clear optional record label of node */
  353. if (mode == 0) {
  354. clear_rlabel_r(maingraph);
  355. }
  356. /* clear self-edges list */
  357. clear_selfedgesnodelist_r(maingraph);
  358. /* clear single nodes list */
  359. clear_singlenodelist_r(maingraph);
  360. /* clear startnodes array */
  361. clear_startnodes_r(maingraph);
  362. /* clear nodes list and its data
  363. * if mode<>0 then keep record label data
  364. * that will be re-used at doing re-layout
  365. * if mode==0 clear the rlabel data
  366. */
  367. clear_nodelist_r(maingraph, mode);
  368. /* clear edges list */
  369. clear_edgelist_r(maingraph);
  370. /* clear bubbling algorithm */
  371. clear_bubbling(maingraph);
  372. if (mode == 0) {
  373. /* clear subgraphs and optional summary node */
  374. clear_sg(maingraph);
  375. /* clear input nodes */
  376. clear_rawnodelist(maingraph);
  377. /* clear input edges */
  378. clear_rawedgelist(maingraph);
  379. /* clear main graph structure */
  380. free(maingraph);
  381. maingraph = NULL;
  382. }
  383. }
  384. return;
  385. }
  386. /* do final (x,y) of nodes/edges for mode 1 */
  387. static void finalxy1(struct gml_graph *g)
  388. {
  389. struct gml_nlist *lnl = NULL;
  390. int hw = 0;
  391. int xoff = 0;
  392. int yoff = 0;
  393. int i = 0;
  394. int ecount = 0;
  395. /* x positioning */
  396. make_posnodes(maingraph);
  397. maxx = 0;
  398. xoff = 0;
  399. /* scan hor. to adjust the x positions. */
  400. for (i = 0; i < (g->widestnnodes + 1); i++) {
  401. /* x spacing between the hor. levels */
  402. xoff = xoff + xspacing;
  403. /* determine half-way of the xpos. */
  404. if (g->wpos[i] == 0) {
  405. /* if only dummy nodes */
  406. hw = xspacing / 2;
  407. } else {
  408. hw = (g->wpos[i] / 2);
  409. }
  410. /* update with current x */
  411. hw = hw + xoff;
  412. lnl = g->posnodes[i];
  413. /* scan the nodes at this x pos. */
  414. while (lnl) {
  415. /* center the node around the half-way */
  416. lnl->node->finx = (hw - (lnl->node->bbx / 2));
  417. if ((lnl->node->finx + lnl->node->bbx) > maxx) {
  418. maxx = (lnl->node->finx + lnl->node->bbx);
  419. }
  420. lnl = lnl->next;
  421. }
  422. lnl = g->posnodes[i];
  423. /* scan the nodes at this x pos. */
  424. while (lnl) {
  425. /* center the node around the half-way */
  426. lnl->node->lx0 = xoff;
  427. lnl->node->lx1 = xoff + g->wpos[i];
  428. lnl = lnl->next;
  429. }
  430. /* x spacing between the hor. levels */
  431. xoff = xoff + xspacing;
  432. /* x to next pos. */
  433. xoff = xoff + g->wpos[i];
  434. }
  435. clear_posnodes_r(maingraph);
  436. /* y positioning */
  437. make_levelnodes(maingraph);
  438. maxy = 0;
  439. yoff = 0;
  440. /* number of edges between level n and n+1 */
  441. g->nume = (int *)calloc(1, (maingraph->maxlevel + 1) * sizeof(int));
  442. /* scan vert. to adjust the y positions. */
  443. for (i = 0; i < (maingraph->maxlevel + 1); i++) {
  444. /* y spacing between the vert. levels */
  445. yoff = yoff + (yspacing / 1);
  446. /* determine half-way of the ypos. */
  447. if (g->hpos[i] == 0) {
  448. /* if only dummy nodes */
  449. hw = (yspacing / 2);
  450. } else {
  451. hw = (g->hpos[i] / 2);
  452. }
  453. /* update with current y */
  454. hw = hw + yoff;
  455. lnl = g->levelnodes[i];
  456. ecount = 0;
  457. /* scan the nodes at this y pos. */
  458. while (lnl) {
  459. /* set start, end of y level */
  460. lnl->node->ly0 = yoff;
  461. lnl->node->ly1 = (yoff + g->hpos[i]);
  462. /* center the node around the half-way */
  463. lnl->node->finy = (hw - (lnl->node->bby / 2));
  464. /* update drawing max y pos used */
  465. if ((lnl->node->finy + lnl->node->bby) > maxy) {
  466. maxy = (lnl->node->finy + lnl->node->bby);
  467. }
  468. /* give dummy nodes a vertical size of the level */
  469. if (lnl->node->dummy) {
  470. lnl->node->bby = g->hpos[i];
  471. /* if only dummy nodes at level, use spacing */
  472. if (g->hpos[i] == 0) {
  473. lnl->node->bby = yspacing;
  474. }
  475. }
  476. /* number of edges between level n and n+1 */
  477. ecount = (ecount + lnl->node->outdegree);
  478. lnl = lnl->next;
  479. }
  480. /* number of edges between level n and n+1 */
  481. g->nume[i] = ecount;
  482. /* y spacing between the vert. levels */
  483. yoff = yoff + (yspacing / 1);
  484. /* yspacing depends on number of edges at this level
  485. * turned off because this add too much y-spacing
  486. * yoff = yoff + (ecount * 3);
  487. */
  488. /* yspacing depends on number of crossing edges at this level
  489. * this has increasing y effect between levels
  490. */
  491. if (g->numce) {
  492. yoff = yoff + (1 * (g->numce[i] / 8));
  493. }
  494. /* y to next pos. */
  495. yoff = yoff + g->hpos[i];
  496. }
  497. clear_levelnodes_r(maingraph);
  498. /* clear number of edges between level n and n+1 */
  499. clear_nume_r(maingraph);
  500. return;
  501. }
  502. /* for pos2.c which does set finx,finy */
  503. static void finalxy2(struct gml_graph *g)
  504. {
  505. struct gml_nlist *lnl = NULL;
  506. int my = 0;
  507. maxx = 0;
  508. maxy = 0;
  509. /* adjust for the y size of single nodes */
  510. if (g->nsinglenodes) {
  511. my = 0;
  512. lnl = maingraph->singlenodelist;
  513. while (lnl) {
  514. if (lnl->node->bby > my) {
  515. my = lnl->node->bby;
  516. }
  517. lnl = lnl->next;
  518. }
  519. /* update level data for single nodes */
  520. lnl = maingraph->singlenodelist;
  521. while (lnl) {
  522. lnl->node->ly0 = 0;
  523. lnl->node->ly1 = my;
  524. lnl = lnl->next;
  525. }
  526. }
  527. /* determine max. x pos in use */
  528. lnl = maingraph->nodelist;
  529. while (lnl) {
  530. /* adjust the non-singlenodes down */
  531. if (lnl->node->indegree || lnl->node->outdegree) {
  532. lnl->node->finy = lnl->node->finy + my;
  533. lnl->node->ly0 = lnl->node->ly0 + my;
  534. lnl->node->ly1 = lnl->node->ly1 + my;
  535. }
  536. if ((lnl->node->finx + lnl->node->bbx) > maxx) {
  537. maxx = lnl->node->finx + lnl->node->bbx;
  538. }
  539. /* update drawing max y pos used */
  540. if ((lnl->node->finy + lnl->node->bby) > maxy) {
  541. maxy = (lnl->node->finy + lnl->node->bby);
  542. }
  543. lnl = lnl->next;
  544. }
  545. return;
  546. }
  547. /* for pos.c which does set absx,absy */
  548. static void finalxy3(struct gml_graph *g)
  549. {
  550. struct gml_nlist *lnl = NULL;
  551. /* recalc drawing size */
  552. maxx = 0;
  553. maxy = 0;
  554. if (g) {
  555. }
  556. /* determine max. x pos in use */
  557. lnl = maingraph->nodelist;
  558. while (lnl) {
  559. /* copy abs to fin */
  560. lnl->node->finx = lnl->node->absx;
  561. lnl->node->finy = lnl->node->absy;
  562. if ((lnl->node->finx + lnl->node->bbx) > maxx) {
  563. maxx = lnl->node->finx + lnl->node->bbx;
  564. }
  565. /* update drawing max y pos used */
  566. if ((lnl->node->finy + lnl->node->bby) > maxy) {
  567. maxy = (lnl->node->finy + lnl->node->bby);
  568. }
  569. lnl = lnl->next;
  570. }
  571. return;
  572. }
  573. static void finalxy(struct gml_graph *g)
  574. {
  575. struct gml_nlist *lnl = NULL;
  576. int xpos = 0;
  577. int my = 0;
  578. /* depends on positioning modus */
  579. switch (postype) {
  580. case 1:
  581. finalxy1(g);
  582. break;
  583. case 2:
  584. finalxy2(g);
  585. break;
  586. case 3:
  587. finalxy3(g);
  588. break;
  589. default:
  590. finalxy1(g);
  591. break;
  592. }
  593. /* position level 0, single nodes if any */
  594. if (g->nsinglenodes) {
  595. my = 0;
  596. xpos = xspacing;
  597. lnl = g->singlenodelist;
  598. while (lnl) {
  599. lnl->node->finx = xpos;
  600. lnl->node->finy = 0;
  601. /* position single nodes at level 0, just next to each other */
  602. xpos = xpos + lnl->node->bbx + xspacing;
  603. if (lnl->node->bby > my) {
  604. my = lnl->node->bby;
  605. }
  606. if (xpos > maxx) {
  607. maxx = xpos;
  608. }
  609. lnl = lnl->next;
  610. }
  611. }
  612. return;
  613. }
  614. /* translate \n in gml string */
  615. static char *unesc_gml(char *str)
  616. {
  617. char *buf = NULL;
  618. char *p = NULL;
  619. char *q = NULL;
  620. buf = calloc(1, (strlen(str) + 1));
  621. if (buf == NULL) {
  622. return (str);
  623. }
  624. p = str;
  625. q = buf;
  626. while (*p) {
  627. /* check for \n to change */
  628. if ((*p) == '\\') {
  629. if (*(p + 1) == 'n') {
  630. (*q) = '\n';
  631. q++;
  632. p++;
  633. p++;
  634. } else {
  635. /* copy other esc char */
  636. (*q) = (*p);
  637. p++;
  638. q++;
  639. (*q) = (*p);
  640. p++;
  641. q++;
  642. }
  643. } else {
  644. (*q) = (*p);
  645. q++;
  646. p++;
  647. }
  648. }
  649. p = uniqstr(buf);
  650. free(buf);
  651. buf = NULL;
  652. return (p);
  653. }
  654. /* translate \n \l \r in dot string */
  655. static char *unesc_dot(char *str)
  656. {
  657. char *buf = NULL;
  658. char *p = NULL;
  659. char *q = NULL;
  660. buf = calloc(1, (strlen(str) + 1));
  661. if (buf == NULL) {
  662. return (str);
  663. }
  664. p = str;
  665. q = buf;
  666. while (*p) {
  667. /* check for \n \l \r to change */
  668. if ((*p) == '\\') {
  669. if (*(p + 1) == 'n' || *(p + 1) == 'l' || *(p + 1) == 'r') {
  670. (*q) = '\n';
  671. q++;
  672. p++;
  673. p++;
  674. } else {
  675. /* copy other esc char */
  676. (*q) = (*p);
  677. p++;
  678. q++;
  679. (*q) = (*p);
  680. p++;
  681. q++;
  682. }
  683. } else {
  684. /* regular char to copy */
  685. (*q) = (*p);
  686. q++;
  687. p++;
  688. }
  689. }
  690. p = uniqstr(buf);
  691. free(buf);
  692. buf = NULL;
  693. return (p);
  694. }
  695. /* translate esc chars in dot or gml graph */
  696. static char *unesc(char *str)
  697. {
  698. char *ret = NULL;
  699. if (str == NULL) {
  700. /* shouldnothappen */
  701. return (uniqstr(" "));
  702. }
  703. if (strchr(str, '\\') == NULL) {
  704. /* str has no esc chars */
  705. return (str);
  706. }
  707. if (graphtype == 0) {
  708. ret = unesc_gml(str);
  709. } else {
  710. ret = unesc_dot(str);
  711. }
  712. return (ret);
  713. }
  714. /* size of fields */
  715. static struct gml_p static_mainwin_textsizes1sz(struct gml_rl *info)
  716. {
  717. struct gml_p d;
  718. struct gml_p dsub;
  719. int i = 0;
  720. d.x = 0;
  721. d.y = 0;
  722. if (info == NULL) {
  723. return (d);
  724. }
  725. if (info->hd) {
  726. d.x = info->txsize;
  727. d.y = info->tysize;
  728. } else {
  729. for (i = 0; i < info->nparts; i++) {
  730. dsub = static_mainwin_textsizes1sz(info->parts[i]);
  731. if (info->dir == 0) {
  732. d.x = d.x + dsub.x;
  733. if (dsub.y > d.y) {
  734. d.y = dsub.y;
  735. }
  736. } else {
  737. if (dsub.x > d.x) {
  738. d.x = dsub.x;
  739. }
  740. d.y = d.y + dsub.y;
  741. }
  742. }
  743. }
  744. info->bbx = d.x;
  745. info->bby = d.y;
  746. if (yydebug || 0) {
  747. printf
  748. ("%s(): hd=%d dir=%d bb(x,y) size is (%d,%d) t(x,x) is (%d,%d) for `%s'\n",
  749. __func__, info->hd, info->dir, info->bbx, info->bby, info->txsize, info->tysize, info->ulabel);
  750. }
  751. return (d);
  752. }
  753. static void static_mainwin_textsizes1eq(struct gml_rl *info)
  754. {
  755. int i = 0;
  756. int eqx = 0;
  757. int eqy = 0;
  758. int xs = 0;
  759. int ys = 0;
  760. int mbbx = 0;
  761. int mbby = 0;
  762. char *sdir = NULL;
  763. if (info == NULL) {
  764. return;
  765. }
  766. if (info->nparts == 0) {
  767. if (yydebug || 0) {
  768. printf("%s(): skip \"%s\"\n", __func__, info->ulabel);
  769. }
  770. return;
  771. }
  772. if (info->hd == 0) {
  773. /* zzz */
  774. for (i = 0; i < info->nparts; i++) {
  775. if (info->dir == 0) {
  776. info->parts[i]->bby = info->bby;
  777. } else {
  778. info->parts[i]->bbx = info->bbx;
  779. }
  780. }
  781. for (i = 0; i < info->nparts; i++) {
  782. if (i == 0) {
  783. mbbx = info->parts[i]->bbx;
  784. mbby = info->parts[i]->bby;
  785. }
  786. if (info->parts[i]->bbx > mbbx) {
  787. mbbx = info->parts[i]->bbx;
  788. }
  789. if (info->parts[i]->bby > mbby) {
  790. mbby = info->parts[i]->bby;
  791. }
  792. }
  793. if (yydebug || 0) {
  794. printf("%s(): info->bbxy(%d,%d) versus mbbxy(%d,%d)\n", __func__, info->bbx, info->bby, mbbx, mbby);
  795. }
  796. xs = info->bbx / info->nparts;
  797. ys = info->bby / info->nparts;
  798. eqx = 1;
  799. eqy = 1;
  800. /* check if parts are same size */
  801. for (i = 0; i < info->nparts; i++) {
  802. if (info->parts[i]->bbx > xs) {
  803. eqx = 0;
  804. }
  805. if (info->parts[i]->bby > ys) {
  806. eqy = 0;
  807. }
  808. }
  809. /* set step factor if equal spread */
  810. for (i = 0; i < info->nparts; i++) {
  811. if (eqx) {
  812. info->parts[i]->xstep = xs;
  813. } else {
  814. info->parts[i]->xstep = 0;
  815. }
  816. if (eqy) {
  817. info->parts[i]->ystep = ys;
  818. } else {
  819. info->parts[i]->ystep = 0;
  820. }
  821. if (yydebug || 0) {
  822. printf("%s(): \"%s\" eqx=%d eqy=%d\n", __func__, info->parts[i]->ulabel, eqx, eqy);
  823. }
  824. }
  825. /* print summary */
  826. if (yydebug || 0) {
  827. if (info->dir == 0) {
  828. sdir = "x-dir";
  829. } else {
  830. sdir = "y-dir";
  831. }
  832. printf
  833. ("%s(): size (%d,%d) %s %d parts eqx=%d eqy=%d xstep %d ystep %d\n",
  834. __func__, info->bbx, info->bby, sdir, info->nparts, eqx, eqy, xs, ys);
  835. for (i = 0; i < info->nparts; i++) {
  836. printf("\t[%d] size (%d,%d) \"%s\" xstep=%d ystep=%d\n", i,
  837. info->parts[i]->bbx, info->parts[i]->bby,
  838. info->parts[i]->ulabel, info->parts[i]->xstep, info->parts[i]->ystep);
  839. }
  840. }
  841. for (i = 0; i < info->nparts; i++) {
  842. static_mainwin_textsizes1eq(info->parts[i]);
  843. }
  844. }
  845. return;
  846. }
  847. static void static_mainwin_textsizes1rl(struct gml_rl *info)
  848. {
  849. RECT c;
  850. int i = 0;
  851. size_t len = 0;
  852. char *tmpb = NULL;
  853. char *p = NULL;
  854. char *q = NULL;
  855. int ii = 0;
  856. char lbuf[NODE_MAXCH];
  857. if (info == NULL) {
  858. return;
  859. }
  860. /* check if has data */
  861. if (info->hd) {
  862. if (info->txsize == 0 && info->tysize == 0) {
  863. if (info->label == NULL) {
  864. /* shouldnothappen */
  865. info->label = uniqstr(" ");
  866. }
  867. len = strlen(info->label);
  868. if (len) {
  869. tmpb = (char *)calloc(1, (len + 1));
  870. p = info->label;
  871. q = tmpb;
  872. /* un-escape the string */
  873. while (*p) {
  874. if (*p == '\\') {
  875. p++;
  876. if (*p == 0) {
  877. *q = '\\';
  878. q++;
  879. break;
  880. }
  881. if (*p == 'n' || *p == 'l' || *p == 'r') {
  882. *q = '\n';
  883. } else {
  884. *q = *p;
  885. }
  886. p++;
  887. q++;
  888. } else {
  889. *q = *p;
  890. p++;
  891. q++;
  892. }
  893. }
  894. len = strlen(tmpb);
  895. if (len) {
  896. if (tmpb[len - 1] == '\n') {
  897. tmpb[len - 1] = 0;
  898. }
  899. } else {
  900. info->ulabel = uniqstr(" ");
  901. }
  902. info->ulabel = uniqstr(tmpb);
  903. free(tmpb);
  904. tmpb = NULL;
  905. /* copy chars per line into lbuf */
  906. p = info->ulabel;
  907. /* determine needed text (x,y) size */
  908. info->txsize = 0;
  909. info->tysize = 0;
  910. ii = 0;
  911. memset(lbuf, 0, NODE_MAXCH);
  912. for (;;) {
  913. if (*p == '\n' || *p == 0) {
  914. ii = 0;
  915. if (0) {
  916. printf("lbuf=\"%s\" len %d\n", lbuf, (int)strlen(lbuf));
  917. }
  918. /* do a fake draw text and calculate the used text area */
  919. c.left = 0;
  920. c.right = 0;
  921. c.top = 0;
  922. c.bottom = 0;
  923. /* calcrect means do set the (x,y) size of the text in rect c */
  924. DrawText(hdc, lbuf, strlen(lbuf), &c, DT_CALCRECT);
  925. if (0) {
  926. printf("%s(): textsize is (%d,%d) for \"%s\"\n", __func__,
  927. (int)c.right, (int)c.bottom, lbuf);
  928. }
  929. /* find widest line of text */
  930. if ((int)c.right > info->txsize) {
  931. info->txsize = (int)c.right;
  932. }
  933. if (thefontsize != (int)c.bottom) {
  934. /* remember y size of one line of text */
  935. thefontsize = (int)c.bottom;
  936. }
  937. /* update y size of block of text lines */
  938. info->tysize = info->tysize + (int)c.bottom;
  939. if (*p == 0) {
  940. /* end of text */
  941. break;
  942. }
  943. memset(lbuf, 0, NODE_MAXCH);
  944. } else {
  945. /* limit the max. length of a single text line */
  946. if (ii < (NODE_MAXCH - 2)) {
  947. lbuf[ii] = (*p);
  948. ii++;
  949. }
  950. /* make sure string is 0 terminated */
  951. lbuf[ii] = 0;
  952. }
  953. p++;
  954. }
  955. /* now set in unode the text area size */
  956. if (info->txsize == 0) {
  957. /* shouldnothappen */
  958. info->txsize = FONTSZ;
  959. }
  960. if (info->tysize == 0) {
  961. /* shouldnothappen */
  962. info->tysize = FONTSZ;
  963. }
  964. /* for a box can add some border space here */
  965. info->txsize = info->txsize + 2;
  966. info->tysize = info->tysize + 2;
  967. /* */
  968. if (yydebug) {
  969. printf("%s(): (%d,%d) size for `%s'\n", __func__, info->txsize, info->tysize, info->ulabel);
  970. }
  971. } else {
  972. /* at "" string */
  973. info->txsize = 4;
  974. info->tysize = 4;
  975. info->ulabel = uniqstr(" ");
  976. }
  977. }
  978. }
  979. for (i = 0; i < info->nparts; i++) {
  980. /* */
  981. if (info->parts) {
  982. static_mainwin_textsizes1rl(info->parts[i]);
  983. }
  984. }
  985. return;
  986. }
  987. static void static_mainwin_textsizes2rl(struct gml_rl *info, int count, int xoff, int yoff, int bbx, int bby)
  988. {
  989. int i = 0;
  990. char *sdir = NULL;
  991. int xo = 0;
  992. int yo = 0;
  993. int ibbx = 0;
  994. int ibby = 0;
  995. int abbx = 0;
  996. int abby = 0;
  997. if (info->hd == 0) {
  998. if (yydebug || 0) {
  999. printf
  1000. ("%s(%d): xyoff(%d,%d) bbxy(%d,%d) nparts=%d info->bbxy(%d,%d)\n",
  1001. __func__, count, xoff, yoff, bbx, bby, info->nparts, info->bbx, info->bby);
  1002. }
  1003. if (yydebug || 0) {
  1004. if (info->dir == 0) {
  1005. sdir = "x-dir";
  1006. } else {
  1007. sdir = "y-dir";
  1008. }
  1009. printf("%s(): rl=%p %s hd=0 bbxy(%d,%d) nparts=%d\n",
  1010. __func__, (void *)info, sdir, info->bbx, info->bby, info->nparts);
  1011. for (i = 0; i < info->nparts; i++) {
  1012. if (info->dir == 0) {
  1013. sdir = "x-dir";
  1014. } else {
  1015. sdir = "y-dir";
  1016. }
  1017. printf("\tparts[%d]=%p %s hd=%d \"%s\"\n", i,
  1018. (void *)info->parts[i], sdir, info->parts[i]->hd, info->parts[i]->ulabel);
  1019. }
  1020. }
  1021. xo = 0;
  1022. yo = 0;
  1023. ibbx = bbx;
  1024. ibby = bby;
  1025. abbx = 0;
  1026. abby = 0;
  1027. for (i = 0; i < info->nparts; i++) {
  1028. if (info->parts[i]->hd == 0) {
  1029. ibbx = info->parts[i]->bbx;
  1030. ibby = info->parts[i]->bby;
  1031. abbx = ibbx;
  1032. abby = ibby;
  1033. static_mainwin_textsizes2rl(info->parts[i], i, xoff + xo, yoff + yo, ibbx, ibby);
  1034. /*
  1035. */
  1036. if ((i + 1) < info->nparts) {
  1037. if (info->parts[i + 1]->hd == 0) {
  1038. if (info->parts[i]->dir == 0) {
  1039. yo = yo + abby;
  1040. } else {
  1041. xo = xo + abbx;
  1042. }
  1043. }
  1044. }
  1045. /*
  1046. *
  1047. */
  1048. } else {
  1049. if (info->parts[i]->dir == 0) {
  1050. info->parts[i]->xoff = xoff + xo + abbx;
  1051. info->parts[i]->yoff = yoff + yo;
  1052. info->parts[i]->bby = bby;
  1053. if (info->parts[i]->xstep) {
  1054. xo = xo + info->parts[i]->xstep + abbx;
  1055. } else {
  1056. xo = xo + info->parts[i]->bbx + abbx;
  1057. }
  1058. } else {
  1059. info->parts[i]->xoff = xoff + xo;
  1060. info->parts[i]->yoff = yoff + yo + abby;
  1061. info->parts[i]->bbx = bbx;
  1062. if (info->parts[i]->ystep) {
  1063. yo = yo + info->parts[i]->ystep + abby;
  1064. } else {
  1065. yo = yo + info->parts[i]->bby + abby;
  1066. }
  1067. }
  1068. abbx = 0;
  1069. abby = 0;
  1070. }
  1071. }
  1072. } else {
  1073. if (yydebug || 0) {
  1074. if (info->dir == 0) {
  1075. sdir = "x-dir";
  1076. } else {
  1077. sdir = "y-dir";
  1078. }
  1079. printf
  1080. ("%s(): rl=%p %s hd=1 bbxy(%d,%d) \"%s\" xyoff(%d,%d) bbxy(%d,%d)\n",
  1081. __func__, (void *)info, sdir, info->bbx, info->bby, info->ulabel, xoff, yoff, bbx, bby);
  1082. }
  1083. }
  1084. return;
  1085. }
  1086. /* handle record label sizes for one node */
  1087. static void static_mainwin_textsizes1n(struct gml_node *node)
  1088. {
  1089. struct gml_p d;
  1090. /* calc (x,y) text size of all parts in record label */
  1091. static_mainwin_textsizes1rl(node->rlabel);
  1092. d = static_mainwin_textsizes1sz(node->rlabel);
  1093. if (yydebug || 0) {
  1094. printf("%s(): d is (%d,%d) versus bbxy(%d,%d)\n", __func__, d.x, d.y, node->bbx, node->bby);
  1095. }
  1096. /* check for use of step of bb */
  1097. static_mainwin_textsizes1eq(node->rlabel);
  1098. /* now position the text parts and result in the rlabel structs */
  1099. node->bbx = d.x;
  1100. node->bby = d.y;
  1101. static_mainwin_textsizes2rl(node->rlabel, 0, 0, 0, node->bbx, node->bby);
  1102. return;
  1103. }
  1104. /* after edge label nodes are created:
  1105. * calculate (x,y) size of text area
  1106. * a label can be in nlabel or rlabel for dot record label
  1107. * this gets the textsize at 100% 1:1 scaling zz
  1108. */
  1109. static void static_mainwin_textsizes(void)
  1110. {
  1111. struct gml_nlist *nl = NULL;
  1112. char *p = NULL;
  1113. char lbuf[NODE_MAXCH];
  1114. int ll = 0;
  1115. int ii = 0;
  1116. int numl = 0;
  1117. int maxlen = 0;
  1118. PAINTSTRUCT ps;
  1119. RECT c;
  1120. HFONT hfont;
  1121. HFONT holdfont;
  1122. if (holdfont) {
  1123. }
  1124. /* starting fake paint */
  1125. hdc = BeginPaint(drw, &ps);
  1126. hfont = CreateFontW(FONTSZ, 0, 0, 0, FW_MEDIUM, 0, 0, 0, 0, 0, 0, 0, 0, FONTNAME);
  1127. holdfont = SelectObject(hdc, hfont);
  1128. /* y size in pixels of the font */
  1129. thefontsize = FONTSZ;
  1130. nl = maingraph->nodelist;
  1131. while (nl) {
  1132. /* check if size needs to be calculated */
  1133. if (nl->node->txsize == 0) {
  1134. /* preset */
  1135. nl->node->tx = 0;
  1136. nl->node->ty = 0;
  1137. nl->node->bbx = 0;
  1138. nl->node->bby = 0;
  1139. if (nl->node->rlabel) {
  1140. /* this is a dot record style label */
  1141. if (nl->node->rlabeldone == 0) {
  1142. static_mainwin_textsizes1n(nl->node);
  1143. nl->node->rlabeldone = 1;
  1144. }
  1145. } else {
  1146. /* this is a regular label */
  1147. if (nl->node->dummy) {
  1148. /* this is a dummy node with zero size */
  1149. nl->node->tx = 0;
  1150. nl->node->ty = 0;
  1151. nl->node->bbx = 0;
  1152. nl->node->bby = 0;
  1153. nl->node->txsize = 1; /* text size is set */
  1154. } else {
  1155. /* this is a real or edgelabel node */
  1156. if (nl->node->nlabel == NULL) {
  1157. /* shouldnothappen */
  1158. nl->node->nlabel = uniqstr(" ");
  1159. }
  1160. /* if the labeltext is "" replace it with " " */
  1161. if (strlen(nl->node->nlabel) == 0) {
  1162. /* to avoid cairo assert */
  1163. nl->node->nlabel = uniqstr(" ");
  1164. }
  1165. /* change esc chars if any */
  1166. nl->node->nlabel = unesc(nl->node->nlabel);
  1167. /* get size of area needed tor this text in chars */
  1168. p = nl->node->nlabel;
  1169. ll = 0;
  1170. numl = 1;
  1171. maxlen = 0;
  1172. while (*p) {
  1173. if (*p == '\n') {
  1174. numl++;
  1175. ll = 0;
  1176. } else {
  1177. ll++;
  1178. if (ll > maxlen) {
  1179. maxlen = ll;
  1180. }
  1181. }
  1182. p++;
  1183. }
  1184. /* if no chars on a line, set at least one. */
  1185. if (maxlen == 0) {
  1186. maxlen = 1;
  1187. }
  1188. if (0) {
  1189. printf("%s(): \"%s\" has size (%d,%d)\n", __func__, nl->node->nlabel, maxlen, numl);
  1190. }
  1191. /* copy chars per line into lbuf */
  1192. p = nl->node->nlabel;
  1193. /* determine needed text (x,y) size */
  1194. nl->node->tx = 0;
  1195. nl->node->ty = 0;
  1196. ii = 0;
  1197. memset(lbuf, 0, NODE_MAXCH);
  1198. for (;;) {
  1199. if (*p == '\n' || *p == 0) {
  1200. ii = 0;
  1201. if (0) {
  1202. printf("lbuf=\"%s\" len %d\n", lbuf, (int)strlen(lbuf));
  1203. }
  1204. /* do a fake draw text and calculate the used text area */
  1205. c.left = 0;
  1206. c.right = 0;
  1207. c.top = 0;
  1208. c.bottom = 0;
  1209. /* calcrect means do set the (x,y) size of the text in rect c */
  1210. DrawText(hdc, lbuf, strlen(lbuf), &c, DT_CALCRECT);
  1211. if (0) {
  1212. printf("%s(): textsize is (%d,%d) for \"%s\"\n", __func__,
  1213. (int)c.right, (int)c.bottom, lbuf);
  1214. }
  1215. /* find widest line of text */
  1216. if ((int)c.right > nl->node->tx) {
  1217. nl->node->tx = (int)c.right;
  1218. }
  1219. if (thefontsize != (int)c.bottom) {
  1220. /* remember y size of one line of text */
  1221. thefontsize = (int)c.bottom;
  1222. }
  1223. /* update y size of block of text lines */
  1224. nl->node->ty = nl->node->ty + (int)c.bottom;
  1225. if (*p == 0) {
  1226. /* end of text */
  1227. break;
  1228. }
  1229. memset(lbuf, 0, NODE_MAXCH);
  1230. } else {
  1231. /* limit the max. length of a single text line */
  1232. if (ii < (NODE_MAXCH - 2)) {
  1233. lbuf[ii] = (*p);
  1234. ii++;
  1235. }
  1236. /* make sure string is 0 terminated */
  1237. lbuf[ii] = 0;
  1238. }
  1239. p++;
  1240. }
  1241. /* now set in unode the text area size */
  1242. if (nl->node->tx == 0) {
  1243. /* shouldnothappen */
  1244. nl->node->tx = FONTSZ;
  1245. }
  1246. if (nl->node->ty == 0) {
  1247. /* shouldnothappen */
  1248. nl->node->ty = FONTSZ;
  1249. }
  1250. /* for a box can add some border space here */
  1251. nl->node->bbx = nl->node->tx + 0;
  1252. nl->node->bby = nl->node->ty + 0;
  1253. }
  1254. nl->node->txsize = 1; /* text size is set */
  1255. }
  1256. }
  1257. nl = nl->next;
  1258. }
  1259. DeleteObject(hfont);
  1260. EndPaint(drw, &ps);
  1261. return;
  1262. }
  1263. /* run all stages of the layout */
  1264. static void do_layout_all(struct gml_graph *g)
  1265. {
  1266. /* this are the regular layout stages */
  1267. /* prepare */
  1268. prep(g);
  1269. /* re-organize nodelist */
  1270. reorg(g);
  1271. /* change cycles in the graph */
  1272. uncycle(g);
  1273. /* re-organize nodelist */
  1274. reorg(g);
  1275. /* longest path algorithm */
  1276. longestpath(g);
  1277. /* set y level of all nodes */
  1278. ylevels(g);
  1279. /* try to find shorter edges */
  1280. shorteredges(g);
  1281. /* change edge directions downwards */
  1282. edgesdownwards(g, 1);
  1283. /* check length of edges */
  1284. edgelen(g);
  1285. /* doublespace the vertical levels */
  1286. doublespacey(g);
  1287. /* split edges with label into node->label->node */
  1288. edgelabels(g);
  1289. /* after edge label nodes are created:
  1290. * calculate (x,y) size of text area
  1291. */
  1292. static_mainwin_textsizes();
  1293. /* split longer edges */
  1294. splitedges(g);
  1295. /* create level node count data */
  1296. nodecounts(g);
  1297. /* run barycenter using defaults (0,0) or a value */
  1298. barycenter(g, 100, 100);
  1299. /* run priority algorithm */
  1300. improve_positions(g);
  1301. /* final (x,y) positioning of nodes/edges */
  1302. finalxy(g);
  1303. /* calculate edge connections */
  1304. edgeconnections(g);
  1305. return;
  1306. }
  1307. /* fit drawing in window */
  1308. static void dofit(void)
  1309. {
  1310. double xzscale = 1.0;
  1311. double yzscale = 1.0;
  1312. double newzscale = 1.0;
  1313. double dval = 1.0;
  1314. int val = 0;
  1315. /* if no maxx, maxy is set */
  1316. if (maxx == 0) {
  1317. maxx = 1;
  1318. }
  1319. if (maxy == 0) {
  1320. maxy = 1;
  1321. }
  1322. xzscale = (double)(10 * drwxsize / maxx);
  1323. yzscale = (double)(10 * drwysize / maxy);
  1324. xzscale = xzscale / 10.0;
  1325. yzscale = yzscale / 10.0;
  1326. if ((xzscale - yzscale) > 0) {
  1327. newzscale = yzscale;
  1328. } else {
  1329. newzscale = xzscale;
  1330. }
  1331. /* old dval = log ((newzscale * (double) 50.0) / 3.0) - 50.0; */
  1332. dval = log(newzscale) / 3.0;
  1333. dval = (dval * 50.0);
  1334. dval = dval + 50.0;
  1335. val = (int)dval;
  1336. if (val < 0) {
  1337. val = 0;
  1338. }
  1339. if (val > 100) {
  1340. val = 100;
  1341. }
  1342. zfactor = exp((double)(3 * (val - 50)) / (double)50);
  1343. SendMessageW(hTrackvl, TBM_SETPOS, TRUE, val);
  1344. /* reset v xy min */
  1345. vxmin = 0;
  1346. vymin = 0;
  1347. SendMessageW(hTrackvr, TBM_SETPOS, TRUE, 0);
  1348. SendMessageW(hTrackhor, TBM_SETPOS, TRUE, 0);
  1349. return;
  1350. }
  1351. /* what is 0 for dot, 1 for gml chosen */
  1352. static void doopen(HWND hwnd, int what)
  1353. {
  1354. RECT area;
  1355. OPENFILENAME ofn;
  1356. TCHAR szFile[MAX_PATH];
  1357. FILE *f = NULL;
  1358. int status = 0;
  1359. ZeroMemory(&ofn, sizeof(ofn));
  1360. ofn.lStructSize = sizeof(ofn);
  1361. ofn.lpstrFile = szFile;
  1362. ofn.lpstrFile[0] = '\0';
  1363. ofn.hwndOwner = hwnd;
  1364. ofn.nMaxFile = sizeof(szFile);
  1365. if (what == 1) {
  1366. ofn.lpstrFilter = TEXT("All files(*.*)\0*.*\0Gml files(*.gml)\0*.gml\0");
  1367. } else {
  1368. ofn.lpstrFilter = TEXT("All files(*.*)\0*.*\0Dot files(*.dot)\0*.dot\0Dot files(*.gv)\0*.gv\0");
  1369. }
  1370. ofn.nFilterIndex = 1;
  1371. ofn.lpstrInitialDir = NULL;
  1372. ofn.lpstrFileTitle = NULL;
  1373. ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  1374. if (GetOpenFileName(&ofn)) {
  1375. f = fopen(ofn.lpstrFile, "rb");
  1376. if (f == NULL) {
  1377. MessageBoxW(NULL, L"Cannot open file", L"File error", MB_OK);
  1378. return;
  1379. }
  1380. /* data is invalid at this point */
  1381. validdata = 0;
  1382. /* wipe old data if any */
  1383. do_clear_all(0);
  1384. /* default white background */
  1385. bgcr = 0xff;
  1386. bgcg = 0xff;
  1387. bgcb = 0xff;
  1388. /* create root graph */
  1389. create_maingraph();
  1390. /* parse the data */
  1391. if (what == 1) {
  1392. status = gmlparse(maingraph, f, ofn.lpstrFile);
  1393. /* type of graph data 0=gml 1=dot */
  1394. graphtype = 0;
  1395. } else {
  1396. status = dotparse(maingraph, f, ofn.lpstrFile, "gml4win");
  1397. /* type of graph data 0=gml 1=dot */
  1398. graphtype = 1;
  1399. }
  1400. if (status) {
  1401. /* some parse error */
  1402. if (strlen(parsermessage) == 0) {
  1403. strcpy(parsermessage, "no parser message");
  1404. }
  1405. printf("%s\n", parsermessage);
  1406. fflush(stdout);
  1407. fclose(f);
  1408. /* data is invalid at this point */
  1409. validdata = 0;
  1410. MessageBoxW(NULL, L"syntax error in graph file", L"Parse error", MB_OK);
  1411. return;
  1412. }
  1413. /* check for empty graph here */
  1414. if (maingraph->rawnodelist == NULL) {
  1415. printf("%s\n", "empty graph without nodes");
  1416. fflush(stdout);
  1417. /* data is invalid at this point */
  1418. validdata = 0;
  1419. MessageBoxW(NULL, L"empty graph without nodes", L"Empty grph", MB_OK);
  1420. return;
  1421. }
  1422. do_layout_all(maingraph);
  1423. /* set sliders to defaults */
  1424. zfactor = 1.0;
  1425. vxmin = 0;
  1426. vymin = 0;
  1427. SendMessageW(hTrackvl, TBM_SETPOS, TRUE, 50);
  1428. SendMessageW(hTrackvr, TBM_SETPOS, TRUE, 0);
  1429. SendMessageW(hTrackhor, TBM_SETPOS, TRUE, 0);
  1430. /* fit drawing in window */
  1431. dofit();
  1432. validdata = 1;
  1433. fclose(f);
  1434. }
  1435. /* force redraw */
  1436. area.left = 0;
  1437. area.top = 0;
  1438. area.right = drwxsize;
  1439. area.bottom = drwysize;
  1440. InvalidateRect(drw, &area, FALSE /*TRUE*/);
  1441. /* make sure drawing is on screen */
  1442. drawit(mainhwnd);
  1443. return;
  1444. }
  1445. /* scale down a number */
  1446. static int scaleit(int pos)
  1447. {
  1448. double num = 0.0;
  1449. int ret = 0;
  1450. num = (double)pos;
  1451. num = num * zfactor;
  1452. num = round(num);
  1453. ret = (int)num;
  1454. return (ret);
  1455. }
  1456. /* */
  1457. static void on_top_level_window_drawingarea1_expose_event_nodes_record_r(struct gml_node
  1458. *node, struct gml_rl
  1459. *info)
  1460. {
  1461. int i = 0;
  1462. int x0 = 0;
  1463. int y0 = 0;
  1464. int cr = 0;
  1465. int cb = 0;
  1466. int cg = 0;
  1467. int xxo = 0;
  1468. int yyo = 0;
  1469. int szx = 0;
  1470. int szy = 0;
  1471. HPEN pen1;
  1472. HPEN holdpen;
  1473. HFONT hfont;
  1474. HFONT holdfont;
  1475. int snewx = 0;
  1476. int snewy = 0;
  1477. int sbbx = 0;
  1478. int sbby = 0;
  1479. double tsize = 0.0;
  1480. int stsize = 0;
  1481. char lbuf[NODE_MAXCH];
  1482. char *p = NULL;
  1483. int ii = 0;
  1484. int yy = 0;
  1485. int stx0 = 0;
  1486. int sty0 = 0;
  1487. if (holdpen) {
  1488. }
  1489. if (holdfont) {
  1490. }
  1491. x0 = node->finx - vxmin;
  1492. y0 = node->finy - vymin;
  1493. if (info->hd == 0) {
  1494. /* not-has-data */
  1495. for (i = 0; i < info->nparts; i++) {
  1496. on_top_level_window_drawingarea1_expose_event_nodes_record_r(node, info->parts[i]);
  1497. }
  1498. } else {
  1499. /* has-data */
  1500. /* black outline color */
  1501. cr = 0;
  1502. cg = 0;
  1503. cb = 0;
  1504. pen1 = CreatePen(PS_SOLID, 1, RGB(cr, cg, cb));
  1505. holdpen = SelectObject(hdc, pen1);
  1506. SelectObject(hdc, pen1);
  1507. szx = info->bbx;
  1508. szy = info->bby;
  1509. if (info->dir == 0) {
  1510. if (info->xstep) {
  1511. szx = info->xstep;
  1512. } else {
  1513. szx = info->bbx;
  1514. }
  1515. } else {
  1516. if (info->ystep) {
  1517. szy = info->ystep;
  1518. } else {
  1519. szy = info->bby;
  1520. }
  1521. }
  1522. /* this is the box to put the part of the text in */
  1523. /* get scaled coords */
  1524. snewx = scaleit(x0 + info->xoff);
  1525. snewy = scaleit(y0 + info->yoff);
  1526. sbbx = scaleit(szx);
  1527. sbby = scaleit(szy);
  1528. MoveToEx(hdc, snewx, snewy, NULL);
  1529. LineTo(hdc, snewx + sbbx, snewy);
  1530. LineTo(hdc, snewx + sbbx, snewy + sbby);
  1531. LineTo(hdc, snewx, snewy + sbby);
  1532. LineTo(hdc, snewx, snewy);
  1533. DeleteObject(pen1);
  1534. if (yydebug || 0) {
  1535. printf("%s(): rect at (%d,%d) size (%d,%d) for \"%s\"\n", __func__,
  1536. x0 + info->xoff, y0 + info->yoff, szx, szy, info->ulabel);
  1537. }
  1538. /* scale text size */
  1539. tsize = thefontsize; /* or: FONTSZ */
  1540. tsize = tsize * zfactor;
  1541. tsize = round(tsize);
  1542. stsize = (int)tsize;
  1543. /* only text if resulting font size is big enough */
  1544. if (stsize > 8) {
  1545. /* set background color of text */
  1546. SetBkMode(hdc, TRANSPARENT);
  1547. /* or:
  1548. * cr = (n->ncolor & 0x00ff0000) >> 16;
  1549. * cg = (n->ncolor & 0x0000ff00) >> 8;
  1550. * cb = (n->ncolor & 0x000000ff);
  1551. * SetBkColor(hdc, RGB(cr, cg, cb));
  1552. */
  1553. /* set color of text */
  1554. cr = (node->fontcolor & 0x00ff0000) >> 16;
  1555. cg = (node->fontcolor & 0x0000ff00) >> 8;
  1556. cb = (node->fontcolor & 0x000000ff);
  1557. SetTextColor(hdc, RGB(cr, cg, cb));
  1558. /* start text inside rectangle */
  1559. xxo = 1;
  1560. yyo = 1;
  1561. /* start of text, draw it line by line */
  1562. stx0 = scaleit(x0 + info->xoff + xxo + 0);
  1563. sty0 = scaleit(y0 + info->yoff + yyo + 0);
  1564. /* adjust y start of text */
  1565. sty0 = sty0 - stsize;
  1566. hfont = CreateFontW(stsize, 0, 0, 0, FW_MEDIUM, 0, 0, 0, 0, 0, 0, 0, 0, FONTNAME);
  1567. holdfont = SelectObject(hdc, hfont);
  1568. p = info->ulabel;
  1569. yy = 0;
  1570. ii = 0;
  1571. memset(lbuf, 0, NODE_MAXCH);
  1572. for (;;) {
  1573. if (*p == '\n' || *p == 0) {
  1574. ii = 0;
  1575. if (0) {
  1576. printf("lbuf=\"%s\" len %d\n", lbuf, (int)strlen(lbuf));
  1577. }
  1578. TextOut(hdc, stx0, sty0 + stsize + yy, lbuf, lstrlen(lbuf));
  1579. yy += stsize;
  1580. if (*p == 0) {
  1581. break;
  1582. }
  1583. memset(lbuf, 0, NODE_MAXCH);
  1584. } else {
  1585. /* limit the max. length of a single text line */
  1586. if (ii < (NODE_MAXCH - 2)) {
  1587. lbuf[ii] = (*p);
  1588. ii++;
  1589. }
  1590. /* make sure string is 0 terminated */
  1591. lbuf[ii] = 0;
  1592. }
  1593. p++;
  1594. }
  1595. DeleteObject(hfont);
  1596. }
  1597. }
  1598. return;
  1599. }
  1600. /* record node drawing */
  1601. static void on_top_level_window_drawingarea1_expose_event_nodes_record(struct gml_node
  1602. *node)
  1603. {
  1604. on_top_level_window_drawingarea1_expose_event_nodes_record_r(node, node->rlabel);
  1605. return;
  1606. }
  1607. /* draw one node */
  1608. static void drawnodes1n(struct gml_node *n)
  1609. {
  1610. int newx = 0;
  1611. int newy = 0;
  1612. int snewx = 0;
  1613. int snewy = 0;
  1614. int sbbx = 0;
  1615. int sbby = 0;
  1616. HPEN pen1;
  1617. HPEN holdpen;
  1618. int cr = 0;
  1619. int cg = 0;
  1620. int cb = 0;
  1621. int yy = 0;
  1622. double tsize = 0.0;
  1623. int stsize = 0;
  1624. int stx0 = 0;
  1625. int sty0 = 0;
  1626. HFONT hfont;
  1627. HFONT holdfont;
  1628. char lbuf[NODE_MAXCH];
  1629. char *p = NULL;
  1630. int ii = 0;
  1631. if (holdfont) {
  1632. }
  1633. if (holdpen) {
  1634. }
  1635. /* get node (x,y) pos */
  1636. newx = n->finx - vxmin;
  1637. newy = n->finy - vymin;
  1638. if (0) {
  1639. printf("vxymin (%d,%d) newxy (%d,%d) nxy (%d,%d)\n", vxmin, vymin, newx, newy, n->finx, n->finy);
  1640. }
  1641. /* check if needed to draw */
  1642. if (newx < 0) {
  1643. if (newx + n->bbx < 0) {
  1644. return;
  1645. }
  1646. }
  1647. if (newy < 0) {
  1648. if (newy + n->bby < 0) {
  1649. return;
  1650. }
  1651. }
  1652. /* get scaled coords */
  1653. snewx = scaleit(newx);
  1654. snewy = scaleit(newy);
  1655. sbbx = scaleit(n->bbx);
  1656. sbby = scaleit(n->bby);
  1657. /* check if drawable */
  1658. if (snewx > drwxsize) {
  1659. return;
  1660. }
  1661. if (snewy > drwysize) {
  1662. return;
  1663. }
  1664. /* draw the background color of node but not for edgelabel */
  1665. if (n->elabel == 0) {
  1666. cr = (n->ncolor & 0x00ff0000) >> 16;
  1667. cg = (n->ncolor & 0x0000ff00) >> 8;
  1668. cb = (n->ncolor & 0x000000ff);
  1669. if (cr != bgcr || cg != bgcg || cb != bgcb) {
  1670. pen1 = CreatePen(PS_SOLID, 1, RGB(cr, cg, cb));
  1671. holdpen = SelectObject(hdc, pen1);
  1672. SelectObject(hdc, pen1);
  1673. if (0) {
  1674. printf("%s(): rect at (%d,%d) size (%d,%d) color #%02x%02x%02x\n", __func__, snewx, snewy,
  1675. sbbx, sbby, cr, cg, cb);
  1676. }
  1677. for (yy = 0; yy < sbby; yy++) {
  1678. MoveToEx(hdc, snewx, snewy + yy, NULL);
  1679. LineTo(hdc, snewx + sbbx, snewy + yy);
  1680. }
  1681. DeleteObject(pen1);
  1682. }
  1683. }
  1684. /* outline color black for node, edgelabel node has no outline */
  1685. if (n->elabel == 0) {
  1686. /* bordercolor of node black default or color */
  1687. cr = (n->nbcolor & 0x00ff0000) >> 16;
  1688. cg = (n->nbcolor & 0x0000ff00) >> 8;
  1689. cb = (n->nbcolor & 0x000000ff);
  1690. if (cr != bgcr || cg != bgcg || cb != bgcb) {
  1691. /* the second arg 2 is the line thickness */
  1692. pen1 = CreatePen(PS_SOLID, 2, RGB(cr, cg, cb));
  1693. holdpen = SelectObject(hdc, pen1);
  1694. MoveToEx(hdc, snewx, snewy, NULL);
  1695. LineTo(hdc, snewx + sbbx, snewy);
  1696. LineTo(hdc, snewx + sbbx, snewy + sbby);
  1697. LineTo(hdc, snewx, snewy + sbby);
  1698. LineTo(hdc, snewx, snewy);
  1699. DeleteObject(pen1);
  1700. }
  1701. }
  1702. if (n->rlabel) {
  1703. /* node with dot record label */
  1704. on_top_level_window_drawingarea1_expose_event_nodes_record(n);
  1705. } else {
  1706. /* node with regular label */
  1707. /* scale text size */
  1708. tsize = thefontsize; /* or: FONTSZ */
  1709. tsize = tsize * zfactor;
  1710. tsize = round(tsize);
  1711. stsize = (int)tsize;
  1712. /* only text if resulting font size is big enough */
  1713. if (stsize > 8) {
  1714. /* set background color of text */
  1715. SetBkMode(hdc, TRANSPARENT);
  1716. /* or:
  1717. * cr = (n->ncolor & 0x00ff0000) >> 16;
  1718. * cg = (n->ncolor & 0x0000ff00) >> 8;
  1719. * cb = (n->ncolor & 0x000000ff);
  1720. * SetBkColor(hdc, RGB(cr, cg, cb));
  1721. */
  1722. /* set color of text */
  1723. cr = (n->fontcolor & 0x00ff0000) >> 16;
  1724. cg = (n->fontcolor & 0x0000ff00) >> 8;
  1725. cb = (n->fontcolor & 0x000000ff);
  1726. SetTextColor(hdc, RGB(cr, cg, cb));
  1727. /* start of text, draw it line by line */
  1728. stx0 = scaleit(newx + 0);
  1729. sty0 = scaleit(newy + 0);
  1730. /* adjust y start of text */
  1731. sty0 = sty0 - stsize;
  1732. hfont = CreateFontW(stsize, 0, 0, 0, FW_MEDIUM, 0, 0, 0, 0, 0, 0, 0, 0, FONTNAME);
  1733. holdfont = SelectObject(hdc, hfont);
  1734. p = n->nlabel;
  1735. yy = 0;
  1736. ii = 0;
  1737. memset(lbuf, 0, NODE_MAXCH);
  1738. for (;;) {
  1739. if (*p == '\n' || *p == 0) {
  1740. ii = 0;
  1741. if (0) {
  1742. printf("lbuf=\"%s\" len %d\n", lbuf, (int)strlen(lbuf));
  1743. }
  1744. TextOut(hdc, stx0, sty0 + stsize + yy, lbuf, lstrlen(lbuf));
  1745. yy += stsize;
  1746. if (*p == 0) {
  1747. break;
  1748. }
  1749. memset(lbuf, 0, NODE_MAXCH);
  1750. } else {
  1751. /* limit the max. length of a single text line */
  1752. if (ii < (NODE_MAXCH - 2)) {
  1753. lbuf[ii] = (*p);
  1754. ii++;
  1755. }
  1756. /* make sure string is 0 terminated */
  1757. lbuf[ii] = 0;
  1758. }
  1759. p++;
  1760. }
  1761. DeleteObject(hfont);
  1762. }
  1763. }
  1764. return;
  1765. }
  1766. /* all nodes */
  1767. static void drawnodes(void)
  1768. {
  1769. struct gml_nlist *lnl = NULL;
  1770. lnl = maingraph->nodelist;
  1771. while (lnl) {
  1772. /* only draw real or edgelabel nodes */
  1773. if (lnl->node->dummy == 0) {
  1774. drawnodes1n(lnl->node);
  1775. }
  1776. lnl = lnl->next;
  1777. }
  1778. return;
  1779. }
  1780. /* real-to-dummy find edge conn. point */
  1781. static int r2d_finx(struct gml_edge *edge)
  1782. {
  1783. struct gml_node *sn = NULL;
  1784. struct gml_node *tn = NULL;
  1785. int ret = 0;
  1786. int i = 0;
  1787. sn = edge->from_node; /* from-node */
  1788. tn = edge->to_node; /* to-node */
  1789. if (tn) {
  1790. }
  1791. if (edge->vedge) {
  1792. ret = (sn->finx + (sn->bbx / 2));
  1793. return (ret);
  1794. }
  1795. if (sn->dx_oedges == 0) {
  1796. ret = (sn->finx + (sn->bbx / 2));
  1797. return (ret);
  1798. }
  1799. for (i = 0; i < sn->outdegree; i++) {
  1800. if (sn->oedges[i] == edge) {
  1801. break;
  1802. }
  1803. }
  1804. ret = (sn->finx + 5 + (i * sn->dx_oedges));
  1805. return (ret);
  1806. }
  1807. /* connection edge at real to-node */
  1808. static int d2r_tnx1(struct gml_edge *edge)
  1809. {
  1810. struct gml_node *sn = NULL;
  1811. struct gml_node *tn = NULL;
  1812. int ret = 0;
  1813. int i = 0;
  1814. sn = edge->from_node; /* from-node */
  1815. tn = edge->to_node; /* to-node */
  1816. if (sn) {
  1817. }
  1818. if (edge->vedge) {
  1819. ret = (tn->finx + (tn->bbx / 2));
  1820. return (ret);
  1821. }
  1822. if (tn->dx_iedges == 0) {
  1823. ret = (tn->finx + (tn->bbx / 2));
  1824. return (ret);
  1825. }
  1826. for (i = 0; i < tn->indegree; i++) {
  1827. if (tn->iedges[i] == edge) {
  1828. break;
  1829. }
  1830. }
  1831. ret = (tn->finx + 5 + (i * tn->dx_iedges));
  1832. return (ret);
  1833. }
  1834. /* pi must be defined */
  1835. #ifndef M_PI
  1836. #define M_PI 3.14
  1837. #endif
  1838. /* draw arrow, option to allow multiple arrow types todo
  1839. * arrow comes from (start_x,start_y) to (end_x,end_y)
  1840. * size is optional, if zero a default size is used
  1841. */
  1842. static void drarrow(int start_x, int start_y, int end_x, int end_y, double size)
  1843. {
  1844. double angle = 0.0;
  1845. double arrow_lenght = 8.0;
  1846. double arrow_degrees = ( /* degrees */ 30 * (M_PI / 180));
  1847. double x1 = 0.0;
  1848. double y1 = 0.0;
  1849. double x2 = 0.0;
  1850. double y2 = 0.0;
  1851. int sp1x = 0;
  1852. int sp1y = 0;
  1853. if (yydebug || 0) {
  1854. printf("%s(): arrow at (%d,%d) coming from (%d,%d) size %f\n", __func__, end_x, end_y, start_x, start_y, size);
  1855. }
  1856. /* if size is specified, use it, otherwise use default size */
  1857. if (size == 0) {
  1858. arrow_lenght = 6.0;
  1859. } else {
  1860. arrow_lenght = size;
  1861. }
  1862. /* gtk has a gtk_render_arrow() function as alternative to use here */
  1863. angle = atan2(end_y - start_y, end_x - start_x) + M_PI;
  1864. x1 = end_x + arrow_lenght * cos(angle - arrow_degrees);
  1865. y1 = end_y + arrow_lenght * sin(angle - arrow_degrees);
  1866. x2 = end_x + arrow_lenght * cos(angle + arrow_degrees);
  1867. y2 = end_y + arrow_lenght * sin(angle + arrow_degrees);
  1868. /* set start position of arrow part 1 */
  1869. sp1x = scaleit(end_x);
  1870. sp1y = scaleit(end_y);
  1871. MoveToEx(hdc, sp1x, sp1y, NULL);
  1872. sp1x = scaleit(x1);
  1873. sp1y = scaleit(y1);
  1874. LineTo(hdc, sp1x, sp1y);
  1875. /* set start position of arrow part 2 */
  1876. sp1x = scaleit(end_x);
  1877. sp1y = scaleit(end_y);
  1878. MoveToEx(hdc, sp1x, sp1y, NULL);
  1879. sp1x = scaleit(x2);
  1880. sp1y = scaleit(y2);
  1881. LineTo(hdc, sp1x, sp1y);
  1882. /* make a triangle */
  1883. sp1x = scaleit(x1);
  1884. sp1y = scaleit(y1);
  1885. LineTo(hdc, sp1x, sp1y);
  1886. return;
  1887. }
  1888. /* return 0 if edge line is out of window */
  1889. static int edgeisok(int sfnx1, int sfny1, int stnx1, int stny1)
  1890. {
  1891. if (sfnx1 < 0 && stnx1 < 0) {
  1892. return (0);
  1893. }
  1894. if (sfny1 < 0 && stny1 < 0) {
  1895. return (0);
  1896. }
  1897. if (sfnx1 > drwxsize && stnx1 > drwxsize) {
  1898. return (0);
  1899. }
  1900. if (sfny1 > drwysize && stny1 > drwysize) {
  1901. return (0);
  1902. }
  1903. /* edge line is in draw area */
  1904. return (1);
  1905. }
  1906. /* all edges */
  1907. static void drawedges(void)
  1908. {
  1909. struct gml_elist *el = NULL;
  1910. struct gml_edge *edge = NULL;
  1911. struct gml_node *sn = NULL;
  1912. struct gml_node *tn = NULL;
  1913. int ecolor = 0;
  1914. int cr = 0;
  1915. int cg = 0;
  1916. int cb = 0;
  1917. int fnx1 = 0;
  1918. int fny1 = 0;
  1919. int tnx1 = 0;
  1920. int tny1 = 0;
  1921. int sfnx1 = 0;
  1922. int sfny1 = 0;
  1923. int stnx1 = 0;
  1924. int stny1 = 0;
  1925. int shx0 = 0;
  1926. int shy0 = 0;
  1927. int shx1 = 0;
  1928. int shy1 = 0;
  1929. int shx2 = 0;
  1930. int shy2 = 0;
  1931. int dx15 = 0;
  1932. HPEN pen1;
  1933. HPEN holdpen;
  1934. int pentype = 0;
  1935. int bezier = 1; /* set to 0 for straight lines */
  1936. POINT points[4];
  1937. if (holdpen) {
  1938. }
  1939. /* only spline edges here, not raw */
  1940. el = maingraph->edgelist;
  1941. while (el) {
  1942. edge = el->edge;
  1943. sn = edge->from_node; /* from-node */
  1944. tn = edge->to_node; /* to-node */
  1945. ecolor = edge->ecolor; /* edge line color */
  1946. /* black or colored line */
  1947. cr = (ecolor & 0x00ff0000) >> 16;
  1948. cg = (ecolor & 0x0000ff00) >> 8;
  1949. cb = (ecolor & 0x000000ff);
  1950. /* if color is background color do not draw line */
  1951. if (cr == bgcr && cg == bgcg && cb == bgcb) {
  1952. el = el->next;
  1953. continue;
  1954. }
  1955. /* if line is out of window do not draw edge line */
  1956. fnx1 = sn->finx - vxmin;
  1957. fny1 = sn->finy - vymin;
  1958. tnx1 = tn->finx - vxmin;
  1959. tny1 = tn->finy - vymin;
  1960. sfnx1 = scaleit(fnx1);
  1961. sfny1 = scaleit(fny1);
  1962. stnx1 = scaleit(tnx1);
  1963. stny1 = scaleit(tny1);
  1964. if (edgeisok(sfnx1, sfny1, stnx1, stny1) == 0) {
  1965. el = el->next;
  1966. continue;
  1967. }
  1968. /* check edge line style
  1969. * some windows line styles are:
  1970. * HPEN hPen1 = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  1971. * HPEN hPen2 = CreatePen(PS_DASH, 1, RGB(0, 0, 0));
  1972. * HPEN hPen3 = CreatePen(PS_DOT, 1, RGB(0, 0, 0));
  1973. * HPEN hPen4 = CreatePen(PS_DASHDOT, 1, RGB(0, 0, 0));
  1974. * HPEN hPen5 = CreatePen(PS_DASHDOTDOT, 1, RGB(0, 0, 0));
  1975. */
  1976. if (edge->style == 1 /* ESTYLE_DASHED */ ) {
  1977. /* dashed edge line */
  1978. pentype = PS_DASH;
  1979. } else if (edge->style == 2 /* ESTYLE_DOTTED */ ) {
  1980. /* dotted edge line */
  1981. pentype = PS_DOT;
  1982. } else {
  1983. /* solid edge line */
  1984. pentype = PS_SOLID;
  1985. }
  1986. if (edge->hedge) {
  1987. /* horizontal edge has original endpoints */
  1988. /* center of from/to nodes */
  1989. fnx1 = (sn->finx + sn->bbx / 2) - vxmin;
  1990. tnx1 = (tn->finx + tn->bbx / 2) - vxmin;
  1991. if (tnx1 > fnx1) {
  1992. /* edge from left to right */
  1993. /* check if nodes are next to each other */
  1994. /* this should also check if to-node is a dummy or real node todo */
  1995. if ((sn->relx + 1) == tn->relx) {
  1996. /* printf ("direct-lr\n"); */
  1997. fnx1 = (sn->finx + sn->bbx) - vxmin;
  1998. fny1 = (sn->finy + sn->bby / 2) - vymin;
  1999. sfnx1 = scaleit(fnx1);
  2000. sfny1 = scaleit(fny1);
  2001. stnx1 = scaleit(tn->finx - vxmin);
  2002. stny1 = scaleit((tn->finy + tn->bby / 2) - vymin);
  2003. sfnx1 = scaleit(fnx1);
  2004. sfny1 = scaleit(fny1);
  2005. MoveToEx(hdc, sfnx1, sfny1, NULL);
  2006. sfnx1 = scaleit((tn->finx) - vxmin);
  2007. sfny1 = scaleit((tn->finy + tn->bby / 2) - vymin);
  2008. LineTo(hdc, sfnx1, sfny1);
  2009. /* add arrow */
  2010. if (edge->reversed == 0) {
  2011. drarrow(fnx1, fny1, (tn->finx) - vxmin, (tn->finy + tn->bby / 2) - vymin, 0);
  2012. } else {
  2013. drarrow((tn->finx) - vxmin, (tn->finy + tn->bby / 2) - vymin, fnx1, fny1, 0);
  2014. }
  2015. } else {
  2016. /* distance length of hor. line / 5 */
  2017. dx15 = (tnx1 - fnx1) / 5;
  2018. /* start line at center */
  2019. fnx1 = (sn->finx + sn->bbx / 2) - vxmin;
  2020. fny1 = (sn->finy + sn->bby) - vymin;
  2021. sfnx1 = scaleit(fnx1);
  2022. sfny1 = scaleit(fny1);
  2023. MoveToEx(hdc, sfnx1, sfny1, NULL);
  2024. if ((sn->finy + sn->bby) >= (tn->finy + tn->bby)) {
  2025. /* from node y is lower then target, put hor. line 10px lower */
  2026. sfnx1 = scaleit(fnx1 + dx15);
  2027. sfny1 = scaleit(((sn->finy + sn->bby) + HEDGE_DY) - vymin);
  2028. LineTo(hdc, sfnx1, sfny1);
  2029. sfnx1 = scaleit((fnx1 + dx15) + (3 * dx15));
  2030. sfny1 = scaleit(((sn->finy + sn->bby) + HEDGE_DY) - vymin);
  2031. LineTo(hdc, sfnx1, sfny1);
  2032. sfnx1 = scaleit((tn->finx + tn->bbx / 2) - vxmin);
  2033. sfny1 = scaleit((tn->finy + tn->bby) - vymin);
  2034. LineTo(hdc, sfnx1, sfny1);
  2035. /* add arrow */
  2036. if (edge->reversed == 0) {
  2037. drarrow((fnx1 + dx15) + (3 * dx15),
  2038. ((sn->finy + sn->bby) + HEDGE_DY) -
  2039. vymin, (tn->finx + tn->bbx / 2) - vxmin,
  2040. (tn->finy + tn->bby) - vymin, 0);
  2041. } else {
  2042. drarrow((tn->finx + tn->bbx / 2) - vxmin,
  2043. (tn->finy + tn->bby) - vymin,
  2044. (fnx1 + dx15) + (3 * dx15),
  2045. ((sn->finy + sn->bby) + HEDGE_DY) - vymin, 0);
  2046. }
  2047. } else {
  2048. /* from-node y is higher */
  2049. sfnx1 = scaleit(fnx1 + dx15);
  2050. sfny1 = scaleit((tn->finy + tn->bby) + HEDGE_DY - vymin);
  2051. LineTo(hdc, sfnx1, sfny1);
  2052. sfnx1 = scaleit((fnx1 + dx15) + (3 * dx15));
  2053. sfny1 = scaleit(((tn->finy + tn->bby) + HEDGE_DY) - vymin);
  2054. LineTo(hdc, sfnx1, sfny1);
  2055. sfnx1 = scaleit((tn->finx + tn->bbx / 2) - vxmin);
  2056. sfny1 = scaleit((tn->finy + tn->bby) - vymin);
  2057. LineTo(hdc, sfnx1, sfny1);
  2058. /* add arrow */
  2059. if (edge->reversed == 0) {
  2060. drarrow((fnx1 + dx15) + (3 * dx15),
  2061. ((tn->finy + tn->bby) + HEDGE_DY) -
  2062. vymin,
  2063. (tn->finx + tn->bbx / 2) - vxmin, (tn->finy + tn->bby) - vymin, 0);
  2064. } else {
  2065. drarrow((fnx1 + dx15),
  2066. (tn->finy + tn->bby) + HEDGE_DY - vymin, fnx1, fny1, 0);
  2067. }
  2068. }
  2069. }
  2070. } else {
  2071. /* edge from right to left fnx1>tnx1 */
  2072. if ((sn->relx) == (tn->relx + 1)) {
  2073. /* printf ("direct-rl\n"); */
  2074. sfnx1 = scaleit((sn->finx) - vxmin);
  2075. sfny1 = scaleit((sn->finy + sn->bby / 2) - vymin);
  2076. MoveToEx(hdc, sfnx1, sfny1, NULL);
  2077. sfnx1 = scaleit(tn->finx + tn->bbx - vxmin);
  2078. sfny1 = scaleit(tn->finy + tn->bby / 2 - vymin);
  2079. LineTo(hdc, sfnx1, sfny1);
  2080. /* add arrow */
  2081. if (edge->reversed == 0) {
  2082. drarrow((sn->finx) - vxmin,
  2083. (sn->finy + sn->bby / 2) - vymin,
  2084. tn->finx + tn->bbx - vxmin, tn->finy + tn->bby / 2 - vymin, 0);
  2085. } else {
  2086. drarrow(tn->finx + tn->bbx - vxmin,
  2087. tn->finy + tn->bby / 2 - vymin,
  2088. (sn->finx) - vxmin, (sn->finy + sn->bby / 2) - vymin, 0);
  2089. }
  2090. } else {
  2091. /* distance length of hor. line / 5 */
  2092. dx15 = (fnx1 - tnx1) / 5;
  2093. /* start line at center */
  2094. fnx1 = (sn->finx + sn->bbx / 2) - vxmin;
  2095. fny1 = (sn->finy + sn->bby) - vymin;
  2096. sfnx1 = scaleit(fnx1);
  2097. sfny1 = scaleit(fny1);
  2098. MoveToEx(hdc, sfnx1, sfny1, NULL);
  2099. if ((sn->finy + sn->bby) >= (tn->finy + tn->bby)) {
  2100. /* from node y is lower then target, put hor. line 10px lower */
  2101. sfnx1 = scaleit(fnx1 - dx15);
  2102. sfny1 = scaleit(((sn->finy + sn->bby) + HEDGE_DY) - vymin);
  2103. LineTo(hdc, sfnx1, sfny1);
  2104. sfnx1 = scaleit((fnx1 - dx15) - (3 * dx15));
  2105. sfny1 = scaleit(((sn->finy + sn->bby) + HEDGE_DY) - vymin);
  2106. LineTo(hdc, sfnx1, sfny1);
  2107. sfnx1 = scaleit((tn->finx + tn->bbx / 2) - vxmin);
  2108. sfny1 = scaleit((tn->finy + tn->bby) - vymin);
  2109. LineTo(hdc, sfnx1, sfny1);
  2110. /* add arrow */
  2111. if (edge->reversed == 0) {
  2112. /* could be improved here todo */
  2113. drarrow((fnx1 - dx15) - (3 * dx15),
  2114. ((sn->finy + sn->bby) +
  2115. HEDGE_DY) - vymin,
  2116. (tn->finx + tn->bbx / 2) - vxmin, (tn->finy + tn->bby) - vymin, 0);
  2117. } else {
  2118. drarrow((fnx1 - dx15),
  2119. ((sn->finy + sn->bby) + HEDGE_DY) - vymin, fnx1, fny1, 0);
  2120. }
  2121. } else {
  2122. /* from-node y is higher */
  2123. sfnx1 = scaleit(fnx1 - dx15);
  2124. sfny1 = scaleit((tn->finy + tn->bby) + HEDGE_DY - vymin);
  2125. LineTo(hdc, sfnx1, sfny1);
  2126. sfnx1 = scaleit((fnx1 - dx15) - (3 * dx15));
  2127. sfny1 = scaleit(((tn->finy + tn->bby) + HEDGE_DY) - vymin);
  2128. LineTo(hdc, sfnx1, sfny1);
  2129. sfnx1 = scaleit((tn->finx + tn->bbx / 2) - vxmin);
  2130. sfny1 = scaleit((tn->finy + tn->bby) - vymin);
  2131. LineTo(hdc, sfnx1, sfny1);
  2132. /* add arrow */
  2133. if (edge->reversed == 0) {
  2134. /* this could be improved, todo */
  2135. drarrow((fnx1 - dx15) - (3 * dx15),
  2136. ((sn->finy + sn->bby) +
  2137. HEDGE_DY) - vymin,
  2138. (tn->finx + tn->bbx / 2) - vxmin, (tn->finy + tn->bby) - vymin, 0);
  2139. } else {
  2140. drarrow((fnx1 - dx15),
  2141. (tn->finy + tn->bby) + HEDGE_DY - vymin, fnx1, fny1, 0);
  2142. }
  2143. }
  2144. }
  2145. }
  2146. /* end of horizontal edge */
  2147. } else {
  2148. /* regular vertical edge */
  2149. if (sn->dummy == 0 && tn->dummy == 0) {
  2150. /* from real node to real node.
  2151. * real nodes are interleaved with dummy nodes
  2152. * this only does happen from real node to edge-label node
  2153. */
  2154. fnx1 = sn->finx + sn->bbx / 2 - vxmin;
  2155. fny1 = sn->finy + sn->bby - vymin;
  2156. tnx1 = tn->finx + tn->bbx / 2 - vxmin;
  2157. tny1 = tn->finy - vymin;
  2158. sfnx1 = scaleit(fnx1);
  2159. sfny1 = scaleit(fny1);
  2160. stnx1 = scaleit(tnx1);
  2161. stny1 = scaleit(tny1);
  2162. pen1 = CreatePen(pentype, 1, RGB(cr, cg, cb));
  2163. holdpen = SelectObject(hdc, pen1);
  2164. MoveToEx(hdc, sfnx1, sfny1, NULL);
  2165. LineTo(hdc, stnx1, stny1);
  2166. /* add arrow */
  2167. if (edge->reversed == 0) {
  2168. drarrow(fnx1, fny1, tnx1, tny1, 0);
  2169. } else {
  2170. drarrow(tnx1, tny1, fnx1, fny1, 0);
  2171. }
  2172. DeleteObject(pen1);
  2173. } else if (sn->dummy == 1 && tn->dummy == 0) {
  2174. /* from dummy node to real node */
  2175. fnx1 = sn->finx - vxmin;
  2176. fny1 = sn->finy - vymin;
  2177. tnx1 = d2r_tnx1(edge) - vxmin;
  2178. tny1 = tn->finy - vymin;
  2179. /* point 0 */
  2180. sfnx1 = scaleit(fnx1);
  2181. sfny1 = scaleit(fny1);
  2182. /* point 1 */
  2183. shx1 = scaleit(fnx1);
  2184. shy1 = scaleit(fny1 + (sn->bby / 2));
  2185. /* point 2 */
  2186. shx2 = scaleit(tnx1);
  2187. shy2 = scaleit(tn->ly0 - vymin);
  2188. /* point 3 */
  2189. stnx1 = scaleit(tnx1);
  2190. stny1 = scaleit(tny1);
  2191. /*
  2192. * cairo_move_to(crp, fnx1, fny1);
  2193. * cairo_curve_to(crp, fnx1, fny1, fnx1, fny1 + (sn->bby / 2), tnx1, (tn->ly0 - vymin));
  2194. * cairo_line_to(crp, tnx1, tny1);
  2195. */
  2196. if (bezier) {
  2197. points[0].x = sfnx1;
  2198. points[0].y = sfny1;
  2199. points[1].x = shx1;
  2200. points[1].y = shy1;
  2201. points[2].x = shx2;
  2202. points[2].y = shy2;
  2203. points[3].x = stnx1;
  2204. points[3].y = stny1;
  2205. pen1 = CreatePen(pentype, 1, RGB(cr, cg, cb));
  2206. holdpen = SelectObject(hdc, pen1);
  2207. PolyBezier(hdc, points, 4);
  2208. /* add arrow */
  2209. if (edge->reversed == 0) {
  2210. drarrow(fnx1, fny1, tnx1, tny1, 0);
  2211. } else {
  2212. /* no arrow */
  2213. }
  2214. DeleteObject(pen1);
  2215. } else {
  2216. pen1 = CreatePen(pentype, 1, RGB(cr, cg, cb));
  2217. holdpen = SelectObject(hdc, pen1);
  2218. MoveToEx(hdc, sfnx1, sfny1, NULL);
  2219. LineTo(hdc, stnx1, stny1);
  2220. /* add arrow */
  2221. if (edge->reversed == 0) {
  2222. drarrow(fnx1, fny1, tnx1, tny1, 0);
  2223. } else {
  2224. /* no arrow */
  2225. }
  2226. DeleteObject(pen1);
  2227. }
  2228. } else if (sn->dummy == 0 && tn->dummy == 1) {
  2229. /* from real node to dummy node */
  2230. fnx1 = r2d_finx(edge) - vxmin;
  2231. fny1 = (sn->finy + sn->bby) - vymin;
  2232. tnx1 = tn->finx - vxmin;
  2233. tny1 = tn->finy - vymin;
  2234. /* point 0 */
  2235. sfnx1 = scaleit(fnx1);
  2236. sfny1 = scaleit(fny1);
  2237. /* point 1 */
  2238. shx1 = scaleit(fnx1);
  2239. shy1 = scaleit(sn->ly1 - vymin);
  2240. /* point 2 */
  2241. shx2 = scaleit(tnx1);
  2242. shy2 = scaleit(tny1 - (tn->bby / 2));
  2243. /* point 3 */
  2244. stnx1 = scaleit(tnx1);
  2245. stny1 = scaleit(tny1);
  2246. /*
  2247. * cairo_move_to(crp, fnx1, fny1);
  2248. * cairo_curve_to(crp, fnx1, (sn->ly1 - vymin), tnx1, tny1 - (tn->bby / 2), tnx1, tny1);
  2249. */
  2250. if (bezier) {
  2251. points[0].x = sfnx1;
  2252. points[0].y = sfny1;
  2253. points[1].x = shx1;
  2254. points[1].y = shy1;
  2255. points[2].x = shx2;
  2256. points[2].y = shy2;
  2257. points[3].x = stnx1;
  2258. points[3].y = stny1;
  2259. pen1 = CreatePen(pentype, 1, RGB(cr, cg, cb));
  2260. holdpen = SelectObject(hdc, pen1);
  2261. PolyBezier(hdc, points, 4);
  2262. /* add arrow */
  2263. if (edge->reversed == 0) {
  2264. /* no arrow */
  2265. } else {
  2266. drarrow(tnx1, tny1, fnx1, fny1, 0);
  2267. }
  2268. DeleteObject(pen1);
  2269. } else {
  2270. /* direct line */
  2271. pen1 = CreatePen(pentype, 1, RGB(cr, cg, cb));
  2272. holdpen = SelectObject(hdc, pen1);
  2273. MoveToEx(hdc, sfnx1, sfny1, NULL);
  2274. LineTo(hdc, stnx1, stny1);
  2275. /* add arrow */
  2276. if (edge->reversed == 0) {
  2277. /* no arrow */
  2278. } else {
  2279. drarrow(tnx1, tny1, fnx1, fny1, 0);
  2280. }
  2281. DeleteObject(pen1);
  2282. }
  2283. } else {
  2284. /* from dummy node to dummy node */
  2285. fnx1 = sn->finx - vxmin;
  2286. fny1 = sn->finy - vymin;
  2287. tnx1 = tn->finx - vxmin;
  2288. tny1 = tn->finy - vymin;
  2289. shx0 = scaleit(fnx1);
  2290. shy0 = scaleit(fny1);
  2291. /* point 0 */
  2292. sfnx1 = scaleit(fnx1);
  2293. sfny1 = scaleit(fny1 + (sn->bby / 2));
  2294. /* point 1 */
  2295. shx1 = scaleit(tnx1);
  2296. shy1 = scaleit(tn->ly0 - vymin);
  2297. /* point 2 */
  2298. shx2 = scaleit(tnx1);
  2299. shy2 = scaleit(tny1 - (tn->bby / 2));
  2300. /* point 3 */
  2301. stnx1 = scaleit(tnx1);
  2302. stny1 = scaleit(tny1);
  2303. /*
  2304. * cairo_move_to(crp, fnx1, fny1);
  2305. * cairo_line_to(crp, fnx1, fny1 + (sn->bby / 2));
  2306. * cairo_move_to(crp, fnx1, fny1 + (sn->bby / 2));
  2307. * cairo_curve_to(crp, tnx1, (tn->ly0 - vymin), tnx1, tny1 - (tn->bby / 2), tnx1, tny1);
  2308. */
  2309. /* */
  2310. if (bezier) {
  2311. points[0].x = sfnx1;
  2312. points[0].y = sfny1;
  2313. points[1].x = shx1;
  2314. points[1].y = shy1;
  2315. points[2].x = shx2;
  2316. points[2].y = shy2;
  2317. points[3].x = stnx1;
  2318. points[3].y = stny1;
  2319. pen1 = CreatePen(pentype, 1, RGB(cr, cg, cb));
  2320. holdpen = SelectObject(hdc, pen1);
  2321. MoveToEx(hdc, shx0, shy0, NULL);
  2322. LineTo(hdc, sfnx1, sfny1);
  2323. PolyBezier(hdc, points, 4);
  2324. DeleteObject(pen1);
  2325. } else {
  2326. /* direct */
  2327. pen1 = CreatePen(pentype, 1, RGB(cr, cg, cb));
  2328. holdpen = SelectObject(hdc, pen1);
  2329. MoveToEx(hdc, sfnx1, sfny1, NULL);
  2330. LineTo(hdc, stnx1, stny1);
  2331. DeleteObject(pen1);
  2332. }
  2333. /* no real nodes, no arrows, optional draw arrows at dummy nodes, see tuxsee */
  2334. }
  2335. }
  2336. el = el->next;
  2337. }
  2338. return;
  2339. }
  2340. /*zz2 draw it */
  2341. static void drawit(HWND hwnd)
  2342. {
  2343. PAINTSTRUCT ps;
  2344. RECT r;
  2345. HBRUSH b1;
  2346. /* main window (x,y) size */
  2347. GetClientRect(hwnd, &r);
  2348. wxsize = (int)r.right - (int)r.left;
  2349. wysize = (int)r.bottom - (int)r.top;
  2350. /* draw window (x,y) size */
  2351. GetClientRect(drw, &r);
  2352. drwxsize = (int)r.right - (int)r.left;
  2353. drwysize = (int)r.bottom - (int)r.top;
  2354. if (0) {
  2355. printf("dr (%d,%d)\n", (int)r.right, (int)r.bottom);
  2356. }
  2357. hdc = BeginPaint(drw, &ps);
  2358. /* draw the background color */
  2359. b1 = CreateSolidBrush(RGB(bgcr, bgcg, bgcb));
  2360. SelectObject(hdc, b1);
  2361. Rectangle(hdc, 0, 0, drwxsize, drwysize);
  2362. /* if there is a graph, draw nodes+edges */
  2363. if (validdata) {
  2364. drawnodes();
  2365. drawedges();
  2366. }
  2367. EndPaint(drw, &ps);
  2368. return;
  2369. }
  2370. /* update crossings text in gui */
  2371. void update_status_text_cross(char *text)
  2372. {
  2373. if (text) {
  2374. }
  2375. /* notused */ return;
  2376. }
  2377. /* end */