Iconedit: add menu "Icon" with functions Replace color in canvas and Count unic colors used

H2d2b: allow input numbers only in 
Sstartrek: rename Readme.txt to sst.doc

git-svn-id: svn://kolibrios.org@7447 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2018-10-10 14:44:01 +00:00
parent f56b0638f4
commit 6c5bb4c9b4
14 changed files with 109 additions and 35 deletions

View File

@ -24,7 +24,6 @@ TODO
#include "../lib/fs.h" #include "../lib/fs.h"
#include "../lib/gui.h" #include "../lib/gui.h"
#include "../lib/list_box.h" #include "../lib/list_box.h"
#include "../lib/menu.h"
#include "../lib/collection.h" #include "../lib/collection.h"
#include "../lib/obj/iconv.h" #include "../lib/obj/iconv.h"

View File

@ -4,7 +4,6 @@
#include "../lib/io.h" #include "../lib/io.h"
#include "../lib/gui.h" #include "../lib/gui.h"
#include "../lib/list_box.h" #include "../lib/list_box.h"
#include "../lib/menu.h"
#include "../lib/obj/box_lib.h" #include "../lib/obj/box_lib.h"
#include "../lib/obj/libini.h" #include "../lib/obj/libini.h"

View File

@ -10,7 +10,6 @@
#include "..\lib\strings.h" #include "..\lib\strings.h"
#include "..\lib\io.h" #include "..\lib\io.h"
#include "..\lib\list_box.h" #include "..\lib\list_box.h"
#include "..\lib\menu.h"
#include "..\lib\gui.h" #include "..\lib\gui.h"
#include "..\lib\obj\box_lib.h" #include "..\lib\obj\box_lib.h"
@ -30,11 +29,13 @@
?define T_SKINS "‘â¨«ì ®ª®­" ?define T_SKINS "‘â¨«ì ®ª®­"
?define T_WALLPAPERS "Ž¡®¨" ?define T_WALLPAPERS "Ž¡®¨"
?define T_SELECT_FOLDER "‚ë¡à âì ¯ ¯ªã" ?define T_SELECT_FOLDER "‚ë¡à âì ¯ ¯ªã"
?define MENU_LIST "Žâªàëâì ä ©« Enter\n“¤ «¨âì ä ©« Del"
#else #else
?define WINDOW_HEADER "Appearance" ?define WINDOW_HEADER "Appearance"
?define T_SKINS "Skins" ?define T_SKINS "Skins"
?define T_WALLPAPERS "Wallpapers" ?define T_WALLPAPERS "Wallpapers"
?define T_SELECT_FOLDER "Select wallpapers" ?define T_SELECT_FOLDER "Select wallpapers"
?define MENU_LIST "Open file Enter\nDelete file Del"
#endif #endif
#define PANEL_H 40 #define PANEL_H 40
@ -69,8 +70,6 @@ char st_str[16];
edit_box edit_st = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff, edit_box edit_st = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
0x10000000,sizeof(st_str),#st_str,0, 0b}; 0x10000000,sizeof(st_str),#st_str,0, 0b};
#define MENU_LIST "Open file Enter\nDelete Del"
char default_dir[] = "/rd/1"; char default_dir[] = "/rd/1";
od_filter filter2 = { 8, "TXT\0\0" }; od_filter filter2 = { 8, "TXT\0\0" };
@ -107,7 +106,7 @@ void main()
select_list.ProcessMouse(mouse.x, mouse.y); select_list.ProcessMouse(mouse.x, mouse.y);
SelectList_Draw(); SelectList_Draw();
EventSetNewCurrent(); EventSetNewCurrent();
menu.show(Form.left+mouse.x, Form.top+mouse.y+skin_height, 185, MENU_LIST, 10); menu.show(Form.left+mouse.x, Form.top+mouse.y+skin_height, 146, MENU_LIST, 10);
} }
break; break;

View File

@ -13,7 +13,6 @@
#include "..\lib\list_box.h" #include "..\lib\list_box.h"
#include "..\lib\cursor.h" #include "..\lib\cursor.h"
#include "..\lib\collection.h" #include "..\lib\collection.h"
#include "..\lib\menu.h"
#include "..\lib\random.h" #include "..\lib\random.h"
#include "..\lib\clipboard.h" #include "..\lib\clipboard.h"

View File

@ -18,7 +18,6 @@
#include "../lib/random.h" #include "../lib/random.h"
#include "../lib/kfont.h" #include "../lib/kfont.h"
#include "../lib/collection.h" #include "../lib/collection.h"
#include "../lib/menu.h"
#include "../lib/copyf.h" #include "../lib/copyf.h"
#include "../lib/obj/libini.h" #include "../lib/obj/libini.h"

View File

@ -3,7 +3,6 @@
#include "../lib/io.h" #include "../lib/io.h"
#include "../lib/list_box.h" #include "../lib/list_box.h"
#include "../lib/gui.h" #include "../lib/gui.h"
#include "../lib/menu.h"
struct _object struct _object
{ {

View File

@ -10,6 +10,7 @@
#include "../lib/random.h" #include "../lib/random.h"
#include "../lib/mem.h" #include "../lib/mem.h"
#include "../lib/cursor.h" #include "../lib/cursor.h"
#include "../lib/list_box.h"
#include "../lib/obj/libimg.h" #include "../lib/obj/libimg.h"
#include "../lib/obj/box_lib.h" #include "../lib/obj/box_lib.h"
@ -30,18 +31,22 @@
//===================================================// //===================================================//
#ifdef LANG_RUS #ifdef LANG_RUS
#define T_NOTIFY_OPEN "'IconEdit char image_menu_items[] =
¤ ­­ë© ¬®¬¥­â IconEdit ¬®¦¥â ®âªà뢠âì ⮫쪮 ¨ª®­ª¨, ᮧ¤ ­­ë¥ ¢ á ¬®¬ । ªâ®à¥. "Š®«¨ç¥á⢮ ¨á¯®«ì§®¢ ­­ëå 梥⮢
᫨ ­ã¦­® ®âªàëâì ¤à㣮¥ ¨§®¡à ¦¥­¨¥, ¢®á¯®«ì§ã©â¥áì ¨­áâà㬥­â®¬ <®â® ¯¯ à â>  ¬¥­¨âì ¢á¥ æ¢¥â  1 ­  2";
¤«ï § å¢ â  ª à⨭ª¨ á íªà ­ .' -Wt" ?define T_MENU_IMAGE "ˆª®­ª "
?define T_TEST_ICON "<EFBFBD>஢¥à¨âì ¨ª®­ªã"
?define T_TITLE "Icon Editor 0.59 Alpha"
#else #else
#define T_NOTIFY_OPEN "'IconEdit char image_menu_items[] =
You can open only files created in IconEdit for now! "Count colors used
In other case please use <Photo> tool to get an image from screen.' -Wt" Replace all colors equal to 1 by 2";
?define T_MENU_IMAGE "Icon"
?define T_TEST_ICON "Test Icon"
?define T_TITLE "<EFBFBD>¥¤ ªâ®à ¨ª®­®ª 0.59 Alpha"
#endif #endif
#define T_TITLE "Icon Editor 0.58 Alpha"
#define TOPBAR_H 24+8 #define TOPBAR_H 24+8
#define LEFTBAR_W 16+5+5+3+3 #define LEFTBAR_W 16+5+5+3+3
@ -57,6 +62,7 @@ In other case please use <Photo> tool to get an image from screen.' -Wt"
block canvas = { NULL, NULL, NULL, NULL }; block canvas = { NULL, NULL, NULL, NULL };
block wrapper = { LEFTBAR_W, TOPBAR_H, NULL, NULL }; block wrapper = { LEFTBAR_W, TOPBAR_H, NULL, NULL };
block right_bar = { NULL, 10+TOPBAR_H, RIGHT_BAR_W+10, NULL }; block right_bar = { NULL, 10+TOPBAR_H, RIGHT_BAR_W+10, NULL };
block image_menu_btn = { NULL, 4, NULL, 22 };
dword linear_gradient[RIGHT_BAR_W]; dword linear_gradient[RIGHT_BAR_W];
block b_color_gradient = {NULL, 40+TOPBAR_H, RIGHT_BAR_W, 25}; block b_color_gradient = {NULL, 40+TOPBAR_H, RIGHT_BAR_W, 25};
@ -100,6 +106,7 @@ enum {
BTN_ZOOM_OUT, BTN_ZOOM_OUT,
BTN_CANVAS_RESIZE, BTN_CANVAS_RESIZE,
BTN_CROP, BTN_CROP,
BTN_IMAGE_MENU,
BTNS_PALETTE_COLOR_MAS = 100, BTNS_PALETTE_COLOR_MAS = 100,
BTNS_LAST_USED_COLORS = 400 BTNS_LAST_USED_COLORS = 400
}; };
@ -333,6 +340,9 @@ void main()
case BTN_CROP: case BTN_CROP:
EventCrop(); EventCrop();
break; break;
case BTN_IMAGE_MENU:
EventShowImageMenu();
break;
case CLOSE_BTN: case CLOSE_BTN:
EventExitIconEdit(); EventExitIconEdit();
break; break;
@ -400,6 +410,7 @@ void main()
case evReDraw: case evReDraw:
Window_CanvasReSize.thread_exists(); Window_CanvasReSize.thread_exists();
EventCheckMenuItemSelected();
DrawWindow(); DrawWindow();
break; break;
} }
@ -416,6 +427,20 @@ void DrawTopPanelButton(dword _id, _x, _icon_n)
img_draw stdcall(top_icons.image, _x+3, 7, 16, 16, 0, _icon_n*16); img_draw stdcall(top_icons.image, _x+3, 7, 16, 16, 0, _icon_n*16);
} }
int DrawFlatPanelButton(dword _id, _x, _y, _text)
{
#define P 10
int w = strlen(_text)*6 + P + P;
DrawBar(_x, _y, w, 22, semi_white);
PutPixel(_x,_y,system.color.work);
PutPixel(_x,_y+21,system.color.work);
PutPixel(_x+w-1,_y,system.color.work);
PutPixel(_x+w-1,_y+21,system.color.work);
DefineHiddenButton(_x, _y, w, 21, _id);
WriteText(_x+P, _y+7, 0x80, system.color.work_text, _text);
return w;
}
void DrawLeftPanelButton(dword _id, _y, _icon_n) void DrawLeftPanelButton(dword _id, _y, _icon_n)
{ {
int x = 5; int x = 5;
@ -476,6 +501,10 @@ void DrawWindow()
DrawTopPanelButton(BTN_CROP, tx.inc(GAP+BLOCK_SPACE), 46); DrawTopPanelButton(BTN_CROP, tx.inc(GAP+BLOCK_SPACE), 46);
image_menu_btn.x = tx.n;
image_menu_btn.w = DrawFlatPanelButton(BTN_IMAGE_MENU, image_menu_btn.x, image_menu_btn.y, T_MENU_IMAGE);
//tx.inc(image_menu_btn.w + BLOCK_SPACE);
DrawEditArea(); DrawEditArea();
DrawBar(0, TOPBAR_H, LEFTBAR_W-1, Form.cheight - TOPBAR_H, system.color.work); DrawBar(0, TOPBAR_H, LEFTBAR_W-1, Form.cheight - TOPBAR_H, system.color.work);
@ -713,7 +742,7 @@ void ShowWindow_TestIcon()
case evReDraw: case evReDraw:
DefineAndDrawWindow(Form.left+100, Form.top+100, preview_size*2+9, DefineAndDrawWindow(Form.left+100, Form.top+100, preview_size*2+9,
preview_size*2+skin_height+4, 0x74, NULL, "Test Icon", 0); preview_size*2+skin_height+4, 0x74, NULL, T_TEST_ICON, 0);
DrawImageWithBg(0, 0, 0x000000); DrawImageWithBg(0, 0, 0x000000);
DrawImageWithBg(1, 0, 0xFFFfff); DrawImageWithBg(1, 0, 0xFFFfff);
DrawImageWithBg(0, 1, GetPixelColorFromScreen(0, 0)); DrawImageWithBg(0, 1, GetPixelColorFromScreen(0, 0));
@ -736,7 +765,6 @@ void EventCreateNewIcon()
void EventOpenIcon() void EventOpenIcon()
{ {
//notify(T_NOTIFY_OPEN);
RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path)); RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path));
} }
@ -818,7 +846,52 @@ void EventCrop()
DrawWindow(); DrawWindow();
} }
else { else {
notify("'You need to select something before usnig crop tool.' -W"); notify("'You need to select something before using crop tool.' -W");
}
}
void EventShowImageMenu()
{
menu.selected = 0;
menu.show(Form.left+5 + image_menu_btn.x,
Form.top+skin_height + image_menu_btn.y + image_menu_btn.h,
240,
#image_menu_items,
20);
}
void EventCheckMenuItemSelected()
{
if (menu.list.cur_y) {
if (20 == menu.list.cur_y) EventCountColorsUsed();
if (21 == menu.list.cur_y) EventReplaceImageColors(color1, color2);
menu.list.cur_y = 0;
}
}
void EventCountColorsUsed()
{
char res_str[64];
int cur, prev;
int max = image.rows*image.columns;
int resi=0;
bool unic;
for (cur=0; cur<max; cur++) {
unic = true;
for (prev=0; prev<cur; prev++) {
if (image.mas[prev] == image.mas[cur]) {unic=false; break;}
}
if (unic) resi++;
}
notify( sprintf(#res_str, "'Image has %i unique colors.' -I", resi) );
}
void EventReplaceImageColors(dword c1, c2)
{
int max = image.rows*image.columns;
int cur;
for (cur=0; cur<max; cur++) {
if (image.mas[cur] == color1) image.mas[cur] = color2;
} }
} }

View File

@ -22,6 +22,7 @@
#include "../lib/gui/checkbox.h" #include "../lib/gui/checkbox.h"
#include "../lib/gui/child_window.h" #include "../lib/gui/child_window.h"
#include "../lib/gui/text_view_area.h" #include "../lib/gui/text_view_area.h"
#include "../lib/gui/menu.h"
:int last_free_button_id = 1000; :int last_free_button_id = 1000;
:int GetFreeButtonId() :int GetFreeButtonId()

View File

@ -1,6 +1,11 @@
dword menu_process_id; #ifndef INCLUDE_MENU_H
#define INCLUDE_MENU_H
struct _menu #include "../lib/list_box.h"
:dword menu_process_id;
:struct _menu
{ {
dword appear_x, appear_y, text, identifier, selected; dword appear_x, appear_y, text, identifier, selected;
llist list; llist list;
@ -10,6 +15,7 @@ struct _menu
void _menu::show(dword _appear_x, _appear_y, _menu_width, _text, _identifier) void _menu::show(dword _appear_x, _appear_y, _menu_width, _text, _identifier)
{ {
#define ITEM_H 21
appear_x = _appear_x; appear_x = _appear_x;
appear_y = _appear_y; appear_y = _appear_y;
text = _text; text = _text;
@ -18,12 +24,12 @@ void _menu::show(dword _appear_x, _appear_y, _menu_width, _text, _identifier)
list.cur_y = -1; list.cur_y = -1;
list.ClearList(); list.ClearList();
list.count = chrnum(text, '\n')+1; list.count = chrnum(text, '\n')+1;
list.SetSizes(2,2,_menu_width,list.count*24,24); list.SetSizes(2,2,_menu_width,list.count*ITEM_H,ITEM_H);
menu_process_id = CreateThread(#_menu_thread,#stak+4092); menu_process_id = CreateThread(#_menu_thread,#stak+4092);
} }
void _menu_thread() :void _menu_thread()
{ {
proc_info MenuForm; proc_info MenuForm;
SetEventMask(100111b); SetEventMask(100111b);
@ -49,7 +55,7 @@ void _menu_thread()
} }
} }
void _menu_draw_list() :void _menu_draw_list()
{ {
int N, bgcol; int N, bgcol;
for (N=0; N<menu.list.count; N++;) for (N=0; N<menu.list.count; N++;)
@ -57,18 +63,20 @@ void _menu_draw_list()
if (N==menu.list.cur_y) bgcol=0xFFFfff; else bgcol=0xE4DFE1; if (N==menu.list.cur_y) bgcol=0xFFFfff; else bgcol=0xE4DFE1;
DrawBar(menu.list.x, N*menu.list.item_h+menu.list.y, menu.list.w-3, menu.list.item_h, bgcol); DrawBar(menu.list.x, N*menu.list.item_h+menu.list.y, menu.list.w-3, menu.list.item_h, bgcol);
} }
WriteTextLines(13, menu.list.item_h-12/2+menu.list.y, 0x90, 0, menu.text, menu.list.item_h); WriteTextLines(13, menu.list.item_h-8/2+menu.list.y, 0x80, 0, menu.text, menu.list.item_h);
if (menu.selected) WriteText(5, menu.selected-1*menu.list.item_h+11, 0x80, 0xEE0000, "\x10"); if (menu.selected) WriteText(5, menu.selected-1*menu.list.item_h+8, 0x80, 0xEE0000, "\x10");
} }
void _menu_item_click() :void _menu_item_click()
{ {
menu.list.cur_y = menu.identifier + menu.list.cur_y; menu.list.cur_y = menu.identifier + menu.list.cur_y;
KillProcess(menu_process_id); KillProcess(menu_process_id);
} }
void _menu_no_item_click() :void _menu_no_item_click()
{ {
menu.list.cur_y = 0; menu.list.cur_y = 0;
KillProcess(menu_process_id); KillProcess(menu_process_id);
} }
#endif

View File

@ -1,4 +1,3 @@
//list_box
#ifndef INCLUDE_LIST_BOX_H #ifndef INCLUDE_LIST_BOX_H
#define INCLUDE_LIST_BOX_H #define INCLUDE_LIST_BOX_H

View File

@ -93,7 +93,7 @@ PathShow_draw stdcall(#PathShow);
#define ed_mouse_on 100000000b #define ed_mouse_on 100000000b
#define ed_mous_adn_b 100011000b #define ed_mous_adn_b 100011000b
#define ed_always_focus 100000000000000b #define ed_always_focus 100000000000000b
#define ed_figure_only 1000000000000000b //symbols only #define ed_figure_only 1000000000000000b //numbers only
#define ed_shift_cl 1111111111100011b #define ed_shift_cl 1111111111100011b
#define ed_shift_mcl 1111111111111011b #define ed_shift_mcl 1111111111111011b
#define ed_shift_off 1111111111111011b #define ed_shift_off 1111111111111011b

View File

@ -3,7 +3,6 @@
#include "../lib/io.h" #include "../lib/io.h"
#include "../lib/gui.h" #include "../lib/gui.h"
#include "../lib/list_box.h" #include "../lib/list_box.h"
#include "../lib/menu.h"
#include "../lib/kfont.h" #include "../lib/kfont.h"
#include "../lib/obj/box_lib.h" #include "../lib/obj/box_lib.h"

View File

@ -282,7 +282,7 @@ else
end if end if
mouse_dd dd 0 mouse_dd dd 0
edit1 edit_box (WIN_W-67-82), 67, 146, 0xffffff, 0xff, 0x80ff, 0, 0x90000000, (string1_end-string1), string1 , mouse_dd, ed_focus+ed_always_focus edit1 edit_box (WIN_W-67-82), 67, 146, 0xffffff, 0xff, 0x80ff, 0, 0x90000000, (string1_end-string1), string1 , mouse_dd, ed_focus+ed_always_focus+ed_figure_only
editboxes_end: editboxes_end: