コード例 #1
0
ファイル: GUI_MainWin.cpp プロジェクト: siharat-th/SDL_gui
SDL_Color GUI_getPantoneRGB( int pantoneCode )
{
    int l = sizeof( pantone_code ) / sizeof( pantone_code[0] );
    for( int i=0; i<l; i++ ) {
        if( pantone_code[i] == pantoneCode )
            return pantone_color[i];
    }
    return sdl_color( 0 );
}
コード例 #2
0
ファイル: main.cpp プロジェクト: siharat-th/SDL_gui
void loadPalette( const char *fn ) {
    SDL_RWops *rw = SDL_RWFromFile(fn, "r");
    if (rw != NULL) {
        for( int i=0; i<numPalette; i++ ) {
            for( int j=0; j<numColor; j++ ) {
                Uint32 c = SDL_ReadBE32(rw);
                mainPalette[i][j] = sdl_color(c);
            }
        }
        SDL_RWclose(rw);
    }
}
コード例 #3
0
ファイル: kick.c プロジェクト: ITikhonov/ll
uint64_t kick(uint64_t f) {
	switch(f) {
	case 0x102: printf("%lx ", *llsp++); fflush(stdout); break;
	case 0x103: stack(); break;
	case 0x104: if(*llsp) putchar(*llsp); llsp++; fflush(stdout); break;

	case 0x204: { void *p=(void*)(*llsp++); return (uint64_t)realloc(p,*llsp++); }

	case 0x300: sdl_init(); break;
	case 0x301: sdl_poll(); break;
	case 0x302: sdl_clear(); break;
	case 0x303: {
			int c=*llsp++;
			int p=*llsp++;
			return sdl_char(c,p&0xffff,p>>16);
		};
	case 0x304: sdl_color(*llsp++); break;
	}
	return 0;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: siharat-th/SDL_gui
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;
}