~samhsmith/AstraOS

f249c961f77eec4dd2ea253f683af9648fd1b630 — Sam H Smith 2 years ago 908d94e
added mouse cursor location to thunder and added a toggle follow cursor to super_cool_square
2 files changed, 70 insertions(+), 1 deletions(-)

M square_src/elf.c
M src/tempuser.c
M square_src/elf.c => square_src/elf.c +28 -1
@@ 76,6 76,11 @@ void _start()
    f64 last_frame_time = start_time;
    u8 input = 0;

    f64 cursor_x = 0.0;
    f64 cursor_y = 0.0;

    u8 lock_square_to_cursor = 0;

while(1)
{
#define DEBUG_IPFC_TIME 0


@@ 105,6 110,20 @@ while(1)
        f64 sec_after_call = AOS_H_time_get_seconds();
        AOS_H_printf("time to get surfaces via ipfc : %5.5lf ms\n", (sec_after_call - sec_before_call) * 1000.0);
#endif

        {
            f64 fscratch[1024/8];
            if(AOS_IPFC_call(twa_session_id, 3, scratch, fscratch))
            {
//                AOS_H_printf("       cursor position is %3.3lf %3.3lf\n", fscratch[0], fscratch[1]);
                cursor_x = fscratch[0];
                cursor_y = fscratch[1];
            }
            else
            {
                AOS_H_printf("failed to get cursor location\n");
            }
        }
    }

    AOS_thread_awake_on_surface(&surfaces, surface_count);


@@ 168,6 187,8 @@ while(1)
                    { input = input | 4; }
                    else if(scancode == 102)
                    { input = input | 8; }
                    else if(scancode == 60)
                    { lock_square_to_cursor = !lock_square_to_cursor; }
                }
                else
                {


@@ 199,6 220,12 @@ while(1)
        f32 square_x = (f32)square_x_control + sineF32(3.0*time)/2.0;
        f32 square_y = (f32)square_y_control + sineF32(3.0*time/M_PI)/2.0;

        if(lock_square_to_cursor)
        {
            square_x = ( cursor_x - 0.5) * 2.0;
            square_y = (-cursor_y + 0.5) * 2.0;
        }

        f32 red = (sineF32((time*M_PI)/2.0) + 1.0) / 2.0;
        f32 green = (sineF32((time*M_PI)/3.0) + 1.0) / 2.0;
        f32 blue = (sineF32((time*M_PI)/5.0) + 1.0) / 2.0;


@@ 269,7 296,7 @@ while(1)
        }
        AOS_surface_commit(surfaces[0]);
        f64 frame_end = AOS_H_time_get_seconds();
        AOS_H_printf("elf time : %10.10lf ms\n", (frame_end - frame_start) * 1000.0);
//        AOS_H_printf("elf time : %10.10lf ms\n", (frame_end - frame_start) * 1000.0);
    }
}
}

M src/tempuser.c => src/tempuser.c +42 -0
@@ 22,6 22,8 @@ typedef struct
    u64 height;
    u64 new_width;
    u64 new_height;
    f64 cursor_x;
    f64 cursor_y;
    AOS_Framebuffer* fb;
    u64 fb_page_count;
    u8 we_have_frame;


@@ 386,6 388,7 @@ const char* TWA_IPFC_API_NAME = "thunder_windowed_application_ipfc_api_v1";
// f0 is create window
// f1 is destroy window
// f2 is get surfaces
// f3 is get cursor pos
void thunder_windowed_application_ipfc_api_entry(u64 source_pid, u16 function_index, void* static_data_1024b)
{
    // this enables the use of global variables


@@ 520,6 523,32 @@ void thunder_windowed_application_ipfc_api_entry(u64 source_pid, u16 function_in
        rwlock_release_read(&thunder_lock);
        AOS_IPFC_return(0);
    }
    else if(function_index == 3)
    {
//        spinlock_acquire(&tempuser_printout_lock);
//        AOS_H_printf("get cursor pos! from pid %llu\n", source_pid);
//        spinlock_release(&tempuser_printout_lock);
        u64 window_handle;
        {
            u64* window_handle_pointer = static_data_1024b;
            window_handle = *window_handle_pointer;
        }

        f64* copy_to = static_data_1024b;

        for(u64 i = 0; i < window_count; i++)
        {
            if(windows[i].pid != source_pid || windows[i].window_handle != window_handle)
            { continue; }

            copy_to[0] = windows[i].cursor_x;
            copy_to[1] = windows[i].cursor_y;
            rwlock_release_read(&thunder_lock);
            AOS_IPFC_return(1);
        }
        rwlock_release_read(&thunder_lock);
        AOS_IPFC_return(0);
    }

    rwlock_release_read(&thunder_lock);
    AOS_IPFC_return(0);


@@ 732,6 761,19 @@ while(1) {
                is_resizing_window = 0;
            }
        }

        for(u64 i = 0; i < window_count; i++)
        {
            f64 dx = (f64)new_cursor_x - (f64)(windows[i].new_x + BORDER_SIZE);
            f64 dy = (f64)new_cursor_y - (f64)(windows[i].new_y + BORDER_SIZE);

            dx /= (f64)(windows[i].new_width - 2*BORDER_SIZE);
            dy /= (f64)(windows[i].new_height - 2*BORDER_SIZE);

            windows[i].cursor_x = dx;
            windows[i].cursor_y = dy;
        }

        rwlock_release_write(&thunder_lock);
        rwlock_acquire_read(&thunder_lock);
    }