/ИНТЕРФЕЙСЫ/ATA/Орфей/soft_all/soft/chars/dialogs.pp

https://bitbucket.org/Alchemist197/elektronika-osnovnoe · Puppet · 217 lines · 191 code · 26 blank · 0 comment · 18 complexity · 2b8a93a5b8fe7464be7c3f9b0742c6d2 MD5 · raw file

  1. unit Dialogs;
  2. interface
  3. uses Inferno, Alf, Mikky, X, XLib, XUtil, VGAColors, Ini;
  4. type
  5. TdgType = (dgDivider, dgRemark, dgBoolean, dgString, dgInt, dgOk, dgCancel, dgRadio);
  6. TdgItem = Record
  7. st : String;
  8. bC, fC : LongInt;
  9. ms : RngMouseArea;
  10. case tp : TdgType of
  11. dgDivider : ();
  12. dgRemark : ();
  13. dgBoolean : (vl_b: Boolean);
  14. dgString : (vl_s: String);
  15. dgInt : (vl_i: LongInt);
  16. dgOk,
  17. dgCancel : (res : Boolean);
  18. dgRadio : (id_l, vl_l: LongInt);
  19. end;
  20. function Dialog(var d: Array of TdgItem): Boolean;
  21. implementation
  22. type
  23. ExitState = (esNo, esRetOk, esRetEsc);
  24. const
  25. FontItem : AnsiString = '-*-*-medium-r-*-*-15-*-*-*-*-*-koi8-*';
  26. FontEnSt : AnsiString = '-*-*-medium-o-*-*-17-*-*-*-*-*-koi8-*';
  27. BorderX = 8; // -
  28. BorderY = 8;
  29. iBorderX = 4; //
  30. iBorderY = 4;
  31. OffsetY = 15;
  32. MaxStrX = 100; //
  33. OfsStrX = 20; //
  34. ColB = 12; // Boolean
  35. var
  36. Wnd : TWindow;
  37. Event : TXEvent;
  38. GC : TGC;
  39. xl, yl, maxX : LongInt;
  40. DrawNeed : Boolean;
  41. procedure DrawDiv(const Wnd: TWindow; var GC: TGC; const Colors: TColors; var dt);
  42. begin with TdgItem(dt) do begin
  43. xl := 0; yl := 5;
  44. end end;
  45. procedure DrawRem(const Wnd: TWindow; var GC: TGC; const Colors: TColors; var dt);
  46. begin with TdgItem(dt) do begin
  47. AlfSetFont(GC, fontItem);
  48. xl := AlfWidth(st) + iBorderX*2;
  49. yl := AlfHeight(st) + iBorderY*2;
  50. if DrawNeed then begin
  51. XSetWindowBorder(prDisplay, Wnd, Colors[0]);
  52. XSetWindowBackGround(prDisplay, Wnd, Colors[bC]);
  53. AlfCenter := True;
  54. AlfOutTextXY(Wnd, GC, maxX div 2, iBorderY, st);
  55. AlfCenter := False;
  56. end;
  57. end end;
  58. procedure DrawBool(const Wnd: TWindow; var GC: TGC; const Colors: TColors; var dt);
  59. begin with TdgItem(dt) do begin
  60. AlfSetFont(GC, fontItem);
  61. yl := AlfHeight(st) + iBorderY*2;
  62. xl := AlfWidth(st) + yl + iBorderX*2;;
  63. if DrawNeed then begin
  64. XSetWindowBackground(prDisplay, Wnd, Colors[bC]);
  65. XSetForeGround(prDisplay, GC, Colors[bC]);
  66. XFillRectangle(prDisplay, Wnd, GC, 0, 0, yl, yl);
  67. XSetForeGround(prDisplay, GC, Colors[fC]);
  68. XDrawRectangle(prDisplay, Wnd, GC, iBorderX, iBorderY, yl - iBorderX*2, yl - iBorderY*2);
  69. AlfOutTextXY(Wnd, GC, yl + iBorderX, iBorderY, st);
  70. if vl_b then begin
  71. XSetForeGround(prDisplay, GC, Colors[ColB]);
  72. XDrawLine(prDisplay, Wnd, GC, 2 + iBorderX, 5 + iBorderY, (yl - iBorderX*2) div 2 + iBorderX, iBorderY + yl - iBorderY*2);
  73. XDrawLine(prDisplay, Wnd, GC, (yl - iBorderX*2) div 2 + iBorderX, iBorderY + yl - iBorderY*2, iBorderX + yl - iBorderX*2, 0);
  74. end;
  75. end;
  76. end end;
  77. procedure CommonDrawStr(const Wnd: TWindow; var GC: TGC; const Colors: TColors; var dt; const s: String);
  78. var ey, i: LongInt;
  79. begin with TdgItem(dt) do begin
  80. AlfSetFont(GC, fontItem);
  81. yl := AlfHeight(st) + iBorderY*2;
  82. xl := AlfWidth(st) + MaxStrX + OfsStrX + iBorderX*2;
  83. AlfSetFont(GC, fontEnSt);
  84. ey := AlfHeight(s) + iBorderY*2;
  85. if yl < ey then yl := ey;
  86. if DrawNeed then begin
  87. AlfOutTextXY(Wnd, GC, iBorderX, iBorderY, '');
  88. for i := 1 to Length(s) do if AlfX + AlfWidth(s[i]) < MaxStrX then AlfOutText(Wnd, GC, s[i]) else break;
  89. AlfSetFont(GC, fontItem);
  90. AlfOutTextXY(Wnd, GC, MaxStrX + OfsStrX + iBorderX, iBorderY, st);
  91. end;
  92. end end;
  93. procedure DrawStr(const Wnd: TWindow; var GC: TGC; const Colors: TColors; var dt);
  94. begin
  95. CommonDrawStr(Wnd, GC, Colors, dt, TdgItem(dt).vl_s);
  96. end;
  97. procedure DrawInt(const Wnd: TWindow; var GC: TGC; const Colors: TColors; var dt);
  98. begin
  99. CommonDrawStr(Wnd, GC, Colors, dt, ValToStrG(TdgItem(dt).vl_i));
  100. end;
  101. procedure DrawBut(const Wnd: TWindow; var GC: TGC; const Colors: TColors; var dt);
  102. begin with TdgItem(dt) do begin
  103. AlfSetFont(GC, fontItem);
  104. xl := AlfWidth(st) + iBorderX * 2;
  105. yl := AlfHeight(st) + iBorderY * 2;
  106. if DrawNeed then begin
  107. XSetWindowBackGround(prDisplay, Wnd, Colors[bC]);
  108. AlfCenter := True;
  109. AlfOutTextXY(Wnd, GC, maxX div 2, iBorderY, st);
  110. AlfCenter := False;
  111. end;
  112. end end;
  113. procedure DrawRadio(const Wnd: TWindow; var GC: TGC; const Colors: TColors; var dt);
  114. begin
  115. runerror(245);
  116. end;
  117. const
  118. DrawProc : Array[TdgType] of TButDrawProc = (@DrawDiv, @DrawRem, @DrawBool, @DrawStr, @DrawInt, @DrawBut, @DrawBut, @DrawRadio);
  119. procedure MouseRegDlg(var d: Array of TdgItem);
  120. var i, x, y: LongInt; Col: TColors;
  121. begin
  122. DrawNeed := False;
  123. maxX := 0;
  124. For i := Low(d) to High(d) do With d[i] do begin
  125. DrawProc[tp](Wnd, GC, Col, d[i]);
  126. if xl > maxX then maxX := xl;
  127. end;
  128. y := BorderY;
  129. For i := Low(d) to High(d) do With d[i] do begin
  130. DrawProc[tp](Wnd, GC, Col, d[i]);
  131. if tp <> dgDivider then begin
  132. NewMouseArea(Wnd, ms);
  133. SetMouseArea(ms, msActive, BorderX, y, maxX, yl, fC, bC, '', DefaultMouseCursor);
  134. SetMouseRoutines(ms, DrawProc[tp], d[i], Nil, Nil, Nil);
  135. end;
  136. if tp in [dgCancel, dgOk] then res := False;
  137. inc(y, yl + OffsetY);
  138. end;
  139. x := maxX + BorderX*2; y := y - OffsetY + BorderY;
  140. XMoveResizeWindow(prDisplay, Wnd, (GetMaxX - x) div 2, (GetMaxY - y) div 2, x, y);
  141. DrawNeed := True;
  142. end;
  143. function MouseProc(var d: Array of TdgItem): ExitState;
  144. var i: LongInt;
  145. begin
  146. MouseProc := esNo;
  147. For i := Low(d) to High(d) do With d[i] do if MouseInArea(ms) then case tp of
  148. dgBoolean : begin vl_b := not vl_b; DrawButton(ms) end;
  149. dgString : begin if AlfEnterString(vl_s, st + ': ', MouseXroot, MouseYroot) then else DrawButton(ms) end;
  150. dgInt : begin if AlfEnterValue (vl_i, st + ': ', MouseXroot, MouseYroot) then else DrawButton(ms) end;
  151. dgOk : begin res := True; MouseProc := esRetOk end;
  152. dgCancel : begin res := True; MouseProc := esRetEsc end;
  153. end;
  154. end;
  155. procedure MouseUnRegDlg(var d: Array of TdgItem);
  156. var i: LongInt;
  157. begin
  158. For i := Low(d) to High(d) do With d[i] do if tp <> dgDivider then SetMouseArea(ms, msFree, 1, 1, 1, 1, 0, 0, '', DefaultMouseCursor);
  159. end;
  160. function Dialog(var d: Array of TdgItem): Boolean;
  161. var fn: ExitState;
  162. begin
  163. NewRootWindow(1, 1, 1, 1, 1, 1, '', '', Wnd);
  164. GC := XCreateGC(prDisplay, Wnd, 0, Nil);
  165. MouseRegDlg(d);
  166. fn := esNo;
  167. Repeat
  168. FlTmWithPause(Event, True);
  169. case Event.EventType of
  170. // Expose:
  171. DeleteNotify: fn := esRetEsc;
  172. KeyPress: case KeyInResult of
  173. XK_Return: fn := esRetOk;
  174. XK_Escape: fn := esRetEsc;
  175. end;
  176. ButtonRelease: // Dialog buttonpress=0. ButtonRelease
  177. fn := MouseProc(d);
  178. end;
  179. Until fn <> esNo;
  180. MouseUnRegDlg(d);
  181. XFreeGC(prDisplay, GC);
  182. XDestroyWindow(prDisplay, Wnd);
  183. Dialog := fn = esRetOk;
  184. KeyInResult := 0;
  185. end;
  186. begin
  187. IniOpen('Dialog');
  188. IniGet('FontItem', FontItem);
  189. IniGet('FontVarString', FontEnSt);
  190. IniClose;
  191. end.