1 /* Written by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>f
2 * Understanding is not required. Only obedience.
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.
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.
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/>.
21 import std
.concurrency
;
23 import arsd
.simpledisplay
;
29 import iv
.nanovg
.oui
.blendish
;
30 import iv
.nanovg
.perf
;
51 //version = debug_draw;
54 // ////////////////////////////////////////////////////////////////////////// //
55 void run (string bookFileName
) {
59 bool fpsVisible
= false;
61 string newBookFileName
;
63 if (GWidth
< 64) GWidth
= 64;
64 if (GHeight
< 64) GHeight
= 64;
70 booktext
= loadBook(bookFileName
);
72 //setOpenGLContextVersion(3, 2); // up to GLSL 150
73 setOpenGLContextVersion(2, 0); // it's enough
74 //openGLContextCompatible = false;
76 auto sdwindow
= new SimpleWindow(GWidth
, GHeight
, booktext
.title
~" -- "~booktext
.authorFirst
~" "~booktext
.authorLast
, OpenGlOptions
.yes
, Resizablity
.allowResizing
);
77 sdwindow
.hideCursor(); // we will do our own
79 auto stt
= MonoTime
.currTime
;
80 auto prevt
= MonoTime
.currTime
;
82 float dt = 0, secs
= 0;
84 int textHeight
= GHeight
-8;
85 bool doSaveCheck
= false;
86 MonoTime nextSaveTime
;
88 MonoTime nextIfTime
= MonoTime
.currTime
;
90 BookInfo
[] recentFiles
;
91 BookMetadata bookmeta
;
93 int toMove
= 0; // for smooth scroller
97 int newYLine
= -1; // index
99 bool newYFade
= false;
100 MonoTime nextFadeTime
;
103 int mouseX
= -666, mouseY
= -666;
104 bool mouseHidden
= false;
105 auto lastMMove
= MonoTime
.currTime
;
107 bool needRedrawFlag
= true;
109 bool firstFormat
= true;
111 bool inGalaxyMap
= false;
113 void delegate (int item
) onPopupSelect
;
114 int shipModelIndex
= 0;
115 bool popupNoShipKill
= false;
117 void refresh () { needRedrawFlag
= true; }
118 void refreshed () { needRedrawFlag
= false; }
121 return (needRedrawFlag ||
(currPopup
!is null && currPopup
.needRedraw
));
124 @property bool inMenu () { return (currPopup
!is null); }
125 void closeMenu () { if (currPopup
!is null) currPopup
.destroy
; currPopup
= null; onPopupSelect
= null; }
127 auto childTid
= spawn(&reformatThreadFn
, thisTid
);
128 childTid
.setMaxMailboxSize(128, OnCrowding
.block
);
129 thisTid
.setMaxMailboxSize(128, OnCrowding
.block
);
131 void setShip (int idx
) {
132 if (eliteShipFiles
.length
) {
133 import core
.memory
: GC
;
134 if (idx
>= eliteShipFiles
.length
) idx
= cast(int)eliteShipFiles
.length
-1;
135 if (idx
< 0) idx
= 0;
136 if (shipModelIndex
== idx
&& shipModel
!is null) return;
138 shipModelIndex
= idx
;
139 if (shipModel
!is null) {
140 shipModel
.glUnload();
141 shipModel
.freeData();
148 shipModel
= new EliteModel(eliteShipFiles
[shipModelIndex
]);
149 shipModel
.glUpload();
150 shipModel
.freeImages();
151 } catch (Exception e
) {}
152 //shipModel = eliteShips[shipModelIndex];
157 void ensureShipModel () {
158 if (eliteShipFiles
.length
&& shipModel
is null) {
159 import std
.random
: uniform
;
160 setShip(uniform
!"[)"(0, eliteShipFiles
.length
));
164 void freeShipModel () {
165 if (!showShip
&& !inMenu
&& shipModel
!is null) {
166 import core
.memory
: GC
;
167 shipModel
.glUnload();
168 shipModel
.freeData();
175 void doSaveState (bool forced
=false) {
177 if (formatWorks
!= 0) return;
178 if (!doSaveCheck
) return;
179 auto ct
= MonoTime
.currTime
;
180 if (ct
< nextSaveTime
) return;
182 if (laytext
is null || laytext
.lineCount
== 0 || formatWorks
!= 0) return;
185 auto fo
= VFile(stateFileName
, "w");
186 if (laytext
!is null && laytext
.lineCount
) {
187 auto lnum
= laytext
.findLineWithY(topY
);
188 if (lnum
>= 0) fo
.writeln("wordindex=", laytext
.line(lnum
).wstart
);
190 } catch (Exception
) {}
194 void stateChanged () {
197 nextSaveTime
= MonoTime
.currTime
+10.seconds
;
201 void hardScrollBy (int delta
) {
202 if (delta
== 0 || laytext
is null || laytext
.lineCount
== 0) return;
205 if (topY
>= laytext
.textHeight
-textHeight
) topY
= cast(int)laytext
.textHeight
-textHeight
;
206 if (topY
< 0) topY
= 0;
213 void scrollBy (int delta
) {
214 if (delta
== 0 || laytext
is null || laytext
.lineCount
== 0) return;
219 // scrolling up, mark top line
220 newYLine
= laytext
.findLineWithY(topY
);
222 // scrolling down, mark bottom line
223 newYLine
= laytext
.findLineWithY(topY
+textHeight
-2);
227 writeln("scrollBy: delta=", delta
, "; newYLine=", newYLine
, "; topLine=", laytext
.findLineWithY(topY
));
229 if (newYLine
< 0) newYFade
= false;
233 if (laytext
is null) return;
241 void goTo (uint widx
) {
242 if (laytext
is null) return;
243 auto lidx
= laytext
.findLineWithWord(widx
);
245 assert(lidx
< laytext
.lineCount
);
247 if (topY
!= laytext
.line(lidx
).y
) {
248 topY
= laytext
.line(lidx
).y
;
254 writeln("goto: widx=", widx
, "; lidx=", lidx
, "; fwn=", laytext
.line(lidx
).wstart
, "; topY=", topY
);
255 auto lnum
= laytext
.findLineWithY(topY
);
256 writeln(" newlnum=", lnum
, "; lidx.y=", laytext
.line(lidx
).y
, "; lnum.y=", laytext
.line(lnum
).y
);
264 xiniParse(VFile(stateFileName
),
267 if (widx
>= 0) goTo(widx
);
268 } catch (Exception
) {}
271 void loadAndFormat (string filename
) {
272 assert(formatWorks
<= 0);
276 //formatWorks = -1; //FIXME
282 //sdwindow.redrawOpenGlSceneNow();
283 //booktext = loadBook(newBookFileName);
284 //newBookFileName = null;
286 //if (formatWorks < 0) formatWorks = 1; else ++formatWorks;
288 //writeln("*** loading new book: '", filename, "'");
289 childTid
.send(ReformatWork(null, filename
, GWidth
, GHeight
));
294 if (formatWorks
< 0) formatWorks
= 1; else ++formatWorks
;
295 childTid
.send(ReformatWork(cast(shared)booktext
, null, GWidth
, GHeight
));
299 void formatComplete (ref ReformatWorkComplete w
) {
300 scope(exit
) { import core
.memory
: GC
; GC
.collect(); GC
.minimize(); }
302 auto lt
= cast(LayText
)w
.laytext
;
303 scope(exit
) if (lt
) lt
.freeMemory();
306 BookMetadata meta
= cast(BookMetadata
)w
.meta
;
309 BookText
bt = cast(BookText
)w
.booktext
;
311 if (bt !is booktext
) {
315 sdwindow
.title
= booktext
.title
~" -- "~booktext
.authorFirst
~" "~booktext
.authorLast
;
317 } else if (bookmeta
is null) {
321 if (doQuit || formatWorks
<= 0) return;
325 if (formatWorks
== 0) reformat();
329 if (formatWorks
!= 0) return;
333 if (!firstFormat
&& laytext
!is null && laytext
.lineCount
) {
334 auto lidx
= laytext
.findLineWithY(topY
);
335 if (lidx
>= 0) widx
= laytext
.line(lidx
).wstart
;
337 if (laytext
!is null) laytext
.freeMemory();
351 void pushPosition () {
352 if (laytext
is null || laytext
.lineCount
== 0) return;
353 auto lidx
= laytext
.findLineWithY(topY
);
354 if (lidx
>= 0) posstack
~= laytext
.line(lidx
).wstart
;
357 void popPosition () {
358 if (posstack
.length
== 0) return;
359 auto widx
= posstack
[$-1];
360 posstack
.length
-= 1;
361 posstack
.assumeSafeAppend
;
365 void gotoSection (int sn
) {
366 if (laytext
is null || laytext
.lineCount
== 0 || bookmeta
is null) return;
367 if (sn
< 0 || sn
>= bookmeta
.sections
.length
) return;
368 auto lidx
= laytext
.findLineWithWord(bookmeta
.sections
[sn
].wordidx
);
370 auto newY
= laytext
.line(lidx
).y
;
379 sdwindow
.closeQuery
= delegate () { doQuit
= true; };
381 void closeWindow () {
382 doSaveState(true); // forced state save
383 if (!sdwindow
.closed
&& vg
!is null) {
384 if (curImg
>= 0) { vg
.deleteImage(curImg
); curImg
= -1; }
392 sdwindow
.visibleForTheFirstTime
= delegate () {
393 sdwindow
.setAsCurrentOpenGlContext(); // make this window active
394 sdwindow
.vsync
= false;
395 //sdwindow.useGLFinish = false;
396 //glbindLoadFunctions();
399 uint flags
= NVG_DEBUG
;
400 if (flagNanoAA
) flags |
= NVG_ANTIALIAS
;
401 if (flagNanoSS
) flags |
= NVG_STENCIL_STROKES
;
402 vg
= createGL2NVG(flags
);
405 writeln("Could not init nanovg.");
410 curImg
= createCursorImage(vg
);
411 fps
= new PerfGraph("Frame Time", PerfGraph
.Style
.FPS
, "ui");
412 } catch (Exception e
) {
413 import std
.stdio
: stderr
;
414 stderr
.writeln("ERROR: ", e
.msg
);
422 sdwindow
.redrawOpenGlScene();
426 void relayout (bool forced
=false) {
427 if (laytext
!is null) {
429 auto lidx
= laytext
.findLineWithY(topY
);
430 if (lidx
>= 0) widx
= laytext
.line(lidx
).wstart
;
431 int maxWidth
= GWidth
-4-2-BND_SCROLLBAR_WIDTH
-2;
432 if (maxWidth
< 64) maxWidth
= 64;
435 auto stt
= MonoTime
.currTime
;
436 laytext
.relayout(maxWidth
, forced
);
437 writeln("relayouted in ", (MonoTime
.currTime
-stt
).total
!"msecs", " milliseconds; lines:", laytext
.lineCount
, "; words:", laytext
.nextWordIndex
);
444 sdwindow
.windowResized
= delegate (int w
, int h
) {
445 //writeln("w=", w, "; h=", h);
448 glViewport(0, 0, w
, h
);
451 textHeight
= GHeight
-8;
456 void drawShipName () {
457 if (shipModel
is null || shipModel
.name
.length
== 0) return;
458 vg
.fontFaceId(uiFont
);
459 vg
.textAlign(NVGAlign
.Left|NVGAlign
.Baseline
);
460 vg
.fontSize(fsizeUI
);
461 auto w
= vg
.bndLabelWidth(-1, shipModel
.name
)+8;
462 float h
= BND_WIDGET_HEIGHT
+8;
463 float mx
= (GWidth
-w
)/2.0;
464 float my
= (GHeight
-h
)-8;
465 vg
.bndMenuBackground(mx
, my
, w
, h
, BND_CORNER_NONE
);
466 vg
.bndMenuItem(mx
+4, my
+4, w
-8, BND_WIDGET_HEIGHT
, BND_DEFAULT
, -1, shipModel
.name
);
467 if (shipModel
.dispName
&& shipModel
.dispName
!= shipModel
.name
) {
468 my
-= BND_WIDGET_HEIGHT
+16;
469 w
= vg
.bndLabelWidth(-1, shipModel
.dispName
)+8;
471 vg
.bndMenuBackground(mx
, my
, w
, h
, BND_CORNER_NONE
);
472 vg
.bndMenuItem(mx
+4, my
+4, w
-8, BND_WIDGET_HEIGHT
, BND_DEFAULT
, -1, shipModel
.dispName
);
476 void createSectionMenu () {
478 writeln("lc=", laytext
.lineCount
, "; bm: ", (bookmeta
!is null));
479 if (laytext
is null || laytext
.lineCount
== 0 || bookmeta
is null) { freeShipModel(); return; }
480 currPopup
= new PopupMenu(vg
, "Sections"d
, () {
482 foreach (const ref sc
; bookmeta
.sections
) items
~= sc
.name
;
485 writeln(currPopup
.items
.length
);
486 // find current section
487 currPopup
.curItemIdx
= 0;
488 auto lidx
= laytext
.findLineWithY(topY
);
489 if (lidx
>= 0 && bookmeta
.sections
.length
> 0) {
490 foreach (immutable sidx
, const ref sc
; bookmeta
.sections
) {
491 auto sline
= laytext
.findLineWithWord(sc
.wordidx
);
492 if (sline
>= 0 && lidx
>= sline
) currPopup
.curItemIdx
= cast(int)sidx
;
495 onPopupSelect
= (int item
) { gotoSection(item
); };
498 void createQuitMenu (bool wantYes
) {
500 currPopup
= new PopupMenu(vg
, "Quit?"d
, () {
501 return ["Yes"d
, "No"d
];
503 currPopup
.curItemIdx
= (wantYes ?
0 : 1);
504 onPopupSelect
= (int item
) { if (item
== 0) doQuit
= true; };
507 void createRecentMenu () {
509 if (recentFiles
.length
== 0) recentFiles
= loadDetailedHistory();
510 if (recentFiles
.length
== 0) { freeShipModel(); return; }
511 currPopup
= new PopupMenu(vg
, "Recent files"d
, () {
512 import std
.conv
: to
;
514 foreach (const ref BookInfo bi
; recentFiles
) {
516 if (bi
.seqname
.length
) {
518 if (bi
.seqnum
) { s
~= to
!string(bi
.seqnum
); s
~= ": "; }
519 //writeln(bi.seqname);
523 if (bi
.author
.length
) { s
~= " -- "; s
~= bi
.author
; }
528 currPopup
.curItemIdx
= cast(int)recentFiles
.length
-1;
529 onPopupSelect
= (int item
) {
530 newBookFileName
= recentFiles
[item
].diskfile
;
531 popupNoShipKill
= true;
535 bool menuKey (KeyEvent event
) {
536 if (formatWorks
!= 0) return false;
537 if (!inMenu
) return false;
538 if (inGalaxyMap
) return false;
539 if (!event
.pressed
) return false;
540 auto res
= currPopup
.onKey(event
);
541 if (res
== PopupMenu
.Close
) {
545 } else if (res
>= 0) {
546 if (onPopupSelect
!is null) onPopupSelect(res
);
548 if (popupNoShipKill
) popupNoShipKill
= false; else freeShipModel();
554 bool menuMouse (MouseEvent event
) {
555 if (formatWorks
!= 0) return false;
556 if (!inMenu
) return false;
557 if (inGalaxyMap
) return false;
558 auto res
= currPopup
.onMouse(event
);
559 if (res
== PopupMenu
.Close
) {
563 } else if (res
>= 0) {
564 if (onPopupSelect
!is null) onPopupSelect(res
);
566 if (popupNoShipKill
) popupNoShipKill
= false; else freeShipModel();
572 bool readerKey (KeyEvent event
) {
573 if (formatWorks
!= 0) return false;
574 if (!event
.pressed
) {
576 case Key
.Up
: arrowDir
= 0; return true;
577 case Key
.Down
: arrowDir
= 0; return true;
584 if (event
.modifierState
&ModifierState
.shift
) {
585 //goto case Key.PageUp;
586 hardScrollBy(toMove
); toMove
= 0;
587 scrollBy(-textHeight
/3*2);
589 //goto case Key.PageDown;
590 hardScrollBy(toMove
); toMove
= 0;
591 scrollBy(textHeight
/3*2);
598 hardScrollBy(toMove
); toMove
= 0;
599 hardScrollBy(-(textHeight
> 32 ? textHeight
-32 : textHeight
));
602 hardScrollBy(toMove
); toMove
= 0;
603 hardScrollBy(textHeight
> 32 ? textHeight
-32 : textHeight
);
621 bool controlKey (KeyEvent event
) {
622 if (!event
.pressed
) return false;
625 if (inGalaxyMap
) { inGalaxyMap
= false; refresh(); return true; }
626 if (inMenu
) { closeMenu(); freeShipModel(); refresh(); return true; }
627 if (showShip
) { showShip
= false; freeShipModel(); refresh(); return true; }
629 createQuitMenu(true);
632 case Key
.P
: if (event
.modifierState
== ModifierState
.ctrl
) { fpsVisible
= !fpsVisible
; refresh(); return true; } break;
633 case Key
.I
: if (event
.modifierState
== ModifierState
.ctrl
) { interAllowed
= !interAllowed
; refresh(); return true; } break;
634 case Key
.N
: if (event
.modifierState
== ModifierState
.ctrl
) { sbLeft
= !sbLeft
; refresh(); return true; } break;
635 case Key
.C
: if (event
.modifierState
== ModifierState
.ctrl
) { if (addIf()) refresh(); return true; } break;
637 if (event
.modifierState
== ModifierState
.ctrl
&& eliteShipFiles
.length
> 0) {
639 showShip
= !showShip
;
640 if (showShip
) ensureShipModel(); else freeShipModel();
646 case Key
.Q
: if (event
.modifierState
== ModifierState
.ctrl
) { doQuit
= true; return true; } break;
647 case Key
.B
: if (formatWorks
== 0 && !inMenu
&& !inGalaxyMap
&& event
.modifierState
== ModifierState
.ctrl
) { pushPosition(); return true; } break;
649 if (formatWorks
== 0 && !showShip
&& !inMenu
&& !inGalaxyMap
) {
656 if (formatWorks
== 0 && event
.modifierState
== ModifierState
.alt
) {
663 if (!inMenu
&& !showShip
) {
664 inGalaxyMap
= !inGalaxyMap
;
669 if (formatWorks
== 0 && event
.modifierState
== ModifierState
.ctrl
) relayout(true);
671 case Key
.Home
: if (showShip
) { setShip(0); return true; } break;
672 case Key
.End
: if (showShip
) { setShip(cast(int)eliteShipFiles
.length
); return true; } break;
673 case Key
.Up
: case Key
.Left
: if (showShip
) { setShip(shipModelIndex
-1); return true; } break;
674 case Key
.Down
: case Key
.Right
: if (showShip
) { setShip(shipModelIndex
+1); return true; } break;
680 sdwindow
.redrawOpenGlScene
= delegate () {
684 curt
= MonoTime
.currTime
;
685 secs
= cast(double)((curt
-stt
).total
!"msecs")/1000.0;
686 dt = cast(double)((curt
-prevt
).total
!"msecs")/1000.0;
688 //glClearColor(0, 0, 0, 0);
689 //glClearColor(0.18, 0.18, 0.18, 0);
690 glClearColor(colorBack
.r
, colorBack
.g
, colorBack
.b
, 0);
691 glClear(glNVGClearFlags|EliteModel
.glClearFlags
);
694 needRedrawFlag
= (fps
!is null && fpsVisible
);
695 if (fps
!is null) fps
.update(dt);
696 if (vg
is null) return;
698 vg
.beginFrame(GWidth
, GHeight
, 1);
702 float curHeight
= (laytext
!is null ? topY
: 0);
703 float th
= (laytext
!is null ? laytext
.textHeight
-textHeight
: 0);
704 if (th
<= 0) { curHeight
= 0; th
= 1; }
705 float sz
= cast(float)(GHeight
-4)/th
;
706 if (sz
> 1) sz
= 1; else if (sz
< 0.05) sz
= 0.05;
707 int sx
= (sbLeft ?
2 : GWidth
-BND_SCROLLBAR_WIDTH
-2);
708 vg
.bndScrollBar(sx
, 2, BND_SCROLLBAR_WIDTH
, GHeight
-4, BND_DEFAULT
, curHeight
/th
, sz
);
710 if (laytext
is null) {
711 if (shipModel
is null) {
713 vg
.fillColor(colorText
);
714 int drawY
= (GHeight
-textHeight
)/2;
715 vg
.intersectScissor((sbLeft ?
2+BND_SCROLLBAR_WIDTH
+2 : 4), drawY
, GWidth
-4-2-BND_SCROLLBAR_WIDTH
-2, textHeight
);
716 vg
.fontFaceId(textFont
);
717 vg
.fontSize(fsizeText
);
718 vg
.textAlign(NVGAlign
.Center|NVGAlign
.Middle
);
719 vg
.text(GWidth
/2, GHeight
/2, "REFORMATTING");
724 if (laytext
!is null && laytext
.lineCount
) {
726 vg
.fillColor(colorText
);
727 int drawY
= (GHeight
-textHeight
)/2;
728 vg
.intersectScissor((sbLeft ?
2+BND_SCROLLBAR_WIDTH
+2 : 4), drawY
, GWidth
-4-2-BND_SCROLLBAR_WIDTH
-2, textHeight
);
729 //FIXME: not GHeight!
730 int lidx
= laytext
.findLineWithY(topY
);
731 if (lidx
>= 0 && lidx
< laytext
.lineCount
) {
732 drawY
-= topY
-laytext
.line(lidx
).y
;
733 vg
.textAlign(NVGAlign
.Left|NVGAlign
.Baseline
);
734 LayFontStyle lastStyle
;
735 int startx
= (sbLeft ?
2+BND_SCROLLBAR_WIDTH
+2 : 4);
736 while (lidx
< laytext
.lineCount
&& drawY
< GHeight
) {
737 auto ln
= laytext
.line(lidx
);
738 foreach (ref LayWord w
; laytext
.lineWords(lidx
)) {
739 if (lastStyle
!= w
.style
) {
740 if (w
.style
.fontface
!= lastStyle
.fontface
) {
741 vg
.fontFace(laytext
.fontFace(w
.style
.fontface
));
743 vg
.fontSize(w
.style
.fontsize
);
744 auto c
= NVGColor(w
.style
.color
);
750 if (newYFade
&& newYLine
== lidx
) vg
.fillColor(nvgLerpRGBA(colorText
, colorTextHi
, newYAlpha
));
751 vg
.text(startx
+w
.x
, drawY
+ln
.h
+ln
.desc
, laytext
.wordText(w
));
752 //TODO: draw lines over whitespace
753 if (lastStyle
.underline
) vg
.rect(startx
+w
.x
, drawY
+ln
.h
+ln
.desc
+1, w
.w
, 1);
754 if (lastStyle
.strike
) vg
.rect(startx
+w
.x
, drawY
+ln
.h
+ln
.desc
-w
.asc
/2, w
.w
, 1);
755 if (lastStyle
.overline
) vg
.rect(startx
+w
.x
, drawY
+ln
.h
+ln
.desc
-w
.asc
-1, w
.w
, 1);
756 version(debug_draw
) {
760 vg
.strokeColor(nvgRGB(0, 0, 255));
761 vg
.rect(startx
+w
.x
, drawY
, w
.w
, w
.h
);
765 if (newYFade
&& newYLine
== lidx
) vg
.fillColor(NVGColor(lastStyle
.color
));
775 if (colorDim
.a
!= 1) {
776 //vg.scissor(0, 0, GWidth, GHeight);
779 vg
.fillColor(colorDim
);
780 vg
.rect(0, 0, GWidth
, GHeight
);
784 // dim more if menu is active
785 if (inMenu || showShip || formatWorks
!= 0) {
786 //vg.scissor(0, 0, GWidth, GHeight);
789 //vg.globalAlpha(0.5);
790 vg
.fillColor(nvgRGBA(0, 0, 0, (showShip || formatWorks
!= 0 ?
127 : 64)));
791 vg
.rect(0, 0, GWidth
, GHeight
);
795 if (shipModel
!is null) {
796 float zz
= shipModel
.bbox
[1].z
-shipModel
.bbox
[0].z
;
810 drawModel(shipAngle
, shipModel
);
811 vg
.beginFrame(GWidth
, GHeight
, 1);
815 if (formatWorks
== 0) {
817 vg
.beginFrame(GWidth
, GHeight
, 1);
818 //vg.scissor(0, 0, GWidth, GHeight);
824 if (fps
!is null && fpsVisible
) {
825 vg
.beginFrame(GWidth
, GHeight
, 1);
826 //vg.scissor(0, 0, GWidth, GHeight);
828 fps
.render(vg
, GWidth
-fps
.width
-4, GHeight
-fps
.height
-4);
831 if (inGalaxyMap
) drawGalaxy(vg
);
833 if (curImg
>= 0 && !mouseHidden
) {
835 vg
.beginFrame(GWidth
, GHeight
, 1);
837 //vg.scissor(0, 0, GWidth, GHeight);
839 vg
.imageSize(curImg
, &w
, &h
);
840 vg
.fillPaint(vg
.imagePattern(mouseX
, mouseY
, w
, h
, 0, curImg
, 1));
841 vg
.rect(mouseX
, mouseY
, w
, h
);
847 void processThreads () {
848 ReformatWorkComplete wd
;
850 bool workDone
= false;
851 auto res
= receiveTimeout(Duration
.zero
,
855 (ReformatWorkComplete w
) {
860 if (!res
) { assert(!workDone
); break; }
861 if (workDone
) { workDone
= false; formatComplete(wd
); }
865 sdwindow
.eventLoop(1000/35,
868 if (sdwindow
.closed
) return;
869 if (doQuit
) { closeWindow(); return; }
870 auto ctt
= MonoTime
.currTime
;
872 if (formatWorks
== 0) {
876 if (sc
> Delta
) sc
= Delta
;
879 nextFadeTime
= ctt
+500.msecs
;
880 } else if (toMove
> 0) {
882 if (sc
> Delta
) sc
= Delta
;
885 nextFadeTime
= ctt
+500.msecs
;
886 } else if (arrowDir
) {
887 hardScrollBy(arrowDir
*6*2);
891 if (ctt
>= nextFadeTime
) {
892 if ((newYAlpha
-= 0.1) <= 0) {
895 nextFadeTime
= ctt
+25.msecs
;
901 // interference processing
902 if (ctt
>= nextIfTime
) {
903 import std
.random
: uniform
;
904 if (uniform
!"[]"(0, 100) >= 50) { if (addIf()) refresh(); }
905 nextIfTime
+= (uniform
!"[]"(50, 1500)).msecs
;
907 if (processIfs()) refresh();
909 if (shipModel
!is null) {
911 if (shipAngle
< 359) shipAngle
+= 360;
916 if ((ctt
-lastMMove
).total
!"msecs" > 2500) {
921 if (needRedraw
) sdwindow
.redrawOpenGlSceneNow();
924 if (newBookFileName
.length
&& formatWorks
== 0) {
925 doSaveState(true); // forced state save
928 loadAndFormat(newBookFileName
);
929 newBookFileName
= null;
930 sdwindow
.redrawOpenGlSceneNow();
934 delegate (KeyEvent event
) {
935 if (sdwindow
.closed
) return;
936 if (event
.key
== Key
.PadEnter
) event
.key
= Key
.Enter
;
937 if ((event
.modifierState
&ModifierState
.numLock
) == 0) {
939 case Key
.Pad0
: event
.key
= Key
.Insert
; break;
940 case Key
.PadDot
: event
.key
= Key
.Delete
; break;
941 case Key
.Pad1
: event
.key
= Key
.End
; break;
942 case Key
.Pad2
: event
.key
= Key
.Down
; break;
943 case Key
.Pad3
: event
.key
= Key
.PageDown
; break;
944 case Key
.Pad4
: event
.key
= Key
.Left
; break;
945 case Key
.Pad6
: event
.key
= Key
.Right
; break;
946 case Key
.Pad7
: event
.key
= Key
.Home
; break;
947 case Key
.Pad8
: event
.key
= Key
.Up
; break;
948 case Key
.Pad9
: event
.key
= Key
.PageUp
; break;
949 //case Key.PadEnter: event.key = Key.Enter; break;
953 if (controlKey(event
)) return;
954 if (menuKey(event
)) return;
955 if (readerKey(event
)) return;
957 delegate (MouseEvent event
) {
958 lastMMove
= MonoTime
.currTime
;
963 if (mouseX
!= event
.x || mouseY
!= event
.y
) {
970 delegate (dchar ch
) {
971 //if (ch == 'q') { doQuit = true; return; }
976 childTid
.send(QuitWork());
977 while (formatWorks
>= 0) processThreads();
981 // ////////////////////////////////////////////////////////////////////////// //
982 void main (string
[] args
) {
984 RcDir
= RcDir
.expandTilde
.absolutePath
;
987 universe
= Galaxy(0);
989 if (args
.length
== 1) {
992 foreach (string line
; VFile(buildPath(RcDir
, ".lastfile")).byLineCopy
) {
993 if (!line
.isComment
) lnn
= line
;
995 if (lnn
.length
) args
~= lnn
;
996 } catch (Exception
) {}
998 if (args
.length
== 1) assert(0, "no filename");