mixster

Untitled

Jun 30th, 2010
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 14.74 KB | None | 0 0
  1. program MSIForm;
  2.  
  3. const
  4.  
  5.  
  6.   PANEL_COUNT = 5;
  7.     PANEL_1   = 0;
  8.     PANEL_2   = 1;
  9.     PANEL_3   = 2;
  10.     PANEL_4   = 3;
  11.     PANEL_5   = 4;
  12.  
  13.  
  14.   IMG_COUNT = 23;
  15.     // Used in frmMain
  16.     IMG_BGND            = 0;
  17.     IMG_X_NORM          = 1;
  18.     IMG_Q_NORM          = 2;
  19.     IMG_LOAD_TAB_NORM   = 3;
  20.     IMG_SAVE_TAB_NORM   = 4;
  21.     IMG_TAB_NORM_1      = 5;
  22.     IMG_TAB_NORM_2      = 6;
  23.     IMG_TAB_NORM_3      = 7;
  24.     IMG_TAB_NORM_4      = 8;
  25.  
  26.     IMG_LOC_MAP         = 9;
  27.     IMG_LOC_NAV         = 10;
  28.     IMG_LOC_EXIT_NORM   = 11;
  29.     IMG_LOC_BORD_TOP    = 12;
  30.     IMG_LOC_BORD_BOTTOM = 13;
  31.     IMG_LOC_BORD_LEFT   = 14;
  32.     IMG_LOC_BORD_RIGHT  = 15;
  33.     IMG_LOC_BOX_TOP     = 16;
  34.     IMG_LOC_BOX_LEFT    = 17;
  35.     IMG_LOC_BOX_RIGHT   = 18;
  36.     IMG_LOC_BOX_BOTTOM  = 19;
  37.  
  38.     // Used in Panel 0 (Is also used for frmMain)
  39.     IMG_LOC_ICON_NORM   = 20;
  40.     IMG_LOC_LABEL       = 21;
  41.     IMG_TAB_HINT        = 22;
  42.  
  43.     // Used in Panel 1
  44.  
  45.     // Used in Panel 2
  46.  
  47.     // Used in Panel 3
  48.  
  49.     // Used in Panel 4
  50.  
  51.   BITMAP_COUNT = 31;
  52.     BGND            = 0;
  53.     X_NORM          = 1;
  54.     X_HOVER         = 2;
  55.     Q_NORM          = 3;
  56.     Q_HOVER         = 4;
  57.     LOAD_TAB_NORM   = 5;
  58.     LOAD_TAB_HOVER  = 6;
  59.     SAVE_TAB_NORM   = 7;
  60.     SAVE_TAB_HOVER  = 8;
  61.     TAB_NORM_1      = 9;
  62.     TAB_HOVER_1     = 10;
  63.     TAB_NORM_2      = 11;
  64.     TAB_HOVER_2     = 12;
  65.     TAB_NORM_3      = 13;
  66.     TAB_HOVER_3     = 14;
  67.     TAB_NORM_4      = 15;
  68.     TAB_HOVER_4     = 16;
  69.     LOC_ICON_NORM   = 17;
  70.     LOC_ICON_HOVER  = 18;
  71.     LOC_EXIT_NORM   = 19;
  72.     LOC_EXIT_HOVER  = 20;
  73.     LOC_MAP         = 21;
  74.     LOC_NAV         = 22;
  75.     LOC_BORD_TOP    = 23;
  76.     LOC_BORD_BOTTOM = 24;
  77.     LOC_BORD_LEFT   = 25;
  78.     LOC_BORD_RIGHT  = 26;
  79.     LOC_BOX_TOP     = 27;
  80.     LOC_BOX_LEFT    = 28;
  81.     LOC_LABEL       = 29;
  82.     TAB_HINT        = 30;
  83.  
  84. var
  85.   frmMain: TForm;
  86.   time: TTimer;
  87.  
  88.   tImages: Array[0..IMG_COUNT - 1] of TImage;
  89.  
  90.   frmBitmaps: Array [0..BITMAP_COUNT - 1] of Integer;
  91.  
  92.   isActiveImage: Array[0..IMG_COUNT - 1] of Boolean;
  93.   isLeftTab: Array[IMG_TAB_NORM_1..IMG_TAB_NORM_4] of Boolean;
  94.   isActivePanel: Array[0..PANEL_COUNT - 1] of Boolean;
  95.  
  96.   MapDragStartX, MapDragStartY: Integer;
  97.  
  98.  
  99. procedure OutsideBox(l,t,r,b, obj: integer);
  100. begin
  101.   if tImages[obj].Left > l then
  102.     tImages[obj].Left := l;
  103.   if tImages[obj].Top > t then
  104.     tImages[obj].Top := t;
  105.   if tImages[obj].Left < r then
  106.     tImages[obj].Left := r;
  107.   if tImages[obj].Top < b then
  108.     tImages[obj].Top := b;
  109. end;
  110.  
  111. procedure OnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  112. var
  113.   BoundL, BoundT: Extended;
  114. begin
  115.   case sender of
  116.     tImages[IMG_LOC_MAP]:
  117.       begin
  118.         MapDragStartX := x;
  119.         MapDragStartY := y;
  120.       end;
  121.     tImages[IMG_LOC_NAV]:
  122.       begin
  123.         GetMousePos(x, y);
  124.         with tImages[IMG_LOC_BOX_TOP] do
  125.           SetBounds({L} x + (x - left), {T} y + (y - top), {W} 83, {H} 1);
  126.  
  127.         OutsideBox(494,322,376, 216, IMG_LOC_BOX_TOP);
  128.  
  129.         with tImages[IMG_LOC_BOX_LEFT] do
  130.           SetBounds({L} tImages[IMG_LOC_BOX_TOP].Left, {T} tImages[IMG_LOC_BOX_TOP].Top + 1, {W} 1, {H} 55);
  131.         with tImages[IMG_LOC_BOX_RIGHT] do
  132.           SetBounds({L} tImages[IMG_LOC_BOX_TOP].Left + 83, {T} tImages[IMG_LOC_BOX_TOP].Top + 1, {W} 1, {H} 55);
  133.         with tImages[IMG_LOC_BOX_BOTTOM] do
  134.           SetBounds({L} tImages[IMG_LOC_BOX_TOP].Left, {T} tImages[IMG_LOC_BOX_TOP].Top + 55, {W} 83, {H} 1);
  135.  
  136.         BoundL := -(x - 155 - 376) * 7.234;
  137.         BoundT := -(y - 140 - 216) * 7.234;
  138.  
  139.         tImages[IMG_LOC_MAP].Left := Round(BoundL);
  140.         tImages[IMG_LOC_MAP].Top := Round(BoundT);
  141.  
  142.         OutsideBox(0,0,-345, -354, IMG_LOC_MAP);
  143.       end;
  144.   end;
  145. end;
  146.  
  147. var sended: Tobject;
  148. accel, move: integer;
  149. {move, }cons: array [0..4] of integer;
  150. procedure TimerTabClick(Sender: TObject);
  151. var
  152.   senderTab, i, CurrentPanel, e, temp, d, top, bottom, diff: Integer;
  153.   truth: boolean;
  154. begin
  155.   for i := IMG_TAB_NORM_1 to IMG_TAB_NORM_4 do
  156.     if (Sended = tImages[i]) then
  157.       senderTab := i;
  158.  
  159.   if isLeftTab[senderTab] then
  160.   begin
  161.     d := 1
  162.     top := IMG_TAB_NORM_4
  163.     bottom := senderTab
  164.     truth := true;
  165.   end else
  166.   begin
  167.     d := -1;
  168.     top := senderTab
  169.     bottom :=  IMG_TAB_NORM_1
  170.     truth := false;
  171.   end;
  172.   diff := top - bottom;
  173.  
  174.   for i := top to bottom do
  175.   begin
  176.     if isLeftTab[i] = truth then
  177.     begin
  178.       if move = 0 then
  179.         for e := 0 to diff do
  180.             cons[e] := tImages[senderTab + e].Left;
  181.       if temp = 0 then
  182.       begin
  183.         accel := accel - 2 * d;
  184.         move := move + accel;
  185.       end;
  186.       tImages[i].Left := tImages[i].Left + accel * d;
  187.       temp := 1;
  188.     end;
  189.   end;
  190.     if move >= 380 then
  191.     begin
  192.       for e := 0 to diff do
  193.         if isLeftTab[bottom + e] = truth then
  194.         begin
  195.           tImages[bottom + e].Left := cons[e] + 380 * d;
  196.           isLeftTab[bottom + e] := not truth;
  197.         end;
  198.       move := 0;
  199.       time.ENABLED := false;
  200.     end;
  201.   CurrentPanel := sendertab - IMG_TAB_NORM_1;
  202.  
  203.   for i := PANEL_1 to PANEL_5 do
  204.     isActivePanel[i] := i = CurrentPanel;
  205.  
  206.   //WriteLn(CurrentPanel);
  207.  
  208.   for i := IMG_LOC_ICON_NORM to IMG_TAB_HINT do
  209.     tImages[i].Visible := isActivePanel[PANEL_1];
  210. end;
  211.  
  212. procedure TabClick(Sender: TObject);
  213. begin
  214.   if not time.ENABLED then
  215.   begin
  216.     accel := 0;
  217.     time.enabled := not time.enabled;
  218.     sended := Sender;
  219.   end;
  220. end;
  221.  
  222. procedure LocViewer(Sender: TObject);
  223. var i: Integer;
  224. begin
  225.   case Sender of
  226.     tImages[IMG_LOC_ICON_NORM]:
  227.     begin
  228.       for i := IMG_LOC_MAP to IMG_LOC_BOX_BOTTOM do
  229.         tImages[i].Visible := True;
  230.       for i := IMG_LOC_ICON_NORM to IMG_TAB_HINT do
  231.         tImages[i].Visible := False;
  232.     end;
  233.  
  234.     tImages[IMG_LOC_EXIT_NORM]:
  235.     begin
  236.       for i := IMG_LOC_MAP to IMG_LOC_BOX_BOTTOM do
  237.         tImages[i].Visible := False;
  238.       for i := IMG_LOC_ICON_NORM to IMG_TAB_HINT do
  239.         tImages[i].Visible := isActivePanel[PANEL_1];
  240.     end;
  241.   end;
  242. end;
  243.  
  244. procedure Clicked(Sender: TObject);
  245. var
  246.   i: Integer;
  247. begin
  248.   for i := 0 to BITMAP_COUNT - 1 do
  249.     FreeBitmap(frmBitmaps[i]);
  250.   frmMain.ModalResult := mrOk;
  251. end;
  252.  
  253. procedure MouseMoved(Sender: TObject; Shift: TShiftState; x, y: Integer);
  254. var
  255.   hi, i, bmp, xdif, ydif, h: Integer;
  256.   BoundL, BoundT: Extended;
  257.   imgSwap, bmpArr, imgArr: Array of Integer;
  258. begin
  259.   bmpArr := [ X_NORM, Q_NORM, LOAD_TAB_NORM,
  260.               SAVE_TAB_NORM, TAB_NORM_1, TAB_NORM_2,
  261.               TAB_NORM_3, TAB_NORM_4, LOC_ICON_NORM, LOC_EXIT_NORM ]
  262.  
  263.   imgArr := [ IMG_X_NORM, IMG_Q_NORM, IMG_LOAD_TAB_NORM,
  264.               IMG_SAVE_TAB_NORM, IMG_TAB_NORM_1, IMG_TAB_NORM_2,
  265.               IMG_TAB_NORM_3, IMG_TAB_NORM_4, IMG_LOC_ICON_NORM, IMG_LOC_EXIT_NORM ]
  266.   hi := High(bmpArr);
  267.   case Sender of
  268.     tImages[IMG_BGND], tImages[IMG_LOC_MAP]:
  269.       begin
  270.         for i := 0 to hi do
  271.         begin
  272.           if (not isActiveImage[imgArr[i]]) then
  273.             Continue;
  274.  
  275.           bmp := frmBitmaps[bmpArr[i]];
  276.           DrawBitmap(bmp,tImages[imgArr[i]].Canvas,0,0);
  277.           isActiveImage[imgArr[i]] := False;
  278.         end;
  279.       end;
  280.   end;
  281.   for h := 0 to hi do
  282.     case Sender of
  283.       tImages[imgArr[h]]:
  284.         begin
  285.           imgSwap := [imgArr[h], frmBitmaps[bmpArr[h] + 1]];
  286.           if not (isActiveImage[imgSwap[0]]) then
  287.           begin
  288.             DrawBitmap(imgSwap[1],tImages[imgSwap[0]].Canvas,0,0);
  289.             isActiveImage[imgSwap[0]] := True;
  290.             for i := 0 to hi do
  291.             begin
  292.               if (not isActiveImage[imgArr[i]]) then
  293.                 Continue;
  294.               if (i = imgSwap[0] - 1) then
  295.                 Continue;
  296.               if imgSwap[0] = IMG_LOC_EXIT_NORM then
  297.                 if (i = imgSwap[0] - 2) then
  298.                   Continue;
  299.               if imgSwap[0] = IMG_LOC_ICON_NORM then
  300.                 if (i = imgSwap[0] - 12) then
  301.                   Continue;
  302.               bmp := frmBitmaps[bmpArr[i]];
  303.               DrawBitmap(bmp, tImages[imgArr[i]].Canvas,0,0);
  304.               isActiveImage[imgArr[i]] := False;
  305.             end;
  306.           end;
  307.       end;
  308.   end;
  309.   case sender of
  310.     tImages[IMG_LOC_MAP]:
  311.       begin
  312.         if not IsMouseButtonDown(1) then exit;
  313.         xdif := x - MapDragStartX;
  314.         ydif := y - MapDragStartY;
  315.         tImages[IMG_LOC_MAP].Left := tImages[IMG_LOC_MAP].Left + xdif;
  316.         tImages[IMG_LOC_MAP].Top := tImages[IMG_LOC_MAP].Top + ydif;
  317.  
  318.         OutsideBox(0,0,-854, -765, IMG_LOC_MAP);
  319.  
  320.         BoundL := -tImages[IMG_LOC_MAP].Left / 7.234 + 376;
  321.         BoundT := -tImages[IMG_LOC_MAP].Top / 7.234 + 216;
  322.  
  323.  
  324.         with tImages[IMG_LOC_BOX_TOP] do
  325.           SetBounds({L} Round(BoundL), {T} Round(BoundT), {W} 83, {H} 1);
  326.  
  327.         OutsideBox(494,322,376, 216, IMG_LOC_BOX_TOP);
  328.  
  329.         with tImages[IMG_LOC_BOX_LEFT] do
  330.           SetBounds({L} tImages[IMG_LOC_BOX_TOP].Left, {T} tImages[IMG_LOC_BOX_TOP].Top + 1, {W} 1, {H} 55);
  331.         with tImages[IMG_LOC_BOX_RIGHT] do
  332.           SetBounds({L} tImages[IMG_LOC_BOX_TOP].Left + 83, {T} tImages[IMG_LOC_BOX_TOP].Top + 1, {W} 1, {H} 55);
  333.         with tImages[IMG_LOC_BOX_BOTTOM] do
  334.           SetBounds({L} tImages[IMG_LOC_BOX_TOP].Left, {T} tImages[IMG_LOC_BOX_TOP].Top + 55, {W} 83, {H} 1);
  335.       end;
  336.     tImages[IMG_LOC_NAV]:
  337.       begin
  338.         if not IsMouseButtonDown(1) then exit;
  339.         GetMousePos(x, y);
  340.         with tImages[IMG_LOC_BOX_TOP] do
  341.           SetBounds({L} x - 55 - 100, {T} y - 40 - 100, {W} 83, {H} 1);
  342.  
  343.         OutsideBox(494,322,376, 216, IMG_LOC_BOX_TOP);
  344.  
  345.         with tImages[IMG_LOC_BOX_LEFT] do
  346.           SetBounds({L} tImages[IMG_LOC_BOX_TOP].Left, {T} tImages[IMG_LOC_BOX_TOP].Top + 1, {W} 1, {H} 55);
  347.         with tImages[IMG_LOC_BOX_RIGHT] do
  348.           SetBounds({L} tImages[IMG_LOC_BOX_TOP].Left + 83, {T} tImages[IMG_LOC_BOX_TOP].Top + 1, {W} 1, {H} 55);
  349.         with tImages[IMG_LOC_BOX_BOTTOM] do
  350.           SetBounds({L} tImages[IMG_LOC_BOX_TOP].Left, {T} tImages[IMG_LOC_BOX_TOP].Top + 55, {W} 83, {H} 1);
  351.  
  352.         BoundL := -(x - 155 - 376) * 7.234;
  353.         BoundT := -(y - 140 - 216) * 7.234;
  354.  
  355.         tImages[IMG_LOC_MAP].Left := Round(BoundL);
  356.         tImages[IMG_LOC_MAP].Top := Round(BoundT);
  357.  
  358.         OutsideBox(0, 0, -854, -765, IMG_LOC_MAP);
  359.       end;
  360.   end;
  361. end;
  362.  
  363. procedure OnClickEvents(Sender: TObject);
  364. begin
  365.   case Sender of
  366.     tImages[IMG_X_NORM]: Clicked(Sender);
  367.     tImages[IMG_TAB_NORM_1], tImages[IMG_TAB_NORM_2],tImages[IMG_TAB_NORM_3], tImages[IMG_TAB_NORM_4]: TabClick(Sender);
  368.     tImages[IMG_LOC_ICON_NORM], tImages[IMG_LOC_EXIT_NORM]: LocViewer(Sender);
  369.   end;
  370. end;
  371.  
  372. procedure InitForm;
  373. var
  374.   Image, bmp, hi, i: Integer;
  375.   consts: TintegerArray;
  376.   bmpArr: TStringArray;
  377.   xy, wh: TPointArray;
  378.   visibl: TBoolArray;
  379. begin
  380.   bmpArr := ['BGND','X_NORM','X_HOVER','Q_NORM','Q_HOVER','LOAD_TAB_NORM','LOAD_TAB_HOVER','SAVE_TAB_NORM','SAVE_TAB_HOVER','TAB_NORM_1','TAB_HOVER_1','TAB_NORM_2','TAB_HOVER_2','TAB_NORM_3','TAB_HOVER_3','TAB_NORM_4','TAB_HOVER_4','LOC_ICON_NORM','LOC_ICON_HOVER','LOC_EXIT_NORM','LOC_EXIT_HOVER','LOC_MAP','LOC_NAV','LOC_BORD_TOP','LOC_BORD_BOTTOM','LOC_BORD_LEFT','LOC_BORD_RIGHT','LOC_BOX_TOP','LOC_BOX_LEFT','LOC_LABEL','TAB_HINT'];
  381.   hi := High(frmBitmaps);
  382.   for i := 0 to hi do
  383.     frmBitmaps[i] := LoadBitmap(ScriptPath + 'Bitmaps\' + bmpArr[i] + '.png');
  384.  
  385.   {
  386.   MAIN FORM
  387.   }
  388.  
  389.   frmMain := TForm.Create(nil);
  390.   with frmMain do
  391.   begin
  392.     SetBounds({L} 100, {T} 100, {W} 600, {H} 400);
  393.     //Position := poScreenCenter;
  394.     //Width := 600;
  395.     //Height := 400;
  396.     BorderStyle := bsNone;
  397.   end;
  398.  
  399.   time := TTimer.Create(frmMain);
  400.   time.ONTIMER := @TimerTabClick;
  401.   time.INTERVAL := 10;
  402.   time.ENABLED := false;
  403.  
  404.   xy := [Point(0,0),     Point(575,7), Point(557,7), Point(7,69),  Point(81,69), Point(390,100), Point(440,100), Point(490,100), Point(540,100), Point(179,204), Point(-300,0),    Point(369,209), Point(475,7),  Point(0,0),   Point(0,393),    Point(0,7),    Point(593,7),   Point(Round( 300 / 7.234 + 376), 216), Point(Round( 300 / 7.234 + 376), 216 + 1), Point(Round( 300 / 7.234 + 376) + 83, 216 + 1), Point(Round( 300 / 7.234 + 376), 216 + 1 + 54), Point(156,250), Point(208,379)];
  405.   wh := [Point(600,400), Point(18,18), Point(18,18), Point(74,22), Point(74,22), Point(50,290),  Point(50,290),  Point(50,290),  Point(50,290),  Point(40,41),   Point(1454,1165), Point(215,175), Point(119,22), Point(600,7), Point(600,7),    Point(7,386),  Point(7,386),   Point(83, 1),                          Point(1,55),                               Point(1,55),                                    Point(83,1),                                    Point(87,11),   Point(174,10)];
  406.   visibl := [true,       true,         true,         true,         true,         true,           true,           true,           true,           true,           false,            false,          false,         false,        false,           false,         false,          false,                                 false,                                     false,                                          false,                                          true,           true];
  407.   consts := [BGND,       X_NORM,       Q_NORM,       LOAD_TAB_NORM,SAVE_TAB_NORM,TAB_NORM_1,     TAB_NORM_2,     TAB_NORM_3,     TAB_NORM_4,     LOC_ICON_NORM,  LOC_MAP,          LOC_NAV,        LOC_EXIT_NORM, LOC_BORD_TOP, LOC_BORD_BOTTOM, LOC_BORD_LEFT, LOC_BORD_RIGHT, LOC_BOX_TOP,                           LOC_BOX_LEFT,                              LOC_BOX_LEFT,                                  LOC_BOX_TOP,                                    LOC_LABEL,      TAB_HINT];
  408.   for Image := 0 to IMG_COUNT - 1 do
  409.   begin
  410.     tImages[Image] := TImage.Create(frmMain);
  411.     with tImages[Image] do
  412.     begin
  413.       Parent := frmMain;
  414.       SetBounds(xy[Image].x, xy[Image].y, wh[Image].x, wh[Image].y);
  415.       bmp := frmBitmaps[consts[image]];
  416.       OnMouseMove := @MouseMoved;
  417.       ONMOUSEDOWN := @OnMouseDown;
  418.       OnClick := @OnClickEvents;
  419.       isActiveImage[Image] := False;
  420.       if (Image > IMG_TAB_NORM_1) and (Image < IMG_TAB_NORM_4) then
  421.         isLeftTab[Image] := false;
  422.       visible := Visibl[Image];
  423.     end;
  424.   DrawBitmap(bmp, tImages[Image].canvas, 0, 0);
  425.   end;
  426.  
  427.   isActivePanel[Panel_1] := True;
  428.   for i := 1 to high(IsActivePanel) do
  429.     isActivePanel[i] := False;
  430. end;
  431.  
  432. procedure SafeInitForm;
  433. var
  434.   v: TVariantArray;
  435. begin
  436.   setarraylength(V, 0);
  437.   ThreadSafeCall('InitForm', v);
  438. end;
  439.  
  440. procedure ShowFormModal;
  441. begin
  442.   frmMain.ShowModal;
  443. end;
  444.  
  445. procedure SafeShowFormModal;
  446. var
  447.   v: TVariantArray;
  448. begin
  449.   setarraylength(V, 0);
  450.   ThreadSafeCall('ShowFormModal', v);
  451. end;
  452.  
  453. begin
  454.   try
  455.     SafeInitForm;
  456.     SafeShowFormModal;
  457.   except
  458.     Writeln(ExceptionToString(ExceptionType, ExceptionParam));
  459.   end;
  460. end.
Add Comment
Please, Sign In to add comment