예제 #1
0
BOOL BaseLimitCtrl::IsKeyAtTime(TimeValue t, DWORD flags)
{
	Control *limitedCtrl = GetLimitedControl();
	if (limitedCtrl)
		return limitedCtrl->IsKeyAtTime(t, flags);
	else
		return FALSE;
}
void OrientConstTimeChangeCallback :: TimeChanged(TimeValue t){
	int selection = SendDlgItemMessage(orient_controller->hWnd, IDC_ORIENT_TARG_LIST, LB_GETCURSEL, 0, 0);
	ISpinnerControl* spin = GetISpinner(GetDlgItem(orient_controller->hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER));
	spin = GetISpinner(GetDlgItem(orient_controller->hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER));

	Control* cont = orient_controller->pblock->GetControllerByID(orientation_target_weight, selection); 
	// until it is animated, paramblock doesn't have a controller assigned in it yet.
	if (spin && (cont !=NULL)) {
		if (cont->IsKeyAtTime(t,KEYAT_ROTATION)) {
			spin->SetKeyBrackets(TRUE);
		} 
		else {
			spin->SetKeyBrackets(FALSE);
		}
	}
	ReleaseISpinner(spin);

	orient_controller->RedrawListbox(t);
}
		INT_PTR DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
		{	

			OrientConstRotation* p = (OrientConstRotation*)map->GetParamBlock()->GetOwner();
			UpdateOrientName(p);
			p->hWnd = hWnd;
			int ct = p->pblock->Count(orientation_target_list);
//			int ctf = p->pblock->Count(orientation_target_weight);

			switch (msg) 
			{
				case WM_INITDIALOG:
				{
					int selection = p->last_selection;

					ICustButton *iBut = GetICustButton(GetDlgItem(hWnd,IDC_ORIENT_TARG_PICKNODE));
					iBut->SetType(CBT_CHECK);
					iBut->SetHighlightColor(GREEN_WASH);
					ReleaseICustButton(iBut);
					
					ISpinnerControl* spin = SetupFloatSpinner(hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER, IDC_ORIENT_CONS_WEIGHT_EDIT, 0.0f, 100.0f, 50.0f, 1.0f);
					spin = GetISpinner(GetDlgItem(hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER));
					
					// CAL-09/10/02: automatically set last_selection to 0 when there're targets
					if (p->pblock->Count(orientation_target_list) < 1) { 
						// nothing is selected OR there are no targets
						// all buttons - target_delete, weight_edit, weight_spinner -- are disabled
						EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_EDIT), FALSE);
						EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER), FALSE);
						ICustButton *iPickOb1;
						iPickOb1	= GetICustButton(GetDlgItem(p->hWnd, IDC_REMOVE_ORIENT_TARG));
						if (iPickOb1 != NULL){
							iPickOb1->Enable(FALSE);		
							ReleaseICustButton(iPickOb1);
						}
						spin->SetValue(0.0f, FALSE);		
					} else {
						if (selection < 0)
							p->last_selection = selection = 0;

						// there is a valid selection 
						// automatically means there is AT LEAST one target
						Control *cont = p->pblock->GetControllerByID(orientation_target_weight, selection); 
						// until it is animated, paramblock doesn't have a controller assigned in it yet.
						if (spin) {
							if ((cont != NULL) && cont->IsKeyAtTime(t,KEYAT_ROTATION))
								spin->SetKeyBrackets(TRUE);
							else
								spin->SetKeyBrackets(FALSE);
						}

						if(p->pickWorldFlag){
							ICustButton *iPickOb;
							iPickOb	= GetICustButton(GetDlgItem(p->hWnd, IDC_ORIENT_PICK_WORLD));
							if (iPickOb != NULL){
								iPickOb->Enable(FALSE);
								ReleaseICustButton(iPickOb);
							}

						}

						if (p->pblock->Count(orientation_target_list) == 1){// there is only one target
							// the "delete" button should be enabled
							ICustButton *iPickOb1;
							iPickOb1 = GetICustButton(GetDlgItem(p->hWnd, IDC_REMOVE_ORIENT_TARG));
							if (iPickOb1 != NULL){
								iPickOb1->Enable(TRUE);		
								ReleaseICustButton(iPickOb1);
							}
							// the rest are disabled
//							EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_EDIT), FALSE);
//							EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER), FALSE);
						}
						else if (p->pblock->Count(orientation_target_list) > 1){ 
							// there are more than one targets
							// all buttons - delete, weight_edit, weight_spinner -- are enabled
							EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_EDIT), TRUE);
							EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER), TRUE);
							ICustButton *iPickOb1;
							iPickOb1 = GetICustButton(GetDlgItem(p->hWnd, IDC_REMOVE_ORIENT_TARG));
							if (iPickOb1 != NULL){
								iPickOb1->Enable(TRUE);		
								ReleaseICustButton(iPickOb1);
							}
						}
					}
					ReleaseISpinner(spin);
					p->RedrawListbox(GetCOREInterface()->GetTime(), selection);
					return TRUE;	
				}
				break;


				case WM_COMMAND:
				{
					
					int selection;
					
					if (LOWORD(wParam) == IDC_ORIENT_TARG_LIST && HIWORD(wParam) == LBN_SELCHANGE)
					{
						selection = SendDlgItemMessage(p->hWnd, IDC_ORIENT_TARG_LIST, LB_GETCURSEL, 0, 0);
						p->last_selection = selection;
						if (selection >= 0){
						// there is a valid selection 
							// automatically means there is AT LEAST one target
							if (p->pblock->Count(orientation_target_list) == 1){ // there is only one target
								// the "delete" button should be enabled
								ICustButton *iPickOb1;
								iPickOb1 = GetICustButton(GetDlgItem(p->hWnd, IDC_REMOVE_ORIENT_TARG));
								if (iPickOb1 != NULL){
									iPickOb1->Enable(TRUE);		
									ReleaseICustButton(iPickOb1);
								}
//								// the rest are disabled
//								EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_EDIT), FALSE);
//								EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER), FALSE);
							}

							else  if (p->pblock->Count(orientation_target_list) > 1){ 
							// there are more than one targets
								// all buttons - delete, weight_edit, weight_spinner -- are enabled
								EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_EDIT), TRUE);
								EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER), TRUE);
								ICustButton *iPickOb1;
								iPickOb1 = GetICustButton(GetDlgItem(p->hWnd, IDC_REMOVE_ORIENT_TARG));
								if (iPickOb1 != NULL){
									iPickOb1->Enable(TRUE);		
									ReleaseICustButton(iPickOb1);
								}

								ISpinnerControl* spin = GetISpinner(GetDlgItem(hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER));
								float value = map->GetParamBlock()->GetFloat(orientation_target_weight, t, selection);
								spin->SetValue(value, FALSE);

								Control *cont = p->pblock->GetControllerByID(orientation_target_weight, selection); // until it is animated, paramblock doesn't have a controller assigned in it yet.
								if (spin && (cont != NULL)) {
									if (cont->IsKeyAtTime(t,KEYAT_ROTATION)){
										spin->SetKeyBrackets(TRUE);
									} 
								}
								else {
									spin->SetKeyBrackets(FALSE);
								}
								ReleaseISpinner(spin);
							}
							p->RedrawListbox(GetCOREInterface()->GetTime(), selection);							
						}
						
						else if (selection < 0 || p->pblock->Count(orientation_target_list) < 1){ 
						// nothing is selected OR there are no targets
							// all buttons - target_delete, weight_edit, weight_spinner -- are disabled
							EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_EDIT), FALSE);
							EnableWindow(GetDlgItem(p->hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER), FALSE);
							ICustButton *iPickOb1;
							iPickOb1	= GetICustButton(GetDlgItem(p->hWnd, IDC_REMOVE_ORIENT_TARG));
							if (iPickOb1 != NULL){
								iPickOb1->Enable(FALSE);		
								ReleaseICustButton(iPickOb1);
							}
						}
					}

					else if (LOWORD(wParam) == IDC_ORIENT_TARG_PICKNODE){
						thePickMode.p  = p;					
						p->ip->SetPickMode(&thePickMode);
					}

					else if (LOWORD(wParam) == IDC_REMOVE_ORIENT_TARG){
						selection = SendDlgItemMessage(p->hWnd, IDC_ORIENT_TARG_LIST, LB_GETCURSEL, 0, 0);
						p->last_selection = selection;
						if (selection >= 0){
							theHold.Begin();
							p->DeleteTarget(selection);
							theHold.Accept(GetString(IDS_AG_ORIENTATION_LIST));
						}
//						p->RedrawListbox(GetCOREInterface()->GetTime(), selection-1);
					}

					else if (LOWORD(wParam) == IDC_ORIENT_PICK_WORLD){
						INode *nullNode = NULL;
						p->AppendTarget(nullNode);
						
						p->pickWorldFlag = 1;

						p->NotifyDependents(FOREVER,PART_ALL,REFMSG_CHANGE); // so that the change is updated
						ICustButton *iPickOb;
						iPickOb	= GetICustButton(GetDlgItem(p->hWnd, IDC_ORIENT_PICK_WORLD));
						if (iPickOb != NULL){
							iPickOb->Enable(FALSE);
							ReleaseICustButton(iPickOb);
						}
						p->RedrawListbox(GetCOREInterface()->GetTime());
					}

				
				}
				break;


				case CC_SPINNER_CHANGE:
				{
					if (LOWORD(wParam) == IDC_ORIENT_CONS_WEIGHT_SPINNER) {
						int selection = SendDlgItemMessage(p->hWnd, IDC_ORIENT_TARG_LIST, LB_GETCURSEL, 0, 0);

						// CAL-09/10/02: need to start a hold if it's not holding to handle type-in values
						BOOL isHold = theHold.Holding();
						if (!isHold) theHold.Begin();

						ISpinnerControl* spin = GetISpinner(GetDlgItem(hWnd, IDC_ORIENT_CONS_WEIGHT_SPINNER));

						if (selection >= 0) {
							float value = ((ISpinnerControl *)lParam)->GetFVal();
							map->GetParamBlock()->SetValue(orientation_target_weight, t, value, selection);

							Control *cont = p->pblock->GetControllerByID(orientation_target_weight, selection); // until it is animated, paramblock doesn't have a controller assigned in it yet.
							if (spin)
								spin->SetKeyBrackets(((cont != NULL) && cont->IsKeyAtTime(t,KEYAT_ROTATION)) ? TRUE : FALSE);

							p->RedrawListbox(GetCOREInterface()->GetTime(), selection);
						} else {
							if (spin) spin->SetValue(0.0f, FALSE);
						}

						if (spin) ReleaseISpinner(spin);

						if (!isHold) theHold.Accept(GetString(IDS_RB_PARAMETERCHANGE));
					}
				}			
				break;

			}
			return FALSE;
		}