libglui / glui

GLUI is a GLUT-based C++ user interface library which provides controls such as buttons, checkboxes, radio buttons, and spinners to OpenGL applications. It is window-system independent, using GLUT or FreeGLUT.
Other
196 stars 81 forks source link

GLUI window does not know size of subwindow #8

Open josch opened 9 years ago

josch commented 9 years ago

https://sourceforge.net/p/glui/bugs/13/

I created a subwindow with controls on it, but since the main GLUI window (the subwindows' parent) doesn't know how much space to leave for the subwindow, it truncates those controls. Please see attached code. It this code I made the window big enough by adding many separators and columns to the main window to fool it into thinking the window is bigger; that way the sub window shows. But shouldn't GLUI know the size of its subwindow to that is not needed?

//  A simple GLUT program using the GLUI User Interface Library
// This program uses only a dialog box without any openGL drawing 

// the next line suppresses the console window
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) 
#include <string.h>
#include <GL/glut.h>
#include "glui.h"
int   main_window;
char  text[sizeof(GLUI_String)] = {"Hello World! GLUI as a dialog app!"};
GLUI_EditText   *edittext;
void myGlutIdle( void )
{
  glutSetWindow(main_window);  
  glutPostRedisplay();
}
void myGlutDisplay( void )
{
  glClearColor( .9f, .9f, .9f, 1.0f );
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  glMatrixMode( GL_PROJECTION );
  glLoadIdentity();
  gluOrtho2D( 0.0, 100.0, 0.0, 100.0  );
  glMatrixMode( GL_MODELVIEW );
  glLoadIdentity();
  glColor3ub( 0, 0, 0 );
  glRasterPos2i( 10, 10 );
  int i;
  for( i=0; i<(int)strlen( text ); i++ )
    glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18, text[i] );
  glutSwapBuffers(); 
}
void myGlutKeyboard(unsigned char Key, int x, int y)
{
  glutSetWindow(main_window);  
  glutPostRedisplay();
}
void control_cb( int control )
{
  myGlutDisplay();
}
void main(int argc, char* argv[])
{
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowPosition(100,100);
  glutInitWindowSize(300,300);
  GLUI *glui = GLUI_Master.create_glui( "GLUI", 0, 400, 50 ); 
                                    /* name, flags, x, and y */
  main_window = glui->get_glut_window_id();

  // The purpose of these separators is to make space for the embedded window
  // of controls. Without them, GLUI does not make the window large enough
  for( int i = 0; i < 15; i++ )
  {
    glui->add_separator();
  }
  for( i = 0; i < 20; i++ )
  {
    glui->add_column( true );
  }
  GLUI *glui_subwin = GLUI_Master.create_glui_subwindow ( main_window, GLUI_SUBWINDOW_TOP );
  glui_subwin->set_main_gfx_window( main_window );
  glutKeyboardFunc( myGlutKeyboard );
  glui_subwin->add_statictext( "GLUI dialog application" );
  glui_subwin->add_separator();
  // For some reason, the arrow keys, and backspace are not being recognized
  // in the editbox, however, I can select text with mouse and type over it that way
  edittext = 
  glui_subwin->add_edittext( "Text:", GLUI_EDITTEXT_TEXT, text, 1, control_cb );
  edittext->set_w( sizeof( text ) );
  glui_subwin->add_button( "Quit", 0,(GLUI_Update_CB)exit );
  glui_subwin->set_main_gfx_window( main_window );
  // Although the manual suggest registering the idle function with GLUI
  // for some reason this results in continuous updates to the window
  //GLUI_Master.set_glutIdleFunc( myGlutIdle );
  GLUI_Master.set_glutIdleFunc( NULL );
  GLUI_Master.set_glutDisplayFunc(myGlutDisplay);
  // Although the manual suggests registering this with GLUI, the program
  // crashes when I do it.
  //GLUI_Master.set_glutKeyboardFunc(myGlutKeyboard);
  glutMainLoop();
}