Ticket #13884: 0006-magnify-make-it-controllable-by-scripting.3.patch
File 0006-magnify-make-it-controllable-by-scripting.3.patch, 7.0 KB (added by , 7 years ago) |
---|
-
src/apps/magnify/Magnify.cpp
From c3cf121d63398c9cfa734874204a66197ac64db4 Mon Sep 17 00:00:00 2001 From: Owen <owenca@users.noreply.github.com> Date: Tue, 19 Dec 2017 10:37:54 +0000 Subject: [PATCH 6/6] magnify: make it controllable by scripting scripting properties: * Info, Grid, and Stick (true/false) * CopyImage * MakeSquare * Zoom (1-100) Decreasing pixel size from the menu will half the size until it's less than 32. fixes #13884 --- src/apps/magnify/Magnify.cpp | 194 +++++++++++++++++++++++++++++++++++++++---- src/apps/magnify/Magnify.h | 5 ++ 2 files changed, 182 insertions(+), 17 deletions(-) diff --git a/src/apps/magnify/Magnify.cpp b/src/apps/magnify/Magnify.cpp index 02d7c4a..08e7fa0 100644
a b 26 26 #include <NodeInfo.h> 27 27 #include <Path.h> 28 28 #include <PopUpMenu.h> 29 #include <PropertyInfo.h> 29 30 #include <Screen.h> 30 31 #include <ScrollView.h> 31 32 #include <TextView.h> … … const int32 kDefaultPixelSize = 8; 98 99 const int32 kBorderSize = 10; 99 100 100 101 102 static property_info sProperties[] = { 103 { "Info", { B_GET_PROPERTY, B_SET_PROPERTY, 0 }, 104 { B_DIRECT_SPECIFIER, 0 }, 105 "Show/hide info.", 0, 106 { B_BOOL_TYPE } 107 }, 108 { "Grid", { B_GET_PROPERTY, B_SET_PROPERTY, 0 }, 109 { B_DIRECT_SPECIFIER, 0 }, 110 "Show/hide grid.", 0, 111 { B_BOOL_TYPE } 112 }, 113 { "MakeSquare", { B_EXECUTE_PROPERTY, 0 }, 114 { B_DIRECT_SPECIFIER, 0 }, 115 "Make the view square.", 0, 116 }, 117 { "Zoom", { B_GET_PROPERTY, B_SET_PROPERTY, 0 }, 118 { B_DIRECT_SPECIFIER, 0 }, 119 "Gets/sets the zoom factor (1-16).", 0, 120 { B_INT32_TYPE } 121 }, 122 { "Stick", { B_GET_PROPERTY, B_SET_PROPERTY, 0 }, 123 { B_DIRECT_SPECIFIER, 0 }, 124 "Stick/unstick coordinates.", 0, 125 { B_BOOL_TYPE } 126 }, 127 { "CopyImage", { B_EXECUTE_PROPERTY, 0 }, 128 { B_DIRECT_SPECIFIER, 0 }, 129 "Copy image to clipboard.", 0, 130 }, 131 132 { 0 } 133 }; 134 135 101 136 static float 102 137 FontHeight(BView* target, bool full) 103 138 { … … TWindow::~TWindow() 304 339 } 305 340 306 341 342 status_t 343 TWindow::GetSupportedSuites(BMessage* msg) 344 { 345 msg->AddString("suites", "suite/x-vnd.Haiku-Magnify"); 346 347 BPropertyInfo propertyInfo(sProperties); 348 msg->AddFlat("messages", &propertyInfo); 349 350 return BHandler::GetSupportedSuites(msg); 351 } 352 353 354 BHandler* 355 TWindow::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier, 356 int32 what, const char* property) 357 { 358 BPropertyInfo propertyInfo(sProperties); 359 if (propertyInfo.FindMatch(msg, index, specifier, what, property) >= 0) 360 return this; 361 362 return BHandler::ResolveSpecifier(msg, index, specifier, what, property); 363 } 364 365 307 366 void 308 367 TWindow::MessageReceived(BMessage* m) 309 368 { 310 369 bool active = fFatBits->Active(); 311 370 312 371 switch (m->what) { 372 case B_EXECUTE_PROPERTY: 373 case B_GET_PROPERTY: 374 case B_SET_PROPERTY: 375 { 376 int32 index; 377 BMessage specifier; 378 int32 what; 379 const char* property; 380 if (m->GetCurrentSpecifier(&index, &specifier, &what, &property) 381 != B_OK) 382 return BWindow::MessageReceived(m); 383 384 status_t result = B_OK; 385 BMessage reply(B_REPLY); 386 387 BPropertyInfo propertyInfo(sProperties); 388 switch (propertyInfo.FindMatch(m, index, &specifier, what, 389 property)) { 390 case 0: 391 if (m->what == B_GET_PROPERTY) 392 result = reply.AddBool("result", fInfoBarState); 393 else if (m->what == B_SET_PROPERTY) { 394 bool showInfo; 395 result = m->FindBool("data", &showInfo); 396 if (result == B_OK) { 397 fInfoBarState = showInfo; 398 ShowInfo(fInfoBarState); 399 } 400 } 401 break; 402 403 case 1: 404 if (m->what == B_GET_PROPERTY) 405 result = reply.AddBool("result", fShowGrid); 406 else if (m->what == B_SET_PROPERTY) { 407 bool showGrid; 408 result = m->FindBool("data", &showGrid); 409 if (result == B_OK) 410 SetGrid(showGrid); 411 } 412 break; 413 414 case 2: 415 if (fHPixelCount != fVPixelCount) { 416 int32 big = fHPixelCount > fVPixelCount ? fHPixelCount 417 : fVPixelCount; 418 ResizeWindow(big, big); 419 } 420 break; 421 422 case 3: 423 if (m->what == B_GET_PROPERTY) 424 result = reply.AddInt32("result", fPixelSize); 425 else if (m->what == B_SET_PROPERTY) { 426 int32 zoom; 427 result = m->FindInt32("data", &zoom); 428 if (result == B_OK) 429 SetPixelSize(zoom); 430 } 431 break; 432 433 case 4: 434 if (m->what == B_GET_PROPERTY) 435 result = reply.AddBool("result", fFatBits->Sticked()); 436 else if (m->what == B_SET_PROPERTY) { 437 bool stick; 438 result = m->FindBool("data", &stick); 439 if (result == B_OK) 440 fFatBits->MakeSticked(stick); 441 } 442 break; 443 444 case 5: 445 fFatBits->CopyImage(); 446 break; 447 448 default: 449 return BWindow::MessageReceived(m); 450 } 451 452 if (result != B_OK) { 453 reply.what = B_MESSAGE_NOT_UNDERSTOOD; 454 reply.AddString("message", strerror(result)); 455 reply.AddInt32("error", result); 456 } 457 458 m->SendReply(&reply); 459 break; 460 } 461 313 462 case msg_show_info: 314 463 if (active) { 315 464 fInfoBarState = !fInfoBarState; … … TWindow::PixelCount(int32* h, int32 *v) 783 932 void 784 933 TWindow::SetPixelSize(int32 s) 785 934 { 935 if (s > 100) 936 s = 100; 937 else if (s < 1) 938 s = 1; 939 786 940 if (s == fPixelSize) 787 941 return; 788 942 … … TWindow::SetPixelSize(int32 s) 791 945 // tell info that size has changed 792 946 // tell mag that size has changed 793 947 948 float w = Bounds().Width(); 949 float h = Bounds().Height(); 794 950 CalcViewablePixels(); 795 951 ResizeWindow(fHPixelCount, fVPixelCount); 952 953 // the window might not actually change in size 954 // in that case force the buffers to the new dimension 955 if (w == Bounds().Width() && h == Bounds().Height()) 956 fFatBits->InitBuffers(fHPixelCount, fVPixelCount, fPixelSize, ShowGrid()); 796 957 } 797 958 798 959 799 960 void 800 TWindow::SetPixelSize(bool d)961 TWindow::SetPixelSize(bool plus) 801 962 { 802 if (d) { // grow 803 fPixelSize++; 804 if (fPixelSize > 16) 805 fPixelSize = 16; 963 int32 pixelSize; 964 965 if (plus) { 966 if (fPixelSize >= 16) 967 return; 968 969 pixelSize = fPixelSize + 1; 806 970 } else { 807 fPixelSize--; 808 if (fPixelSize < 1) 809 fPixelSize = 1; 810 } 971 pixelSize = fPixelSize / 2; 811 972 812 float w = Bounds().Width(); 813 float h = Bounds().Height(); 814 CalcViewablePixels(); 815 ResizeWindow(fHPixelCount, fVPixelCount); 973 if (pixelSize < 16) 974 if (fPixelSize > 16) 975 pixelSize = (fPixelSize + 16) / 2; 976 else 977 pixelSize = fPixelSize - 1; 978 } 816 979 817 // the window might not actually change in size 818 // in that case force the buffers to the new dimension 819 if (w == Bounds().Width() && h == Bounds().Height()) 820 fFatBits->InitBuffers(fHPixelCount, fVPixelCount, fPixelSize, ShowGrid()); 980 SetPixelSize(pixelSize); 821 981 } 822 982 823 983 -
src/apps/magnify/Magnify.h
diff --git a/src/apps/magnify/Magnify.h b/src/apps/magnify/Magnify.h index 35cfa83..9b9663b 100644
a b class TWindow : public BWindow { 201 201 virtual void MessageReceived(BMessage* message); 202 202 virtual bool QuitRequested(); 203 203 204 status_t GetSupportedSuites(BMessage* msg); 205 BHandler* ResolveSpecifier(BMessage* msg, int32 index, 206 BMessage* specifier, int32 what, 207 const char* property); 208 204 209 void GetPrefs(int32 pixelCount = -1); 205 210 void SetPrefs(); 206 211