post
poster: G-man
description: Scrollbar
language: C
[download]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    
    // The height of the area the scrollbar can be drawn upon:
    int scrollbar_area_height = limit - 20;
    int scrollbar_start_y = f_show_search ? (tm.tmHeight + tm.tmExternalLeading) * 2
        : (tm.tmHeight + tm.tmExternalLeading) + 5;
    scrollbar_start_y += 10;
    int scrollbar_y = 0;
    int scrollbar_height = 0; // Height of scroll bar in px

    if(main_list->last_item <= files_per_area){
        scrollbar_height = scrollbar_area_height;
        scrollbar_y = scrollbar_start_y;
    }
    else{
        // For the height of the scroll bar:
        // Get percentage of files_per_area from total number of files
        int foo = (100 * files_per_area) / main_list->last_item;
        // Get corresponding percentage from the scrollbar area's height 
        scrollbar_height = (foo * scrollbar_area_height) / 100; 
        
        // For the y position of the scroll bar:
        // Get percentage of this item from the total number of items
        int foo2 = (100 * main_list->start_id) / main_list->last_item;
        // Get corresponding percentage from the scrollbar area's height 
        scrollbar_y = (scrollbar_area_height * foo2) / 100;
        scrollbar_y += scrollbar_start_y;
        draw_scrollbar(hdc, 3, scrollbar_y, scrollbar_height);
    }