// File: /workspace/github_c_makefile_star2_O2/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 *0x54cd3(%rip)          # 0x5e2c0
cmpb $0x1, %al
jne 0x9a7c
cmpb $0x7, %bpl
jne 0x9618
leaq 0x31c5e(%rip), %rsi     # 0x3b260
movq %r12, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x684b
movq %r14, %rdi
callq 0x6747
movq %rax, %r15
movzbl %bpl, %eax
movb $0x1, %bl
leal -0x2(%rax), %ecx
cmpl $0x7, %ecx
ja 0x968f
leaq 0x31b98(%rip), %rax     # 0x3b1d0
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %r14, %rdi
callq 0x5308
movzwl 0x4(%r12), %ecx
subw (%r12), %cx
incl %ecx
cmpw %cx, %ax
jne 0x967a
movq %r14, %rdi
callq 0x5332
movzwl 0x6(%r12), %ecx
subw 0x2(%r12), %cx
incl %ecx
cmpw %cx, %ax
je 0x9a7e
movq %r14, %rdi
callq 0x617f
movq %r14, %rdi
callq 0xa22b
jmp 0x9a7e
cmpl $0x12, %eax
jne 0x9a7e
movl (%r12), %eax
movl %eax, %ecx
andl $-0x3, %ecx
cmpl $0x11, %ecx
jne 0x98d8
movzwl (%r15), %ecx
movb 0x2(%r15), %sil
movb 0x3(%r15), %dil
movzbl 0x24(%r15), %eax
andl $0x3, %eax
leaq 0x31b4b(%rip), %rdx     # 0x3b210
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movzwl %cx, %eax
incl %eax
movl $0x168, %ecx            # imm = 0x168
xorl %edx, %edx
divl %ecx
movl %edx, %ecx
jmp 0x9ab9
callq 0x35b3
testq %rax, %rax
je 0x9a7e
movq %rax, %r12
leaq 0x4(%rsp), %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x3661
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 0x9744
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 0x9761
callq 0x801a
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 0x5308
movl %eax, %ebp
testb $0x8, 0x24(%r15)
jne 0x991d
movl 0x1c(%r15), %edi
callq 0x8031
movzwl 0x2a(%r12), %ecx
addl %ecx, %ecx
cmpl %ecx, %eax
jbe 0x97aa
testb $0x4, 0x24(%r15)
je 0x999c
movswl 0x4(%rsp), %eax
imull $0x168, %eax, %eax      # imm = 0x168
movzwl %bp, %ecx
cltd
idivl %ecx
cmpw $0x167, %ax             # imm = 0x167
movl $0x167, %ecx            # imm = 0x167
cmovll %eax, %ecx
xorl %edx, %edx
testw %ax, %ax
cmovnsl %ecx, %edx
movzwl (%r15), %edi
movb 0x2(%r15), %cl
movb 0x3(%r15), %sil
movzbl 0x24(%r15), %eax
andl $0x3, %eax
leaq 0x31a36(%rip), %r8      # 0x3b220
movslq (%r8,%rax,4), %rax
addq %r8, %rax
jmpq *%rax
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xa76b
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 0x9852
movq %r14, %rdi
callq 0x5332
movw $0x2, %r15w
cwtd
idivw %r15w
movl %eax, %ecx
movl %ebp, %eax
cmpw %cx, %bp
jg 0x984e
movq %r14, %rdi
callq 0x5332
cwtd
idivw %r15w
addl %ebp, %eax
movl %eax, %ebp
movl 0x5c(%r14), %eax
cmpw %bp, %ax
cmovlel %ebp, %eax
movw %ax, 0x5c(%r14)
jmp 0x9a7e
callq 0x801a
movl %eax, 0x1c(%r15)
callq 0x35b3
addq $0x20, %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x3661
movq %r14, %rdi
callq 0x6747
movq %rax, %r15
callq 0x35b3
movq %rax, %r12
movl 0x18(%r15), %edi
callq 0x8031
movzwl 0x2a(%r12), %ecx
cmpl %ecx, %eax
jae 0x9a22
movzwl (%r15), %eax
movb 0x2(%r15), %cl
movb 0x3(%r15), %dl
movzbl 0x24(%r15), %esi
andl $0x3, %esi
leaq 0x31928(%rip), %rdi     # 0x3b1f0
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
xorl %eax, %eax
jmp 0x99f2
cmpl $0x14, %eax
je 0x98e6
cmpl $0x12, %eax
jne 0x9a7e
movzwl (%r15), %eax
movb 0x2(%r15), %cl
movb 0x3(%r15), %dl
movzbl 0x24(%r15), %esi
andl $0x3, %esi
leaq 0x318ff(%rip), %rdi     # 0x3b200
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 0x9aea
movq %r14, %rdi
xorl %esi, %esi
callq 0xa76b
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 0x995e
subl %eax, %ecx
cmpw $0x33, %cx
pushq $0x32
popq %rax
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 0x99b6
movl 0x1c(%r15), %edi
callq 0x8031
movzwl 0x2a(%r12), %ecx
cmpl %ecx, %eax
jbe 0x9a7e
testb $0x4, 0x24(%r15)
jne 0x9a7e
movq %r14, %rdi
callq 0xaa06
callq 0x35b3
movq %rax, %rdi
callq 0x36d4
jmp 0x9a7e
callq 0x28e4f
movw $0x168, %cx             # imm = 0x168
xorl %edx, %edx
divw %cx
movzwl (%r15), %edi
movb 0x2(%r15), %cl
movb 0x3(%r15), %sil
movzbl 0x24(%r15), %eax
andl $0x3, %eax
leaq 0x31841(%rip), %r8      # 0x3b220
movslq (%r8,%rax,4), %rax
addq %r8, %rax
jmpq *%rax
movl %edx, %edi
jmp 0x9a4f
movb $0x64, %cl
jmp 0x99f2
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 0xa44e
testb %al, %al
je 0x9a22
pushq $0xe
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x4caf
cmpb $0x1, %al
jne 0x9a7c
callq 0x801a
movl %eax, 0x18(%r15)
jmp 0x9a7e
movswl %dx, %eax
imull $0x64, %eax, %eax
movl $0x168, %ecx            # imm = 0x168
cltd
idivl %ecx
movl %eax, %ecx
jmp 0x9a4f
movswl %dx, %eax
imull $0x64, %eax, %eax
movl $0x168, %esi            # imm = 0x168
cltd
idivl %esi
movl %eax, %esi
movzbl %sil, %eax
shll $0x18, %eax
movzbl %cl, %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzwl %di, %esi
orl %ecx, %esi
movq %r14, %rdi
callq 0xa44e
testb %al, %al
je 0x9a7e
pushq $0xe
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x4caf
movl %eax, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %sil, %eax
movzwl %ax, %eax
incl %eax
movw $0x64, %si
xorl %edx, %edx
divw %si
movl %edx, %esi
jmp 0x9ab9
movzbl %dil, %eax
movzwl %ax, %eax
incl %eax
movw $0x64, %di
xorl %edx, %edx
divw %di
movl %edx, %edi
movzbl %dil, %eax
shll $0x18, %eax
movzbl %sil, %edx
shll $0x10, %edx
orl %eax, %edx
movzwl %cx, %esi
orl %edx, %esi
jmp 0x9afd
subb $0x1, %cl
movzbl %cl, %esi
pushq $0x64
popq %rcx
cmovael %esi, %ecx
jmp 0x9aea
subb $0x1, %dl
movzbl %dl, %esi
pushq $0x64
popq %rdx
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 0xa44e
testb %al, %al
je 0x9a7e
pushq $0xe
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4caf