1 /* 2 * Copyright 2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #include "SetColorCommand.h" 10 11 #include <new> 12 #include <stdio.h> 13 14 #include "Gradient.h" 15 #include "Style.h" 16 17 using std::nothrow; 18 19 // constructor 20 SetColorCommand::SetColorCommand(Style* style, 21 const rgb_color& color) 22 : Command(), 23 fStyle(style), 24 fColor(color) 25 { 26 } 27 28 // destructor 29 SetColorCommand::~SetColorCommand() 30 { 31 } 32 33 // InitCheck 34 status_t 35 SetColorCommand::InitCheck() 36 { 37 return fStyle ? B_OK : B_NO_INIT; 38 } 39 40 // Perform 41 status_t 42 SetColorCommand::Perform() 43 { 44 // toggle the color 45 rgb_color previous = fStyle->Color(); 46 fStyle->SetColor(fColor); 47 fColor = previous; 48 49 return B_OK; 50 } 51 52 // Undo 53 status_t 54 SetColorCommand::Undo() 55 { 56 return Perform(); 57 } 58 59 // GetName 60 void 61 SetColorCommand::GetName(BString& name) 62 { 63 name << "Change Color"; 64 } 65 66 // CombineWithNext 67 bool 68 SetColorCommand::CombineWithNext(const Command* command) 69 { 70 const SetColorCommand* next 71 = dynamic_cast<const SetColorCommand*>(command); 72 73 if (next && next->fTimeStamp - fTimeStamp < 1000000) { 74 fTimeStamp = next->fTimeStamp; 75 // NOTE: next was already performed, but 76 // when undoing, we want to use our 77 // remembered color 78 return true; 79 } 80 return false; 81 } 82 83