Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8236 | IgorA | 1 | #include |
2 | #include |
||
3 | #include |
||
4 | #include |
||
5 | #include |
||
6 | |||
7 | using namespace Kolibri; |
||
8 | |||
9 | const char header[] = "Image"; |
||
10 | unsigned char* img_d = 0; |
||
11 | long img_w, img_h; |
||
12 | char library_path[2048]; |
||
13 | |||
14 | namespace Kolibri{ |
||
15 | char CurrentDirectoryPath[2048]; |
||
16 | } |
||
17 | |||
18 | bool KolibriOnStart(TStartData &kos_start, TThreadData /*th*/) |
||
19 | { |
||
20 | kos_start.Left = 10; |
||
21 | kos_start.Top = 40; |
||
22 | kos_start.Width = 280; |
||
23 | kos_start.Height = 200; |
||
24 | kos_start.WinData.WindowColor = 0xFFFFFF; |
||
25 | kos_start.WinData.WindowType = 0x33; // 0x34 - fixed, 0x33 - not fixed |
||
26 | kos_start.WinData.Title = header; |
||
27 | LoadLibrary("libimg.obj", library_path, "/sys/lib/libimg.obj", &import_libimg); |
||
28 | return true; |
||
29 | } |
||
30 | |||
31 | void KolibriOnPaint(void) |
||
32 | { |
||
33 | // If button have ID 1, this is close button |
||
34 | DrawButton(2,0xf0f0f0, 10,10,50,20); |
||
35 | DrawText(20,16,0,"Open"); |
||
36 | if(img_d) PutImage(img_d,10,40,img_w,img_h); |
||
37 | } |
||
38 | |||
39 | void KolibriOnButton(long id, TThreadData /*th*/) |
||
40 | { |
||
41 | FileInfoBlock* file; |
||
42 | long int k; |
||
43 | |||
44 | switch(id){ |
||
45 | case 2: |
||
46 | file = FileOpen("1.png"); |
||
47 | if (!file){ |
||
48 | SetWindowCaption("Error open file '1.png'"); |
||
49 | break; |
||
50 | } |
||
51 | k = FileGetLength(file); |
||
52 | if (k > 0){ |
||
53 | if(img_d) Free(img_d); |
||
54 | img_d = (unsigned char*)Alloc(k); |
||
55 | if (img_d){ |
||
56 | if (FileRead(file, img_d, k) != k){ |
||
57 | Free(img_d); img_d = 0; |
||
58 | } |
||
59 | else{ |
||
60 | Image* img; |
||
61 | img = img_decode(img_d,k,0); |
||
62 | img_w = img->Width; |
||
63 | img_h = img->Height; |
||
64 | img_d = (unsigned char*)ReAlloc(img_d, 3*img_w*img_h); |
||
65 | //if (!img_d){ ... } |
||
66 | img_to_rgb2(img,img_d); |
||
67 | img_destroy(img); |
||
68 | SetWindowCaption("1.png"); |
||
69 | Redraw(1); |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | FileClose(file); |
||
74 | //break; |
||
75 | }; |
||
76 | } |
||
77 | |||
78 | bool KolibriOnClose(TThreadData /*th*/) { |
||
79 | if(img_d) {Free(img_d); img_d = 0;} |
||
80 | return true; |
||
81 | } |