source: titan/titan/textinput.h @ 40399

Last change on this file since 40399 was 38396, checked in by gost, 8 years ago

[titan] test... save pin

File size: 3.8 KB
Line 
1#ifndef TEXTINPUT_H
2#define TEXTINPUT_H
3
4char* textinput(char* title, char* text)
5{
6        int rcret = -1, fromthread = 0, height = 0;
7        struct skin* textinput = getscreen("textinput");
8        struct skin* input = getscreennode(textinput, "input");
9        struct skin* framebuffer = getscreen("framebuffer");
10        char* ret = NULL, *bg = NULL;
11
12        if(pthread_self() != status.mainthread)
13                fromthread = 1;
14
15        if(title == NULL) title = ostrcat(_("Input field"), NULL, 0, 0);
16
17        changetitle(textinput, title);
18        height = textinput->height;
19        if(title != NULL)
20                textinput->height += textinput->fontsize + 6 + (textinput->bordersize * 2);
21        changeinput(input, text);
22
23        if(fromthread == 1)
24        {
25                delrc(getrcconfigint("rcvolup", NULL), NULL, NULL);
26                delrc(getrcconfigint("rcvoldown", NULL), NULL, NULL);
27                delrc(getrcconfigint("rcmute", NULL), NULL, NULL);
28                m_lock(&status.drawingmutex, 0);
29                m_lock(&status.rcmutex, 10);
30                setnodeattr(textinput, framebuffer, 2);
31                status.rcowner = textinput;
32                bg = savescreen(textinput);
33                drawscreen(textinput, 0, 2);
34        }
35        else
36                drawscreen(textinput, 0, 0);
37        addscreenrc(textinput, input);
38
39        while(1)
40        {
41                rcret = waitrc(textinput, 0, 0);
42                if(rcret == getrcconfigint("rcexit", NULL)) break;
43                if(rcret == getrcconfigint("rcok", NULL))
44                {
45                        ret = ostrcat(input->input, NULL, 0, 0);
46                        break;
47                }
48        }
49
50        delownerrc(textinput);
51
52        if(fromthread == 1)
53        {
54                clearscreennolock(textinput);
55                restorescreen(bg, textinput);
56                blitfb(0);
57                sleep(1);
58                status.rcowner = NULL;
59                m_unlock(&status.rcmutex, 3);
60                m_unlock(&status.drawingmutex, 0);
61                addrc(getrcconfigint("rcvolup", NULL), screenvolumeup, NULL, NULL);
62                addrc(getrcconfigint("rcvoldown", NULL), screenvolumedown, NULL, NULL);
63                addrc(getrcconfigint("rcmute", NULL), screenmute, NULL, NULL);
64        }
65        else
66        {
67                clearscreen(textinput);
68                drawscreen(skin, 0, 0);
69        }
70
71        textinput->height = height;
72        return ret;
73}
74
75char* textinputsave(char* title, char* text, char* tconfig)
76{
77        int rcret = -1, fromthread = 0, height = 0;
78        struct skin* textinput = getscreen("textinput");
79        struct skin* input = getscreennode(textinput, "input");
80        struct skin* framebuffer = getscreen("framebuffer");
81        char* ret = NULL, *bg = NULL;
82
83        if(pthread_self() != status.mainthread)
84                fromthread = 1;
85
86        if(title == NULL) title = ostrcat(_("Input field"), NULL, 0, 0);
87
88        changetitle(textinput, title);
89        height = textinput->height;
90        if(title != NULL)
91                textinput->height += textinput->fontsize + 6 + (textinput->bordersize * 2);
92        changeinput(input, text);
93
94        if(fromthread == 1)
95        {
96                delrc(getrcconfigint("rcvolup", NULL), NULL, NULL);
97                delrc(getrcconfigint("rcvoldown", NULL), NULL, NULL);
98                delrc(getrcconfigint("rcmute", NULL), NULL, NULL);
99                m_lock(&status.drawingmutex, 0);
100                m_lock(&status.rcmutex, 10);
101                setnodeattr(textinput, framebuffer, 2);
102                status.rcowner = textinput;
103                bg = savescreen(textinput);
104                drawscreen(textinput, 0, 2);
105        }
106        else
107                drawscreen(textinput, 0, 0);
108        addscreenrc(textinput, input);
109
110        while(1)
111        {
112                rcret = waitrc(textinput, 0, 0);
113                if(rcret == getrcconfigint("rcexit", NULL)) break;
114                if(rcret == getrcconfigint("rcyellow", NULL))
115                {
116                        ret = ostrcat(input->input, NULL, 0, 0);
117                        if(tconfig != NULL)
118                                addconfig(tconfig, ret);
119                        break;
120                }
121                if(rcret == getrcconfigint("rcok", NULL))
122                {
123                        ret = ostrcat(input->input, NULL, 0, 0);
124                        break;
125                }
126        }
127
128        delownerrc(textinput);
129
130        if(fromthread == 1)
131        {
132                clearscreennolock(textinput);
133                restorescreen(bg, textinput);
134                blitfb(0);
135                sleep(1);
136                status.rcowner = NULL;
137                m_unlock(&status.rcmutex, 3);
138                m_unlock(&status.drawingmutex, 0);
139                addrc(getrcconfigint("rcvolup", NULL), screenvolumeup, NULL, NULL);
140                addrc(getrcconfigint("rcvoldown", NULL), screenvolumedown, NULL, NULL);
141                addrc(getrcconfigint("rcmute", NULL), screenmute, NULL, NULL);
142        }
143        else
144        {
145                clearscreen(textinput);
146                drawscreen(skin, 0, 0);
147        }
148
149        textinput->height = height;
150        return ret;
151}
152
153#endif
Note: See TracBrowser for help on using the repository browser.