Patch by dziadek: localize Magnify

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40022 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues
2010-12-29 10:39:59 +00:00
parent 238df8fb85
commit d462be1157
2 changed files with 145 additions and 79 deletions
+7 -1
View File
@@ -6,10 +6,16 @@ AddSubDirSupportedPlatforms libbe_test ;
Application Magnify : Application Magnify :
Magnify.cpp Magnify.cpp
: be tracker game $(TARGET_LIBSUPC++) : be tracker game $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS)
: Magnify.rdef : Magnify.rdef
; ;
DoCatalogs Magnify :
x-vnd.Haiku-Magnify
:
Magnify.cpp
;
if $(TARGET_PLATFORM) = libbe_test { if $(TARGET_PLATFORM) = libbe_test {
HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : Magnify HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : Magnify
: tests!apps ; : tests!apps ;
+138 -78
View File
@@ -12,18 +12,20 @@
#include <Alert.h> #include <Alert.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Catalog.h>
#include <Clipboard.h>
#include <Debug.h> #include <Debug.h>
#include <Directory.h> #include <Directory.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Locale.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <MenuField.h> #include <MenuField.h>
#include <Path.h> #include <Path.h>
#include <PopUpMenu.h>
#include <Screen.h> #include <Screen.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <TextView.h> #include <TextView.h>
#include <PopUpMenu.h>
#include <Clipboard.h>
#include <WindowScreen.h> #include <WindowScreen.h>
#include <stdio.h> #include <stdio.h>
@@ -34,6 +36,10 @@
#include <sys/stat.h> #include <sys/stat.h>
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Magnify-Main"
const int32 msg_help = 'help'; const int32 msg_help = 'help';
const int32 msg_update_info = 'info'; const int32 msg_update_info = 'info';
const int32 msg_show_info = 'show'; const int32 msg_show_info = 'show';
@@ -126,46 +132,60 @@ BuildInfoMenu(BMenu *menu)
{ {
BMenuItem* menuItem; BMenuItem* menuItem;
menuItem = new BMenuItem("About Magnify" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED)); menuItem = new BMenuItem(B_TRANSLATE("About Magnify" B_UTF8_ELLIPSIS),
new BMessage(B_ABOUT_REQUESTED));
menu->AddItem(menuItem); menu->AddItem(menuItem);
menuItem = new BMenuItem("Help" B_UTF8_ELLIPSIS, new BMessage(msg_help)); menuItem = new BMenuItem(B_TRANSLATE("Help" B_UTF8_ELLIPSIS),
new BMessage(msg_help));
menu->AddItem(menuItem); menu->AddItem(menuItem);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menuItem = new BMenuItem("Save image", new BMessage(msg_save),'S'); menuItem = new BMenuItem(B_TRANSLATE("Save image"),
new BMessage(msg_save),'S');
menu->AddItem(menuItem); menu->AddItem(menuItem);
// menuItem = new BMenuItem("Save selection", new BMessage(msg_save),'S'); // menuItem = new BMenuItem(B_TRANSLATE("Save selection"), new BMessage(msg_save),'S');
// menu->AddItem(menuItem); // menu->AddItem(menuItem);
menuItem = new BMenuItem("Copy image", new BMessage(msg_copy_image),'C'); menuItem = new BMenuItem(B_TRANSLATE("Copy image"),
new BMessage(msg_copy_image),'C');
menu->AddItem(menuItem); menu->AddItem(menuItem);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menuItem = new BMenuItem("Hide/Show info", new BMessage(msg_show_info),'T'); menuItem = new BMenuItem(B_TRANSLATE("Hide/Show info"),
new BMessage(msg_show_info),'T');
menu->AddItem(menuItem); menu->AddItem(menuItem);
menuItem = new BMenuItem("Add a crosshair", new BMessage(msg_add_cross_hair),'H'); menuItem = new BMenuItem(B_TRANSLATE("Add a crosshair"),
new BMessage(msg_add_cross_hair),'H');
menu->AddItem(menuItem); menu->AddItem(menuItem);
menuItem = new BMenuItem("Remove a crosshair", new BMessage(msg_remove_cross_hair), 'H', menuItem = new BMenuItem(B_TRANSLATE("Remove a crosshair"),
B_SHIFT_KEY); new BMessage(msg_remove_cross_hair), 'H', B_SHIFT_KEY);
menu->AddItem(menuItem); menu->AddItem(menuItem);
menuItem = new BMenuItem("Hide/Show grid", new BMessage(msg_toggle_grid),'G'); menuItem = new BMenuItem(B_TRANSLATE("Hide/Show grid"),
new BMessage(msg_toggle_grid),'G');
menu->AddItem(menuItem); menu->AddItem(menuItem);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menuItem = new BMenuItem("Freeze/Unfreeze image", new BMessage(msg_freeze),'F'); menuItem = new BMenuItem(B_TRANSLATE("Freeze/Unfreeze image"),
new BMessage(msg_freeze),'F');
menu->AddItem(menuItem); menu->AddItem(menuItem);
menuItem = new BMenuItem("Stick coordinates", new BMessage(msg_stick), 'I'); menuItem = new BMenuItem(B_TRANSLATE("Stick coordinates"),
new BMessage(msg_stick), 'I');
menu->AddItem(menuItem); menu->AddItem(menuItem);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menuItem = new BMenuItem("Make square", new BMessage(msg_make_square),'/'); menuItem = new BMenuItem(B_TRANSLATE("Make square"),
new BMessage(msg_make_square),'/');
menu->AddItem(menuItem); menu->AddItem(menuItem);
menuItem = new BMenuItem("Decrease window size", new BMessage(msg_shrink),'-'); menuItem = new BMenuItem(B_TRANSLATE("Decrease window size"),
new BMessage(msg_shrink),'-');
menu->AddItem(menuItem); menu->AddItem(menuItem);
menuItem = new BMenuItem("Increase window size", new BMessage(msg_grow),'+'); menuItem = new BMenuItem(B_TRANSLATE("Increase window size"),
new BMessage(msg_grow),'+');
menu->AddItem(menuItem); menu->AddItem(menuItem);
menuItem = new BMenuItem("Decrease pixel size", new BMessage(msg_shrink_pixel),','); menuItem = new BMenuItem(B_TRANSLATE("Decrease pixel size"),
new BMessage(msg_shrink_pixel),',');
menu->AddItem(menuItem); menu->AddItem(menuItem);
menuItem = new BMenuItem("Increase pixel size", new BMessage(msg_grow_pixel),'.'); menuItem = new BMenuItem(B_TRANSLATE("Increase pixel size"),
new BMessage(msg_grow_pixel),'.');
menu->AddItem(menuItem); menu->AddItem(menuItem);
} }
@@ -207,8 +227,10 @@ TApp::ReadyToRun()
void void
TApp::AboutRequested() TApp::AboutRequested()
{ {
(new BAlert("", "Magnify!\n\n" B_UTF8_COPYRIGHT "2002-2006 Haiku\n(C)1999 Be Inc.\n\n" (new BAlert("", B_TRANSLATE("Magnify!\n\n" B_UTF8_COPYRIGHT
"Now with even more features and recompiled for Haiku.", "OK"))->Go(); "2002-2006 Haiku\n(C)1999 Be Inc.\n\n"
"Now with even more features and recompiled for Haiku."),
B_TRANSLATE("OK")))->Go();
} }
@@ -216,7 +238,9 @@ TApp::AboutRequested()
TWindow::TWindow(int32 pixelCount) TWindow::TWindow(int32 pixelCount)
: BWindow(BRect(0, 0, 0, 0), "Magnify", B_TITLED_WINDOW, B_OUTLINE_RESIZE) :
BWindow(BRect(0, 0, 0, 0), B_TRANSLATE("Magnify"),
B_TITLED_WINDOW, B_OUTLINE_RESIZE)
{ {
GetPrefs(pixelCount); GetPrefs(pixelCount);
@@ -767,11 +791,15 @@ TWindow::PixelSize()
} }
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Magnify-Help"
void void
TWindow::ShowHelp() TWindow::ShowHelp()
{ {
BRect r(0, 0, 375, 240); BRect r(0, 0, 450, 240);
BWindow* w = new BWindow(r, "Magnify help", B_TITLED_WINDOW, BWindow* w = new BWindow(r, B_TRANSLATE("Magnify help"), B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_NOT_RESIZABLE); B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_NOT_RESIZABLE);
r.right -= B_V_SCROLL_BAR_WIDTH; r.right -= B_V_SCROLL_BAR_WIDTH;
@@ -785,52 +813,64 @@ TWindow::ShowHelp()
BScrollView* scroller = new BScrollView("", text, B_FOLLOW_ALL, 0, true, true); BScrollView* scroller = new BScrollView("", text, B_FOLLOW_ALL, 0, true, true);
w->AddChild(scroller); w->AddChild(scroller);
text->Insert("General:\n"); text->Insert(B_TRANSLATE(
text->Insert(" 32 x 32 - the top left numbers are the number of visible\n"); "General:\n"
text->Insert(" pixels (width x height)\n"); " 32 x 32 - the top left numbers are the number of visible\n"
text->Insert(" 8 pixels/pixel - represents the number of pixels that are\n"); " pixels (width x height)\n"
text->Insert(" used to magnify a pixel\n"); " 8 pixels/pixel - represents the number of pixels that are\n"
text->Insert(" R:152 G:52 B:10 - the RGB values for the pixel under\n"); " used to magnify a pixel\n"
text->Insert(" the red square\n"); " R:152 G:52 B:10 - the RGB values for the pixel under\n"
" the red square\n"));
text->Insert("\n\n"); text->Insert("\n\n");
text->Insert("Copy/Save:\n"); text->Insert(B_TRANSLATE(
text->Insert(" copy - copies the current image to the clipboard\n"); "Copy/Save:\n"
text->Insert(" save - prompts the user for a file to save to and writes out\n"); " copy - copies the current image to the clipboard\n"
text->Insert(" the bits of the image\n"); " save - prompts the user for a file to save to and writes out\n"
" the bits of the image\n"));
text->Insert("\n\n"); text->Insert("\n\n");
text->Insert("Info:\n"); text->Insert(B_TRANSLATE(
text->Insert(" hide/show info - hides/shows all these new features\n"); "Info:\n"
text->Insert(" note: when showing, a red square will appear which signifies\n"); " hide/show info - hides/shows all these new features\n"
text->Insert(" which pixel's rgb values will be displayed\n"); " note: when showing, a red square will appear which signifies\n"
text->Insert(" add/remove crosshairs - 2 crosshairs can be added (or removed)\n"); " which pixel's rgb values will be displayed\n"
text->Insert(" to aid in the alignment and placement of objects.\n"); " add/remove crosshairs - 2 crosshairs can be added (or removed)\n"
text->Insert(" The crosshairs are represented by blue squares and blue lines.\n"); " to aid in the alignment and placement of objects.\n"
text->Insert(" hide/show grid - hides/shows the grid that separates each pixel\n"); " The crosshairs are represented by blue squares and blue lines.\n"
" hide/show grid - hides/shows the grid that separates each pixel\n"
));
text->Insert("\n\n"); text->Insert("\n\n");
text->Insert(" freeze - freezes/unfreezes magnification of whatever the\n"); text->Insert(B_TRANSLATE(
text->Insert(" cursor is currently over\n"); " freeze - freezes/unfreezes magnification of whatever the\n"
" cursor is currently over\n"));
text->Insert("\n\n"); text->Insert("\n\n");
text->Insert("Sizing/Resizing:\n"); text->Insert(B_TRANSLATE(
text->Insert(" make square - sets the width and the height to the larger\n"); "Sizing/Resizing:\n"
text->Insert(" of the two making a square image\n"); " make square - sets the width and the height to the larger\n"
text->Insert(" increase/decrease window size - grows or shrinks the window\n"); " of the two making a square image\n"
text->Insert(" size by 4 pixels.\n"); " increase/decrease window size - grows or shrinks the window\n"
text->Insert(" note: this window can also be resized to any size via the\n"); " size by 4 pixels.\n"
text->Insert(" resizing region of the window\n"); " note: this window can also be resized to any size via the\n"
text->Insert(" increase/decrease pixel size - increases or decreases the number\n"); " resizing region of the window\n"
text->Insert(" of pixels used to magnify a 'real' pixel. Range is 1 to 16.\n"); " increase/decrease pixel size - increases or decreases the number\n"
" of pixels used to magnify a 'real' pixel. Range is 1 to 16.\n"));
text->Insert("\n\n"); text->Insert("\n\n");
text->Insert("Navigation:\n"); text->Insert(B_TRANSLATE(
text->Insert(" arrow keys - move the current selection (rgb indicator or crosshair)\n"); "Navigation:\n"
text->Insert(" around 1 pixel at a time\n"); " arrow keys - move the current selection "
text->Insert(" option-arrow key - moves the mouse location 1 pixel at a time\n"); "(rgb indicator or crosshair)\n"
text->Insert(" x marks the selection - the current selection has an 'x' in it\n"); " around 1 pixel at a time\n"
" option-arrow key - moves the mouse location 1 pixel at a time\n"
" x marks the selection - the current selection has an 'x' in it\n"));
w->CenterOnScreen(); w->CenterOnScreen();
w->Show(); w->Show();
} }
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Magnify-Main"
bool bool
TWindow::IsActive() TWindow::IsActive()
{ {
@@ -891,14 +931,22 @@ TInfoView::Draw(BRect updateRect)
MovePenTo(10, fFontHeight + 5); MovePenTo(10, fFontHeight + 5);
char str[64]; BString dimensionsInfo(
sprintf(str, "%li x %li @ %li pixels/pixel", hPixelCount, vPixelCount, B_TRANSLATE("%width x %height @ %pixelSize pixels/pixel"));
pixelSize); BString rep;
rep << hPixelCount;
dimensionsInfo.ReplaceAll("%width", rep);
rep = "";
rep << vPixelCount;
dimensionsInfo.ReplaceAll("%height", rep);
rep = "";
rep << pixelSize;
dimensionsInfo.ReplaceAll("%pixelSize", rep);
invalRect.Set(10, 5, 10 + StringWidth(fInfoStr), fFontHeight+7); invalRect.Set(10, 5, 10 + StringWidth(fInfoStr), fFontHeight+7);
SetHighColor(ViewColor()); SetHighColor(ViewColor());
FillRect(invalRect); FillRect(invalRect);
SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
strcpy(fInfoStr, str); strcpy(fInfoStr, dimensionsInfo);
DrawString(fInfoStr); DrawString(fInfoStr);
rgb_color c = { 0,0,0, 255 }; rgb_color c = { 0,0,0, 255 };
@@ -909,6 +957,7 @@ TInfoView::Draw(BRect updateRect)
index = s.IndexForColor(c); index = s.IndexForColor(c);
} }
MovePenTo(10, fFontHeight*2+5); MovePenTo(10, fFontHeight*2+5);
char str[64];
sprintf(str, "R: %i G: %i B: %i (0x%x)", sprintf(str, "R: %i G: %i B: %i (0x%x)",
c.red, c.green, c.blue, index); c.red, c.green, c.blue, index);
invalRect.Set(10, fFontHeight+7, 10 + StringWidth(fRGBStr), fFontHeight*2+7); invalRect.Set(10, fFontHeight+7, 10 + StringWidth(fRGBStr), fFontHeight*2+7);
@@ -1013,31 +1062,31 @@ TMenu::AttachedToWindow()
if (fMainWindow) if (fMainWindow)
state = fMainWindow->IsActive(); state = fMainWindow->IsActive();
BMenuItem* menuItem = FindItem("Hide/Show info"); BMenuItem* menuItem = FindItem(B_TRANSLATE("Hide/Show info"));
if (menuItem) if (menuItem)
menuItem->SetEnabled(state); menuItem->SetEnabled(state);
menuItem = FindItem("Add a crosshair"); menuItem = FindItem(B_TRANSLATE("Add a crosshair"));
if (menuItem) if (menuItem)
menuItem->SetEnabled(state); menuItem->SetEnabled(state);
menuItem = FindItem("Remove a crosshair"); menuItem = FindItem(B_TRANSLATE("Remove a crosshair"));
if (menuItem) if (menuItem)
menuItem->SetEnabled(state); menuItem->SetEnabled(state);
menuItem = FindItem("Hide/Show grid"); menuItem = FindItem(B_TRANSLATE("Hide/Show grid"));
if (menuItem) if (menuItem)
menuItem->SetEnabled(state); menuItem->SetEnabled(state);
menuItem = FindItem("Make square"); menuItem = FindItem(B_TRANSLATE("Make square"));
if (menuItem) if (menuItem)
menuItem->SetEnabled(state); menuItem->SetEnabled(state);
menuItem = FindItem("Decrease window size"); menuItem = FindItem(B_TRANSLATE("Decrease window size"));
if (menuItem) if (menuItem)
menuItem->SetEnabled(state); menuItem->SetEnabled(state);
menuItem = FindItem("Increase window size"); menuItem = FindItem(B_TRANSLATE("Increase window size"));
if (menuItem) if (menuItem)
menuItem->SetEnabled(state); menuItem->SetEnabled(state);
menuItem = FindItem("Decrease pixel size"); menuItem = FindItem(B_TRANSLATE("Decrease pixel size"));
if (menuItem) if (menuItem)
menuItem->SetEnabled(state); menuItem->SetEnabled(state);
menuItem = FindItem("Increase pixel size"); menuItem = FindItem(B_TRANSLATE("Increase pixel size"));
if (menuItem) if (menuItem)
menuItem->SetEnabled(state); menuItem->SetEnabled(state);
@@ -1186,6 +1235,7 @@ TMagnify::KeyDown(const char *key, int32 numBytes)
} }
} }
void void
TMagnify::FrameResized(float newW, float newH) TMagnify::FrameResized(float newW, float newH)
{ {
@@ -1239,7 +1289,7 @@ TMagnify::MouseDown(BPoint where)
if ((buttons & B_SECONDARY_MOUSE_BUTTON) || (modifiers & B_CONTROL_KEY)) { if ((buttons & B_SECONDARY_MOUSE_BUTTON) || (modifiers & B_CONTROL_KEY)) {
// secondary button was clicked or control key was down, show menu and return // secondary button was clicked or control key was down, show menu and return
BPopUpMenu *menu = new BPopUpMenu("Info"); BPopUpMenu *menu = new BPopUpMenu(B_TRANSLATE("Info"));
menu->SetFont(be_plain_font); menu->SetFont(be_plain_font);
BuildInfoMenu(menu); BuildInfoMenu(menu);
@@ -1519,7 +1569,8 @@ TMagnify::CopyImage()
BMessage *message = be_clipboard->Data(); BMessage *message = be_clipboard->Data();
if (!message) { if (!message) {
printf("no clip msg\n"); printf(B_TRANSLATE_WITH_CONTEXT("no clip msg\n",
"In console, when clipboard is empty after clicking Copy image"));
return; return;
} }
@@ -1803,6 +1854,7 @@ TOSMagnify::TOSMagnify(BRect r, TMagnify* parent, color_space space)
InitObject(); InitObject();
} }
TOSMagnify::~TOSMagnify() TOSMagnify::~TOSMagnify()
{ {
delete fPixel; delete fPixel;
@@ -2054,20 +2106,28 @@ main(int argc, char* argv[])
int32 pixelCount = -1; int32 pixelCount = -1;
if (argc > 2) { if (argc > 2) {
printf("usage: magnify [size] (magnify size * size pixels)\n"); printf(B_TRANSLATE_WITH_CONTEXT(
"usage: magnify [size] (magnify size * size pixels)\n",
"Console"));
exit(1); exit(1);
} else { } else {
if (argc == 2) { if (argc == 2) {
pixelCount = abs(atoi(argv[1])); pixelCount = abs(atoi(argv[1]));
if ((pixelCount > 100) || (pixelCount < 4)) { if ((pixelCount > 100) || (pixelCount < 4)) {
printf("usage: magnify [size] (magnify size * size pixels)\n"); printf(B_TRANSLATE_WITH_CONTEXT(
printf(" size must be > 4 and a multiple of 4\n"); "usage: magnify [size] (magnify size * size pixels)\n",
"Console"));
printf(B_TRANSLATE_WITH_CONTEXT(
" size must be > 4 and a multiple of 4\n",
"Console"));
exit(1); exit(1);
} }
if (pixelCount % 4) { if (pixelCount % 4) {
printf("magnify: size must be a multiple of 4\n"); printf(B_TRANSLATE_WITH_CONTEXT(
"magnify: size must be a multiple of 4\n",
"Console"));
exit(1); exit(1);
} }
} }