/* SetUpMui.c -- set up the (magic) user interface
 * Copyright (C) 1994  Torsten Klein
 *
 * This file is part of ASpringies, a mass and spring simulation system for the Amiga
 *
 * ASpringies is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 1, or (at your option)
 * any later version.
 *
 * ASpringies is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ASpringies; see the file COPYING.  If not, write to
 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: SetUpMui.c,v 1.11 1994/08/19 11:55:43 Torsten_Klein Exp $ 
 */

#include "main.h"

#define eN "\033n"
#define eU "\033u"

#define SetID(obj, id, attrib, value) \
  (DoMethod((obj), MUIM_Notify, (attrib), (value), \
	    AP_ASpringies, 2, MUIM_Application_ReturnID, (id)), obj)

#define SetRAID(obj) SetID(obj, ID_ ## obj, MUIA_Radio_Active,       MUIV_EveryTime)
#define SetBTID(obj) SetID(obj, ID_ ## obj, MUIA_Pressed,            FALSE)
#define SetCKID(obj) SetID(obj, ID_ ## obj, MUIA_Selected,           MUIV_EveryTime)
#define SetSTID(obj) SetID(obj, ID_ ## obj, MUIA_String_Acknowledge, MUIV_EveryTime)
#define SetSLID(obj) SetID(obj, ID_ ## obj, MUIA_Slider_Level,       MUIV_EveryTime)

static struct NewMenu Menu[] = 
{
  {NM_TITLE, "Project",      0, 0, 0, (APTR)0},
  {NM_ITEM,  "About...",   "?", 0, 0, (APTR)ID_ME_About},
  {NM_ITEM,  "Help...",    "H", 0, 0, (APTR)ID_ME_Help},
  {NM_ITEM,  NM_BARLABEL,    0, 0 ,0, (APTR)0},
  {NM_ITEM,  "Load...",    "L", 0, 0, (APTR)ID_ME_Load},
  {NM_ITEM,  "Insert...",  "I", 0, 0, (APTR)ID_ME_Insert},
  {NM_ITEM,  NM_BARLABEL,    0, 0 ,0, (APTR)0},
  {NM_ITEM,  "Save",       "S", 0, 0, (APTR)ID_ME_Save},
  {NM_ITEM,  "Save as...", "A", 0, 0, (APTR)ID_ME_SaveAs},
  {NM_ITEM,  NM_BARLABEL,    0, 0 ,0, (APTR)0},
  {NM_ITEM,  "Screen mode...","M",0,0,(APTR)ID_ME_ScreenMode},
  {NM_ITEM,  NM_BARLABEL,    0, 0 ,0, (APTR)0},
  {NM_ITEM,  "Quit...",    "Q", 0, 0, (APTR)MUIV_Application_ReturnID_Quit},

  {NM_TITLE, "Edit",         0, 0, 0, (APTR)0},
  {NM_ITEM,  "Duplicate",  "D", 0, 0, (APTR)ID_ME_DupSel},
  {NM_ITEM,  "Delete",     "X", 0, 0, (APTR)ID_ME_DeleteSel},

  {NM_TITLE, "State",        0, 0, 0, (APTR)0},
  {NM_ITEM,  "Restore...", "R", 0, 0, (APTR)ID_ME_Restore},
  {NM_ITEM,  "Snapshot",   "Z", 0, 0, (APTR)ID_ME_Snapshot},
  {NM_ITEM,  "Reset...",   "N", 0, 0, (APTR)ID_ME_Reset},
  {NM_END,   NULL,           0, 0, 0, (APTR)0},
};

static const char *mode_labels[] = { " " eU "E" eN "dit", " " eU "M" eN "ass",
				       " " eU "S" eN "pring", NULL};

APTR FloatString(APTR *obj, STRPTR label, int maxlen)
{
  return(
	 HGroup,
	  Child, Label2(label),
	  Child, HVSpace,
	  Child, *obj = StringObject, StringFrame,
	   MUIA_FixWidthTxt     , "0000000000",  
	   MUIA_Font            , MUIV_Font_Fixed, 
	   MUIA_String_MaxLen   , maxlen,
	   MUIA_String_Format   , MUIV_String_Format_Right,
	   MUIA_String_Accept   , "0123456789-.",
	   End,
	  End
	 );
}

APTR LabKeyCheck(APTR *obj, STRPTR label, char control)
{
  return(
	 HGroup,
	  Child, KeyLabel1(label, control),
	  Child, HVSpace,
	  Child, *obj = ImageObject, ImageButtonFrame,
	   MUIA_InputMode        , MUIV_InputMode_Toggle,
	   MUIA_Image_Spec       , MUII_CheckMark,
	   MUIA_Image_FreeVert   , TRUE,
	   MUIA_Background       , MUII_ButtonBack,
	   MUIA_ShowSelState     , FALSE,
	   MUIA_ControlChar      , control,
	   End,
	  End
	 );
}

void SetUpMui(void)
{
  AP_ASpringies = ApplicationObject,
   MUIA_Application_Title         , "ASpringies",
   MUIA_Application_Version       , "$VER: ASpringies 1.0 (29.07.94)",
   MUIA_Application_Copyright     , "Copyright ©1994, Torsten Klein",
   MUIA_Application_Author        , "Torsten Klein",
   MUIA_Application_Description   , "Interactive mass & spring simulation",
   MUIA_Application_Base          , "ASPRINGIES",
   MUIA_Application_Menu          ,  Menu, 
   MUIA_HelpFile                  ,  HELP_FILE,

   SubWindow, WI_ASpringies = WindowObject,
    MUIA_HelpNode, "Main",
    MUIA_Window_Title, "ASpringies V1.0 - "
      "<space>: toggle screens - <help>: online help",
    MUIA_Window_ID,    MAKE_ID('A', 'S', 'P', 'R'),

    WindowContents, VGroup,
     Child, HGroup,
      Child, VGroup,
       Child, HGroup, GroupFrameT("Edit Mode"),
        MUIA_HelpNode, "Editing Modes",
        Child, RA_Mode = RadioObject,  MUIA_Radio_Entries, mode_labels, End,
        Child, HVSpace,
        End,
       Child, HVSpace,
       Child, ColGroup(3), GroupFrameT("Walls"),
        MUIA_HelpNode, "Walls",
        Child, HVSpace, Child, CK_WallTop = CheckMark(TRUE), Child, HVSpace,
        Child, CK_WallLeft = CheckMark(TRUE), Child, HVSpace, 
                                              Child, CK_WallRight = CheckMark(TRUE),
        Child, HVSpace, Child, CK_WallBottom = CheckMark(TRUE), Child, HVSpace,
        End,
       Child, HVSpace, 
       End,  

      Child, VGroup, GroupFrameT("Control"),
       MUIA_HelpNode, "Control",
       Child, BT_SelAll = KeyButton("Select All", 'l'),
       Child, HVSpace,
       Child, BT_SetCenter = KeyButton("Set Center", 'n'),
       Child, HVSpace, 
       Child, BT_SetRLen = KeyButton("SetRestLen",'r'),
       Child, HVSpace,
       Child, LabKeyCheck(&CK_DrawSpr, "Draw Spring", 'd'), 
       Child, HVSpace, 
       Child, LabKeyCheck(&CK_Action, "Action", 'a'), 
       Child, HGroup, 
        Child, Label2("Grid"), 
        Child, SL_Grid = SliderObject, 
         MUIA_Slider_Min, 1, MUIA_Slider_Max, 99, MUIA_Slider_Level, 1,
         End,
        End,
       End,

      Child, VGroup, GroupFrameT("S&M Settings"),
       MUIA_HelpNode, "S&M settings",
       Child, FloatString(&ST_Mass, "Mass", 10),
       Child, FloatString(&ST_Elas, "Elas", 10),
       Child, FloatString(&ST_Kspr, "KSpr", 10),
       Child, FloatString(&ST_Kdmp, "KDmp", 10),
       Child, HVSpace,
       Child, LabKeyCheck(&CK_FixedMass, "Fixed Mass", 'f'), 
       End,

      Child, VGroup, GroupFrameT("Global Settings"),
       MUIA_HelpNode, "Global Settings",
       Child, FloatString(&ST_Visc, "Visc", 10),
       Child, FloatString(&ST_Stic, "Stic", 10),
       Child, FloatString(&ST_Step, "Step", 10),
       Child, FloatString(&ST_Prec, "Prec", 10),
       Child, HVSpace, 
       Child, LabKeyCheck(&CK_AdaptTStep, "AdaptTimeStep", 't'), 
       Child, HVSpace, 
       Child, HGroup,
        Child, Label1("Frames/sec"),
        Child, HVSpace, 
        Child, TX_Fps = TextObject, TextFrame,
               MUIA_Text_Contents, "00",
               MUIA_Text_SetMax,   TRUE,
               End,
        End,
       End,
      End,

     Child, HGroup, /*MUIA_Group_SameSize, TRUE, */ 
      MUIA_HelpNode, "Forces",

      Child, VGroup, GroupFrameT("Gravity"),
       Child, LabKeyCheck(&CK_GravActive, "Active (g)", 'g'),
       Child, FloatString(&ST_GravGrav, "Grav", 10),
       Child, FloatString(&ST_GravDir,  "Dir ", 10),
       End,

      Child, VGroup, GroupFrameT("Center"),
       Child, LabKeyCheck(&CK_CenterActive, "Active (x)", 'x'),
       Child, FloatString(&ST_CenterMagn, "Magn", 10),
       Child, FloatString(&ST_CenterDamp, "Damp", 10),
       End,

      Child, VGroup, GroupFrameT("PtAttract"),
       Child, LabKeyCheck(&CK_PtAttrActive, "Active (p)", 'p'),
       Child, FloatString(&ST_PtAttrMagn, "Magn", 10),
       Child, FloatString(&ST_PtAttrExpo, "Expo", 10),
       End,

      Child, VGroup, GroupFrameT("WallForce"),
       Child, LabKeyCheck(&CK_WallFActive, "Active (w)", 'w'),
       Child, FloatString(&ST_WallFMagn, "Magn", 10),
       Child, FloatString(&ST_WallFExpo, "Expo", 10),
       End,
      End,			/* HGroup (forces)          */
     End,			/* VGroup (window contents) */
    End,			/* Window                   */
   End;				/* Application              */

  FAILOPEN("application object (MUI)", AP_ASpringies);

  DoMethod(WI_ASpringies, MUIM_Window_SetCycleChain,
	   SetRAID(RA_Mode),
	   SetCKID(CK_WallTop),
	   SetCKID(CK_WallLeft),
	   SetCKID(CK_WallRight),
	   SetCKID(CK_WallBottom),
	   SetBTID(BT_SelAll),
	   SetBTID(BT_SetCenter),
	   SetBTID(BT_SetRLen),
	   SetCKID(CK_DrawSpr),
	   SetCKID(CK_Action),
	   SetSLID(SL_Grid),
	   SetSTID(ST_Mass),
	   SetSTID(ST_Elas),
       	   SetSTID(ST_Kspr),
	   SetSTID(ST_Kdmp),
	   SetCKID(CK_FixedMass),
	   SetSTID(ST_Visc),
	   SetSTID(ST_Stic),
	   SetSTID(ST_Step),
	   SetSTID(ST_Prec),
	   SetCKID(CK_AdaptTStep),

	   SetCKID(CK_GravActive),
	   SetSTID(ST_GravGrav),
	   SetSTID(ST_GravDir),
	   SetCKID(CK_CenterActive),
	   SetSTID(ST_CenterMagn),
	   SetSTID(ST_CenterDamp),
	   SetCKID(CK_PtAttrActive),
	   SetSTID(ST_PtAttrMagn),
	   SetSTID(ST_PtAttrExpo),
	   SetCKID(CK_WallFActive),
	   SetSTID(ST_WallFMagn),
	   SetSTID(ST_WallFExpo),

	   NULL
	   );

  DoMethod(CK_Action, MUIM_Notify, MUIA_Selected, TRUE, 
	   TX_Fps, 3, MUIM_Set, MUIA_Disabled, FALSE);
  DoMethod(CK_Action, MUIM_Notify, MUIA_Selected, FALSE, 
	   TX_Fps, 3, MUIM_Set, MUIA_Disabled, TRUE);

  DoMethod(CK_AdaptTStep, MUIM_Notify, MUIA_Selected, TRUE, 
	   ST_Prec, 3, MUIM_Set, MUIA_Disabled, FALSE);
  DoMethod(CK_AdaptTStep, MUIM_Notify, MUIA_Selected, FALSE, 
	   ST_Prec, 3, MUIM_Set, MUIA_Disabled, TRUE);
  DoMethod(CK_AdaptTStep, MUIM_Notify, MUIA_Selected, MUIV_EveryTime, 
	   ST_Step, 3, MUIM_Set, MUIA_Disabled, MUIV_TriggerValue);


  DoMethod(WI_ASpringies, MUIM_Notify, MUIA_Window_InputEvent, "control c",
	   AP_ASpringies, 2, MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  DoMethod(WI_ASpringies, MUIM_Notify, MUIA_Window_InputEvent, "e",
	   RA_Mode, 3, MUIM_Set, MUIA_Radio_Active, 0);
  DoMethod(WI_ASpringies, MUIM_Notify, MUIA_Window_InputEvent, "m",
	   RA_Mode, 3, MUIM_Set, MUIA_Radio_Active, 1);
  DoMethod(WI_ASpringies, MUIM_Notify, MUIA_Window_InputEvent, "s",
	   RA_Mode, 3, MUIM_Set, MUIA_Radio_Active, 2);

  DoMethod(WI_ASpringies, MUIM_Notify, MUIA_Window_InputEvent, "space",
	   AP_ASpringies, 2, MUIM_Application_ReturnID, ID_KY_AnimToFront);

  DoMethod(WI_ASpringies, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
	   AP_ASpringies, 2, MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);


  DoMethod(AP_ASpringies, MUIM_Notify, MUIA_Application_MenuHelp, MUIV_EveryTime, 
	   AP_ASpringies, 5, MUIM_Application_ShowHelp, WI_ASpringies, 
	   HELP_FILE, "Menus", 0);

  set(WI_ASpringies, MUIA_Window_Open, TRUE);
  set(TX_Fps,  MUIA_Disabled, TRUE);
  set(ST_Prec, MUIA_Disabled, TRUE);
}




