// File: /workspace/github_c_makefile_star2_O2/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 $0x40a8, %rsp           # imm = 0x40A8
pushq $0x20
popq %rbp
movl %ebp, %edi
callq 0x2340
leaq 0x1dbce(%rip), %rdi     # 0x2003c
xorl %esi, %esi
xorl %edx, %edx
movl $0x4b0, %ecx            # imm = 0x4B0
movl $0x2d0, %r8d            # imm = 0x2D0
xorl %r9d, %r9d
callq 0x2120
movq %rax, 0x40(%rsp)
movq %rax, %rdi
callq 0x2170
movq %rax, 0x38(%rsp)
xorl %edi, %edi
movl $0x4b0, %esi            # imm = 0x4B0
callq 0x2190
movl %eax, %r14d
imull $0x2d0, %eax, %eax      # imm = 0x2D0
movslq %eax, %rdi
callq 0x22a0
movq %rax, %rbx
subq $0x8, %rsp
movq %rax, %rdi
movl $0x4b0, %esi            # imm = 0x4B0
movl $0x2d0, %edx            # imm = 0x2D0
movl %ebp, %ecx
movl %r14d, %r8d
movl $0xff0000, %r9d         # imm = 0xFF0000
pushq $-0x1000000             # imm = 0xFF000000
pushq $0xff
pushq $0xff00                 # imm = 0xFF00
callq 0x2230
addq $0x20, %rsp
movq %rax, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x4b0, %edx            # imm = 0x4B0
movl $0x2d0, %ecx            # imm = 0x2D0
movl %r14d, %r8d
callq 0x21f0
movq %rax, %rdi
callq 0x22c0
movq %rax, %r13
movsd 0x1dae9(%rip), %xmm0    # 0x20008
movq %rax, %rdi
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x22b0
movq %r13, %rdi
callq 0x20c0
callq 0x3658
callq 0x360e
cvtsi2ss %eax, %xmm0
leaq 0x90(%rsp), %rsi
movss %xmm0, 0x8(%rsi)
leaq 0x1027(%rip), %rax      # 0x357e
movq %rax, 0x10(%rsi)
leaq 0xa8(%rsp), %rbp
movq %rbp, %rdi
callq 0x970e
leaq 0x48(%rsp), %r15
pushq $0x1
popq %r14
pushq $0x2
popq %rbx
cmpb $0x1, 0x2cc3a(%rip)     # 0x2f1b8
jne 0x2940
movq %rbp, %rdi
callq 0x7896
movq %r15, %rdi
callq 0x2310
testl %eax, %eax
je 0x2620
movl 0x48(%rsp), %eax
cmpl $0x100, %eax            # imm = 0x100
je 0x25dc
cmpl $0x200, %eax            # imm = 0x200
je 0x25d5
cmpl $0x402, %eax            # imm = 0x402
je 0x2601
cmpl $0x401, %eax            # imm = 0x401
je 0x25e5
cmpl $0x400, %eax            # imm = 0x400
jne 0x258c
movl 0x5c(%rsp), %esi
movl 0x60(%rsp), %edx
movq %rbp, %rdi
callq 0x7950
jmp 0x258c
cmpb $0xe, 0x54(%rsp)
jne 0x258c
movb $0x0, 0x2cbd5(%rip)     # 0x2f1b8
jmp 0x258c
movzbl 0x58(%rsp), %esi
decl %esi
movl 0x5c(%rsp), %edx
movl 0x60(%rsp), %ecx
movq %rbp, %rdi
movl %r14d, %r8d
callq 0x79cd
jmp 0x258c
movzbl 0x58(%rsp), %esi
decl %esi
movl 0x5c(%rsp), %edx
movl 0x60(%rsp), %ecx
movq %rbp, %rdi
xorl %r8d, %r8d
callq 0x79cd
jmp 0x258c
movq %rbp, %rdi
callq 0x7902
movss 0x1d9e0(%rip), %xmm0    # 0x20010
movaps %xmm0, %xmm1
movss 0x1d9d9(%rip), %xmm2    # 0x20014
movaps %xmm2, %xmm3
callq 0x369f
movq %rbp, %rdi
leaq 0x1d9fb(%rip), %rsi     # 0x20048
pushq $0xf
popq %rdx
callq 0xa0d8
testl %eax, %eax
je 0x28e5
movq %rbp, %rdi
movss 0x1d9b0(%rip), %xmm0    # 0x20018
pushq $0x50
popq %rsi
movl %r14d, %edx
callq 0xf506
movq %rbp, %rdi
leaq 0x1d9d0(%rip), %rsi     # 0x2004d
callq 0x1327a
testl %eax, %eax
je 0x2692
leaq 0x1d9c7(%rip), %rdi     # 0x20054
callq 0x22e0
movq %rbp, %rdi
movss 0x1d97b(%rip), %xmm0    # 0x20018
movl %ebx, %esi
callq 0xf441
movzbl 0x2cb21(%rip), %edx     # 0x2f1cc
xorl $0x1, %edx
movq %rbp, %rdi
leaq 0x1d9ab(%rip), %rsi     # 0x20063
callq 0x14602
testl %eax, %eax
je 0x26cc
movb $0x0, 0x2cb04(%rip)     # 0x2f1cc
xorl %edx, %edx
jmp 0x26d3
movzbl 0x2caf9(%rip), %edx     # 0x2f1cc
movq %rbp, %rdi
leaq 0x1d98b(%rip), %rsi     # 0x20068
callq 0x14602
testl %eax, %eax
je 0x26ed
movb $0x1, 0x2cadf(%rip)     # 0x2f1cc
movq %rbp, %rdi
movl %r14d, %esi
movss 0x1d91d(%rip), %xmm0    # 0x20018
movl %ebx, %r12d
movl %ebx, %edx
callq 0xf510
movq %rbp, %rdi
movss 0x1d90c(%rip), %xmm0    # 0x2001c
callq 0xf737
movq %rbp, %rdi
leaq 0x1d94e(%rip), %rsi     # 0x2006d
pushq $0x11
popq %rdx
callq 0x12b7f
movq %rbp, %rdi
movss 0x1d8ee(%rip), %xmm0    # 0x20020
callq 0xf737
xorps %xmm0, %xmm0
movq %rbp, %rdi
leaq 0x2ca78(%rip), %rsi     # 0x2f1bc
movss 0x1d8d8(%rip), %xmm1    # 0x20024
movss 0x1d8d4(%rip), %xmm2    # 0x20028
callq 0x1527a
movq %rbp, %rdi
callq 0xf835
movq %rbp, %rdi
movss 0x1d8ac(%rip), %xmm0    # 0x20018
movl %r14d, %esi
callq 0xf441
movaps 0x10(%rsp), %xmm0
movaps (%rsp), %xmm1
callq 0x4343
movl %eax, %ebx
movq %rbp, %rdi
callq 0x11f4b
movss 0x1d898(%rip), %xmm1    # 0x2002c
callq 0x36e7
movq %rbp, %rdi
movl %ebx, %esi
callq 0x1b128
testl %eax, %eax
je 0x28e2
movq %rbp, %rdi
movss 0x1d86a(%rip), %xmm0    # 0x20020
movl %r14d, %esi
callq 0xf441
movq %rbp, %rdi
movaps 0x10(%rsp), %xmm0
movaps (%rsp), %xmm1
movl %r14d, %esi
callq 0x1aacb
movaps %xmm0, (%rsp)
movaps %xmm1, 0x80(%rsp)
movq %rbp, %rdi
movss 0x1d847(%rip), %xmm0    # 0x20030
movl %r14d, %esi
callq 0xf441
xorps %xmm0, %xmm0
movq %rbp, %rdi
leaq 0x1d877(%rip), %rsi     # 0x20075
movaps (%rsp), %xmm1
movss 0x1d81a(%rip), %xmm2    # 0x20024
movss 0x1d822(%rip), %xmm3    # 0x20034
movss 0x1d81e(%rip), %xmm4    # 0x20038
callq 0x196ed
movaps %xmm0, 0x10(%rsp)
movaps (%rsp), %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
xorps %xmm0, %xmm0
movq %rbp, %rdi
leaq 0x1d840(%rip), %rsi     # 0x20079
movss 0x1d7e3(%rip), %xmm2    # 0x20024
movss 0x1d7eb(%rip), %xmm3    # 0x20034
movss 0x1d7e7(%rip), %xmm4    # 0x20038
callq 0x196ed
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 0x1d80d(%rip), %rsi     # 0x2007d
movaps 0x80(%rsp), %xmm1
movss 0x1d7a4(%rip), %xmm2    # 0x20024
movss 0x1d7ac(%rip), %xmm3    # 0x20034
movss 0x1d7a8(%rip), %xmm4    # 0x20038
callq 0x196ed
movaps %xmm0, (%rsp)
movaps 0x80(%rsp), %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
xorps %xmm0, %xmm0
movq %rbp, %rdi
leaq 0x1d7cf(%rip), %rsi     # 0x20081
movss 0x1d76a(%rip), %xmm2    # 0x20024
movss 0x1d772(%rip), %xmm3    # 0x20034
movss 0x1d76e(%rip), %xmm4    # 0x20038
callq 0x196ed
movaps (%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movaps %xmm1, (%rsp)
movq %rbp, %rdi
callq 0x1c329
movl %r12d, %ebx
movq %rbp, %rdi
callq 0xb158
movq %r13, %rdi
movsd 0x1d710(%rip), %xmm0    # 0x20008
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x22b0
movq %r13, %rdi
callq 0x20c0
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2964
movq %rbp, %rdi
callq 0x9a70
movq 0x30(%rsp), %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2250
movq 0x40(%rsp), %rdi
callq 0x2330
jmp 0x2577
callq 0x20e0
movq 0x28(%rsp), %rdi
callq 0x20b0
xorl %eax, %eax
addq $0x40a8, %rsp           # imm = 0x40A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop