source: titan/titan/textbox.h @ 27944

Last change on this file since 27944 was 27680, checked in by obi, 10 years ago

fix

File size: 3.5 KB
Line 
1#ifndef TEXTBOX_H
2#define TEXTBOX_H
3
4//flag 1: for barcode show
5//flag 2: enable wrap
6//flag 3: no clearscreen
7int textbox(char* title, char* text, char* b1, int rc1, char* b2, int rc2, char* b3, int rc3, char* b4, int rc4, int width, int height, int timeout, int flag)
8{
9        int rcret = -1, fromthread = 0;
10        struct skin* messagebox = getscreen("messagebox");
11        struct skin* textbox = getscreennode(messagebox, "textbox");
12        struct skin *button = NULL;
13        struct skin* framebuffer = getscreen("framebuffer");
14        char* bg = NULL;
15
16        m_lock(&status.textboxmutex, 22);
17        if(pthread_self() != status.mainthread)
18                fromthread = 1;
19
20        textbox->aktline = 0;
21        textbox->aktpage = 0;
22        textbox->linecount = 0;
23        textbox->pagecount = 0;
24        textbox->poscount = 0;
25
26        //show barcode for cpuid
27        if(flag == 1)
28        {
29                struct skin* tmp = addscreennode(messagebox, NULL, NULL);
30                if(tmp != NULL)
31                {
32                        char* tmpstr = NULL;
33                       
34                        tmpstr = ostrcat("*", getcpuid(), 0, 1);
35                        tmpstr = ostrcat(tmpstr, "*", 1, 0);
36                        changetext(tmp, tmpstr);
37                        free(tmpstr); tmpstr = NULL;
38                        tmp->fontsize = 40;
39                        tmp->halign = MIDDLE;
40                        tmp->valign = CENTER;
41
42                        changefont(tmp, "free3of9x");
43                        tmp->width = 150;
44                        tmp->height = 50;
45                        tmp->bgcol = 0xffffff;
46                        tmp->fontcol = 0x000001;
47                        tmp->posx = 900;
48                        tmp->del = 1;
49                }
50        }
51
52        if(flag == 2)
53                textbox->wrap = YES;
54        else
55                textbox->wrap = NO;
56
57        changetitle(messagebox, title);
58        if(width != 0) messagebox->width = width;
59        if(height != 0) messagebox->height = height;
60
61        changetext(textbox, text);
62
63        button = getscreennode(messagebox, "b1");
64        if(b1 != NULL)
65        {
66                changetext(button, b1);
67                button->hidden = NO;
68        }
69        else
70                button->hidden = YES;
71
72        button = getscreennode(messagebox, "b2");
73        if(b2 != NULL)
74        {
75                changetext(button, b2);
76                button->hidden = NO;
77        }
78        else
79                button->hidden = YES;
80
81        button = getscreennode(messagebox, "b3");
82        if(b3 != NULL)
83        {
84                changetext(button, b3);
85                button->hidden = NO;
86        }
87        else
88                button->hidden = YES;
89
90        button = getscreennode(messagebox, "b4");
91        if(b4 != NULL)
92        {
93                changetext(button, b4);
94                button->hidden = NO;
95        }
96        else
97                button->hidden = YES;
98
99       
100        if(fromthread == 1)
101        {
102                delrc(getrcconfigint("rcvolup", NULL), NULL, NULL);
103                delrc(getrcconfigint("rcvoldown", NULL), NULL, NULL);
104                delrc(getrcconfigint("rcmute", NULL), NULL, NULL);
105                m_lock(&status.drawingmutex, 0);
106                m_lock(&status.rcmutex, 10);
107                setnodeattr(messagebox, framebuffer, 2);
108                status.rcowner = messagebox;
109                bg = savescreen(messagebox);
110                drawscreen(messagebox, 0, 2);
111        }
112        else
113                drawscreen(messagebox, 0, 0);
114
115        if(fromthread != 1)
116                addscreenrc(messagebox, textbox);
117
118        while(rcret != RCTIMEOUT && rcret != rc1 && rcret != rc2 && rcret != rc3 && rcret != rc4)
119                        rcret = waitrc(messagebox, timeout * 1000, 0);
120
121        if(fromthread != 1)
122                delownerrc(messagebox);
123
124        if(fromthread == 1)
125        {
126                clearscreennolock(messagebox);
127                restorescreen(bg, messagebox);
128                blitfb(0);
129                sleep(1);
130                status.rcowner = NULL;
131                m_unlock(&status.rcmutex, 3);
132                m_unlock(&status.drawingmutex, 0);
133                addrc(getrcconfigint("rcvolup", NULL), screenvolumeup, NULL, NULL);
134                addrc(getrcconfigint("rcvoldown", NULL), screenvolumedown, NULL, NULL);
135                addrc(getrcconfigint("rcmute", NULL), screenmute, NULL, NULL);
136        }
137        else if(flag != 3)
138        {
139                clearscreen(messagebox);
140                drawscreen(skin, 0, 0);
141        }
142
143        if(flag == 1) delmarkedscreennodes(messagebox, 1);
144
145        changetitle(messagebox, NULL);
146        changetext(textbox, NULL);
147
148        m_unlock(&status.textboxmutex, 22);
149        if(rcret == rc1) return 1;
150        else if(rcret == rc2) return 2;
151        else if(rcret == rc3) return 3;
152        else if(rcret == rc4) return 4;
153        else return 0;
154}
155
156#endif
Note: See TracBrowser for help on using the repository browser.