// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x4148, %rsp           # imm = 0x4148
movl $0x0, 0x4144(%rsp)
movl %edi, 0x4140(%rsp)
movq %rsi, 0x4138(%rsp)
movl $0x20, %edi
callq 0x2340
leaq 0x42bba(%rip), %rdi     # 0x4503c
xorl %r9d, %r9d
movl $0x4b0, %ecx            # imm = 0x4B0
movl $0x2d0, %r8d            # imm = 0x2D0
movl %r9d, %esi
movl %r9d, %edx
callq 0x2120
movq %rax, 0x4130(%rsp)
movq 0x4130(%rsp), %rdi
callq 0x2170
movq %rax, 0x4128(%rsp)
xorl %edi, %edi
movl $0x4b0, %esi            # imm = 0x4B0
callq 0x2190
movl %eax, 0x4124(%rsp)
imull $0x2d0, 0x4124(%rsp), %eax # imm = 0x2D0
movslq %eax, %rdi
callq 0x22a0
movq %rax, 0x4118(%rsp)
movq 0x4118(%rsp), %rdi
movl 0x4124(%rsp), %r8d
movl $0x4b0, %esi            # imm = 0x4B0
movl $0x2d0, %edx            # imm = 0x2D0
movl $0x20, %ecx
movl $0xff0000, %r9d         # imm = 0xFF0000
movl $0xff00, (%rsp)         # imm = 0xFF00
movl $0xff, 0x8(%rsp)
movl $0xff000000, 0x10(%rsp) # imm = 0xFF000000
callq 0x2230
movq %rax, 0x4110(%rsp)
movq 0x4118(%rsp), %rdi
movl 0x4124(%rsp), %r8d
xorl %esi, %esi
movl $0x4b0, %edx            # imm = 0x4B0
movl $0x2d0, %ecx            # imm = 0x2D0
callq 0x21f0
movq %rax, 0x4108(%rsp)
movq 0x4108(%rsp), %rdi
callq 0x22c0
movq %rax, 0x4100(%rsp)
movq 0x4100(%rsp), %rdi
movsd 0x42a8b(%rip), %xmm2    # 0x45008
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x22b0
movq 0x4100(%rsp), %rdi
callq 0x20c0
callq 0x3f50
callq 0x3f00
cvtsi2ss %eax, %xmm0
movss %xmm0, 0xf0(%rsp)
leaq 0x188d(%rip), %rax      # 0x3e40
movq %rax, 0xf8(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x12cd0
testb $0x1, 0x50be9(%rip)     # 0x531c0
je 0x2b5e
leaq 0x100(%rsp), %rdi
callq 0xcd80
leaq 0xa0(%rsp), %rdi
callq 0x2310
cmpl $0x0, %eax
je 0x26fd
movl 0xa0(%rsp), %eax
movl %eax, 0x3c(%rsp)
subl $0x100, %eax            # imm = 0x100
je 0x26f1
jmp 0x2618
movl 0x3c(%rsp), %eax
subl $0x200, %eax            # imm = 0x200
je 0x26db
jmp 0x2629
movl 0x3c(%rsp), %eax
subl $0x300, %eax            # imm = 0x300
je 0x2660
jmp 0x2636
movl 0x3c(%rsp), %eax
subl $0x400, %eax            # imm = 0x400
je 0x2665
jmp 0x2643
movl 0x3c(%rsp), %eax
subl $0x401, %eax            # imm = 0x401
je 0x2682
jmp 0x2650
movl 0x3c(%rsp), %eax
subl $0x402, %eax            # imm = 0x402
je 0x26b0
jmp 0x26f8
jmp 0x26f8
movl 0xb4(%rsp), %esi
movl 0xb8(%rsp), %edx
leaq 0x100(%rsp), %rdi
callq 0xcf60
jmp 0x26f8
movzbl 0xb0(%rsp), %esi
subl $0x1, %esi
movl 0xb4(%rsp), %edx
movl 0xb8(%rsp), %ecx
leaq 0x100(%rsp), %rdi
movl $0x1, %r8d
callq 0xd0a0
jmp 0x26f8
movzbl 0xb0(%rsp), %esi
subl $0x1, %esi
movl 0xb4(%rsp), %edx
movl 0xb8(%rsp), %ecx
leaq 0x100(%rsp), %rdi
xorl %r8d, %r8d
callq 0xd0a0
jmp 0x26f8
movzbl 0xac(%rsp), %eax
cmpl $0xe, %eax
jne 0x26ef
movb $0x0, 0x50ad1(%rip)     # 0x531c0
jmp 0x26f8
movb $0x0, 0x50ac8(%rip)     # 0x531c0
jmp 0x25ea
leaq 0x100(%rsp), %rdi
callq 0xcec0
movss 0x428fe(%rip), %xmm1    # 0x45010
movss 0x428fa(%rip), %xmm3    # 0x45014
movaps %xmm1, %xmm0
movaps %xmm3, %xmm2
callq 0x3fc0
movlpd %xmm0, 0x90(%rsp)
movlpd %xmm1, 0x98(%rsp)
movsd 0x90(%rsp), %xmm0
movsd 0x98(%rsp), %xmm1
leaq 0x428f8(%rip), %rsi     # 0x45048
leaq 0x100(%rsp), %rdi
movl $0xf, %edx
callq 0x141c0
cmpl $0x0, %eax
je 0x2ad9
leaq 0x100(%rsp), %rdi
movss 0x4289d(%rip), %xmm0    # 0x45018
movl $0x50, %esi
movl $0x1, %edx
callq 0x1ea80
leaq 0x100(%rsp), %rdi
leaq 0x428b4(%rip), %rsi     # 0x4504d
callq 0x261a0
cmpl $0x0, %eax
je 0x27af
leaq 0x428aa(%rip), %rdi     # 0x45054
callq 0x22e0
leaq 0x100(%rsp), %rdi
movss 0x42859(%rip), %xmm0    # 0x45018
movl $0x2, %esi
callq 0x1e8b0
cmpl $0x0, 0x50aec(%rip)     # 0x532bc
sete %al
andb $0x1, %al
movzbl %al, %edx
leaq 0x100(%rsp), %rdi
leaq 0x4287c(%rip), %rsi     # 0x45063
callq 0x285c0
cmpl $0x0, %eax
je 0x27fb
movl $0x0, 0x50ac1(%rip)     # 0x532bc
cmpl $0x1, 0x50aba(%rip)     # 0x532bc
sete %al
andb $0x1, %al
movzbl %al, %edx
leaq 0x100(%rsp), %rdi
leaq 0x4284f(%rip), %rsi     # 0x45068
callq 0x285c0
cmpl $0x0, %eax
je 0x282d
movl $0x1, 0x50a8f(%rip)     # 0x532bc
leaq 0x100(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movl $0x1, %esi
movl %esi, 0x2c(%rsp)
movss 0x427cd(%rip), %xmm0    # 0x45018
movss %xmm0, 0x28(%rsp)
movl $0x2, %edx
callq 0x1eac0
movq 0x30(%rsp), %rdi
movss 0x427b4(%rip), %xmm0    # 0x4501c
callq 0x1ef80
movq 0x30(%rsp), %rdi
leaq 0x427f4(%rip), %rsi     # 0x4506d
movl $0x11, %edx
callq 0x254a0
movq 0x30(%rsp), %rdi
movss 0x42790(%rip), %xmm0    # 0x45020
callq 0x1ef80
movq 0x30(%rsp), %rdi
leaq 0x50923(%rip), %rsi     # 0x531c4
xorps %xmm0, %xmm0
movss 0x42778(%rip), %xmm1    # 0x45024
movss 0x42774(%rip), %xmm2    # 0x45028
callq 0x2a0e0
movq 0x30(%rsp), %rdi
callq 0x1f210
movss 0x28(%rsp), %xmm0
movl 0x2c(%rsp), %esi
movq 0x30(%rsp), %rdi
callq 0x1e8b0
movups 0xd8(%rsp), %xmm0
movaps %xmm0, 0x70(%rsp)
movsd 0x70(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
callq 0x6730
movq 0x30(%rsp), %rdi
movl %eax, 0x8c(%rsp)
callq 0x23d50
movss 0x4271e(%rip), %xmm1    # 0x4502c
callq 0x41b0
movlpd %xmm0, 0x68(%rsp)
movl 0x8c(%rsp), %esi
movsd 0x68(%rsp), %xmm0
leaq 0x100(%rsp), %rdi
callq 0x33ec0
cmpl $0x0, %eax
je 0x2ad7
leaq 0x100(%rsp), %rdi
movq %rdi, 0x18(%rsp)
movss 0x426cf(%rip), %xmm0    # 0x45020
movl $0x1, %esi
movl %esi, 0x24(%rsp)
callq 0x1e8b0
movq 0x18(%rsp), %rdi
movl 0x24(%rsp), %esi
movups 0xd8(%rsp), %xmm0
movaps %xmm0, 0x40(%rsp)
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
callq 0x330f0
movlpd %xmm0, 0x58(%rsp)
movlpd %xmm1, 0x60(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0xe0(%rsp)
leaq 0x100(%rsp), %rdi
movss 0x4267c(%rip), %xmm0    # 0x45038
movl $0x1, %esi
callq 0x1e8b0
movss 0xd8(%rsp), %xmm1
leaq 0x100(%rsp), %rdi
leaq 0x42697(%rip), %rsi     # 0x45075
xorps %xmm0, %xmm0
movss 0x4263b(%rip), %xmm2    # 0x45024
movss 0x4263f(%rip), %xmm3    # 0x45030
movss 0x4263b(%rip), %xmm4    # 0x45034
callq 0x307e0
movss %xmm0, 0xd8(%rsp)
movss 0xdc(%rsp), %xmm1
leaq 0x100(%rsp), %rdi
leaq 0x4265a(%rip), %rsi     # 0x45079
xorps %xmm0, %xmm0
movss 0x425fa(%rip), %xmm2    # 0x45024
movss 0x425fe(%rip), %xmm3    # 0x45030
movss 0x425fa(%rip), %xmm4    # 0x45034
callq 0x307e0
movss %xmm0, 0xdc(%rsp)
movss 0xe0(%rsp), %xmm1
leaq 0x100(%rsp), %rdi
leaq 0x4261d(%rip), %rsi     # 0x4507d
xorps %xmm0, %xmm0
movss 0x425b9(%rip), %xmm2    # 0x45024
movss 0x425bd(%rip), %xmm3    # 0x45030
movss 0x425b9(%rip), %xmm4    # 0x45034
callq 0x307e0
movss %xmm0, 0xe0(%rsp)
movss 0xe4(%rsp), %xmm1
leaq 0x100(%rsp), %rdi
leaq 0x425e0(%rip), %rsi     # 0x45081
xorps %xmm0, %xmm0
movss 0x42578(%rip), %xmm2    # 0x45024
movss 0x4257c(%rip), %xmm3    # 0x45030
movss 0x42578(%rip), %xmm4    # 0x45034
callq 0x307e0
movss %xmm0, 0xe4(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x36b20
jmp 0x2ad9
leaq 0x100(%rsp), %rdi
callq 0x16900
movq 0x4100(%rsp), %rdi
movsd 0x42512(%rip), %xmm2    # 0x45008
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x22b0
movq 0x4100(%rsp), %rdi
callq 0x20c0
movq 0x4100(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x2b80
leaq 0x100(%rsp), %rdi
callq 0x132f0
movq 0x4110(%rsp), %rdi
movq 0x4128(%rsp), %rdx
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
callq 0x2250
movq 0x4130(%rsp), %rdi
callq 0x2330
jmp 0x25d0
callq 0x20e0
movq 0x4118(%rsp), %rdi
callq 0x20b0
xorl %eax, %eax
addq $0x4148, %rsp           # imm = 0x4148
retq
nopw (%rax,%rax)