// File: /workspace/github_c_makefile_star2_O1/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 *0x56424(%rip)          # 0x602c0
movl %eax, %ebx
cmpb $0x1, %al
jne 0xa27c
cmpb $0x7, %bpl
jne 0x9ec9
leaq 0x3539d(%rip), %rsi     # 0x3f250
movq %r12, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6bf5
movq %r14, %rdi
callq 0x6ad8
movq %rax, %r15
movzbl %bpl, %ecx
leal -0x2(%rcx), %eax
cmpl $0x7, %eax
ja 0x9f3e
leaq 0x352d9(%rip), %rcx     # 0x3f1c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x5651
movzwl 0x4(%r12), %ecx
subw (%r12), %cx
incl %ecx
cmpw %cx, %ax
jne 0x9f29
movq %r14, %rdi
callq 0x567b
movzwl 0x6(%r12), %ecx
subw 0x2(%r12), %cx
incl %ecx
cmpw %cx, %ax
je 0xa27c
movq %r14, %rdi
callq 0x64f5
movq %r14, %rdi
callq 0xaba9
jmp 0xa27c
cmpl $0x12, %ecx
jne 0xa27c
movl (%r12), %eax
movl %eax, %ecx
andl $-0x3, %ecx
cmpl $0x11, %ecx
jne 0xa16e
movzwl (%r15), %eax
movb 0x2(%r15), %cl
movb 0x3(%r15), %dl
movzbl 0x24(%r15), %esi
andl $0x3, %esi
leaq 0x3528c(%rip), %rdi     # 0x3f200
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 0xa383
callq 0x3784
testq %rax, %rax
je 0xa274
movq %rax, %r12
leaq 0x4(%rsp), %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x3832
movswl (%r13), %eax
movswl 0x20(%r15), %ecx
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movzwl %cx, %ecx
movzbl 0x28(%r12), %eax
shrl %eax
cmpl %eax, %ecx
ja 0x9ff7
movswl 0x6(%rsp), %ecx
movswl 0x22(%r15), %edx
subl %edx, %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
movzwl %dx, %ecx
cmpl %eax, %ecx
jbe 0xa014
callq 0x883e
movl %eax, 0x1c(%r15)
movzwl 0x4(%rsp), %eax
movw %ax, 0x20(%r15)
movzwl 0x6(%rsp), %eax
movw %ax, 0x22(%r15)
movzwl 0x20(%r14), %eax
subw %ax, 0x4(%rsp)
movzwl 0x22(%r14), %eax
subw %ax, 0x6(%rsp)
movq %r14, %rdi
callq 0x5651
movl %eax, %ebp
testb $0x8, 0x24(%r15)
jne 0xa1b3
movl 0x1c(%r15), %edi
callq 0x8855
movzwl 0x2a(%r12), %ecx
addl %ecx, %ecx
cmpl %ecx, %eax
jbe 0xa248
testb $0x4, 0x24(%r15)
jne 0xa248
movq %r14, %rdi
callq 0xb3dc
callq 0x3784
movq %rax, %rdi
callq 0x38a7
xorl %eax, %eax
xorl %ecx, %ecx
jmp 0xa270
movq %r14, %rdi
movl $0x1, %esi
callq 0xb115
movzwl 0x1a(%rax), %ecx
movzwl 0x1c(%rax), %ebp
cmpw %bp, %cx
cmovgl %ecx, %ebp
movzwl 0x16(%rax), %ecx
cmpw %cx, %bp
cmovlel %ecx, %ebp
movzwl 0x18(%rax), %eax
cmpw %ax, %bp
cmovlel %eax, %ebp
testb $0x8, 0x24(%r15)
jne 0xa0ea
movq %r14, %rdi
callq 0x567b
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %ecx
shrl %ecx
movl %ebp, %eax
cmpw %cx, %bp
jg 0xa0e6
movq %r14, %rdi
callq 0x567b
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 0xa27c
callq 0x883e
movl %eax, 0x1c(%r15)
callq 0x3784
addq $0x20, %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x3832
movq %r14, %rdi
callq 0x6ad8
movq %rax, %r15
callq 0x3784
movq %rax, %rbx
movl 0x18(%r15), %edi
callq 0x8855
movzwl 0x2a(%rbx), %ecx
cmpl %ecx, %eax
jae 0xa335
movzwl (%r15), %eax
movb 0x2(%r15), %cl
movb 0x3(%r15), %dl
movzbl 0x24(%r15), %esi
andl $0x3, %esi
leaq 0x35082(%rip), %rdi     # 0x3f1e0
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
xorl %eax, %eax
jmp 0xa2f8
cmpl $0x14, %eax
je 0xa17c
cmpl $0x12, %eax
jne 0xa350
movzwl (%r15), %eax
movb 0x2(%r15), %cl
movb 0x3(%r15), %dl
movzbl 0x24(%r15), %esi
andl $0x3, %esi
leaq 0x35059(%rip), %rdi     # 0x3f1f0
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 0xa427
movq %r14, %rdi
xorl %esi, %esi
callq 0xb115
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 0xa1f6
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, %ebp
imull %esi, %ebp
addl %eax, %ebp
movswl %cx, %r13d
imull %r13d, %r13d
cmpl %r13d, %ebp
jae 0xa28d
movl 0x1c(%r15), %edi
callq 0x8855
movzwl 0x2a(%r12), %ecx
cmpl %ecx, %eax
jbe 0xa244
testb $0x4, 0x24(%r15)
jne 0xa244
movq %r14, %rdi
callq 0xb3dc
callq 0x3784
movq %rax, %rdi
callq 0x38a7
xorl %eax, %eax
jmp 0xa2a6
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
movb $0x1, %cl
testb %cl, %cl
jne 0xa2ab
xorl %edx, %edx
movl %ebx, %eax
testb %dl, %dl
je 0xa27e
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2ae6d
movzwl %ax, %ecx
imull $0x2d83, %ecx, %ecx     # imm = 0x2D83
shrl $0x16, %ecx
imull $0x168, %ecx, %ecx      # imm = 0x168
subl %ecx, %eax
cmpl %r13d, %ebp
jb 0xa274
movzwl (%r15), %esi
movb 0x2(%r15), %cl
movb 0x3(%r15), %dl
movzbl 0x24(%r15), %edi
andl $0x3, %edi
leaq 0x34f4a(%rip), %r8      # 0x3f210
movslq (%r8,%rdi,4), %rdi
addq %r8, %rdi
jmpq *%rdi
cwtl
imull $0x64, %eax, %eax
movslq %eax, %rcx
imulq $-0x49f49f49, %rcx, %rax # imm = 0xB60B60B7
shrq $0x20, %rax
addl %eax, %ecx
movl %ecx, %eax
shrl $0x1f, %eax
shrl $0x8, %ecx
addl %eax, %ecx
jmp 0xa3b7
movb $0x64, %cl
jmp 0xa2f8
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 0xadf8
testb %al, %al
je 0xa32f
movq %r14, %rdi
movl $0xe, %esi
xorl %edx, %edx
callq 0x4fea
movl %eax, %ebx
cmpb $0x1, %al
sete %al
jmp 0xa331
movb $0x1, %al
testb %al, %al
je 0xa340
callq 0x883e
movl %eax, 0x18(%r15)
movb $0x1, %bl
movl %ebx, %eax
cmpb $0x1, %bl
je 0xa27c
jmp 0xa27e
jmp 0xa464
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 0xa383
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 0xa438
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
movl %esi, %eax
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 0xadf8
movl %eax, %ecx
movb $0x1, %dl
movl %ebx, %eax
testb %cl, %cl
je 0xa278
movq %r14, %rdi
movl $0xe, %esi
xorl %edx, %edx
callq 0x4fea
movl %eax, %ecx
movzbl %bl, %eax
cmpb $0x1, %cl
sete %dl
movzbl %cl, %esi
cmovnel %esi, %eax
movl %ecx, %ebx
jmp 0xa278
subb $0x1, %cl
movzbl %cl, %esi
movl $0x64, %ecx
cmovael %esi, %ecx
jmp 0xa427
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 0xadf8
testb %al, %al
je 0xa45e
movq %r14, %rdi
movl $0xe, %esi
xorl %edx, %edx
callq 0x4fea
movl %eax, %ebx
cmpb $0x1, %al
sete %cl
jmp 0xa460
movb $0x1, %cl
testb %cl, %cl
je 0xa468
movb $0x1, %cl
jmp 0xa46a
xorl %ecx, %ecx
testb %cl, %cl
jne 0xa27c
jmp 0xa27e