Planeshift
|
00001 /* 00002 * pawsnumberpromptwindow.h - Author: Ondrej Hurt 00003 * 00004 * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org) 00005 * 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation (version 2 of the License) 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * 00018 */ 00019 00020 #ifndef PAWS_COLOR_PROMPT_WINDOW_HEADER 00021 #define PAWS_COLOR_PROMPT_WINDOW_HEADER 00022 00023 #include <csutil/list.h> 00024 #include <iutil/document.h> 00025 #include "pawspromptwindow.h" 00026 #include "pawsbutton.h" 00027 #include "pawscrollbar.h" 00028 00029 class pawsButton; 00030 class pawsEditTextBox; 00031 class pawsScrollbar; 00032 00037 class iOnColorEnteredAction 00038 { 00039 public: 00040 virtual void OnColorEntered(const char* name,int param,int color) = 0; 00041 // can be -1 00042 virtual ~iOnColorEnteredAction() {}; 00043 }; 00044 00045 class pawsColorInput : public pawsWidget 00046 { 00047 public: 00048 pawsColorInput() 00049 { 00050 SetRelativeFrameSize(140, 80); 00051 00052 // we have three scroll bars, one for Red, Green and Blue and a button used for "Preview". 00053 // The preview works following: As soon as the user scrolls, the buttons background colour 00054 // changes to the set colour. 00055 scrollBarR = new pawsScrollBar(); 00056 scrollBarR->SetHorizontal(true); 00057 scrollBarR->SetRelativeFrame(1, 1, 110, 20); 00058 scrollBarR->SetTickValue(1); 00059 scrollBarR->PostSetup(); 00060 00061 scrollBarG = new pawsScrollBar(); 00062 scrollBarG->SetHorizontal(true); 00063 scrollBarG->SetRelativeFrame(1, 31, 110, 20); 00064 scrollBarG->SetTickValue(1); 00065 scrollBarG->PostSetup(); 00066 00067 scrollBarB = new pawsScrollBar(); 00068 scrollBarB->SetHorizontal(true); 00069 scrollBarB->SetRelativeFrame(1, 61, 110, 20); 00070 scrollBarB->SetTickValue(1); 00071 scrollBarB->PostSetup(); 00072 00073 buttonPreview = new pawsButton(); 00074 buttonPreview->SetRelativeFrame(115, 35, 20, 20); 00075 00076 AddChild(scrollBarR); 00077 AddChild(scrollBarG); 00078 AddChild(scrollBarB); 00079 AddChild(buttonPreview); 00080 } 00081 00082 pawsColorInput(const pawsColorInput &origin):pawsWidget(origin) 00083 { 00084 buttonPreview = 0; 00085 scrollBarB = 0; 00086 scrollBarG = 0; 00087 scrollBarR = 0; 00088 for(unsigned int i = 0 ; i < origin.children.GetSize(); i++) 00089 { 00090 if(origin.children[i] == origin.buttonPreview) 00091 buttonPreview = dynamic_cast<pawsButton*>(children[i]); 00092 else if(origin.children[i] == origin.scrollBarB) 00093 scrollBarB = dynamic_cast<pawsScrollBar*>(children[i]); 00094 else if(origin.children[i] == origin.scrollBarG) 00095 scrollBarG = dynamic_cast<pawsScrollBar*>(children[i]); 00096 else if(origin.children[i] == origin.scrollBarR) 00097 scrollBarR = dynamic_cast<pawsScrollBar*>(children[i]); 00098 00099 if(buttonPreview != 0 && scrollBarB != 0 && scrollBarG != 0 && scrollBarR != 0) break; 00100 } 00101 } 00102 00103 pawsScrollBar* scrollBarR; 00104 pawsScrollBar* scrollBarG; 00105 pawsScrollBar* scrollBarB; 00106 pawsButton* buttonPreview; 00107 }; 00108 00109 CREATE_PAWS_FACTORY(pawsColorInput); 00113 class pawsColorPromptWindow : public pawsPromptWindow 00114 { 00115 public: 00116 pawsColorPromptWindow(); 00117 pawsColorPromptWindow(const pawsColorPromptWindow &origin); 00118 //from pawsWidget: 00119 virtual bool PostSetup(); 00120 bool OnButtonPressed(int mouseButton, int keyModifier, pawsWidget* widget); 00121 virtual bool OnKeyDown(utf32_char keyCode, utf32_char keyChar, int modifiers); 00122 virtual bool OnScroll(int scrollDirection, pawsScrollBar* widget); 00123 00124 void Initialize(const csString &label, int color, int minColor, int maxColor, 00125 iOnColorEnteredAction* action,const char* name, int param=0); 00126 00127 static pawsColorPromptWindow* Create(const csString &label, 00128 int color, int minColor, int maxColor, 00129 iOnColorEnteredAction* action,const char* name, int param=0); 00130 00131 00132 protected: 00135 void SetBoundaries(int minColor, int maxColor); 00136 00138 void ColorWasEntered(int color); 00139 00140 int maxColor, minColor; 00141 00143 csString lastValidText; 00144 00145 pawsScrollBar* scrollBarR; 00146 pawsScrollBar* scrollBarG; 00147 pawsScrollBar* scrollBarB; 00148 00149 pawsButton* buttonPreview; 00150 00151 iOnColorEnteredAction* action; 00152 csString name; 00153 int param; 00154 }; 00155 00156 CREATE_PAWS_FACTORY(pawsColorPromptWindow); 00157 00160 #endif 00161