#include "kosSyst.h" #include "gfx.cpp" #include "dlgopen.h" #include "formats\pcx.h" #include "formats\bmp.h" #include "formats\tga.h" #define btn_open 10 #define btn_prev 11 #define btn_next 12 #define btn_fit 13 #define scrl_up 30 #define scrl_down 31 #define scrl_left 32 #define scrl_right 33 char params[2048] = "PARAM"; const char header[] = "ImageView v 0.08"; int image_opened=0; Byte* image_buffer=NULL; // Полное RAW-Изображение Byte* img_cuted=NULL; // Усеченное RAW-изображение (используется при прокрутке или масштабировании) Byte* cur_files=NULL; // Буфер для общего списка файлов текущей папки Word* img_files=NULL; // Указатель массив со список граф.файлов в текущей папке Dword cnt_imgfiles; // Количество элементов массива img_files[] Dword cur_image; // Номер текущего изображения в массиве char cur_folder[512]; // Путь к текущей папке с / на конце Dword image_width; Dword image_height; Dword old_status_size=0; char szStatus[256]; bool scale=0; sProcessInfo proc; Dword img_area_left,img_area_top,img_area_width,img_area_height; int vscrl_max=100,vscrl_value=0,vscrl_coord_x,vscrl_coord_y,vscrl_coord_min,vscrl_coord_max,vscrl_using=0; int hscrl_max=100,hscrl_value=0,hscrl_coord_x,hscrl_coord_y,hscrl_coord_min,hscrl_coord_max,hscrl_using=0; Dword width_old,height_old; /* Вырезает квадрат из изображения по координатам*/ void GetRectImage(Byte* src, Byte* dst, Dword left,Dword top,Dword width,Dword height) { int x,y; int pImgS,pImgD=0; for(y=top;yimage_width) new_width=image_width; if (new_height>image_height) new_height=image_height; ResizeImage(image_buffer,img_cuted,new_width,new_height); /* Центрирование изображения */ scale_left=(img_area_width/2)-(new_width/2); scale_top=(img_area_height/2)-(new_height/2); kos_PutImage((RGB*)img_cuted,new_width,new_height,img_area_left+scale_left,img_area_top+scale_top); } } void draw_window(void) { kos_WindowRedrawStatus(1); kos_DefineAndDrawWindow(0,0,450,350,0x33,0xEFEBEF,0,0,(Dword)header); //ToolBar //open kos_DefineButton(2,4,20,20,btn_open+0x40000000,0xEFEBEF); kos_PutImage(tbOpen,21,21,2,4); //prev kos_DefineButton(25,4,20,20,btn_prev+0x40000000,0xEFEBEF); kos_PutImage(tbPrev,21,21,25,4); //next kos_DefineButton(48,4,20,20,btn_next+0x40000000,0xEFEBEF); kos_PutImage(tbNext,21,21,48,4); //fit image kos_DefineButton(71,4,20,20,btn_fit+0x40000000,0xEFEBEF); kos_PutImage(tbFit,21,21,71,4); //Lines kos_ProcessInfo(&proc,-1); kos_DrawBar(2,30,proc.processInfo.work_width-3,1,0x94AECE); //Scroll controls //vertical scroll bar vscrl_coord_x=proc.processInfo.work_width-16; vscrl_coord_max=proc.processInfo.work_height-46; kos_DrawBar(proc.processInfo.work_width-16,33,15,proc.processInfo.work_height-79,0xDADADA); kos_DefineButton(proc.processInfo.work_width-16,33,14,14,scrl_up+0x40000000,0xEFEBEF); kos_DefineButton(proc.processInfo.work_width-16,proc.processInfo.work_height-46,14,14,scrl_down+0x40000000,0xEFEBEF); kos_PutImage(arrow_up,15,15,proc.processInfo.work_width-16,33); kos_PutImage(arrow_down,15,15,proc.processInfo.work_width-16,proc.processInfo.work_height-46); kos_PutImage(scroll_v,15,35,vscrl_coord_x,vscrl_coord_y); //horisontal scroll bar hscrl_coord_y=proc.processInfo.work_height-31; hscrl_coord_max=proc.processInfo.work_width-31; kos_DrawBar(2,proc.processInfo.work_height-31,proc.processInfo.work_width-18,15,0xDADADA); kos_DefineButton(2,proc.processInfo.work_height-31,14,14,scrl_left+0x40000000,0xEFEBEF); kos_DefineButton(proc.processInfo.work_width-31,proc.processInfo.work_height-31,14,14,scrl_right+0x40000000,0xEFEBEF); kos_PutImage(arrow_left,15,15,2,proc.processInfo.work_height-31); kos_PutImage(arrow_right,15,15,proc.processInfo.work_width-31,proc.processInfo.work_height-31); kos_PutImage(scroll_h,35,15,hscrl_coord_x,hscrl_coord_y); img_area_left=2; img_area_top=33; img_area_width=proc.processInfo.work_width-img_area_left-3-16; img_area_height=proc.processInfo.work_height-img_area_top-3-16-15; kos_WriteTextToWindow(2,proc.processInfo.work_height-12, 0x80, 0, szStatus, 0); if (img_area_widthimage_width) win_width=image_width+img_area_left+3+16+10; else win_width=scr_right-scr_left+1; if (scr_bot-scr_top+1>image_height) win_height=image_height+img_area_top+3+16+15+5+skin_height; else win_height=scr_bot-scr_top+1; if (win_width<150) win_width=150; if (win_height<160) win_height=160; img_cuted=kos_GetMemory(image_width*image_height*3); kos_ChangeWindow(scr_left,scr_top,win_width,win_height); if (img_area_width= vscrl_coord_max) break; set_vscroll_values(vscrl_max, ((vscrl_coord_y + 2 - vscrl_coord_min) * vscrl_max) / (vscrl_coord_max - vscrl_coord_min - 35)); break; */ case btn_fit: scale = scale ? 0 : 1; draw_window(); break; } break; case 6: default: kos_GetMouseState(mButton,mX,mY); //Вертикальная прокрутка if (mButton==1) { if (vscrl_using) { kos_DrawBar(vscrl_coord_x,vscrl_coord_y,15,35,0xDADADA); if (vscrl_coord_y+mY-mYOldvscrl_coord_max) { vscrl_value=vscrl_max; vscrl_coord_y=vscrl_coord_max-35; } else { vscrl_value=(((vscrl_coord_y-vscrl_coord_min)*vscrl_max)/(vscrl_coord_max-vscrl_coord_min-35)); vscrl_coord_y=vscrl_coord_y+mY-mYOld; mYOld=mY; } kos_PutImage(scroll_v,15,35,vscrl_coord_x,vscrl_coord_y); draw_image(); } else { if (mY>=vscrl_coord_y && mY<=vscrl_coord_y+35 && mX>=vscrl_coord_x && mX<=vscrl_coord_x+15) { vscrl_using=1; mYOld=mY; } } } else if(mButton==0) { if (vscrl_using) {vscrl_using=0; draw_image();} } //Горизонтальная прокрутка if (mButton==1) { if (hscrl_using) { kos_DrawBar(hscrl_coord_x,hscrl_coord_y,35,15,0xDADADA); if (hscrl_coord_x+mX-mXOldhscrl_coord_max) { hscrl_value=hscrl_max; hscrl_coord_x=hscrl_coord_max-35; } else { hscrl_value=(((hscrl_coord_x-hscrl_coord_min)*hscrl_max)/(hscrl_coord_max-hscrl_coord_min-35)); hscrl_coord_x=hscrl_coord_x+mX-mXOld; mXOld=mX; } kos_PutImage(scroll_h,35,15,hscrl_coord_x,hscrl_coord_y); draw_image(); } else { if (mX>=hscrl_coord_x && mX<=hscrl_coord_x+35 && mY>=hscrl_coord_y && mY<=hscrl_coord_y+15) { hscrl_using=1; mXOld=mX; } } } else if(mButton==0) { if (hscrl_using) {hscrl_using=0; draw_image();} } break; } } }