// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_cpicker.c
// Function: lv_cpicker_signal
static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * param)
{
    /* Include the ancient signal function */
    lv_res_t res = ancestor_signal(cpicker, sign, param);
    if(res != LV_RES_OK) return res;
    if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);

    lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker);

    if(sign == LV_SIGNAL_CLEANUP) {
        /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
    } else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
        const lv_style_t * style_indic = lv_cpicker_get_style(cpicker, LV_CPICKER_STYLE_INDICATOR);
        lv_coord_t indic_pad = LV_MATH_MAX(style_indic->body.padding.left, style_indic->body.padding.right);
        indic_pad = LV_MATH_MAX(indic_pad, style_indic->body.padding.top);
        indic_pad = LV_MATH_MAX(indic_pad, style_indic->body.padding.bottom);

        if(ext->type == LV_CPICKER_TYPE_RECT) indic_pad += LV_MATH_MAX(indic_pad, lv_obj_get_height(cpicker) / 2);

        cpicker->ext_draw_pad = LV_MATH_MAX(cpicker->ext_draw_pad, indic_pad);
    } else if(sign == LV_SIGNAL_CORD_CHG) {
        /*Refresh extended draw area to make knob visible*/
        if(lv_obj_get_width(cpicker) != lv_area_get_width(param) ||
           lv_obj_get_height(cpicker) != lv_area_get_height(param)) {
            lv_obj_refresh_ext_draw_pad(cpicker);
            refr_indic_pos(cpicker);
        }
    }  else if(sign == LV_SIGNAL_STYLE_CHG) {
        /*Refresh extended draw area to make knob visible*/
        lv_obj_refresh_ext_draw_pad(cpicker);
        refr_indic_pos(cpicker);
    }
    else if(sign == LV_SIGNAL_CONTROL) {
        uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/
        if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
            lv_color_hsv_t hsv_cur;
            hsv_cur = ext->hsv;

            switch(ext->color_mode) {
            case LV_CPICKER_COLOR_MODE_HUE:
                hsv_cur.h = (ext->hsv.h + 1) % 360;
                break;
            case LV_CPICKER_COLOR_MODE_SATURATION:
                hsv_cur.s = (ext->hsv.s + 1) % 100;
                break;
            case LV_CPICKER_COLOR_MODE_VALUE:
                hsv_cur.v = (ext->hsv.v + 1) % 100;
                break;
            }

            if (lv_cpicker_set_hsv(cpicker, hsv_cur)) {
                res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL);
                if(res != LV_RES_OK) return res;
            }
        }
        else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN)  {
            lv_color_hsv_t hsv_cur;
            hsv_cur = ext->hsv;

            switch(ext->color_mode) {
            case LV_CPICKER_COLOR_MODE_HUE:
                hsv_cur.h = ext->hsv.h > 0?(ext->hsv.h - 1) : 360;
                break;
            case LV_CPICKER_COLOR_MODE_SATURATION:
                hsv_cur.s = ext->hsv.s > 0?(ext->hsv.s - 1) : 100;
                break;
            case LV_CPICKER_COLOR_MODE_VALUE:
                hsv_cur.v = ext->hsv.v > 0?(ext->hsv.v - 1) : 100;
                break;
            }

            if (lv_cpicker_set_hsv(cpicker, hsv_cur)) {
                res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL);
                if(res != LV_RES_OK) return res;
            }
        }
    }
    else if(sign == LV_SIGNAL_PRESSED) {
        ext->last_change_time = lv_tick_get();
        lv_indev_get_point(lv_indev_get_act(), &ext->last_press_point);
        res = double_click_reset(cpicker);
        if(res != LV_RES_OK) return res;
    } else if(sign == LV_SIGNAL_PRESSING) {
        lv_indev_t * indev = lv_indev_get_act();
        if(indev == NULL) return res;

        lv_point_t p;
        lv_indev_get_point(indev, &p);

        if((LV_MATH_ABS(p.x - ext->last_press_point.x) > indev->driver.drag_limit / 2) ||
           (LV_MATH_ABS(p.y - ext->last_press_point.y) > indev->driver.drag_limit / 2)) {
            ext->last_change_time = lv_tick_get();
            ext->last_press_point.x = p.x;
            ext->last_press_point.y = p.y;
        }

        p.x -= cpicker->coords.x1;
        p.y -= cpicker->coords.y1;

        /*Ignore pressing in the inner area*/
        uint16_t w = lv_obj_get_width(cpicker);

        int16_t angle = 0;

        if(ext->type == LV_CPICKER_TYPE_RECT) {
            /*If pressed long enough without change go to next color mode*/
            uint32_t diff = lv_tick_elaps(ext->last_change_time);
            if(diff > (uint32_t)indev->driver.long_press_time * 2 && !ext->color_mode_fixed) {
                next_color_mode(cpicker);
                lv_indev_wait_release(lv_indev_get_act());
                return res;
            }

            angle = (p.x * 360) / w;
            if(angle < 0) angle = 0;
            if(angle >= 360) angle = 359;

        } else if(ext->type == LV_CPICKER_TYPE_DISC) {
            const lv_style_t * style_main = lv_cpicker_get_style(cpicker, LV_CPICKER_STYLE_MAIN);
            lv_coord_t r_in = w / 2;
            p.x -= r_in;
            p.y -= r_in;
            r_in -= style_main->line.width;

            if(r_in > LV_DPI / 2) {
            	r_in -= style_main->line.width; /* to let some sensitive space inside*/

            	if(r_in < LV_DPI / 2) r_in = LV_DPI / 2;
            }

            /*If the inner area is being pressed, go to the next color mode on long press*/
            if(p.x * p.x + p.y * p.y < r_in * r_in) {
                uint32_t diff = lv_tick_elaps(ext->last_change_time);
                if(diff > indev->driver.long_press_time && !ext->color_mode_fixed) {
                    next_color_mode(cpicker);
                    lv_indev_wait_release(lv_indev_get_act());
                }
                return res;
            }

            angle = lv_atan2(p.x, p.y) % 360;
        }

        lv_color_hsv_t hsv_cur;
        hsv_cur = ext->hsv;

        switch(ext->color_mode) {
        case LV_CPICKER_COLOR_MODE_HUE:
            hsv_cur.h = angle;
            break;
        case LV_CPICKER_COLOR_MODE_SATURATION:
            hsv_cur.s = (angle * 100) / 360;
            break;
        case LV_CPICKER_COLOR_MODE_VALUE:
            hsv_cur.v = (angle * 100) / 360;
            break;
        }

        if (lv_cpicker_set_hsv(cpicker, hsv_cur)) {
            res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL);
            if(res != LV_RES_OK) return res;
        }
    }

    return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r12
movl %esi, %ebp
movq %rdi, %r14
callq *0x5649c(%rip)          # 0x602c0
cmpb $0x1, %al
jne 0xa2f5
cmpb $0x7, %bpl
jne 0x9e4f
leaq 0x354c7(%rip), %rsi     # 0x3f300
movq %r12, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6c02
movq %r14, %rdi
callq 0x6af7
movq %rax, %r15
movzbl %bpl, %eax
movb $0x1, %bl
leal -0x2(%rax), %ecx
cmpl $0x7, %ecx
ja 0x9ec6
leaq 0x35401(%rip), %rax     # 0x3f270
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %r14, %rdi
callq 0x566d
movzwl 0x4(%r12), %ecx
subw (%r12), %cx
incl %ecx
cmpw %cx, %ax
jne 0x9eb1
movq %r14, %rdi
callq 0x5697
movzwl 0x6(%r12), %ecx
subw 0x2(%r12), %cx
incl %ecx
cmpw %cx, %ax
je 0xa2f7
movq %r14, %rdi
callq 0x6514
movq %r14, %rdi
callq 0xab17
jmp 0xa2f7
cmpl $0x12, %eax
jne 0xa2f7
movl (%r12), %eax
movl %eax, %ecx
andl $-0x3, %ecx
cmpl $0x11, %ecx
jne 0xa121
movzwl (%r15), %eax
movb 0x2(%r15), %cl
movb 0x3(%r15), %dl
movzbl 0x24(%r15), %esi
andl $0x3, %esi
leaq 0x353b4(%rip), %rdi     # 0x3f2b0
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
movzwl %ax, %eax
incl %eax
imulq $0xb60b61, %rax, %rsi   # imm = 0xB60B61
shrq $0x20, %rsi
imull $0x168, %esi, %esi      # imm = 0x168
subl %esi, %eax
jmp 0xa336
callq 0x378a
testq %rax, %rax
je 0xa2f7
movq %rax, %r12
leaq 0x4(%rsp), %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x3838
movswl (%r13), %eax
movswl 0x20(%r15), %ecx
movl %eax, %edx
subl %ecx, %edx
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
movzwl %cx, %ecx
movzbl 0x28(%r12), %edx
shrl %edx
cmpl %edx, %ecx
ja 0x9f83
movswl 0x6(%rsp), %ecx
movswl 0x22(%r15), %esi
movl %ecx, %edi
subl %esi, %edi
movl %edi, %esi
negl %esi
cmovsl %edi, %esi
movzwl %si, %esi
cmpl %edx, %esi
jbe 0x9fa0
callq 0x87b6
movl %eax, 0x1c(%r15)
movzwl 0x4(%rsp), %eax
movw %ax, 0x20(%r15)
movzwl 0x6(%rsp), %ecx
movw %cx, 0x22(%r15)
subw 0x20(%r14), %ax
movw %ax, 0x4(%rsp)
subw 0x22(%r14), %cx
movw %cx, 0x6(%rsp)
movq %r14, %rdi
callq 0x566d
movl %eax, %ebp
testb $0x8, 0x24(%r15)
jne 0xa166
movl 0x1c(%r15), %edi
callq 0x87cd
movzwl 0x2a(%r12), %ecx
addl %ecx, %ecx
cmpl %ecx, %eax
jbe 0x9fe9
testb $0x4, 0x24(%r15)
je 0xa1e7
movswl 0x4(%rsp), %eax
imull $0x168, %eax, %eax      # imm = 0x168
movzwl %bp, %ecx
cltd
idivl %ecx
movswl %ax, %ecx
movl $0x167, %edx            # imm = 0x167
cmpl %edx, %ecx
cmovll %eax, %edx
xorl %eax, %eax
testw %cx, %cx
cmovnsl %edx, %eax
movzwl (%r15), %ecx
movb 0x2(%r15), %dl
movb 0x3(%r15), %sil
movzbl 0x24(%r15), %edi
andl $0x3, %edi
leaq 0x35296(%rip), %r8      # 0x3f2c0
movslq (%r8,%rdi,4), %rdi
addq %r8, %rdi
jmpq *%rdi
movq %r14, %rdi
movl $0x1, %esi
callq 0xb08b
movq 0x16(%rax), %xmm0
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
pmaxsw %xmm0, %xmm1
movdqa %xmm1, %xmm0
psrld $0x10, %xmm0
pmaxsw %xmm1, %xmm0
movd %xmm0, %ebp
testb $0x8, 0x24(%r15)
jne 0xa09b
movq %r14, %rdi
callq 0x5697
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %ecx
shrl %ecx
movl %ebp, %eax
cmpw %cx, %bp
jg 0xa097
movq %r14, %rdi
callq 0x5697
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %eax
shrl %eax
addl %ebp, %eax
movl %eax, %ebp
movl 0x5c(%r14), %eax
cmpw %bp, %ax
cmovlel %ebp, %eax
movw %ax, 0x5c(%r14)
jmp 0xa2f7
callq 0x87b6
movl %eax, 0x1c(%r15)
callq 0x378a
addq $0x20, %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x3838
movq %r14, %rdi
callq 0x6af7
movq %rax, %r15
callq 0x378a
movq %rax, %r12
movl 0x18(%r15), %edi
callq 0x87cd
movzwl 0x2a(%r12), %ecx
cmpl %ecx, %eax
jae 0xa27d
movzwl (%r15), %eax
movb 0x2(%r15), %cl
movb 0x3(%r15), %dl
movzbl 0x24(%r15), %esi
andl $0x3, %esi
leaq 0x3517f(%rip), %rdi     # 0x3f290
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
xorl %eax, %eax
jmp 0xa24b
cmpl $0x14, %eax
je 0xa12f
cmpl $0x12, %eax
jne 0xa2f7
movzwl (%r15), %eax
movb 0x2(%r15), %cl
movb 0x3(%r15), %dl
movzbl 0x24(%r15), %esi
andl $0x3, %esi
leaq 0x35156(%rip), %rdi     # 0x3f2a0
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
subw $0x1, %ax
movl $0x168, %esi            # imm = 0x168
cmovael %eax, %esi
movl %esi, %eax
jmp 0xa367
movq %r14, %rdi
xorl %esi, %esi
callq 0xb08b
movzwl %bp, %ecx
shrl %ecx
movzwl 0x4(%rsp), %edx
subl %ecx, %edx
movw %dx, 0x4(%rsp)
movzwl 0x6(%rsp), %esi
subl %ecx, %esi
movw %si, 0x6(%rsp)
movzwl 0x3e(%rax), %eax
subl %eax, %ecx
cmpw $0x33, %cx
jl 0xa1a9
subl %eax, %ecx
cmpw $0x33, %cx
movl $0x32, %eax
cmovgel %ecx, %eax
movl %eax, %ecx
movswl %dx, %edi
movl %edi, %eax
imull %edi, %eax
movswl %si, %esi
movl %esi, %edx
imull %esi, %edx
addl %eax, %edx
movswl %cx, %eax
imull %eax, %eax
cmpl %eax, %edx
jae 0xa201
movl 0x1c(%r15), %edi
callq 0x87cd
movzwl 0x2a(%r12), %ecx
cmpl %ecx, %eax
jbe 0xa2f7
testb $0x4, 0x24(%r15)
jne 0xa2f7
movq %r14, %rdi
callq 0xb352
callq 0x378a
movq %rax, %rdi
callq 0x38ad
jmp 0xa2f7
callq 0x2b5af
movzwl %ax, %ecx
imull $0x2d83, %ecx, %ecx     # imm = 0x2D83
shrl $0x16, %ecx
imull $0x168, %ecx, %ecx      # imm = 0x168
subl %ecx, %eax
movzwl (%r15), %ecx
movb 0x2(%r15), %dl
movb 0x3(%r15), %sil
movzbl 0x24(%r15), %edi
andl $0x3, %edi
leaq 0x3508b(%rip), %r8      # 0x3f2c0
movslq (%r8,%rdi,4), %rdi
addq %r8, %rdi
jmpq *%rdi
movl %eax, %ecx
jmp 0xa2c6
movb $0x64, %cl
jmp 0xa24b
movb $0x64, %dl
movzbl %dl, %edx
shll $0x18, %edx
movzbl %cl, %ecx
shll $0x10, %ecx
orl %edx, %ecx
movzwl %ax, %esi
orl %ecx, %esi
movq %r14, %rdi
callq 0xad66
testb %al, %al
je 0xa27d
movq %r14, %rdi
movl $0xe, %esi
xorl %edx, %edx
callq 0x5018
cmpb $0x1, %al
jne 0xa2f5
callq 0x87b6
movl %eax, 0x18(%r15)
jmp 0xa2f7
cwtl
imull $0x64, %eax, %eax
movslq %eax, %rdx
imulq $-0x49f49f49, %rdx, %rax # imm = 0xB60B60B7
shrq $0x20, %rax
addl %eax, %edx
movl %edx, %eax
shrl $0x1f, %eax
shrl $0x8, %edx
addl %eax, %edx
jmp 0xa2c6
cwtl
imull $0x64, %eax, %eax
movslq %eax, %rsi
imulq $-0x49f49f49, %rsi, %rax # imm = 0xB60B60B7
shrq $0x20, %rax
addl %eax, %esi
movl %esi, %eax
shrl $0x1f, %eax
shrl $0x8, %esi
addl %eax, %esi
movzbl %sil, %eax
shll $0x18, %eax
movzbl %dl, %edx
shll $0x10, %edx
orl %eax, %edx
movzwl %cx, %esi
orl %edx, %esi
movq %r14, %rdi
callq 0xad66
testb %al, %al
je 0xa2f7
movq %r14, %rdi
movl $0xe, %esi
xorl %edx, %edx
callq 0x5018
movl %eax, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %cl, %ecx
movzwl %cx, %ecx
incl %ecx
imull $0x290, %ecx, %esi      # imm = 0x290
shrl $0x10, %esi
imull $0x64, %esi, %esi
subl %esi, %ecx
jmp 0xa336
movzbl %dl, %edx
movzwl %dx, %edx
incl %edx
imull $0x290, %edx, %esi      # imm = 0x290
shrl $0x10, %esi
imull $0x64, %esi, %esi
subl %esi, %edx
movzbl %dl, %edx
shll $0x18, %edx
movzbl %cl, %ecx
shll $0x10, %ecx
orl %edx, %ecx
movzwl %ax, %esi
jmp 0xa378
subb $0x1, %cl
movzbl %cl, %esi
movl $0x64, %ecx
cmovael %esi, %ecx
jmp 0xa367
subb $0x1, %dl
movzbl %dl, %esi
movl $0x64, %edx
cmovael %esi, %edx
movzbl %dl, %edx
shll $0x18, %edx
movzbl %cl, %ecx
shll $0x10, %ecx
orl %edx, %ecx
movzwl %ax, %esi
orl %ecx, %esi
movq %r14, %rdi
callq 0xad66
testb %al, %al
je 0xa2f7
movq %r14, %rdi
movl $0xe, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5018