rslist.rs revision e5f2f66f8c802d64ecf869081036ae13d4e9e19c
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.example.android.rs.miscsamples)
18
19#include "rs_graphics.rsh"
20
21float gDY;
22
23rs_font gItalic;
24
25typedef struct ListAllocs_s {
26    rs_allocation text;
27} ListAllocs;
28
29ListAllocs *gList;
30
31void init() {
32    gDY = 0.0f;
33}
34
35int textPos = 0;
36
37int root(void) {
38
39    rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
40
41    textPos -= (int)gDY*2;
42    gDY *= 0.95;
43
44    rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f);
45    rsgBindFont(gItalic);
46
47    rs_allocation listAlloc;
48    listAlloc = rsGetAllocation(gList);
49    int allocSize = rsAllocationGetDimX(listAlloc);
50
51    int width = rsgGetWidth();
52    int height = rsgGetHeight();
53
54    int itemHeight = 80;
55    int currentYPos = itemHeight + textPos;
56
57    for (int i = 0; i < allocSize; i ++) {
58        if (currentYPos - itemHeight > height) {
59            break;
60        }
61
62        if (currentYPos > 0) {
63            rsgDrawRect(0, currentYPos - 1, width, currentYPos, 0);
64            rsgDrawText(gList[i].text, 30, currentYPos - 32);
65        }
66        currentYPos += itemHeight;
67    }
68
69    return 10;
70}
71