commit 7494fd3
chld
·
2026-07-20 15:55:03 +0000 UTC
parent 7494fd3
cxx programs
7 files changed,
+785,
-0
+35,
-0
1@@ -0,0 +1,35 @@
2+#include <Alert.h>
3+#include <Application.h>
4+
5+#include <iostream>
6+
7+int main(void){
8+ BApplication app("application/x-vnd.example.dialogdemo");
9+
10+ BAlert *a = new BAlert("Closed Emacs",
11+ "Your code is too low quality. Emacs has been closed to prevent garbage on the disk.",
12+ "Cancel", "OK", NULL,
13+ B_WIDTH_AS_USUAL, B_INFO_ALERT);
14+ a->SetFeel(B_MODAL_ALL_WINDOW_FEEL);
15+ a->Activate(true);
16+
17+ int32 r=a->Go();
18+
19+ if (r == 0){
20+ do{
21+ BAlert *b = new BAlert("Close Emacs",
22+ "Please agree to close emacs.",
23+ "Cancel", "OK", NULL,
24+ B_WIDTH_AS_USUAL, B_INFO_ALERT);
25+ b->SetFeel(B_MODAL_ALL_WINDOW_FEEL);
26+ b->Activate(true);
27+ r=b->Go();
28+ } while (r==0);
29+ }
30+
31+ if (r!=0){
32+ std::cout<< "okay\n";
33+ system("kill `pidof Emacs`");
34+ }
35+ return 0;
36+}
+129,
-0
1@@ -0,0 +1,129 @@
2+#include <Application.h>
3+#include <Window.h>
4+#include <Bitmap.h>
5+
6+#include <vector>
7+
8+struct Bmp {
9+ BBitmap *b;
10+ BView *v;
11+ BPoint l;
12+ bool dr;
13+};
14+
15+class View:public BView
16+{
17+public:View(BRect f):
18+ BView(f, "Text", B_FOLLOW_ALL, B_WILL_DRAW){
19+
20+ /* bitmap shit */
21+ SetHighColor(0,0,0);
22+ bmp.b=new BBitmap(Bounds(), B_RGB32, true);
23+ bmp.v=new BView(Bounds(), "bmpView", B_FOLLOW_ALL, B_WILL_DRAW);
24+ bmp.b->AddChild(bmp.v);
25+ bmp.b->Lock();
26+
27+ z=20;
28+
29+ bmp.v->SetHighColor(255,255,255);
30+ bmp.v->FillRect(Bounds());
31+ bmp.v->SetHighColor(0,0,0);
32+
33+ bmp.v->SetPenSize(z);
34+ bmp.v->SetLineMode(B_ROUND_CAP, B_ROUND_JOIN);
35+ bmp.b->Unlock();
36+ bmp.dr=false;
37+}
38+
39+ void AttachedToWindow()
40+ {
41+ MakeFocus(true);
42+ }
43+
44+ void Draw(BRect r)
45+ {
46+ bmp.b->Lock();
47+ bmp.v->Sync();
48+ bmp.b->Unlock();
49+ DrawBitmap(bmp.b, r, r);
50+ }
51+
52+ void MouseMoved(BPoint p, uint32 c, const BMessage *m)
53+ {
54+ if (!bmp.dr) return;
55+
56+ bmp.b->Lock();
57+ bmp.v->StrokeLine(bmp.l, p);
58+ bmp.v->Sync();
59+ bmp.b->Unlock();
60+
61+ Invalidate();
62+ bmp.l=p;
63+ }
64+
65+ void MouseDown(BPoint p)
66+ {
67+ bmp.dr=true;
68+ bmp.l=p;
69+ }
70+
71+ void MouseUp(BPoint p)
72+ {
73+ bmp.dr=false;
74+ }
75+
76+ void KeyDown(const char *c, int32 n)
77+ {
78+ bmp.b->Lock();
79+ switch (c[0])
80+ {
81+ case 'c':
82+ bmp.v->SetHighColor(255, 255, 255);
83+ bmp.v->FillRect(Bounds());
84+ bmp.v->SetHighColor(0, 0, 0);
85+ break;
86+ case 'e':
87+ er=!er;
88+ if (er){
89+ bmp.v->SetHighColor(255, 255, 255);
90+ }else{
91+ bmp.v->SetHighColor(0, 0, 0);
92+ }
93+ break;
94+ }
95+ bmp.b->Unlock();
96+ Invalidate();
97+ }
98+private:
99+ Bmp bmp;
100+ uint32 z;
101+ bool er=false;
102+
103+};
104+
105+class Win:public BWindow
106+{
107+public:Win(BRect f):
108+ BWindow(f, "Bitdraw", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
109+ {
110+ View *view=new View(Bounds());
111+ AddChild(view);
112+ }
113+};
114+
115+class App:public BApplication
116+{
117+public:App():BApplication("application/x-vnd.example.typist")
118+ {
119+ BRect rect(100,100,640,480);
120+ Win *w = new Win(rect);
121+ w->Show();
122+ }
123+};
124+
125+int main(void)
126+{
127+ App a;
128+ a.Run();
129+ return 0;
130+}
+229,
-0
1@@ -0,0 +1,229 @@
2+#include <Application.h>
3+#include <Window.h>
4+#include <Bitmap.h>
5+#include <View.h>
6+
7+#include <vector>
8+#include <cstdio>
9+
10+struct Bmp {
11+ BBitmap *b;
12+ BView *v;
13+ BPoint l;
14+ bool dr;
15+ uint32 s;
16+};
17+
18+struct Fnt {
19+ BFont f;
20+ uint32 s;
21+ font_height h;
22+};
23+
24+class View:public BView
25+{
26+public:View(BRect f):
27+ BView(f, "Text", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS){
28+
29+ /* bitmap shit */
30+ SetHighColor(0,0,0);
31+ bmp.b=new BBitmap(Bounds(), B_RGB32, true);
32+ bmp.v=new BView(Bounds(), "bmpView", B_FOLLOW_ALL, B_WILL_DRAW);
33+ bmp.b->AddChild(bmp.v);
34+ bmp.b->Lock();
35+
36+ bmp.s=20;
37+
38+ bmp.v->SetHighColor(255,255,255);
39+ bmp.v->FillRect(Bounds());
40+ bmp.v->SetHighColor(0,0,0);
41+
42+ bmp.v->SetPenSize(bmp.s);
43+ bmp.v->SetLineMode(B_ROUND_CAP, B_ROUND_JOIN);
44+ bmp.b->Unlock();
45+ bmp.dr=false;
46+
47+ l.push_back(BString());
48+
49+ fnt.s=16;
50+ fnt.f.SetSize(fnt.s);
51+ fnt.f.SetFamilyAndStyle("PxPlus IBM VGA 9x16", "Regular");
52+}
53+
54+ void AttachedToWindow()
55+ {
56+ MakeFocus(true);
57+ }
58+
59+ virtual void FrameResized(float w, float h) override
60+ {
61+ if (w > bmp.b->Bounds().Width() || h > bmp.b->Bounds().Height()){
62+ BRect nB(0, 0, w, h);
63+ BBitmap *nBmp = new BBitmap(nB, B_RGB32, true);
64+ BView *nV = new BView(nB, "bmpView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS);
65+ nBmp->AddChild(nV);
66+
67+ bmp.b->Lock();
68+ bmp.v->Sync();
69+ bmp.b->Unlock();
70+
71+ nBmp->Lock();
72+ nV->SetHighColor(255, 255, 255);
73+ nV->FillRect(nB);
74+ nV->SetHighColor(0, 0, 0);
75+ nV->DrawBitmap(bmp.b, BPoint(0, 0));
76+ nV->SetPenSize(bmp.s);
77+ nV->SetLineMode(B_ROUND_CAP, B_ROUND_JOIN);
78+ nV->Sync();
79+ nBmp->Unlock();
80+
81+ delete bmp.b;
82+ bmp.b=nBmp;
83+ bmp.v=nV;
84+ }
85+
86+ Invalidate();
87+ }
88+
89+ void Draw(BRect r)
90+ {
91+ bmp.b->Lock();
92+ bmp.v->Sync();
93+ bmp.b->Unlock();
94+ DrawBitmap(bmp.b, r, r);
95+
96+ fnt.f.GetHeight(&fnt.h);
97+
98+ SetFont(&fnt.f, B_FONT_ALL);
99+ float y=fnt.h.ascent+fnt.h.descent;
100+
101+ for (size_t i=0; i<l.size(); i++)
102+ {
103+ DrawString(l[i], l[i].Length(), BPoint(0, (y)));
104+ y+=fnt.h.ascent+fnt.h.descent;
105+ }
106+ }
107+
108+ void MouseMoved(BPoint p, uint32 c, const BMessage *m)
109+ {
110+ if (!bmp.dr){
111+ if (p.y<=20)
112+ kbd=true;
113+ else
114+ kbd=false;
115+
116+ return;
117+ };
118+
119+ bmp.b->Lock();
120+ bmp.v->StrokeLine(bmp.l, p);
121+ bmp.v->Sync();
122+ bmp.b->Unlock();
123+
124+ Invalidate();
125+ bmp.l=p;
126+ }
127+
128+ void MouseDown(BPoint p)
129+ {
130+ bmp.dr=true;
131+ bmp.l=p;
132+ }
133+
134+ void MouseUp(BPoint p)
135+ {
136+ bmp.dr=false;
137+ }
138+
139+ void KeyDown(const char *c, int32 n)
140+ {
141+ bmp.b->Lock();
142+ if (kbd){
143+ switch (c[0])
144+ {
145+ case 'c':
146+ bmp.v->SetHighColor(255, 255, 255);
147+ bmp.v->FillRect(Bounds());
148+ bmp.v->SetHighColor(0, 0, 0);
149+ break;
150+ case 'e':
151+ er=!er;
152+ if (er){
153+ bmp.v->SetHighColor(255, 255, 255);
154+ }else{
155+ bmp.v->SetHighColor(0, 0, 0);
156+ }
157+ break;
158+ case 'i':
159+ bmp.s+=2;
160+ bmp.v->SetPenSize(bmp.s);
161+ break;
162+ case 'o':
163+ bmp.s-=2;
164+ bmp.v->SetPenSize(bmp.s);
165+ break;
166+ case 'p':
167+ bmp.s=20;
168+ bmp.v->SetPenSize(bmp.s);
169+ break;
170+ }
171+ bmp.b->Unlock();
172+ Invalidate();
173+ return;
174+ }
175+
176+ if (c[0]==B_BACKSPACE){
177+ if (l.size()>0){
178+ l[l.size()-1].Truncate(l[l.size()-1].Length() - 1);
179+ if (l[l.size()-1].Length()<1 && l.size()-1>0) l.pop_back();
180+ }
181+ }else if (c[0]==B_ENTER){
182+ l.push_back(BString());
183+ }else{
184+ l[l.size()-1].Append(c, n);
185+ }
186+
187+ if (fnt.f.StringWidth(l[l.size()-1])>Bounds().Width()-5){
188+ l.push_back(BString());
189+ }
190+ if (l.size()*(fnt.h.ascent+fnt.h.descent) > Bounds().Height()){
191+ l.erase(l.begin());
192+ }
193+ Invalidate();
194+ }
195+private:
196+ Bmp bmp;
197+ Fnt fnt;
198+ std::vector<BString> l;
199+ uint32 z;
200+ bool er=false;
201+ bool kbd=false;
202+
203+};
204+
205+class Win:public BWindow
206+{
207+public:Win(BRect f):
208+ BWindow(f, "BitType", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
209+ {
210+ View *view=new View(Bounds());
211+ AddChild(view);
212+ }
213+};
214+
215+class App:public BApplication
216+{
217+public:App():BApplication("application/x-vnd.example.bitype")
218+ {
219+ BRect rect(100,100,640,480);
220+ Win *w = new Win(rect);
221+ w->Show();
222+ }
223+};
224+
225+int main(void)
226+{
227+ App a;
228+ a.Run();
229+ return 0;
230+}
+25,
-0
1@@ -0,0 +1,25 @@
2+#include <Application.h>
3+#include <Window.h>
4+
5+class Win:public BWindow
6+{
7+public:Win(BRect f):
8+ BWindow(f, "Blank", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE){}
9+};
10+
11+class App:public BApplication
12+{
13+public:App():BApplication("application/x-vnd.example.blank")
14+ {
15+ BRect rect(100,100,640,480);
16+ Win *w = new Win(rect);
17+ w->Show();
18+ }
19+};
20+
21+int main(void)
22+{
23+ App a;
24+ a.Run();
25+ return 0;
26+}
+168,
-0
1@@ -0,0 +1,168 @@
2+#include <Application.h>
3+#include <Window.h>
4+#include <View.h>
5+
6+#include <Button.h>
7+#include <Message.h>
8+
9+#include <vector>
10+#include <iostream>
11+#include <random>
12+
13+class Dot:public BView
14+{
15+public: Dot(BRect f):BView(f, "dot", B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED),
16+ rd(),
17+ gen(std::random_device{}()),
18+ distrib(-2,2){}
19+ void Draw(BRect r)
20+ {
21+ for(size_t s=0; s+1<fP.size(); ++s)
22+ {
23+ if (fP[s] == BPoint(-1, -1) || fP[s+1] == BPoint(-1 ,-1)) continue;
24+ int pr=distrib(gen);
25+
26+ if(!fC[s])
27+ SetHighColor(0,0,0);
28+ else
29+ SetHighColor(255,255,255);
30+
31+ StrokeLine(BPoint(fP[s].x+(pr), fP[s].y), BPoint(fP[s+1].x, fP[s+1].y+(pr)));
32+ }
33+ }
34+
35+ void MouseMoved(BPoint w, uint32 c, const BMessage *m)
36+ {
37+ if (draw)
38+ {
39+ fP.push_back(w);
40+ fC.push_back(black);
41+ Invalidate();
42+ }
43+ }
44+
45+ void MouseDown(BPoint w)
46+ {
47+ draw=true;
48+ }
49+
50+ void MouseUp(BPoint w)
51+ {
52+ draw=false;
53+
54+ /* prevent up connecting w down */
55+ fP.push_back(BPoint(-1, -1));
56+ fC.push_back(black);
57+ }
58+
59+ void ClearAll()
60+ {
61+ fP.clear();
62+ fC.clear();
63+ Invalidate();
64+ }
65+
66+ void Pulse()
67+ {
68+ Invalidate();
69+ }
70+
71+ void Undo()
72+ {
73+ if (!fP.empty()){
74+ for (int i=0; i<10; ++i){
75+ fP.pop_back();
76+ fC.pop_back();
77+ }
78+ }
79+ fP.push_back(BPoint(-1, -1));
80+ Invalidate();
81+ }
82+
83+private:
84+ std::vector<BPoint> fP;
85+ std::vector<bool> fC;
86+ bool draw=false;
87+
88+ std::mt19937 gen;
89+ std::random_device rd;
90+ std::uniform_int_distribution<int> distrib;
91+public:
92+ bool black=false;
93+};
94+
95+class Win:public BWindow
96+{
97+public:Win(BRect f):
98+ BWindow(f, "Drawkun", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE){
99+ dot = new Dot(BRect(0, 30, f.Width(), f.Height()));
100+ AddChild(dot);
101+ SetPulseRate(100000);
102+ dot->SetHighColor(0,0,0);
103+ dot->SetPenSize(z);
104+ dot->SetLineMode(B_ROUND_CAP, B_ROUND_JOIN);
105+
106+ BButton *cButton = new BButton(BRect(10, 10, 100, 20), "clear", "Clear", new BMessage('c'));
107+ AddChild(cButton);
108+
109+ BButton *eButton = new BButton(BRect(110, 10, 200, 20), "toggle", "Toggle", new BMessage('e'));
110+ AddChild(eButton);
111+
112+ BButton *uButton = new BButton(BRect(210, 10, 300, 20), "undo", "Undo", new BMessage('u'));
113+ AddChild(uButton);
114+
115+ BButton *pButton = new BButton(BRect(310, 10, 330, 20), "add", "+", new BMessage('a'));
116+ AddChild(pButton);
117+
118+ BButton *mButton = new BButton(BRect(340, 10, 360, 20), "min", "-", new BMessage('m'));
119+ AddChild(mButton);
120+}
121+
122+ void MessageReceived(BMessage *m)
123+ {
124+ switch(m->what){
125+ case 'c':
126+ dot->ClearAll();
127+ break;
128+ case 'e':
129+ dot->black=!dot->black;
130+ break;
131+ case 'u':
132+ dot->Undo();
133+ break;
134+ case 'a':
135+ z+=3;
136+ dot->SetPenSize(z);
137+ break;
138+ case 'm':
139+ if(z==0) break;
140+ z-=3;
141+ dot->SetPenSize(z);
142+ break;
143+ default:
144+ BWindow::MessageReceived(m);
145+ }
146+ }
147+
148+private:
149+ Dot *dot;
150+ bool e=false;
151+ int32 z=0;
152+};
153+
154+class App:public BApplication
155+{
156+public:App():BApplication("application/x-vnd.example.blank")
157+ {
158+ BRect rect(100,100,640,480);
159+ Win *w = new Win(rect);
160+ w->Show();
161+ }
162+};
163+
164+int main(void)
165+{
166+ App a;
167+ a.Run();
168+ return 0;
169+}
+106,
-0
1@@ -0,0 +1,106 @@
2+#include <Application.h>
3+#include <Window.h>
4+#include <View.h>
5+
6+#include <Button.h>
7+#include <Message.h>
8+
9+#include <vector>
10+
11+class Dot:public BView
12+{
13+public: Dot(BRect f):BView(f, "dot", B_FOLLOW_ALL, B_WILL_DRAW){}
14+ void Draw(BRect r)
15+ {
16+ for(size_t s=0; s+1<fP.size(); ++s)
17+ {
18+ if (fP[s] == BPoint(-1, -1) || fP[s+1] == BPoint(-1 ,-1)) continue;
19+ StrokeLine(fP[s], fP[s+1]);
20+ }
21+ }
22+
23+ void MouseMoved(BPoint w, uint32 c, const BMessage *m)
24+ {
25+ if (draw)
26+ {
27+ fP.push_back(w);
28+ Invalidate();
29+ }
30+ }
31+
32+ void MouseDown(BPoint w)
33+ {
34+ draw=true;
35+ }
36+
37+ void MouseUp(BPoint w)
38+ {
39+ draw=false;
40+
41+ /* prevent up connecting w down */
42+ fP.push_back(BPoint(-1, -1));
43+ }
44+
45+ void ClearAll()
46+ {
47+ fP.clear();
48+ Invalidate();
49+ }
50+
51+private:
52+ std::vector<BPoint> fP;
53+ std::vector<BPoint> sP;
54+ bool draw=false;
55+};
56+
57+class Win:public BWindow
58+{
59+public:Win(BRect f):
60+ BWindow(f, "Drawkun", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE){
61+ dot = new Dot(BRect(0, 30, f.Width(), f.Height()));
62+ AddChild(dot);
63+ dot->SetHighColor(0,0,0);
64+ dot->SetPenSize(10);
65+ dot->SetLineMode(B_ROUND_CAP, B_ROUND_JOIN);
66+
67+ BButton *cButton = new BButton(BRect(10, 10, 100, 20), "clear", "Clear", new BMessage('c'));
68+ AddChild(cButton);
69+
70+ BButton *eButton = new BButton(BRect(110, 10, 200, 20), "undo", "Undo", new BMessage('u'));
71+ AddChild(eButton);
72+}
73+ void MessageReceived(BMessage *m)
74+ {
75+ switch(m->what){
76+ case 'c':
77+ dot->ClearAll();
78+ break;
79+ case 'e':
80+ dot->Undo();
81+ break;
82+ default:
83+ BWindow::MessageReceived(m);
84+ }
85+ }
86+
87+private:
88+ Dot *dot;
89+ bool erase=false;
90+};
91+
92+class App:public BApplication
93+{
94+public:App():BApplication("application/x-vnd.example.blank")
95+ {
96+ BRect rect(100,100,640,480);
97+ Win *w = new Win(rect);
98+ w->Show();
99+ }
100+};
101+
102+int main(void)
103+{
104+ App a;
105+ a.Run();
106+ return 0;
107+}
+93,
-0
1@@ -0,0 +1,93 @@
2+#include <Application.h>
3+#include <Window.h>
4+
5+#include <vector>
6+
7+class View:public BView
8+{
9+public:View(BRect f):
10+ BView(f, "Text", B_FOLLOW_ALL, B_WILL_DRAW){
11+ l.push_back(BString());
12+ fnt.SetSize(size);
13+}
14+
15+ void AttachedToWindow()
16+ {
17+ MakeFocus(true);
18+ }
19+
20+ void Draw(BRect r)
21+ {
22+ float w=fnt.StringWidth(txt.String());
23+ fnt.GetHeight(&f);
24+
25+ SetFont(&fnt, B_FONT_ALL);
26+ float y=f.ascent+f.descent;
27+
28+ for (size_t i=0; i<l.size(); i++)
29+ {
30+ DrawString(l[i], l[i].Length(), BPoint(0, (y)));
31+ y+=f.ascent+f.descent;
32+ }
33+ }
34+
35+
36+
37+ void KeyDown(const char *c, int32 n)
38+ {
39+ if (c[0]==B_BACKSPACE){
40+ if (l.size()>0){
41+ l[l.size()-1].Truncate(l[l.size()-1].Length() - 1);
42+ if (l[l.size()-1].Length()<1 && l.size()-1>0) l.pop_back();
43+ }
44+ }else if (c[0]==B_ENTER){
45+ l.push_back(BString());
46+ }else{
47+ l[l.size()-1].Append(c, n);
48+ }
49+
50+ if (fnt.StringWidth(l[l.size()-1])>Bounds().Width()-5){
51+ l.push_back(BString());
52+ }
53+ if (l.size()*(f.ascent+f.descent) > Bounds().Height()){
54+ l.erase(l.begin());
55+ }
56+ Invalidate();
57+ }
58+public:
59+ BFont fnt;
60+ BString txt;
61+ int32 size=16;
62+private:
63+ std::vector<BString> l;
64+ font_height f;
65+};
66+
67+class Win:public BWindow
68+{
69+public:Win(BRect f):
70+ BWindow(f, "Typist", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
71+ {
72+ View *view=new View(Bounds());
73+ AddChild(view);
74+ view->ForceFontAliasing(false);
75+ view->fnt.SetFamilyAndStyle("PxPlus IBM VGA 9x16", "Regular");
76+ }
77+};
78+
79+class App:public BApplication
80+{
81+public:App():BApplication("application/x-vnd.example.typist")
82+ {
83+ BRect rect(100,100,640,480);
84+ Win *w = new Win(rect);
85+ w->Show();
86+ }
87+};
88+
89+int main(void)
90+{
91+ App a;
92+ a.Run();
93+ return 0;
94+}