Files
@ ce282c5d04a9
Branch filter:
Location: ATITD-Tools/Desert-Paint-Lab/UI/CaptureView.cs - annotation
ce282c5d04a9
24.9 KiB
text/x-csharp
Added tag T9_V7 for changeset e53fa6e66029
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 | 5d0a31247a93 63ce80f17b8c 41381c24d35a 63ce80f17b8c 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 41381c24d35a 41381c24d35a 41381c24d35a 5d0a31247a93 5d0a31247a93 5d0a31247a93 cca1f914411a 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 e53fa6e66029 5d0a31247a93 5d0a31247a93 e53fa6e66029 e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 e53fa6e66029 e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 e53fa6e66029 e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 e53fa6e66029 e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 e53fa6e66029 e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 e53fa6e66029 e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 e53fa6e66029 e53fa6e66029 5d0a31247a93 e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 41381c24d35a 5d0a31247a93 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a e53fa6e66029 41381c24d35a 41381c24d35a 41381c24d35a e53fa6e66029 41381c24d35a f1323ba34306 f1323ba34306 63ce80f17b8c 991c95f4da74 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 991c95f4da74 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a d792b40d3ef9 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a cca1f914411a 41381c24d35a 41381c24d35a cca1f914411a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a cca1f914411a cca1f914411a 41381c24d35a 41381c24d35a 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 41381c24d35a 991c95f4da74 41381c24d35a f1323ba34306 f1323ba34306 f1323ba34306 f1323ba34306 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 991c95f4da74 cca1f914411a 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 991c95f4da74 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a cca1f914411a 41381c24d35a cca1f914411a 41381c24d35a cca1f914411a 5d0a31247a93 5d0a31247a93 5d0a31247a93 cca1f914411a 5d0a31247a93 41381c24d35a 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 41381c24d35a 5d0a31247a93 5d0a31247a93 5d0a31247a93 41381c24d35a 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 41381c24d35a 5d0a31247a93 5d0a31247a93 5d0a31247a93 41381c24d35a 5d0a31247a93 41381c24d35a 9d927a271fbb 9d927a271fbb 0c583dbbd95f 5d0a31247a93 5d0a31247a93 5d0a31247a93 41381c24d35a 5d0a31247a93 41381c24d35a 5d0a31247a93 5d0a31247a93 5d0a31247a93 41381c24d35a 5d0a31247a93 5d0a31247a93 9d927a271fbb 9d927a271fbb e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 41381c24d35a 5d0a31247a93 41381c24d35a 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 41381c24d35a 5d0a31247a93 41381c24d35a 5d0a31247a93 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a cca1f914411a cca1f914411a cca1f914411a 41381c24d35a 41381c24d35a d792b40d3ef9 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a f1323ba34306 f1323ba34306 41381c24d35a cca1f914411a cca1f914411a 41381c24d35a 41381c24d35a 41381c24d35a cca1f914411a f1323ba34306 cca1f914411a f1323ba34306 f1323ba34306 cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 41381c24d35a 5d0a31247a93 cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a cca1f914411a 5d0a31247a93 5d0a31247a93 991c95f4da74 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 e53fa6e66029 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 | using System;
using System.IO;
using System.Threading;
namespace DesertPaintLab
{
[System.ComponentModel.ToolboxItem(true)]
public partial class CaptureView : Gtk.Bin
{
Reagent[] reagents = new Reagent[3];
PaintRecipe recipe = new PaintRecipe();
PaintColor expectedColor = new PaintColor();
PaintColor reactedColor = new PaintColor();
PlayerProfile profile = null;
Gdk.Pixbuf screenBuffer = null;
Gtk.ThreadNotify notifyCaptureProgress;
Gtk.ThreadNotify notifyCaptureComplete;
bool recordEnabled = true;
bool isCaptured = false;
public CaptureView(PlayerProfile profile, Gdk.Pixbuf screenBuffer)
{
this.profile = profile;
this.screenBuffer = screenBuffer;
this.Build();
reagents[0] = null;
reagents[1] = null;
reagents[2] = null;
if (unmodifiedSwatch != null)
{
unmodifiedSwatch.Clear();
}
if (reactionSwatch != null)
{
reactionSwatch.Clear();
}
PopulateDropDowns();
recipe.Reactions = profile.Reactions;
}
public Gdk.Pixbuf ScreenBuffer
{
get { return screenBuffer; }
set {
if (screenBuffer != null)
{
// TODO: free it up?
}
screenBuffer = value;
}
}
public Gdk.Pixbuf RecordBuffer
{
get; set;
}
public PlayerProfile Profile
{
set {
profile = value;
PopulateDropDowns();
recipe.Reactions = profile.Reactions;
UpdateIngredients();
// TODO: reset views
}
}
public void DisableRecord()
{
recordEnabled = false;
recordButton.Sensitive = false;
recordNoReactionButton.Sensitive = false;
}
public void EnableRecord()
{
recordEnabled = true;
if (isCaptured)
{
recordEnabled = true;
}
UpdateIngredients();
}
public void PopulateDropDowns()
{
ReagentManager.PopulateReagents(ref ingredient1ComboBox);
ReagentManager.PopulateReagents(ref ingredient2ComboBox);
ReagentManager.PopulateReagents(ref ingredient3ComboBox);
ingredient2ComboBox.Sensitive = false;
ingredient3ComboBox.Sensitive = false;
Gtk.TreeIter iter;
ingredient1ComboBox.Model.IterNthChild(out iter, 0);
ingredient1ComboBox.SetActiveIter(iter);
ingredient2ComboBox.Model.IterNthChild(out iter, 0);
ingredient2ComboBox.SetActiveIter(iter);
ingredient3ComboBox.Model.IterNthChild(out iter, 0);
ingredient3ComboBox.SetActiveIter(iter);
}
protected void SetExpectedColor(byte red, byte green, byte blue)
{
expectedColor.Red = red;
expectedColor.Green = green;
expectedColor.Blue = blue;
unmodifiedSwatch.Color = expectedColor;
}
protected void SetExpectedColor(PaintColor color)
{
SetExpectedColor(color.Red, color.Green, color.Blue);
}
protected string GetSelectedReagentName(int reagentNum)
{
Gtk.ComboBox[] comboBox = { ingredient1ComboBox, ingredient2ComboBox, ingredient3ComboBox };
Gtk.ComboBox desired = comboBox[reagentNum-1];
Gtk.TreeIter selectIter;
string reagentName = null;
if (desired.GetActiveIter(out selectIter))
{
reagentName = (string)desired.Model.GetValue(selectIter, 0);
}
if (reagentName != null && reagentName.Length == 0)
{
reagentName = null;
}
return reagentName;
}
protected void UpdateIngredients()
{
Reaction reaction1, reaction2;
string reagentName;
reagents[0] = null;
reagents[1] = null;
reagents[2] = null;
bool reactionKnown = true;
isCaptured = false;
recordButton.Sensitive = false;
recordNoReactionButton.Sensitive = false;
clearReactionButton.Sensitive = false;
clearReactionButton.Visible = false;
recordNoReactionButton.Sensitive = false;
recordNoReactionButton.Visible = false;
recipe.Clear();
if ((reagentName = GetSelectedReagentName(1)) == null)
{
// Nothing selected as reagent 1
ingredient2ComboBox.Sensitive = false;
ingredient3ComboBox.Sensitive = false;
unmodifiedSwatch.Clear();
reactionSwatch.Clear();
captureButton.Sensitive = false;
recordNoReactionButton.Sensitive = false;
recordNoReactionButton.Visible = false;
return;
}
recipe.AddReagent(reagentName);
reagents[0] = ReagentManager.GetReagent(reagentName);
ingredient2ComboBox.Sensitive = true;
if ((reagentName = GetSelectedReagentName(2)) == null)
{
ingredient3ComboBox.Sensitive = false;
recordButton.Sensitive = false;
recordNoReactionButton.Sensitive = false;
recordNoReactionButton.Visible = false;
reactionKnown = false;
reactionSwatch.Clear();
return;
}
recipe.AddReagent(reagentName);
reagents[1] = ReagentManager.GetReagent(reagentName);
ingredient3ComboBox.Sensitive = true;
captureButton.Sensitive = true;
recordNoReactionButton.Sensitive = true;
reaction1 = profile.FindReaction(reagents[0], reagents[1]);
// TODO: really should handle reagent0==reagent1 better
if ((reaction1 != null) || (reagents[0] == reagents[1]))
{
clearReactionButton.Sensitive = recordEnabled;
clearReactionButton.Visible = true;
ingredient3ComboBox.Sensitive = true;
recordNoReactionButton.Sensitive = false;
recordNoReactionButton.Visible = false;
if ((reagentName = GetSelectedReagentName(3)) != null)
{
clearReactionButton.Sensitive = false;
clearReactionButton.Visible = false;
recordNoReactionButton.Sensitive = false;
recordNoReactionButton.Visible = false;
recipe.AddReagent(reagentName);
reagents[2] = ReagentManager.GetReagent(reagentName);
if (!reactionKnown)
{
Gtk.MessageDialog md = new Gtk.MessageDialog((Gtk.Window)Toplevel,
Gtk.DialogFlags.DestroyWithParent,
Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
"To do a three-ingredient reaction test, " +
"you must first recored the reaction of " +
"the first two ingredients.");
md.Run();
md.Destroy();
captureButton.Sensitive = false;
}
reaction1 = profile.FindReaction(reagents[0], reagents[2]);
reaction2 = profile.FindReaction(reagents[1], reagents[2]);
if (reactionKnown && (reaction1 == null) && (reaction2 == null))
{
Gtk.MessageDialog md = new Gtk.MessageDialog((Gtk.Window)Toplevel,
Gtk.DialogFlags.DestroyWithParent,
Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
"To do a three-ingredient reaction test, " +
"you must first record the reaction of " +
"either the first or second ingredient " +
"with the third ingredient.");
md.Run();
md.Destroy();
captureButton.Sensitive = false;
}
if ((reaction1 == null) && (reagents[0] != reagents[2]))
{
reactionKnown = false;
}
if ((reaction2 == null) && (reagents[1] != reagents[2]))
{
reactionKnown = false;
}
}
}
else
{
reactionKnown = false;
ingredient3ComboBox.Sensitive = false;
recordNoReactionButton.Sensitive = recordEnabled;
recordNoReactionButton.Visible = true;
}
expectedColor.Set(recipe.BaseColor);
unmodifiedSwatch.Color = expectedColor;
//SetExpectedColor(recipeColor.Red, recipeColor.Green, recipeColor.Blue);
if (reactionKnown)
{
reactedColor.Set(recipe.ReactedColor);
reactionSwatch.Color = reactedColor;
}
else
{
reactionSwatch.Clear();
}
}
unsafe void BeginCapture()
{
captureButton.Sensitive = false;
ingredient1ComboBox.Sensitive = false;
ingredient2ComboBox.Sensitive = false;
ingredient3ComboBox.Sensitive = false;
clearReactionButton.Sensitive = false;
recordNoReactionButton.Sensitive = false;
progressBar.Show();
recordButton.Hide();
recordNoReactionButton.Hide();
bool enableDebugMenu;
AppSettings.Get("EnableDebugMenu", out enableDebugMenu, false);
StreamWriter log = null;
if (enableDebugMenu)
{
string logfile = FileUtils.FindNumberedFile("DesertPaintLab_Capture", "log", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
log = new StreamWriter(logfile);
ReactionRecorder.Instance.Log = log;
}
if (notifyCaptureProgress == null)
{
notifyCaptureProgress = new Gtk.ThreadNotify(new Gtk.ReadyEvent(NotifyCaptureProgress));
notifyCaptureComplete = new Gtk.ThreadNotify(new Gtk.ReadyEvent(NotifyCaptureComplete));
}
this.reactionSwatch.Clear();
Thread thr = new Thread(new ThreadStart(this.CaptureReactionThread));
thr.Priority = ThreadPriority.AboveNormal;
thr.Start();
//OnCaptureComplete(isCaptured, reactedColor, screenWidth, screenHeight, stride, redPixelStart);
}
unsafe private void CaptureReactionThread()
{
byte* pixBytes = (byte*)RecordBuffer.Pixels;
ReactionRecorder.Instance.OnCaptureProgress += OnCaptureProgress;
ReactionRecorder.Instance.CaptureReaction(pixBytes, RecordBuffer.Width, RecordBuffer.Height, RecordBuffer.Rowstride, RecordBuffer.NChannels, RecordBuffer.BitsPerSample);
ReactionRecorder.Instance.OnCaptureProgress -= OnCaptureProgress;
notifyCaptureComplete.WakeupMain();
}
private void OnCaptureProgress(int x, int y)
{
notifyCaptureProgress.WakeupMain();
}
private void NotifyCaptureProgress()
{
// TODO: progress bar
//ReactionRecorder.Instance.X;
//ReactionRecorder.Instance.Y;
double denom = (double)(ReactionRecorder.Instance.ScreenWidth - ReactionRecorder.Instance.ColorBarWidth);
double numer = (double)(ReactionRecorder.Instance.X);
double fraction = (denom > 0 && numer > 0) ? (numer / denom) : 0;
if (numer > denom)
{
fraction = 1;
}
progressBar.Fraction = fraction;
}
void OnCaptureComplete(bool isCaptured, PaintColor reactedColor, int swatchX, int swatchY)
{
int screenWidth = screenBuffer.Width;
int screenHeight = RecordBuffer.Height;
int stride = RecordBuffer.Rowstride;
StreamWriter log = ReactionRecorder.Instance.Log;
if (log != null)
{
log.Flush();
log.Close();
log = null;
ReactionRecorder.Instance.Log = null;
}
bool enableDebugMenu;
DesertPaintLab.AppSettings.Get("EnableDebugMenu", out enableDebugMenu, false);
bool debugScreenshot;
DesertPaintLab.AppSettings.Get("DebugScreenshot", out debugScreenshot, false);
if (enableDebugMenu && debugScreenshot)
{
if (!isCaptured)
{
// write out the whole screenshot on a failure to capture
string screenshotDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string filename = FileUtils.FindNumberedFile("DesertPaintLab_Colormatch", "png", screenshotDir);
RecordBuffer.Save(filename, "png");
}
else
{
// record the swatch that was captured
// write out the screenshot
string screenshotDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string filename = FileUtils.FindNumberedFile("DesertPaintLab_Colormatch", "png", screenshotDir);
int x = swatchX - 16;
int captureAreaWidth = ReactionRecorder.Instance.ColorBarWidth + 32;
captureAreaWidth = Math.Min(screenWidth - x, captureAreaWidth);
int y = swatchY - 16;
int captureAreaHeight = ReactionRecorder.Instance.BlueBarSpacing + 42;
captureAreaHeight = Math.Min(screenHeight - y, captureAreaHeight);
Gdk.Pixbuf outPixBuf = new Gdk.Pixbuf(RecordBuffer, Math.Max(0, x), Math.Max(0, y),
captureAreaWidth, captureAreaHeight);
//Gdk.Pixbuf outPixBuf = new Gdk.Pixbuf(RecordBuffer, Math.Max(0, redPixelStartX), Math.Max(0, redPixelStartY),
// ReactionRecorder.Instance.ColorBarWidth, ReactionRecorder.Instance.GreenBarSpacing - ReactionRecorder.Instance.RedBarSpacing);
//RecordBuffer.Save(filename, "png");
outPixBuf.Save(filename, "png");
}
}
//RecordBuffer.Save("screenshot.png", "png");
if (isCaptured)
{
string warning = "";
if (reactedColor.Red == 0)
{
warning = warning + "\nRed is too low.";
}
if (reactedColor.Green == 0)
{
warning = warning + "\nGreen is too low.";
}
if (reactedColor.Blue == 0)
{
warning = warning + "\nBlue is too low.";
}
if (reactedColor.Red == 255)
{
warning = warning + "\nRed is too high.";
}
if (reactedColor.Green == 255)
{
warning = warning + "\nGreen is too high.";
}
if (reactedColor.Blue == 255)
{
warning = warning + "\nBlue is too high.";
}
// Always update the reacted swatch
this.reactionSwatch.Color = reactedColor;
this.reactedColor.Set(reactedColor);
if (warning.Length != 0)
{
isCaptured = true;
Gtk.MessageDialog md = new Gtk.MessageDialog((Gtk.Window)Toplevel,
Gtk.DialogFlags.DestroyWithParent,
Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
"Reaction clipped. You will need to do a " +
"3-way reaction to test this pair. Details: " +
warning);
md.Run();
md.Destroy();
// reaction clipped - don't let them record
recordButton.Sensitive = false;
recordNoReactionButton.Sensitive = false;
}
else
{
recordButton.Sensitive = recordEnabled;
recordNoReactionButton.Sensitive = false;
}
}
else
{
Gtk.MessageDialog md = new Gtk.MessageDialog((Gtk.Window)Toplevel,
Gtk.DialogFlags.DestroyWithParent,
Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
"Pigment Lab dialog box NOT FOUND. Please ensure " +
"that there is an unobstructed view of the dialog " +
"and that your interface size is set to 'small' " +
"when you press the Capture button.");
md.Run();
md.Destroy();
}
progressBar.Hide();
recordButton.Show();
// release
RecordBuffer = null;
ingredient1ComboBox.Sensitive = true;
ingredient2ComboBox.Sensitive = true;
ingredient3ComboBox.Sensitive = (GetSelectedReagentName(1) != null) && (GetSelectedReagentName(2) != null);
}
private void NotifyCaptureComplete()
{
OnCaptureComplete(
ReactionRecorder.Instance.IsCaptured,
ReactionRecorder.Instance.RecordedColor,
ReactionRecorder.Instance.SwatchX,
ReactionRecorder.Instance.SwatchY);
}
unsafe void CaptureReactionColor()
{
// Take a screenshot.
int screenWidth, screenHeight;
Gdk.Window rootWindow = Gdk.Global.DefaultRootWindow;
AppSettings.Get("ScreenWidth", out screenWidth, 1920);
AppSettings.Get("ScreenHeight", out screenHeight, 1080);
Gdk.Image rootImage = rootWindow.GetImage(0, 0, screenWidth, screenHeight);
RecordBuffer = screenBuffer;
RecordBuffer.GetFromImage(rootImage, rootImage.Colormap, 0, 0, 0, 0, screenWidth, screenHeight);
rootImage.Unref();
System.GC.Collect(); // really, clean up now
int pixelMultiplier;
AppSettings.Get("PixelMultiplier", out pixelMultiplier, 1);
if (pixelMultiplier == 0) pixelMultiplier = 1;
int interfaceSizeIndex;
AppSettings.Get("InterfaceSize", out interfaceSizeIndex, (int)InterfaceSize.Small);
InterfaceSize interfaceSize = (InterfaceSize)interfaceSizeIndex;
ReactionRecorder.Instance.PixelMultiplier = pixelMultiplier;
ReactionRecorder.Instance.InterfaceSize = interfaceSize;
BeginCapture();
}
unsafe void CaptureReactionColorFromLoadedImage(string filePath)
{
// read the screenshot from a file
string screenshotDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
FileStream pixStream = new FileStream(filePath, FileMode.Open);
RecordBuffer = new Gdk.Pixbuf(pixStream);
ReactionRecorder.Instance.SetPixelMultiplier(1);
// TODO: allow for other size
InterfaceSize interfaceSize = InterfaceSize.Small;
if (filePath.Contains("Large"))
{
interfaceSize = InterfaceSize.Large;
}
else if (filePath.Contains("Huge"))
{
interfaceSize = InterfaceSize.Huge;
}
ReactionRecorder.Instance.InterfaceSize = interfaceSize;
System.Console.WriteLine("Loaded {0} size {1} x {2} stride {3} bits {4} colorspace {5} channels {6} hasAlpha {7}", filePath, RecordBuffer.Width, RecordBuffer.Height, RecordBuffer.Rowstride, RecordBuffer.BitsPerSample, RecordBuffer.Colorspace, RecordBuffer.NChannels, RecordBuffer.HasAlpha);
System.GC.Collect(); // really, clean up now
BeginCapture();
}
protected virtual void OnCapture(object sender, System.EventArgs e)
{
CaptureReactionColor();
}
protected void OnCaptureFromFile(object sender, EventArgs e)
{
Gtk.FileChooserDialog fileDialog =
new Gtk.FileChooserDialog("Select screenshot file.",
(Gtk.Window)Toplevel, Gtk.FileChooserAction.Open,
Gtk.Stock.Cancel, Gtk.ResponseType.Cancel,
Gtk.Stock.Open, Gtk.ResponseType.Accept);
Gtk.FileFilter filter = new Gtk.FileFilter();
filter.AddPattern("*.png");
fileDialog.AddFilter(filter);
Gtk.ResponseType resp = (Gtk.ResponseType)fileDialog.Run();
if (resp == Gtk.ResponseType.Accept)
{
string fileName = fileDialog.Filename;
string directory = fileDialog.CurrentFolder;
if (directory != null)
{
CaptureReactionColorFromLoadedImage(System.IO.Path.Combine(directory, fileName));
}
else
{
CaptureReactionColorFromLoadedImage(fileName);
}
}
fileDialog.Destroy();
}
protected virtual void OnRecord(object sender, System.EventArgs e)
{
if (ReactionRecorder.Instance.RecordReaction(profile, expectedColor, reactedColor, reagents))
{
recordButton.Sensitive = false;
}
}
protected virtual void OnRecordNoReaction(object sender, System.EventArgs e)
{
if (ReactionRecorder.Instance.RecordReaction(profile, expectedColor, expectedColor, reagents))
{
recordNoReactionButton.Sensitive = false;
recordNoReactionButton.Visible = false;
clearReactionButton.Sensitive = true;
clearReactionButton.Visible = true;
this.reactionSwatch.Color = expectedColor;
this.reactedColor.Set(expectedColor);
}
}
protected virtual void OnChangedIngredient1(object sender, System.EventArgs e)
{
UpdateIngredients();
}
protected virtual void OnChangedIngredient2(object sender, System.EventArgs e)
{
UpdateIngredients();
}
protected virtual void OnChangedIngredient3(object sender, System.EventArgs e)
{
UpdateIngredients();
}
protected void OnClearReaction(object sender, EventArgs e)
{
string reagentName1 = GetSelectedReagentName(1);
string reagentName2 = GetSelectedReagentName(2);
string reagentName3 = GetSelectedReagentName(3);
if ((reagentName1 != null) && (reagentName2 != null) && (reagentName3 == null))
{
Reagent reagent1 = ReagentManager.GetReagent(reagentName1);
Reagent reagent2 = ReagentManager.GetReagent(reagentName2);
if (null != profile.FindReaction(reagent1, reagent2))
{
Gtk.MessageDialog md = new Gtk.MessageDialog((Gtk.Window)Toplevel,
Gtk.DialogFlags.DestroyWithParent,
Gtk.MessageType.Warning, Gtk.ButtonsType.OkCancel,
"This will delete the reaction status between " +
// TODO: ingredient1Name + " and " + ingredient2Name + "\n\n" +
"ARE YOU SURE?"
);
Gtk.ResponseType response = (Gtk.ResponseType)md.Run();
if (response == Gtk.ResponseType.Ok)
{
// really delete it
profile.ClearReaction(reagent1, reagent2);
reactionSwatch.Clear();
reactedColor.Clear();
clearReactionButton.Sensitive = false;
clearReactionButton.Visible = false;
recordNoReactionButton.Sensitive = true;
recordNoReactionButton.Visible = true;
}
md.Destroy();
}
}
}
}
}
|