Menu

Blending sub-windows

Help
2008-07-13
2013-04-15
  • Gary D Stewart

    Gary D Stewart - 2008-07-13

    I have two problems that I'm not sure what's going on. On the first one it's not clear to me if I just don't understand
    the window hierarchy or if there is a real problem. It is best shown with a slightly modified version of the test program
    applicaton1.c as shown:

    /***********************************************************************************/
    /* app1a.c - A variation of an example application for Otk library.                */
    /*  Shows how to make: toggle and radio buttons, pull-down                         */
    /*  menu, and selection lists.                                                     */
    /*                                                                                 */
    /* Compile:                                                                        */
    /*  cc -L/usr/X11R6/lib application1.c -lGLU -lGL -lXmu -lXext -lX11 -lm -o app1a  */
    /*                                                                                 */
    /* Jul. 1, 2008                                                                    */
    /*                                                                                 */
    /***********************************************************************************/

    #include "otk_lib/otk_lib.c"

    OtkWidget tbutton1, tbutton2;

    void toggled( int state, void *x )
    {
    if (state==1) printf("Toggle button %d toggled ON.\n", (int)x);
    else printf("Toggle button %d toggled OFF.\n", (int)x);

    printf(" (Toggle button states: %d %d\n",Otk_Get_Button_State(tbutton1),Otk_Get_Button_State(tbutton2));
    }

    char directory[500]=".", wildcards[500]="", filename[500]="";

    void my_file_answer( char *filename )
    { printf("To open file %s\n", filename); }

    void fileopener()
    { Otk_Browse_Files( "File to Open:", 500, directory, wildcards, filename, my_file_answer ); }

    void saveas_answer( char *filename )
    { printf("To saveas file %s\n", filename); }

    void filesaver()
    { Otk_Browse_Files( "File to Save:", 500, directory, wildcards, filename, saveas_answer ); }

    void radiocallback( void *x )
    {
    printf("Radio button %d selected.\n", (int)x );
    }

    void selectlistcallback( void *x )
    {
    printf("Item %d selected.\n", (int)x );
    }

    void testbutton()
    { printf("Test button pressed.\n"); }

    void quit( void *x )
    { printf("Exiting\n"); exit(0); }

    void cut()
    {
    float x = 5, y = 10 ;
    OtkWidget mw ;

      mw = OtkMakeWindow(Otk_Recessed, Otk_Blue, Otk_LightGray, 10, 10, 70, 80) ;
      OtkMakeTextLabel(mw, "Cut", Otk_Black, 3.0, 1.0, 5, y) ;
    }

    void copy()
    {
    float x = 5, y = 10 ;
    OtkWidget mw ;

      mw = OtkMakeWindow(Otk_Recessed, Otk_Blue, Otk_LightGray, 10, 10, 70, 80) ;
      OtkMakeTextLabel(mw, "Copy", Otk_Black, 3.0, 1.0, 5, y) ;
    }

    void paste()
    {
    float x = 5, y = 10 ;
    OtkWidget mw ;

      mw = OtkMakeWindow(Otk_Recessed, Otk_Blue, Otk_LightGray, 10, 10, 70, 80) ;
      OtkMakeTextLabel(mw, "Paste", Otk_Black, 3.0, 1.0, 5, y) ;
    }

    /* ===================== MAIN ======================== */
    main( int argc, char **argv )
    {
    OtkWidget menubar, pdmenu1, pdmenu2, pdmenu3, pdmenu4, pdmenu5, sbmenu, mw;
    OtkWidget rbutton1, slist;
    float x=3.0, y=5.0, dx, dy, hsz, vsz;
    int nrows, ncols;

    OtkInitWindow( 400, 450, argc, argv );

    /******************************/
    /* Make some Pull-down Menus. */
    /******************************/
    menubar = OtkMakePanel( OtkOuterWindow, Otk_Flat, OtkSetColor(0.7,0.7,0.7), 0, 0, 100, 5 );

    pdmenu1 = Otk_Make_Menu( menubar, 0, 0, 15, 100, " File " );
    Otk_Add_Menu_Item( pdmenu1, "Open", fileopener, 0 );
    Otk_Add_Menu_Item( pdmenu1, "Save", 0, 0 );
    Otk_Add_Menu_Item( pdmenu1, "Save As", filesaver, 0 );
    Otk_Add_Menu_Item( pdmenu1, "Print", 0, 0 );
    Otk_Add_Menu_Item( pdmenu1, "Exit", quit, 0 );

    pdmenu2 = Otk_Make_Menu( menubar, 15, 0, 15, 100, " Edit " );
    Otk_Add_Menu_Item( pdmenu2, "Cut", cut, 0 );
    Otk_Add_Menu_Item( pdmenu2, "Copy", copy, 0 );
    Otk_Add_Menu_Item( pdmenu2, "Paste", paste, 0 );

    pdmenu3 = Otk_Make_Menu( menubar, 30, 0, 15, 100, " View " );
    Otk_Add_Menu_Item( pdmenu3, "Normal", 0, 0 );
    sbmenu = Otk_Add_SubMenu( pdmenu3, "Zoom" );    /* Add a Sub-Menu. */
    Otk_Add_Menu_Item( sbmenu, "Zoom-In", 0, 0 );
    Otk_Add_Menu_Item( sbmenu, "Zoom-Out", 0, 0 );

    pdmenu4 = Otk_Make_Menu( menubar, 45, 0, 15, 100, " Tools " );
    Otk_Add_Menu_Item( pdmenu4, "Search", 0, 0 );

    pdmenu5 = Otk_Make_Menu( menubar, 60, 0, 15, 100, " Help " );
    Otk_Add_Menu_Item( pdmenu5, "About", 0, 0 );

    /******************************/
    /* Make some toggle buttons.  */
    /******************************/
    x = 3.0;    y = 12.0;        /* x = horizontal position, y = vertical. */
    hsz = 8.0;  vsz=2.0;
    OtkMakeTextLabel( OtkOuterWindow, "Toggle Buttons:", Otk_Black, 2.0, 1.0, x, y );
    tbutton1 = OtkMakeToggleButton( OtkOuterWindow, x+50, y, hsz, vsz, toggled, (void *)1 );
    OtkMakeTextLabel( OtkOuterWindow, "T1", Otk_Black, 2.0, 1.0, x+59, y+0.4 );
    tbutton2 = OtkMakeToggleButton( OtkOuterWindow, x+70, y, hsz, vsz, toggled, (void *)2 );
    OtkMakeTextLabel( OtkOuterWindow, "T2", Otk_Black, 2.0, 1.0, x+79, y+0.4 );

    /******************************/
    /* Make some Radio Buttons.   */
    /******************************/
    x = 3.0;    y = 30.0;
    hsz = 8.0;  vsz=2.0;    dx = 20.0;
    OtkMakeTextLabel( OtkOuterWindow, "Radio Buttons:", Otk_Black, 2.0, 1.0, x, y );
    x = 10.0;  y = y + 5.0;
    rbutton1 = OtkMakeRadioButton( OtkOuterWindow, x, y, hsz, vsz, radiocallback, (void *)1 );
    OtkMakeTextLabel( OtkOuterWindow, "R1", Otk_Black, 2.0, 1.0, x+9.0, y );
    x = x + dx;
    OtkMakeRadioButton( rbutton1, x, y, hsz, vsz, radiocallback, (void *)2 );
    OtkMakeTextLabel( OtkOuterWindow, "R2", Otk_Black, 2.0, 1.0, x+9.0, y );
    x = x + dx;
    OtkMakeRadioButton( rbutton1, x, y, hsz, vsz, radiocallback, (void *)3 );
    OtkMakeTextLabel( OtkOuterWindow, "R3", Otk_Black, 2.0, 1.0, x+9.0, y );
    x = x + dx;
    OtkMakeRadioButton( rbutton1, x, y, hsz, vsz, radiocallback, (void *)4 );
    OtkMakeTextLabel( OtkOuterWindow, "R4", Otk_Black, 2.0, 1.0, x+9.0, y );

    /******************************/
    /* Make a selection-list.     */
    /******************************/
    x = 3.0;     y = 50.0;
    OtkMakeTextLabel( OtkOuterWindow, "Selection List:", Otk_Black, 2.0, 1.0, x, y );
    hsz = 70.0;  vsz=20.0;
    x = 10.0;  y = y + 5.0;
    nrows = 5;  ncols = 25;
    slist = Otk_Make_Selection_List( OtkOuterWindow, nrows, ncols, x, y, hsz, vsz );
    Otk_Add_Selection_Item( slist, "Grapes", selectlistcallback, (void *)1 );
    Otk_Add_Selection_Item( slist, "Olives", selectlistcallback, (void *)2 );
    Otk_Add_Selection_Item( slist, "Bananas", selectlistcallback, (void *)3 );
    Otk_Add_Selection_Item( slist, "Cherries", selectlistcallback, (void *)4 );
    Otk_Add_Selection_Item( slist, "Apples", selectlistcallback, (void *)5 );
    Otk_Add_Selection_Item( slist, "Cigars", selectlistcallback, (void *)6 );
    Otk_Add_Selection_Item( slist, "Lemons", selectlistcallback, (void *)7 );
    Otk_Add_Selection_Item( slist, "Tangerines", selectlistcallback, (void *)8 );
    Otk_Frame_Selection_List( slist );

    mw = OtkMakeWindow( Otk_Recessed, Otk_Blue, Otk_LightGray, 10.0, 10.0, 70.0, 80.0 );
    OtkMakeTextLabel( mw, "First window", Otk_Black, 2.3, 1.0, 4.0, 5.0 );

    OtkMakeButton( OtkOuterWindow, 45.0, 89.0, 10.0, 4.0, "Test", testbutton, 0 );
    OtkMakeButton( OtkOuterWindow, 45.0, 95.0, 10.0, 4.0, "Exit", quit, 0 );
    OtkMainLoop();
    }

    After compiling this (in Debian and PCLinux OS 2007) a sub-window will display the "First window" message. If you go to the Edit
    pull down menu and select any sub-menu, another sub-window will open and display the text name of the sub-menu selected. if you
    move this window it will do exactly as I expect in regards to overlaying the first window. If you then go again to the Edit pull
    down menu and select a different sub-menu item things do not act as I expect. The text and the window edges blend together. The
    best example of what I expect to happen occurs when running the degrees test program and you open multiple sub-windows with the
    help button. They all cleanly overlay each other.

    I will start a new thread for the second problem.

     
    • kindman

      kindman - 2008-07-22

      Gary,

      If you close the second window before going to the first window's Edit pull-down again, then everything should work OK.  Otherwise, in the present version of OTK, some additional items drawn on the first window, may be on the same layer as the second window, and may collide as you observe.

      Thanks for mentioning this.  The original sub-windowing code was written under the assumption that no further items would be drawn on an underlying window after a new window was brought up.  However, I now see how this could be expected to happen.

      I will look into adjusting OTK to better support this.

      In the meantime, you could add some additional depth layer-padding between windows by the following simple method, which should avoid the problem you observe.  Add the following line after making the first window, or before any additional windows are created.

          Otk_window_level = Otk_window_level + 10.0;

      I will post the permanent fix in a near future release.
      Thanks,
          Carl

       
    • Gary D Stewart

      Gary D Stewart - 2008-08-06

      Thanks again, I'll also give that a try. I'm using these windows for general purpose message windows (low level and high level I/O errors, pull down menu options windows, etc.) and with the application I'm using OTK with it is very possible to have more than one open (automatically) at a time.

       

Log in to post a comment.

MongoDB Logo MongoDB