1// Copyright (C) 2009 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma version(1)
16
17#pragma rs java_package_name(com.android.rs.test_v16)
18
19#include "rs_graphics.rsh"
20
21float gDY;
22
23rs_font gFont;
24
25typedef struct ListAllocs_s {
26    rs_allocation text;
27    int result;
28} ListAllocs;
29
30ListAllocs *gList;
31
32void init() {
33    gDY = 0.0f;
34}
35
36int textPos = 0;
37
38int root(void) {
39
40    rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
41    rsgClearDepth(1.0f);
42
43    textPos -= (int)gDY*2;
44    gDY *= 0.95;
45
46    rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f);
47    rsgBindFont(gFont);
48
49    rs_allocation listAlloc;
50    listAlloc = rsGetAllocation(gList);
51    int allocSize = rsAllocationGetDimX(listAlloc);
52
53    int width = rsgGetWidth();
54    int height = rsgGetHeight();
55
56    int itemHeight = 80;
57    int totalItemHeight = itemHeight * allocSize;
58
59    /* Prevent scrolling above the top of the list */
60    int firstItem = height - totalItemHeight;
61    if (firstItem < 0) {
62        firstItem = 0;
63    }
64
65    /* Prevent scrolling past the last line of the list */
66    int lastItem = -1 * (totalItemHeight - height);
67    if (lastItem > 0) {
68        lastItem = 0;
69    }
70
71    if (textPos > firstItem) {
72        textPos = firstItem;
73    }
74    else if (textPos < lastItem) {
75        textPos = lastItem;
76    }
77
78    int currentYPos = itemHeight + textPos;
79
80    for(int i = 0; i < allocSize; i ++) {
81        if(currentYPos - itemHeight > height) {
82            break;
83        }
84
85        if(currentYPos > 0) {
86            switch(gList[i].result) {
87                case 1: /* Passed */
88                    rsgFontColor(0.5f, 0.9f, 0.5f, 1.0f);
89                    break;
90                case -1: /* Failed */
91                    rsgFontColor(0.9f, 0.5f, 0.5f, 1.0f);
92                    break;
93                case 0: /* Still Testing */
94                    rsgFontColor(0.9f, 0.9f, 0.5f, 1.0f);
95                    break;
96                default: /* Unknown */
97                    rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f);
98                    break;
99            }
100            rsgDrawRect(0, currentYPos - 1, width, currentYPos, 0);
101            rsgDrawText(gList[i].text, 30, currentYPos - 32);
102        }
103        currentYPos += itemHeight;
104    }
105
106    return 10;
107}
108