// File: /workspace/github_c_makefile_star2_O3/space222[P]silo/main.cpp
// Function: main
int main(int argc, char** args)
{
	SDL_Init(SDL_INIT_VIDEO);

	SDL_Window* MainWindow = SDL_CreateWindow("SRGUI Tests", 0, 0, 1200,720, 0); //SDL_WINDOW_OPENGL
	SDL_Surface* MainWindowSurf = SDL_GetWindowSurface(MainWindow);

	int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, 1200);
	uint8_t* buffer =(uint8_t*) malloc(stride*720);
	
	SDL_Surface* boom = SDL_CreateRGBSurfaceFrom(buffer, 1200, 720, 32, stride, 0xFF0000, 0xFF00, 0xFF, 0xFF000000);
	cairo_surface_t* csurf = cairo_image_surface_create_for_data(buffer, CAIRO_FORMAT_ARGB32, 1200, 720, stride);
	cairo_t* ct = cairo_create(csurf);
	cairo_set_source_rgb(ct, 0.5f, 0.5f, 0.5f);
	cairo_paint(ct);

	silo_init();

	nk_context ctx;
	nk_user_font font;
	font.height = silo_get_font_height();
	font.width = &silo_get_text_width;

	nk_init_default(&ctx, (nk_user_font*)&font );

	enum {EASY, HARD};
	static int op = EASY;
	static float value = 0.6f;
	static int i =  20;
	struct nk_colorf color1;

	while( MainRunning )
	{
		SDL_Event event;
		nk_input_begin(&ctx);
		while( SDL_PollEvent(&event) ) 
		{
			switch( event.type )
			{
			case SDL_KEYDOWN:{
				
				}break;
			case SDL_MOUSEMOTION:
				nk_input_motion(&ctx, event.motion.x, event.motion.y);
				break;
			case SDL_MOUSEBUTTONDOWN: // SDL's defines start at 1, but are at least in the same order
				nk_input_button(&ctx, (nk_buttons)(event.button.button-1), event.button.x, event.button.y, 1);
				break;
			case SDL_MOUSEBUTTONUP:
				nk_input_button(&ctx, (nk_buttons)(event.button.button-1), event.button.x, event.button.y, 0);
				break;
			case SDL_WINDOWEVENT:
				if( event.window.event == SDL_WINDOWEVENT_CLOSE )
				{
					MainRunning = false;
				}
				break;
			case SDL_QUIT:
				MainRunning = false;
				break;
			}
		}
		nk_input_end(&ctx);

	if (nk_begin(&ctx, "Show", nk_rect(50, 50, 320, 320),
	    NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE|NK_WINDOW_SCALABLE)) {

	    /* fixed widget pixel width */
	    nk_layout_row_static(&ctx, 30, 80, 1);
	    if (nk_button_label(&ctx, "button")) {
		/* event handling */
			puts("it was clicked");
	    }

	    /* fixed widget window ratio width */
	    nk_layout_row_dynamic(&ctx, 30, 2);
	    if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
	    if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;

	    /* custom widget pixel width */
	    nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
	    {
		nk_layout_row_push(&ctx, 80);
		nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
		nk_layout_row_push(&ctx, 120);
		nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
	    }
	    nk_layout_row_end(&ctx);

			nk_layout_row_dynamic(&ctx, 30, 1);
			if (nk_combo_begin_color(&ctx, nk_rgb_cf(color1), nk_vec2(nk_widget_width(&ctx),400))) {
				nk_layout_row_dynamic(&ctx, 120, 1);
				color1 = nk_color_picker(&ctx, color1, NK_RGBA);
				nk_layout_row_dynamic(&ctx, 25, 1);
				color1.r = nk_propertyf(&ctx, "#R:", 0, color1.r, 1.0f, 0.01f,0.005f);
				color1.g = nk_propertyf(&ctx, "#G:", 0, color1.g, 1.0f, 0.01f,0.005f);
				color1.b = nk_propertyf(&ctx, "#B:", 0, color1.b, 1.0f, 0.01f,0.005f);
				color1.a = nk_propertyf(&ctx, "#A:", 0, color1.a, 1.0f, 0.01f,0.005f);
				nk_combo_end(&ctx);
			}
	}
	nk_end(&ctx);

		cairo_set_source_rgb(ct, 0.5f, 0.5f, 0.5f);
		cairo_paint(ct);
		
		silo_launch(ct, &ctx);
		nk_clear(&ctx);
		SDL_BlitSurface(boom, nullptr, MainWindowSurf, nullptr);

		
		SDL_UpdateWindowSurface(MainWindow);	
	}

	SDL_Quit();
	free(buffer);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4098, %rsp           # imm = 0x4098
movl $0x20, %edi
callq 0x2340
leaq 0x20bce(%rip), %rdi     # 0x2303c
xorl %esi, %esi
xorl %edx, %edx
movl $0x4b0, %ecx            # imm = 0x4B0
movl $0x2d0, %r8d            # imm = 0x2D0
xorl %r9d, %r9d
callq 0x2120
movq %rax, %rbx
movq %rax, %rdi
callq 0x2170
movq %rax, 0x30(%rsp)
xorl %edi, %edi
movl $0x4b0, %esi            # imm = 0x4B0
callq 0x2190
movl %eax, %ebp
imull $0x2d0, %eax, %eax      # imm = 0x2D0
movslq %eax, %rdi
callq 0x22a0
movq %rax, %r14
subq $0x8, %rsp
movq %rax, %rdi
movl $0x4b0, %esi            # imm = 0x4B0
movl $0x2d0, %edx            # imm = 0x2D0
movl $0x20, %ecx
movl %ebp, %r8d
movl $0xff0000, %r9d         # imm = 0xFF0000
pushq $-0x1000000             # imm = 0xFF000000
pushq $0xff
pushq $0xff00                 # imm = 0xFF00
callq 0x2230
addq $0x20, %rsp
movq %rax, %r12
movq %r14, 0x28(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movl $0x4b0, %edx            # imm = 0x4B0
movl $0x2d0, %ecx            # imm = 0x2D0
movl %ebp, %r8d
callq 0x21f0
movq %rax, %rdi
callq 0x22c0
movq %rax, %r13
movsd 0x20aeb(%rip), %xmm0    # 0x23008
movq %rax, %rdi
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x22b0
movq %r13, %rdi
callq 0x20c0
callq 0x3881
callq 0x3835
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
leaq 0x80(%rsp), %rsi
movss %xmm0, 0x8(%rsi)
leaq 0x124d(%rip), %rax      # 0x37a5
movq %rax, 0x10(%rsi)
leaq 0x98(%rsp), %rdi
callq 0xa728
cmpb $0x1, 0x2fc48(%rip)     # 0x321b8
jne 0x2953
leaq 0x98(%rsp), %rbp
leaq 0x38(%rsp), %r15
movq %rbp, %rdi
callq 0x823f
movq %r15, %rdi
callq 0x2310
testl %eax, %eax
je 0x2624
movl 0x38(%rsp), %eax
cmpl $0x3ff, %eax            # imm = 0x3FF
jle 0x25cd
cmpl $0x402, %eax            # imm = 0x402
je 0x25eb
cmpl $0x401, %eax            # imm = 0x401
je 0x2602
cmpl $0x400, %eax            # imm = 0x400
jne 0x258b
movl 0x4c(%rsp), %esi
movl 0x50(%rsp), %edx
movq %rbp, %rdi
callq 0x83ba
jmp 0x258b
cmpl $0x100, %eax            # imm = 0x100
je 0x25e2
cmpl $0x200, %eax            # imm = 0x200
jne 0x258b
cmpb $0xe, 0x44(%rsp)
jne 0x258b
movb $0x0, 0x2fbcf(%rip)     # 0x321b8
jmp 0x258b
movzbl 0x48(%rsp), %esi
decl %esi
movl 0x4c(%rsp), %edx
movl 0x50(%rsp), %ecx
movq %rbp, %rdi
xorl %r8d, %r8d
jmp 0x261a
movzbl 0x48(%rsp), %esi
decl %esi
movl 0x4c(%rsp), %edx
movl 0x50(%rsp), %ecx
movq %rbp, %rdi
movl $0x1, %r8d
callq 0x8437
jmp 0x258b
movq %rbp, %rdi
callq 0x836b
movss 0x209dc(%rip), %xmm0    # 0x23010
movaps %xmm0, %xmm1
movss 0x209d5(%rip), %xmm2    # 0x23014
movaps %xmm2, %xmm3
callq 0x38cb
movq %rbp, %rdi
leaq 0x209f7(%rip), %rsi     # 0x23048
movl $0xf, %edx
callq 0xb36a
testl %eax, %eax
je 0x28f4
movq %rbp, %rdi
movss 0x209aa(%rip), %xmm0    # 0x23018
movl $0x50, %esi
movl $0x1, %edx
callq 0x10c81
movq %rbp, %rdi
leaq 0x209c6(%rip), %rsi     # 0x2304d
callq 0x14be9
testl %eax, %eax
je 0x269c
leaq 0x209bd(%rip), %rdi     # 0x23054
callq 0x22e0
movq %rbp, %rdi
movss 0x20971(%rip), %xmm0    # 0x23018
movl $0x2, %esi
callq 0x10bb5
movzbl 0x2fb14(%rip), %edx     # 0x321cc
xorl $0x1, %edx
movq %rbp, %rdi
leaq 0x2099e(%rip), %rsi     # 0x23063
callq 0x16052
testl %eax, %eax
je 0x26d9
movb $0x0, 0x2faf7(%rip)     # 0x321cc
xorl %edx, %edx
jmp 0x26e0
movzbl 0x2faec(%rip), %edx     # 0x321cc
movq %rbp, %rdi
leaq 0x2097e(%rip), %rsi     # 0x23068
callq 0x16052
testl %eax, %eax
je 0x26fa
movb $0x1, 0x2fad2(%rip)     # 0x321cc
movq %rbp, %rdi
movl $0x1, %esi
movss 0x2090e(%rip), %xmm0    # 0x23018
movl $0x2, %edx
callq 0x10c8d
movq %rbp, %rdi
movss 0x208fd(%rip), %xmm0    # 0x2301c
callq 0x10ebd
movq %rbp, %rdi
leaq 0x2093f(%rip), %rsi     # 0x2306d
movl $0x11, %edx
callq 0x144e7
movq %rbp, %rdi
movss 0x208dd(%rip), %xmm0    # 0x23020
callq 0x10ebd
xorps %xmm0, %xmm0
movq %rbp, %rdi
leaq 0x2fa67(%rip), %rsi     # 0x321bc
movss 0x208c7(%rip), %xmm1    # 0x23024
movss 0x208c3(%rip), %xmm2    # 0x23028
callq 0x16cc2
movq %rbp, %rdi
callq 0x10fbb
movq %rbp, %rdi
movss 0x2089b(%rip), %xmm0    # 0x23018
movl $0x1, %esi
callq 0x10bb5
movaps 0x10(%rsp), %xmm0
movaps (%rsp), %xmm1
callq 0x475a
movl %eax, %r14d
movq %rbp, %rdi
callq 0x13945
movss 0x20884(%rip), %xmm1    # 0x2302c
callq 0x3913
movq %rbp, %rdi
movl %r14d, %esi
callq 0x1d958
testl %eax, %eax
je 0x28f4
movq %rbp, %rdi
movss 0x20855(%rip), %xmm0    # 0x23020
movl $0x1, %esi
callq 0x10bb5
movq %rbp, %rdi
movaps 0x10(%rsp), %xmm0
movaps (%rsp), %xmm1
movl $0x1, %esi
callq 0x1d2b6
movaps %xmm0, (%rsp)
movaps %xmm1, 0x70(%rsp)
movq %rbp, %rdi
movss 0x20831(%rip), %xmm0    # 0x23030
movl $0x1, %esi
callq 0x10bb5
xorps %xmm0, %xmm0
movq %rbp, %rdi
leaq 0x2085f(%rip), %rsi     # 0x23075
movaps (%rsp), %xmm1
movss 0x20802(%rip), %xmm2    # 0x23024
movss 0x2080a(%rip), %xmm3    # 0x23034
movss 0x20806(%rip), %xmm4    # 0x23038
callq 0x1b8e9
movaps %xmm0, 0x10(%rsp)
movaps (%rsp), %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
xorps %xmm0, %xmm0
movq %rbp, %rdi
leaq 0x20828(%rip), %rsi     # 0x23079
movss 0x207cb(%rip), %xmm2    # 0x23024
movss 0x207d3(%rip), %xmm3    # 0x23034
movss 0x207cf(%rip), %xmm4    # 0x23038
callq 0x1b8e9
movaps 0x10(%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movaps %xmm1, 0x10(%rsp)
xorps %xmm0, %xmm0
movq %rbp, %rdi
leaq 0x207f5(%rip), %rsi     # 0x2307d
movaps 0x70(%rsp), %xmm1
movss 0x2078f(%rip), %xmm2    # 0x23024
movss 0x20797(%rip), %xmm3    # 0x23034
movss 0x20793(%rip), %xmm4    # 0x23038
callq 0x1b8e9
movaps %xmm0, (%rsp)
movaps 0x70(%rsp), %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
xorps %xmm0, %xmm0
movq %rbp, %rdi
leaq 0x207bd(%rip), %rsi     # 0x23081
movss 0x20758(%rip), %xmm2    # 0x23024
movss 0x20760(%rip), %xmm3    # 0x23034
movss 0x2075c(%rip), %xmm4    # 0x23038
callq 0x1b8e9
movaps (%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movaps %xmm1, (%rsp)
movq %rbp, %rdi
callq 0x1ec11
movq %rbp, %rdi
callq 0xc47e
movq %r13, %rdi
movsd 0x20701(%rip), %xmm0    # 0x23008
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x22b0
movq %r13, %rdi
callq 0x20c0
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2978
movq %rbp, %rdi
callq 0xac52
movq %r12, %rdi
xorl %esi, %esi
movq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2250
movq %rbx, %rdi
callq 0x2330
cmpb $0x0, 0x2f86b(%rip)     # 0x321b8
jne 0x2583
callq 0x20e0
movq 0x28(%rsp), %rdi
callq 0x20b0
xorl %eax, %eax
addq $0x4098, %rsp           # imm = 0x4098
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop