home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / xfitsvew.zip / XFITSview / control.c < prev    next >
C/C++ Source or Header  |  1996-02-22  |  8KB  |  224 lines

  1. /*    control panel functions for XFITSview */
  2. /*-----------------------------------------------------------------------
  3. *  Copyright (C) 1996
  4. *  Associated Universities, Inc. Washington DC, USA.
  5. *  This program is free software; you can redistribute it and/or
  6. *  modify it under the terms of the GNU General Public License as
  7. *  published by the Free Software Foundation; either version 2 of
  8. *  the License, or (at your option) any later version.
  9. *
  10. *  This program is distributed in the hope that it will be useful,
  11. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. *  GNU General Public License for more details.
  14. *-----------------------------------------------------------------------*/
  15. #include <Xm/Xm.h> 
  16. #include <Xm/DrawingA.h> 
  17. #include <Xm/MainW.h> 
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <Xm/Scale.h>
  21. #include <Xm/Form.h>
  22. #include <Xm/PushB.h>
  23. #include <Xm/Label.h>
  24. #include <Xm/ToggleB.h>
  25. #include "imagedisp.h"
  26. #include "color.h"
  27.  
  28. /* callback functions */
  29. void ContrastCB (Widget w, XtPointer clientData, XtPointer callData)
  30. {
  31.     ImageDisplay *IDdata = (ImageDisplay *)clientData;
  32.     XmScaleCallbackStruct *call_data = (XmScaleCallbackStruct *) callData;
  33.  
  34. /* read value of scrollbar */
  35.     IDdata->value[1] = call_data->value;
  36.  
  37. /* reset color table */
  38.     SetColorTable(IDdata);
  39. } /* end ContrastCB */
  40.  
  41. void BrightnessCB (Widget w, XtPointer clientData, XtPointer callData)
  42. {
  43.     ImageDisplay *IDdata = (ImageDisplay *)clientData;
  44.     XmScaleCallbackStruct *call_data = (XmScaleCallbackStruct *) callData;
  45.  
  46. /* read value of scrollbar */
  47.     IDdata->value[0] = call_data->value;
  48.  
  49. /* reset color table */
  50.     SetColorTable(IDdata);
  51. } /* end BrightnessCB */
  52.  
  53.  
  54. Widget MakeControl(Widget mainWindow, XtPointer data)
  55. /* Make brightness/contrast and info panel */
  56. {
  57.   Widget control, BriScroll, ConScroll, toplab, brilab, conlab;
  58.   Arg          args[10];
  59.   Dimension    width, height;
  60.   int          n;
  61.   XmString     topstr = XmStringCreateSimple ("Control panel");
  62.   XmString     bristr = XmStringCreateSimple ("Brightness");
  63.   XmString     constr = XmStringCreateSimple ("Contrast");
  64.   XmString     blankstr = XmStringCreateSimple ("");
  65.   ImageDisplay *IDdata = (ImageDisplay *)data;
  66.  
  67. /* make Form widget for control/info */
  68.   control = XtVaCreateManagedWidget ("control", xmFormWidgetClass,
  69.                      mainWindow,
  70.                        XmNwidth,           CONTROLWIDTH,
  71.                        XmNheight,          400,
  72.                          XmNtopAttachment,  XmATTACH_FORM,
  73.                        XmNleftAttachment,  XmATTACH_FORM,
  74.                        NULL);
  75.  
  76.  
  77. /* panel label */
  78.    toplab = XtVaCreateManagedWidget ("CPtoplab", xmLabelWidgetClass, 
  79.                        control, 
  80.                        XmNwidth,           CONTROLWIDTH,
  81.                        XmNlabelString,   topstr,
  82.                        XmNtopAttachment,  XmATTACH_FORM,
  83.                        XmNleftAttachment,  XmATTACH_FORM,
  84.                        NULL);
  85.  
  86. /* add scroll bar ("scale" in X) controls */
  87.  
  88. /* Brightness */
  89. /*  label */
  90.    brilab = XtVaCreateManagedWidget ("CPbrilab", xmLabelWidgetClass, 
  91.                        control, 
  92.                        XmNwidth,           CONTROLWIDTH,
  93.                        XmNlabelString,   bristr,
  94.                        XmNtopAttachment, XmATTACH_WIDGET,
  95.                        XmNtopWidget,     toplab, 
  96.                        XmNleftAttachment,  XmATTACH_FORM,
  97.                        NULL);
  98.  
  99.   BriScroll = XtVaCreateManagedWidget ("briscroll", xmScaleWidgetClass, 
  100.                        control, 
  101.                        XmNwidth,   CONTROLWIDTH,
  102.                        XmNmaximum,          256,
  103.                        XmNminimum,            1,
  104.                        XmNvalue,            128,
  105.                        XmNshowValue,       True,
  106.                        XmNscaleMultiple,      1,
  107.                        XmNorientation, XmHORIZONTAL,
  108.                        XmNprocessingDirection, XmMAX_ON_RIGHT,
  109.                        XmNtopAttachment, XmATTACH_WIDGET,
  110.                        XmNtopWidget,     brilab, 
  111.                        NULL);
  112.   XtAddCallback(BriScroll, XmNvalueChangedCallback, BrightnessCB, data);
  113.   XtAddCallback(BriScroll, XmNdragCallback, BrightnessCB, data);
  114.   IDdata->BriScroll = BriScroll;
  115.  
  116. /* Contrast */  
  117. /*  label */
  118.    conlab = XtVaCreateManagedWidget ("CPconlab", xmLabelWidgetClass, 
  119.                        control, 
  120.                        XmNwidth,        CONTROLWIDTH,
  121.                        XmNlabelString,   constr,
  122.                        XmNtopAttachment, XmATTACH_WIDGET,
  123.                        XmNtopWidget,     BriScroll,
  124.                        XmNleftAttachment,  XmATTACH_FORM,
  125.                        NULL);
  126.  
  127.   ConScroll = XtVaCreateManagedWidget ("conscroll", xmScaleWidgetClass, 
  128.                        control,
  129.                        XmNwidth,   CONTROLWIDTH,
  130.                        XmNmaximum,          256,
  131.                        XmNminimum,            1,
  132.                        XmNvalue,            128,
  133.                        XmNscaleMultiple,      1,
  134.                        XmNshowValue,       True,
  135.                        XmNorientation, XmHORIZONTAL,
  136.                        XmNprocessingDirection, XmMAX_ON_RIGHT,
  137.                        XmNtopAttachment, XmATTACH_WIDGET,
  138.                        XmNtopWidget,     conlab,
  139.                        NULL);
  140.   
  141.   XtAddCallback(ConScroll, XmNvalueChangedCallback, ContrastCB, data);
  142.   XtAddCallback(ConScroll, XmNdragCallback, ContrastCB, data);
  143.   IDdata->ConScroll = ConScroll;
  144.   
  145. /* info label widgets */
  146.   IDdata->Info1 = XtVaCreateManagedWidget ("Info1", xmLabelWidgetClass, 
  147.                        control, 
  148.                        XmNwidth,        CONTROLWIDTH,
  149.                        XmNlabelString,   blankstr,
  150.                        XmNtopAttachment, XmATTACH_WIDGET,
  151.                        XmNtopWidget,     ConScroll,
  152.                        XmNleftAttachment,  XmATTACH_FORM,
  153.                        NULL);
  154.  
  155.  
  156.   IDdata->Info2 = XtVaCreateManagedWidget ("Info2", xmLabelWidgetClass, 
  157.                        control, 
  158.                        XmNwidth,        CONTROLWIDTH,
  159.                        XmNlabelString,   blankstr,
  160.                        XmNtopAttachment, XmATTACH_WIDGET,
  161.                        XmNtopWidget, IDdata->Info1,
  162.                        XmNleftAttachment,  XmATTACH_FORM,
  163.                        NULL);
  164.  
  165.  
  166.   IDdata->Info3 = XtVaCreateManagedWidget ("Info3", xmLabelWidgetClass, 
  167.                        control, 
  168.                        XmNwidth,        CONTROLWIDTH,
  169.                        XmNlabelString,   blankstr,
  170.                        XmNtopAttachment, XmATTACH_WIDGET,
  171.                        XmNtopWidget, IDdata->Info2,
  172.                        XmNleftAttachment,  XmATTACH_FORM,
  173.                        NULL);
  174.  
  175.  
  176.   IDdata->Info4 = XtVaCreateManagedWidget ("Info4", xmLabelWidgetClass, 
  177.                        control, 
  178.                        XmNwidth,         CONTROLWIDTH,
  179.                        XmNlabelString,   blankstr,
  180.                        XmNtopAttachment, XmATTACH_WIDGET,
  181.                        XmNtopWidget, IDdata->Info3,
  182.                        XmNleftAttachment,  XmATTACH_FORM,
  183.                        NULL);
  184.  
  185.  
  186.   IDdata->Info5 = XtVaCreateManagedWidget ("Info5", xmLabelWidgetClass, 
  187.                        control, 
  188.                        XmNwidth,          CONTROLWIDTH,
  189.                        XmNlabelString,   blankstr,
  190.                        XmNtopAttachment, XmATTACH_WIDGET,
  191.                        XmNtopWidget,  IDdata->Info4,
  192.                        XmNleftAttachment,  XmATTACH_FORM,
  193.                        NULL);
  194.  
  195.  
  196.   IDdata->Info6 = XtVaCreateManagedWidget ("Info6", xmLabelWidgetClass, 
  197.                        control, 
  198.                        XmNwidth,         CONTROLWIDTH,
  199.                        XmNlabelString,   blankstr,
  200.                        XmNtopAttachment, XmATTACH_WIDGET,
  201.                        XmNtopWidget,  IDdata->Info5,
  202.                        XmNleftAttachment,  XmATTACH_FORM,
  203.                        NULL);
  204.  
  205.   IDdata->Info7 = XtVaCreateManagedWidget ("Info7", xmLabelWidgetClass, 
  206.                        control, 
  207.                        XmNwidth,         CONTROLWIDTH,
  208.                        XmNlabelString,   blankstr,
  209.                        XmNtopAttachment, XmATTACH_WIDGET,
  210.                        XmNtopWidget,  IDdata->Info6,
  211.                        XmNleftAttachment,  XmATTACH_FORM,
  212.                        NULL);
  213.  
  214.  
  215.   XtManageChild (control);
  216.  
  217.   if (topstr) XmStringFree(topstr);
  218.   if (bristr) XmStringFree(bristr);
  219.   if (constr) XmStringFree(constr);
  220.   if (blankstr) XmStringFree(blankstr);
  221.   return control;
  222. } /* end MakeControl */
  223.  
  224.