Esempio n. 1
0
/**
 * @function Gui_DemoGraph1
 * @brief single graph with multiple curves demo
 * @param signal_t sig: unused
 * @return none
 */
void Gui_DemoGraph1(signal_t sig) {

  rect_st rec;
  int8_t res = -1;

  /*init.*/
  frameCount = fps = nbCurve = 0;
  wdtTrig = circularGraph = 0;

  do {

    Gui_DemoNewPage("Graph (multiple curves)");

    /*allocate memory for curves*/
    data = salloc( (uint32_t) NB_MAX_CURVE * GRAPH_W);
    if(data == NULL) break;

    /*create the graph*/
    rec = GUI_Rect(10, 25, GRAPH_W, GRAPH_H);
    pGraph = GUI_W_GraphAdd(&rec, GRAPH_GRID_DISABLED, 0);
    if(pGraph == NULL) break;

    /*FPS box*/
    rec = GUI_Rect(10, 248, 55, 20);
    if(GUI_W_ValueBoxAdd(&rec, &fps, BOX_T_UINT16, "%d fps") == NULL) break;

    /*nb of curve box*/
    rec = GUI_Rect(70, 248, 105, 20);
    if(GUI_W_ValueBoxAdd(&rec, &nbCurve, BOX_T_UINT16, "Curve count: %d") == NULL) break;

    /*button 'add curve' */
    rec = GUI_Rect(180, 248, 50, 20);
    if(GUI_W_ButtonAdd(&rec, "Add", G_IMG_GRAPH_ADD) == NULL) break;
    GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_ADD_CURVE);

    /*checkbox 'scroll graph'*/
    rec = GUI_Rect(235, 248, 71, 20);
    if(GUI_W_CheckBoxAdd(&rec, "Circular", &circularGraph) == NULL) break;
    GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_CHECKBOX_CIRCULAR);

    res = 0;

  } while(0);


  if(res == 0) {
    /*done; go to handler*/
    GUI_SetUserTask(Gui_DemoGraph1Handler);
  }
  else {
    /*serious error, exit*/
    GUI_SetUserTask(Gui_Demo);
  }
}
/**
 * @function Gui_DemoFileBrowser
 * @brief File browser demo
 * @param signal_t sig: unused
 * @return none
 */
void Gui_DemoFileBrowser(signal_t sig) {

  rect_st rec;
  coord_t hEntry, y, pitch;

  Gui_DemoNewPage("built-in file browser");

  /*allocate memory for storing file paths*/
  if(path_file == NULL) path_file = salloc(PATH_BUFF_SIZE);
  if(path_folder == NULL) path_folder = salloc(PATH_BUFF_SIZE);
  if(path_file != NULL && path_folder != NULL) {

    SetFont(G_FONT_DEFAULT);
    hEntry = P2D_GetTextHeight() + 4;
    pitch = hEntry - 3;
    y = 20;

    /**
     * widgets for file selection
     */
    path_file[0] = 0;
    rec = GUI_Rect(15, y, 295, hEntry);
    GUI_W_TextAdd(&rec, "Select a file"); y += pitch;

    rec = GUI_Rect(15, y, 265, hEntry);
    GUI_W_UsrEntryAdd(&rec, path_file, PATH_BUFF_SIZE, false);

    rec = GUI_Rect(285, y, hEntry, hEntry);
    GUI_W_ButtonAdd(&rec, NULL, G_IMG_OPEN);
    GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_SELECT_FILE);

    /**
     * widgets for folder selection
     */
    path_folder[0] = 0;
    y += pitch*2;
    rec = GUI_Rect(15, y, 295, hEntry);
    GUI_W_TextAdd(&rec, "Select a folder"); y += pitch;

    rec = GUI_Rect(15, y, 265, hEntry);
    GUI_W_UsrEntryAdd(&rec, path_folder, PATH_BUFF_SIZE, false);

    rec = GUI_Rect(285, y, hEntry, hEntry);
    GUI_W_ButtonAdd(&rec, NULL, G_IMG_OPEN);
    GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_SELECT_FOLDER);

    /* => page creation is now completed. Jump to the page's handler*/
    GUI_SetUserTask(Gui_DemoFileBrowserHandler);
  }
  else {

    /*critical: salloc error*/
    CleanExit();
  }
}
Esempio n. 3
0
/**
 * @function Gui_DemoText
 * @brief text area demo
 * @param signal_t sig: unused
 * @return none
 */
void Gui_DemoText(signal_t sig) {

  rect_st rec;
  disableObj = 0;

  Gui_DemoNewPage("Text area");

  rec = GUI_Rect(10, 20, 299, 137);
  GUI_SetAlign(align);
  GUI_SetGroup(GRP_DISABLED);
  GUI_W_TextAdd(&rec,
      "This program 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 3 of the License, or "
      "(at your option) any later version.");
  GUI_SetGroup(GRP_DEFAULT);
  GUI_SetAlign(0); /*reset the alignment (recommended)*/

  /*draw the dimension of the text area*/
  rec.x--;
  rec.y--;
  rec.w += 2;
  rec.h += 2;
  P2D_SetLineType(LINE_SOLID);
  P2D_SetColor(COLOR_PURPLE);
  P2D_Rect(&rec);


  /**
   * alignment controls
   */
  rec = GUI_Rect(253, 160, 17, 17);
  GUI_W_RadioAdd(&rec, NULL, &align, SIG_RADIO_TL);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_RADIO_TL);
  rec = GUI_Rect(273, 160, 17, 17);
  GUI_W_RadioAdd(&rec, NULL, &align, SIG_RADIO_TC);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_RADIO_TC);
  rec = GUI_Rect(293, 160, 17, 17);
  GUI_W_RadioAdd(&rec, NULL, &align, SIG_RADIO_TR);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_RADIO_TR);

  rec = GUI_Rect(253, 178, 17, 17);
  GUI_W_RadioAdd(&rec, NULL, &align, SIG_RADIO_CL);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_RADIO_CL);
  rec = GUI_Rect(273, 178, 17, 17);
  GUI_W_RadioAdd(&rec, NULL, &align, SIG_RADIO_CC);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_RADIO_CC);
  rec = GUI_Rect(293, 178, 17, 17);
  GUI_W_RadioAdd(&rec, NULL, &align, SIG_RADIO_CR);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_RADIO_CR);

  rec = GUI_Rect(253, 196, 17, 17);
  GUI_W_RadioAdd(&rec, NULL, &align, SIG_RADIO_BL);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_RADIO_BL);
  rec = GUI_Rect(273, 196, 17, 17);
  GUI_W_RadioAdd(&rec, NULL, &align, SIG_RADIO_BC);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_RADIO_BC);
  rec = GUI_Rect(293, 196, 17, 17);
  GUI_W_RadioAdd(&rec, NULL, &align, SIG_RADIO_BR);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_RADIO_BR);

  /**
   * disable control
   */
  rec = GUI_Rect(10, 160, 115, 19);
  GUI_W_CheckBoxAdd(&rec, "Disable objects", &disableObj);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_DISABLE_OBJ);

  /* => page creation is now completed. Jump to the page's handler*/
  GUI_SetUserTask(Gui_DemoTextHandler);
}
Esempio n. 4
0
/**
 * @function Gui_DemoValueBox
 * @brief value box demo
 * @param signal_t sig: unused
 * @return none
 */
void Gui_DemoValueBox(signal_t sig) {

  rect_st rec;
  disableObj = notifyObj = 0;

  Gui_DemoNewPage("Text area");

  /**
   * some value boxes
   */
  rec = GUI_Rect(10, 20, 220, 19);
  GUI_W_TextAdd(&rec, "Default value box, (e.g. float):");
  rec = GUI_Rect(230, 20, 75, 19);
  GUI_W_ValueBoxAdd(&rec, &fVal, BOX_T_FLOAT, "%.3f");

  rec = GUI_Rect(10, 42, 220, 19);
  GUI_W_TextAdd(&rec, "Value box with format string:");
  rec = GUI_Rect(230, 42, 75, 19);
  GUI_W_ValueBoxAdd(&rec, &fVal, BOX_T_FLOAT, "I=%.2f µA");

  rec = GUI_Rect(10, 70, 300, 19);
  GUI_W_TextAdd(&rec, "Value boxes of different type, format & style:");
  rec = GUI_Rect(10, 92, 55, 19);
  GUI_W_ValueBoxAdd(&rec, &u8Slider, BOX_T_INT8, "i8:%d");
  rec = GUI_Rect(75, 92, 55, 19);
  GUI_W_ValueBoxAdd(&rec, &u8Slider, BOX_T_UINT8, "u8:%d");
  rec = GUI_Rect(140, 92, 75, 19);
  GUI_W_ValueBoxAdd(&rec, &u16Val, BOX_T_INT16, "i16:%d");
  rec = GUI_Rect(225, 92, 75, 19);
  GUI_W_ValueBoxAdd(&rec, &u16Val, BOX_T_UINT16, "u16:%d");

  rec = GUI_Rect(10, 114, 110, 19);
  GUI_W_ValueBoxAdd(&rec, &u32Val, BOX_T_INT32, "i32:%d");

  SetColor(G_COL_TEXT, P2D_Color(255, 0, 0));
  rec = GUI_Rect(125, 114, 65, 19);
  GUI_W_ValueBoxAdd(&rec, &u16Val, BOX_T_UINT16, "0x%04X");
  SetColor(G_COL_TEXT, P2D_Color(0, 0, 0));

  SetFont(G_FONT_DIGIT);
  rec = GUI_Rect(195, 114, 65, 19);
  GUI_W_ValueBoxAdd(&rec, &u16Val, BOX_T_UINT16, "%04d");
  SetFont(G_FONT_DEFAULT);

  rec = GUI_Rect(10, 136, 125, 19);
  GUI_SetGroup(GRP_DISABLED);
  GUI_W_ValueBoxAdd(&rec, &u8Slider, BOX_T_UINT8, "Disable me! u8:%d");
  GUI_SetGroup(GRP_DEFAULT);

  rec = GUI_Rect(140, 136, 135, 19);
  GUI_SetGroup(GRP_NOTIFIED);
  GUI_W_ValueBoxAdd(&rec, &u8Slider, BOX_T_UINT8, "Notify me! u8:%d");
  GUI_SetGroup(GRP_DEFAULT);

  /**
   * some sliders
   */
  GUI_SetGroup(GRP_DISABLED);
  rec = GUI_Rect(20, 165, 255, 15);
  GUI_W_SliderAdd(&rec, &u8Slider);
  rec = GUI_Rect(285, 117, 15, 85);
  GUI_W_SliderAdd(&rec, &u8Slider);
  GUI_SetGroup(GRP_DEFAULT);

  /**
   * disable control
   */
  rec = GUI_Rect(10, 185, 110, 19);
  GUI_W_CheckBoxAdd(&rec, "Notify objects", &notifyObj);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_NOTIFY_OBJ);

  rec = GUI_Rect(130, 185, 115, 19);
  GUI_W_CheckBoxAdd(&rec, "Disable objects", &disableObj);
  GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_DISABLE_OBJ);

  /* => page creation is now completed. Jump to the page's handler*/
  GUI_SetUserTask(Gui_DemoValueBoxHandler);
}
Esempio n. 5
0
/**
 * @function Gui_DemoKeyboard
 * @brief keyboard demo
 * @param signal_t sig: unused
 * @return none
 */
void Gui_DemoKeyboard(signal_t sig) {

  rect_st rec;
  coord_t hEntry, y, pitch;

  Gui_DemoNewPage("built-in keyboards");

  /*allocate memory for usr entries*/
  if(buf_azerty == NULL) buf_azerty = salloc(KBD_BUFF_SIZE);
  if(buf_qwerty == NULL) buf_qwerty = salloc(KBD_BUFF_SIZE);
  if(buf_num == NULL) buf_num = salloc(KBD_BUFF_SIZE);
  if(buf_azerty != NULL && buf_qwerty != NULL && buf_num != NULL) {

    SetFont(G_FONT_DEFAULT);
    hEntry = P2D_GetTextHeight() + 4;
    pitch = hEntry - 3;
    y = 20;

    /**
     * widgets for azerty
     */
    rec = GUI_Rect(15, y, 295, hEntry);
    GUI_W_TextAdd(&rec, "String input, with AZERTY keyboard"); y += pitch;

    snprintf(buf_azerty, KBD_BUFF_SIZE, "azerty"); /*make sure that the buffer is \0 terminated*/

    rec = GUI_Rect(15, y, 265, hEntry);
    GUI_W_UsrEntryAdd(&rec, buf_azerty, KBD_BUFF_SIZE, false);

    rec = GUI_Rect(285, y, hEntry, hEntry);
    GUI_W_ButtonAdd(&rec, NULL, G_IMG_EDIT);
    GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_CREATE_AZERTY);

    /**
     * widgets for qwerty
     */
    y += pitch*2;
    rec = GUI_Rect(15, y, 295, hEntry);
    GUI_W_TextAdd(&rec, "String input, with QWERTY keyboard"); y += pitch;

    snprintf(buf_qwerty, KBD_BUFF_SIZE, "qwerty");

    rec = GUI_Rect(15, y, 265, hEntry);
    GUI_W_UsrEntryAdd(&rec, buf_qwerty, KBD_BUFF_SIZE, false);

    rec = GUI_Rect(285, y, hEntry, hEntry);
    GUI_W_ButtonAdd(&rec, NULL, G_IMG_EDIT);
    GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_CREATE_QWERTY);

    /**
     * widgets for num
     */
    y += pitch*2;
    rec = GUI_Rect(15, y, 295, hEntry);
    GUI_W_TextAdd(&rec, "String input, with NUM keyboard"); y += pitch;
    snprintf(buf_num, KBD_BUFF_SIZE, "0");

    rec = GUI_Rect(15, y, 265, hEntry);
    GUI_W_UsrEntryAdd(&rec, buf_num, KBD_BUFF_SIZE, false);

    rec = GUI_Rect(285, y, hEntry, hEntry);
    GUI_W_ButtonAdd(&rec, NULL, G_IMG_EDIT);
    GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_CREATE_NUM);


    /* => page creation is now completed. Jump to the page's handler*/
    GUI_SetUserTask(Gui_DemoKeyboardHandler);
  }
  else {

    /*critical: salloc error*/
    CleanExit();
  }
}
Esempio n. 6
0
int
main(int argc, char *argv[])
{
    /* initialize SDL */
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        GUI_Log("Could not initialize SDL");
    }
    if (TTF_Init() != 0){
        GUI_Log( "TTF_Init failed.");
        SDL_Quit();
        return 1;
    }
    if( GUI_Init() != 0 ) {
        GUI_Log( "GUI_Init failed." );
        TTF_Quit();
        SDL_Quit();
        return 1;
    }
    
    char *pref = SDL_GetPrefPath( "JimmySoftware.com", "ToolBarDialog" );
    strcpy( preferenctPath, pref );
    strcat( preferenctPath, "preference.conf" );
    
    SDL_Log( "Pref: %s\n", preferenctPath );
    if( access( preferenctPath, 0 ) != -1 ) {
        GUI_Log( "File Existed\n" );
        loadPalette( preferenctPath );
    } else {
        GUI_Log( "File not existed\n" );
        for( int i=0; i<numPalette; i++ ) {
            for( int j=0; j<numColor; j++ ) {
                mainPalette[i][j] = mColor[j];
            }
        }
    }
    activePalette = 0;
    
    //int sx = 720, sy = 405;
#if __IPHONEOS__ or __ANDROID__
    int sx = 640, sy = 360;
#else
    int sx = 640, sy = 360;
#endif
    SDL_Window *window = GUI_CreateWindow( "GUI", sx, sy );
    if (window == NULL) {
        fatalError("GUI_CreateWindow Error");
        return 1;
    }
    
    SCREEN_WIDTH = GUI_windowWidth;
    SCREEN_HEIGHT = GUI_windowHeight;
    
    topWin=new GUI_TopWin( "TopWin", GUI_Rect(0,0,GUI_windowWidth,GUI_windowHeight),0,
       []( GUI_WinBase *tw ) {
           //tw->clear();
       }
    );
    
    textureFileIcon = loadTexture( "icon_file.png", GUI_renderer );

    
    GUI_WinBase *topBar = new GUI_WinBase( topWin, "TopBar", 0, 0, GUI_windowWidth, 48, cDarkGrey );
    if( topBar ) {
        GUI_Button *bttnFile = new GUI_Button( topBar, "F", 8, 8, 32, 32, cGrey,
            [](GUI_Button *bt) {
                if( menuFile == NULL ) {
                    GUI_Log( "create new MenuFile\n" );
                    static const char *menuText[] = {
                        "File", "Open", "Save", "Exit", NULL
                    };
                    menuFile = new GUI_List( topWin, menuText, 4, bt->tw_area.x, bt->tw_area.y+bt->tw_area.w+10, 240, 0, 0, true,
                        [](GUI_List *l,const char *sel, int index) {
                            switch (index) {
                                case 1:
                                    OpenFile();
                                    break;
                                case 3:
                                    SDL_AddTimer( 100, ExitCallback, NULL );
                                    break;
                                default:
                                    break;
                            }
                            menuFile = NULL;
                        }
                    );
                    menuFile->title_str = "Menu File";
                    menuFile->onClose = [] (GUI_WinBase *) -> bool {
                        menuFile = NULL;
                        return true;
                    };
                }
            }
        );
        bttnFile->texImage = textureFileIcon;
        bttnFile->color = cClear;
        
        new GUI_Button( topBar, "C", 48, 8, 32, 32, cGrey,
            [](GUI_Button *bt) {
                OpenColor();
            }
        );
        
        GUI_WinBase *colorBox = new GUI_WinBase( topBar, "สี", 88, 6, 32*9+18, 36, cClear,
                                                [](GUI_WinBase *wb) {
                                                    GUI_FillRoundRect( 0, 0, wb->tw_area.w, wb->tw_area.h, wb->tw_area.h/2, sdl_color( 0x484848ff ) );
                                                }
                                                );
        if( colorBox ) {
            for( int i=0; i<numColor; i++ ) {
                c[i] = new GUI_Button( colorBox, "", 6+32*i, 3, 31, 31, mainPalette[activePalette][i], setActiveColor );
                c[i]->tag = i;
                c[i]->radius = 15;
                c[i]->border = 1;
            }
            
            setActiveColor( c[0] );
            
            GUI_WinBase *paletteButton = new GUI_WinBase( colorBox, "Palette", 6+32*numColor+5, 3+8, 25, 15, cClear,
                [](GUI_WinBase *w)
                {
                    //GUI_DrawRect( GUI_MakeRect(0, 0, w->tw_area.w, w->tw_area.h), cBlack );
                    SDL_RenderCopy(GUI_renderer, GUI_dropdownTexture, NULL, GUI_MakeRect(1, 1, w->tw_area.w-2, w->tw_area.h-2));
                }
            );
            paletteButton->handle_event_cmd = [](GUI_WinBase *w, SDL_Event* ev ) -> bool {
                switch (ev->type) {
                    case SDL_MOUSEBUTTONUP: {
                        static const char *menuPalette[] = {
                            "Palette1", "Palette2", "Palette3", "Palette4", "Palette5", "---", "Load", "Save", NULL
                        };

                        //GUI_Log( "Palette\n" );
                        GUI_List *listPal = new GUI_List( topWin, menuPalette, 8, w->tw_area.x, w->tw_area.y+w->tw_area.h+18, 240, 0, 0, true,
                                     [](GUI_List* l,const char*sz,int n) {
                                         if( n < numPalette ) {
                                             activePalette = n;
                                             l->setCheck( n );
                                             for( int i=0; i<numColor; i++ ) {
                                                 c[i]->color = mainPalette[n][i];
                                             }
                                         }
                                         else if( n == numPalette + 1 ) {
                                             SDL_AddTimer( 100, LoadPaletteCallback, NULL );
                                         }
                                         else if( n == numPalette + 2 ) {
                                             SDL_AddTimer( 100, SavePaletteCallback, NULL );
                                         }
                                     });
                        for( int i=0; i<numPalette; i++ ) {
                            GUI_ListCell *cell = listPal->getCell( i );
                            cell->checkable = true;
                            cell->display_cmd = cellDraw;
                        }
                        listPal->setCheck( activePalette );
                    }
                }
                return false;
            };

        }
    }
    
    GUI_WinBase *sizeBox = new GUI_WinBase( topBar, "สี", 402, 6, 32*3+6, 36, cClear,
                                            [](GUI_WinBase *wb) {
                                                GUI_FillRoundRect( 0, 0, wb->tw_area.w, wb->tw_area.h, 10, sdl_color( 0x484848ff ) );
                                            }
                                            );
    if( sizeBox ) {
        for( int i=0; i<numSize; i++ ) {
            s[i] = new GUI_Button( sizeBox, "", 3+32*i, 3, 30, 30, cClear, setActiveSize );
            s[i]->tag = i;
            s[i]->radius = 5;
            s[i]->border = 1;
            s[i]->display_cmd = [](GUI_WinBase *w) {
                int bw = 12 + w->tag * 6;
                int cw = 0;
                if( w->tag == 1 )
                    cw -= 3;
                GUI_FillRect( cw+(w->tw_area.w-bw)/2, (w->tw_area.h-bw)/2, bw, bw, cGrey );
                GUI_DrawRect( cw+(w->tw_area.w-bw)/2, (w->tw_area.h-bw)/2, bw, bw, ((GUI_Button*)w)->borderColor );
            };
        }
        setActiveSize( s[0] );
    }
    
    GUI_WinBase *bottomBar = new GUI_WinBase( topWin, "BottomBar", 0, GUI_windowHeight-48, GUI_windowWidth, 48, cDarkGrey );


    //createTestWindows( 20, 20, "Red", cRed );

    
    GUI_Run();
    
    savePalette( preferenctPath );
    
    
    
    /* shutdown SDL */
    GUI_Quit();
    TTF_Quit();
    SDL_Quit();
    
    return 0;
}