Tcc:
Add libimg example, update other examples git-svn-id: svn://kolibrios.org@8187 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
d9bb1a8d08
commit
9a24f3f7fb
BIN
programs/develop/ktcc/trunk/samples/clayer/kolibrios.jpg
Executable file
BIN
programs/develop/ktcc/trunk/samples/clayer/kolibrios.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
86
programs/develop/ktcc/trunk/samples/clayer/libimg.c
Executable file
86
programs/develop/ktcc/trunk/samples/clayer/libimg.c
Executable file
@ -0,0 +1,86 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <clayer/libimg.h>
|
||||||
|
#include <kos32sys1.h>
|
||||||
|
|
||||||
|
struct kolibri_system_colors sys_color_table;
|
||||||
|
|
||||||
|
char path[4096];
|
||||||
|
char* picture;
|
||||||
|
int x_size = 200, y_size = 150;
|
||||||
|
|
||||||
|
char* load_file_inmem(char* fname, int32_t* read_sz)
|
||||||
|
{
|
||||||
|
FILE *f = fopen(fname, "rb");
|
||||||
|
if (!f) {
|
||||||
|
printf("Can't open file: %s\n", fname);
|
||||||
|
}
|
||||||
|
if (fseek(f, 0, SEEK_END)) {
|
||||||
|
printf("Can't SEEK_END file: %s\n", fname);
|
||||||
|
}
|
||||||
|
int filesize = ftell(f);
|
||||||
|
rewind(f);
|
||||||
|
char* fdata = malloc(filesize);
|
||||||
|
if(!fdata) {
|
||||||
|
printf("No memory for file %s\n", fname);
|
||||||
|
}
|
||||||
|
*read_sz = fread(fdata, 1, filesize, f);
|
||||||
|
if (ferror(f)) {
|
||||||
|
printf("Error reading file %s\n", fname);
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
return fdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_window()
|
||||||
|
{
|
||||||
|
BeginDraw();
|
||||||
|
DrawWindow(10, 40, x_size + 50, y_size + 50, "Libimg", sys_color_table.work_area, 0x34);
|
||||||
|
|
||||||
|
// Draw Picture
|
||||||
|
draw_bitmap(picture, 10, 10, x_size, y_size);
|
||||||
|
|
||||||
|
EndDraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
if (kolibri_libimg_init() == -1)
|
||||||
|
{
|
||||||
|
printf("Error loading lib_img.obj\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load Image
|
||||||
|
const int icon_rgb_size = x_size * y_size;
|
||||||
|
char *image_data,
|
||||||
|
*filedata;
|
||||||
|
|
||||||
|
strcpy(path, "kolibrios.jpg"); // Filename
|
||||||
|
int32_t read_bytes;
|
||||||
|
filedata = load_file_inmem(path, &read_bytes);
|
||||||
|
picture = malloc(icon_rgb_size * 3);
|
||||||
|
image_data = img_decode(filedata, read_bytes, 0);
|
||||||
|
img_to_rgb2(image_data, picture);
|
||||||
|
img_destroy(image_data);
|
||||||
|
free(filedata);
|
||||||
|
// End Load Image
|
||||||
|
|
||||||
|
get_system_colors(&sys_color_table);
|
||||||
|
set_event_mask(0xC0000027);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
switch(get_os_event())
|
||||||
|
{
|
||||||
|
case KOLIBRI_EVENT_REDRAW:
|
||||||
|
draw_window();
|
||||||
|
break;
|
||||||
|
case KOLIBRI_EVENT_BUTTON:
|
||||||
|
if (get_os_button() == 1) exit(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
msgbox *msg1=NULL;
|
msgbox *msg1 = NULL;
|
||||||
msg1 = kolibri_new_msgbox("MsgBoxTest", "Hello world!", 0, "ok");
|
msg1 = kolibri_new_msgbox("Title", "Text in window", 0, "Ok");
|
||||||
kolibri_start_msgbox(msg1, NULL);
|
kolibri_start_msgbox(msg1, NULL);
|
||||||
}
|
}
|
||||||
|
@ -1,45 +1,55 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <kos32sys1.h>
|
#include <kos32sys1.h>
|
||||||
#include <clayer/rasterworks.h>
|
#include <clayer/rasterworks.h>
|
||||||
|
|
||||||
|
// Sizes
|
||||||
|
int x_size = 768, y_size = 256;
|
||||||
|
|
||||||
|
// Out example string
|
||||||
|
char* string = "Пример/Example";
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
unsigned int event;
|
// Count length
|
||||||
int ln_str = countUTF8Z("Example", -1);
|
int ln_str = countUTF8Z(string, -1);
|
||||||
void *buffi = malloc(768*256*3 * sizeof(char));
|
|
||||||
*((int*)buffi) = 768;
|
// Create image buffer
|
||||||
*((int*)buffi+1) = 256;
|
void *buffi = malloc(x_size * y_size * 3 * sizeof(char) + 8);
|
||||||
memset((char*)buffi+8, (char)-1, 768*256*3);
|
|
||||||
drawText(buffi, 0, 0, "Example", ln_str, 0xFF000000, 0x30C18);
|
// Set sizes
|
||||||
drawText(buffi, 0, 32, "Example", ln_str, 0xFF000000, 0x1030C18);
|
*((int*)buffi) = x_size;
|
||||||
drawText(buffi, 0, 64, "Example", ln_str, 0xFF000000, 0x2030C18);
|
*((int*)buffi+1) = y_size;
|
||||||
drawText(buffi, 0, 96, "Example", ln_str, 0xFF000000, 0x4030C18);
|
|
||||||
drawText(buffi, 0, 128, "Example", ln_str, 0xFF000000, 0x8030C18);
|
// Fill color
|
||||||
drawText(buffi, 0, 160, "Example", ln_str, 0xFF000000, 0x0F031428);
|
memset((char*)buffi + 8, 0xFF, x_size * y_size * 3);
|
||||||
for (;;){
|
|
||||||
event = get_os_event();
|
// Draw text on buffer
|
||||||
switch (event)
|
drawText(buffi, 5, 0, string, ln_str, 0xFF000000, 0x30C18);
|
||||||
{
|
drawText(buffi, 5, 32, string, ln_str, 0xFF000000, 0x1030C18);
|
||||||
case 1:
|
drawText(buffi, 5, 64, string, ln_str, 0xFF000000, 0x2030C18);
|
||||||
begin_draw();
|
drawText(buffi, 5, 96, string, ln_str, 0xFF000000, 0x4030C18);
|
||||||
sys_create_window(50, 50, 800, 300, "rasterworks example" ,0x34f0f0f0, 0x14);
|
drawText(buffi, 5, 128, string, ln_str, 0xFF000000, 0x8030C18);
|
||||||
draw_bitmap(buffi+8, 5, 25, 768, 256);
|
drawText(buffi, 5, 160, string, ln_str, 0xFF000000, 0x0F031428);
|
||||||
end_draw();
|
|
||||||
break;
|
while (1)
|
||||||
|
{
|
||||||
case 2:
|
switch (get_os_event())
|
||||||
get_key();
|
{
|
||||||
break;
|
case 1:
|
||||||
|
BeginDraw();
|
||||||
case 3:
|
DrawWindow(50, 50, 800, 300, "Rasterworks Example", 0x999999, 0x34);
|
||||||
if (1==get_os_button())
|
DrawBitmap(buffi + 8, 10, 10, 768, 256);
|
||||||
{
|
EndDraw();
|
||||||
exit(0);
|
break;
|
||||||
}
|
case 2:
|
||||||
break;
|
get_key();
|
||||||
};
|
break;
|
||||||
}
|
case 3:
|
||||||
exit(0);
|
if (get_os_button() == 1) exit(0);
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user