コード例 #1
0
ファイル: main.cpp プロジェクト: Hronom/GraphicSystem
int main(int argc, char *argv[])
{
    Q_UNUSED(argc)
    Q_UNUSED(argv)

    //////////////////////////////////////////////////////////////////
    /// Init GraphicSystem singleton
    GraphicSystem::initialize("GraphicSystemTest", "data/fonts/DejaVuSans.ttf");
    //////////////////////////////////////////////////////////////////



    //////////////////////////////////////////////////////////////////
    /// Get pointers of GraphicSystem
    sf::RenderWindow *window;
    window = GraphicSystem::instance()->getWindow();

    tgui::Gui *gui;
    gui = GraphicSystem::instance()->getGUI();
    //////////////////////////////////////////////////////////////////



    //////////////////////////////////////////////////////////////////
    /// Create widgets
    tgui::Picture::Ptr picture((*gui));
    picture->load("data/others/Linux.jpg");

    tgui::Button::Ptr button((*gui));
    button->load(THEME_CONFIG_FILE);
    button->setPosition(40, 25);
    button->setText("Quit");
    button->setCallbackId(1);
    button->bindCallback(tgui::Button::LeftMouseClicked);
    button->setSize(300, 40);

    tgui::ChatBox::Ptr chatbox((*gui));
    chatbox->load(THEME_CONFIG_FILE);
    chatbox->setSize(200, 100);
    chatbox->setTextSize(20);
    chatbox->setPosition(400, 25);
    chatbox->addLine("Line 1", sf::Color::Red);
    chatbox->addLine("Line 2", sf::Color::Blue);
    chatbox->addLine("Line 3", sf::Color::Green);
    chatbox->addLine("Line 4", sf::Color::Yellow);
    chatbox->addLine("Line 5", sf::Color::Cyan);
    chatbox->addLine("Line 6", sf::Color::Magenta);

    tgui::Checkbox::Ptr checkbox((*gui));
    checkbox->load(THEME_CONFIG_FILE);
    checkbox->setPosition(40, 80);
    checkbox->setText("Checkbox");
    checkbox->setSize(32, 32);

    tgui::ChildWindow::Ptr child((*gui));
    child->load(THEME_CONFIG_FILE);
    child->setSize(200, 100);
    child->setBackgroundColor(sf::Color(80, 80, 80));
    child->setPosition(400, 460);
    child->setTitle("Child window");
    child->setIcon("data/others/icon.jpg");

    tgui::ComboBox::Ptr comboBox((*gui));
    comboBox->load(THEME_CONFIG_FILE);
    comboBox->setSize(120, 21);
    comboBox->setPosition(210, 440);
    comboBox->addItem("Item 1");
    comboBox->addItem("Item 2");
    comboBox->addItem("Item 3");
    comboBox->setSelectedItem("Item 2");

    tgui::EditBox::Ptr editBox((*gui));
    editBox->load(THEME_CONFIG_FILE);
    editBox->setPosition(40, 200);
    editBox->setSize(300, 30);

    tgui::Label::Ptr label((*gui));
    label->load(THEME_CONFIG_FILE);
    label->setText("Label");
    label->setPosition(40, 160);
    label->setTextColor(sf::Color(200, 200, 200));
    label->setTextSize(24);

    tgui::ListBox::Ptr listBox((*gui));
    listBox->load(THEME_CONFIG_FILE);
    listBox->setSize(150, 120);
    listBox->setItemHeight(20);
    listBox->setPosition(40, 440);
    listBox->addItem("Item 1");
    listBox->addItem("Item 2");
    listBox->addItem("Item 3");

    tgui::LoadingBar::Ptr loadingbar((*gui));
    loadingbar->load(THEME_CONFIG_FILE);
    loadingbar->setPosition(40, 330);
    loadingbar->setSize(300, 30);
    loadingbar->setValue(35);

    tgui::MenuBar::Ptr menu((*gui));
    menu->load(THEME_CONFIG_FILE);
    menu->setSize(window->getSize().x, 20);
    menu->addMenu("File");
    menu->addMenuItem("File", "Load");
    menu->addMenuItem("File", "Save");
    menu->addMenuItem("File", "Exit");
    menu->bindCallback(tgui::MenuBar::MenuItemClicked);
    menu->setCallbackId(2);

    sf::Texture texture;
    texture.loadFromFile("data/others/ThinkLinux.jpg");

    tgui::Panel::Ptr panel((*gui));
    panel->setSize(200, 140);
    panel->setPosition(400, 150);
    panel->setBackgroundTexture(&texture);

    tgui::RadioButton::Ptr radioButton((*gui));
    radioButton->load(THEME_CONFIG_FILE);
    radioButton->setPosition(40, 120);
    radioButton->setText("Radio Button");
    radioButton->setSize(32, 32);

    tgui::Slider::Ptr slider((*gui));
    slider->load(THEME_CONFIG_FILE);
    slider->setVerticalScroll(false);
    slider->setPosition(40, 250);
    slider->setSize(300, 25);
    slider->setValue(2);

    tgui::Scrollbar::Ptr scrollbar((*gui));
    scrollbar->load(THEME_CONFIG_FILE);
    scrollbar->setVerticalScroll(false);
    scrollbar->setPosition(40, 290);
    scrollbar->setSize(300, 25);
    scrollbar->setMaximum(5);
    scrollbar->setLowValue(3);

    tgui::Slider2d::Ptr slider2d((*gui));
    slider2d->load("data/widgets/Slider2d/Black.conf");
    slider2d->setPosition(400, 300);
    slider2d->setSize(200, 150);

    tgui::SpinButton::Ptr spinButton((*gui));
    spinButton->load(THEME_CONFIG_FILE);
    spinButton->setPosition(40, 410);
    spinButton->setVerticalScroll(false);
    spinButton->setSize(40, 20);

    tgui::SpriteSheet::Ptr spritesheet((*gui));
    spritesheet->load("data/others/ThinkLinux.jpg");
    spritesheet->setCells(4, 4);
    spritesheet->setVisibleCell(2, 3);
    spritesheet->setSize(160, 120);
    spritesheet->setPosition(620, 25);

    tgui::Tab::Ptr tab((*gui));
    tab->load(THEME_CONFIG_FILE);
    tab->setPosition(40, 370);
    tab->add("Item 1");
    tab->add("Item 2");
    tab->add("Item 3");

    tgui::TextBox::Ptr textBox((*gui));
    textBox->load(THEME_CONFIG_FILE);
    textBox->setPosition(210, 470);
    textBox->setSize(180, 120);
    textBox->setTextSize(16);

    comboBox->moveToFront();
    //////////////////////////////////////////////////////////////////



    //////////////////////////////////////////////////////////////////
    /// Start main loop
    while(window->isOpen())
    {
        GraphicSystem::instance()->injectPreUpdate(0);

        sf::Event event;
        while(GraphicSystem::instance()->pollWindowEvent(event))
        {
            if(event.type == sf::Event::Closed)
                window->close();

            GraphicSystem::instance()->handleGUIEvent(event);
        }

        tgui::Callback callback;
        while(GraphicSystem::instance()->pollGUICallback(callback))
        {
            if(callback.id == 1)
                window->close();

            else if(callback.id == 2)
            {
                if(callback.text == "Exit")
                    window->close();
            }
        }

        GraphicSystem::instance()->injectPostUpdate(0);
    }
    //////////////////////////////////////////////////////////////////



    //////////////////////////////////////////////////////////////////
    /// Destroy GraphicSystem
    GraphicSystem::shutdown();
    //////////////////////////////////////////////////////////////////

    return 0;
}
コード例 #2
0
/*------------------------------------------------------------------------------
| Dialog::createControlsFromTemplate                                           |
------------------------------------------------------------------------------*/
Dialog& Dialog :: createControlsFromTemplate( )
{
  PDLGTEMPLATE pdlgt;                /* Dialog Template Pointer         */
  void*        pvStart;              /* Dialog Template Item Pointer    */
  register unsigned long cItems,     /* Dialog Items Counter            */
                         ulRc,       /* Return code                     */
                         i;          /* Loop Counter                    */

                       /* Set mouse pointer to "wait" in case template  */
                       /* is large                                      */
  IPointerHandle oldPointer = mousePointer();
  ISystemPointerHandle systemPointer( ISystemPointerHandle::wait );
  setMousePointer( systemPointer );

                       /* Try reading in the dialog template for the    */
                       /* given dialog ID                               */
  ulRc = DosGetResource( 0, RT_DIALOG, this->ulId, (void **)&pdlgt );
  if ( ulRc != 0 )
  {
                       /* Dialog template not found;  reset mouse       */
                       /* pointer and throw exception                   */
    setMousePointer( oldPointer );
    ITHROWSYSTEMERROR( ulRc,
                       "DosGetResource",
                       IErrorInfo::accessError,
                       IException::recoverable );
  }
                       /* Save pointer to the start of the dlg template */
  pvStart = (void *)pdlgt;

                       /* Save the number of controls found within the  */
                       /* dialog template                               */
  cItems = pdlgt->adlgti[0].cChildren + 1;

                       /* Read in and create an Open Class Library C++  */
                       /* object for each of the controls within the    */
                       /* dialog template                               */
  for ( i = 1; i < cItems; i++ )
  {
                       /* Obtain the id of the control                  */
    unsigned long ulId = (unsigned long)(pdlgt->adlgti[i].id & 0xffff);

                       /* Skip the control if its id is -1              */
    if ( ulId != 0xffff )
    {
                       /* Check to see if a custom control is specified */
                       /* or if a standard PM control class is being    */
                       /* used                                          */
      if ( pdlgt->adlgti[i].cchClassName )
      {
                       /* Since a length for the class name present,    */
                       /* a custom control class name is being used for */
                       /* the control.  Point to the memory location    */
                       /* where the class name is found within the      */
                       /* dialog template information.                  */
        customControl( ulId,
                       ((char *)pvStart + pdlgt->adlgti[i].offClassName) );
      }
      else
      {
                       /* No class name length given indicating that a  */
                       /* standard PM class is being used.  The class   */
                       /* name is stored as an index value.  For        */
                       /* example, the class for static's is defined as */
                       /*                                               */
                       /* #define WC_STATIC ((PSZ)0xffff0005L)          */
                       /*                                               */
                       /* The values within the dialog template for     */
                       /* the static class would be                     */
                       /*                                               */
                       /* adlgti[i].cchClassName = 0                    */
                       /* adlgti[i].offClassName = 5                    */
                       /*                                               */
                       /* Therefore, the value of offClassName field    */
                       /* must be used as an index that is used to      */
                       /* actually select the class name.               */

        switch ( pdlgt->adlgti[i].offClassName )
        {
          case WINCLASS_BUTTON :
            {
              unsigned long ulStyle = pdlgt->adlgti[i].flStyle &
                                      BS_PRIMARYSTYLES;

              switch ( ulStyle )
              {
                case BS_PUSHBUTTON:
                  {
                    if ( pdlgt->adlgti[i].flStyle & (BS_BITMAP | BS_ICON) )
                    {
                      IGraphicPushButton*
                        pGraphicPushButton = new IGraphicPushButton( ulId,
                                                                     this );
                      pGraphicPushButton->setAutoDeleteObject( true );
                      graphicPushButton( pGraphicPushButton );
                    }
                    else
                    {
                      IPushButton*
                        pPushButton = new IPushButton( ulId, this );
                      pPushButton->setAutoDeleteObject( true );
                      this->pushButton( pPushButton );
                    }
                  }
                  break;

                case BS_CHECKBOX:
                case BS_AUTOCHECKBOX:
                  {
                    ICheckBox*
                      pCheckBox = new ICheckBox( ulId, this );
                    pCheckBox->setAutoDeleteObject( true );
                    checkBox( pCheckBox );
                  }
                  break;

                case BS_RADIOBUTTON:
                case BS_AUTORADIOBUTTON:
                  {
                    IRadioButton*
                      pRadioButton = new IRadioButton( ulId, this );
                    pRadioButton->setAutoDeleteObject( true );
                    radioButton( pRadioButton );
                  }
                  break;

                case BS_3STATE:
                case BS_AUTO3STATE:
                  {
                    I3StateCheckBox*
                      p3StateCheckBox = new I3StateCheckBox( ulId, this );
                    p3StateCheckBox->setAutoDeleteObject( true );
                    threeStateCheckBox( p3StateCheckBox );
                  }
                  break;

                case BS_USERBUTTON:
                  {
                    customButton( ulId );
                  }
                  break;
              } //end switch

            } //WINCLASS_BUTTON
            break;

          case WINCLASS_SCROLLBAR :
            {
              IScrollBar*
                pScrollBar = new IScrollBar( ulId, this );
              pScrollBar->setAutoDeleteObject( true );
              scrollBar( pScrollBar );
            }
            break;

          case WINCLASS_LISTBOX :
            {
              IListBox*
                pListBox = new IListBox( ulId, this );
              pListBox->setAutoDeleteObject( true );
              listBox( pListBox );
            }
            break;

          case WINCLASS_ENTRYFIELD :
            {
              IEntryField*
                pEntryField = new IEntryField( ulId, this );
              pEntryField->setAutoDeleteObject( true );
              entryField( pEntryField );
            }
            break;

          case WINCLASS_STATIC :
            {
              unsigned long ulStyle = pdlgt->adlgti[i].flStyle &
                                (SS_TEXT | SS_GROUPBOX | SS_ICON | SS_BITMAP);

              switch ( ulStyle )
              {
                case SS_TEXT:
                  {
                    IStaticText*
                      pStaticText = new IStaticText( ulId, this );
                    pStaticText->setAutoDeleteObject( true );
                    staticText( pStaticText );
                  }
                  break;

                case SS_GROUPBOX:
                  {
                    IGroupBox*
                      pGroupBox = new IGroupBox( ulId, this );
                    pGroupBox->setAutoDeleteObject( true );
                    groupBox( pGroupBox );
                  }
                  break;

                case SS_ICON:
                  {
                    IIconControl*
                      pIcon = new IIconControl( ulId, this );
                    pIcon->setAutoDeleteObject( true );
                    iconControl( pIcon );
                  }
                  break;

                case SS_BITMAP:
                  {
                    IBitmapControl*
                      pBitmap = new IBitmapControl( ulId, this );
                    pBitmap->setAutoDeleteObject( true );
                    bitmapControl( pBitmap );
                  }
                  break;
              } //end switch

            } //WINCLASS_STATIC
            break;

          case WINCLASS_COMBOBOX :
            {
              IComboBox*
                pComboBox = new IComboBox( ulId, this );
              pComboBox->setAutoDeleteObject( true );
              comboBox( pComboBox );
            }
            break;

          case WINCLASS_MLE :
            {
              IMultiLineEdit*
                pMLE = new IMultiLineEdit( ulId, this );
              pMLE->setAutoDeleteObject( true );
              mle( pMLE );
            }
            break;

          case WINCLASS_SPINBUTTON :
            {
              if ( pdlgt->adlgti[i].flStyle & SPBS_NUMERICONLY )
              {
                INumericSpinButton*
                  pNumericSpinButton = new INumericSpinButton( ulId, this );
                pNumericSpinButton->setAutoDeleteObject( true );
                numericSpinButton( pNumericSpinButton );
              }
              else
              {
                ITextSpinButton*
                  pTextSpinButton = new ITextSpinButton( ulId, this );
                pTextSpinButton->setAutoDeleteObject( true );
                textSpinButton( pTextSpinButton );
              }
            }
            break;

          case WINCLASS_CONTAINER :
            {
              IContainerControl*
                pContainer = new IContainerControl( ulId, this );
              pContainer->setAutoDeleteObject( true );
              container( pContainer );
            }
            break;

          case WINCLASS_SLIDER :
            {
              if ( pdlgt->adlgti[i].flStyle & SLS_READONLY )
              {
                IProgressIndicator*
                  pProgressIndicator = new IProgressIndicator( ulId, this );
                pProgressIndicator->setAutoDeleteObject( true );
                progressIndicator( pProgressIndicator );
              }
              else
              {
                ISlider*
                  pSlider = new ISlider( ulId, this );
                pSlider->setAutoDeleteObject( true );
                slider( pSlider );
              }
            }
            break;

          case WINCLASS_VALUESET :
            //No valueset class - see OS/2 C++ Class Library Power GUI
            //Programming with C Set++ for an implementation of a
            //valueset class.
            break;

          case WINCLASS_NOTEBOOK :
            {
              INotebook*
                pNotebook = new INotebook( ulId, this );
              pNotebook->setAutoDeleteObject( true );
              notebook( pNotebook );
            }
            break;

          case WINCLASS_CIRCULARSLIDER :
            {
              ICircularSlider*
                pCircularSlider = new ICircularSlider( ulId, this );
              pCircularSlider->setAutoDeleteObject( true );
              circularSlider( pCircularSlider );
            }
            break;
        } //end switch
      } //end if
    } //end if - id != -1

  } //end for
                       /* Release the memory allocated for the dlg      */
                       /* template before returning                     */
  DosFreeResource( pvStart );
                       /* Reset mouse pointer                           */
  setMousePointer( oldPointer );
  return( *this );
} //Dialog::createControlsFromTemplate