//-------------------------------- // //-------------------------------- void Quaternion::Normalize() { float norm = sqrtf( SQR(x) + SQR(y) + SQR(z) + SQR(w) ); if( FLOAT_EQ( 0.0F, norm ) ) { return ; } //if norm = 1.0F / norm; x = x * norm; y = y * norm; z = z * norm; w = w * norm; norm = sqrtf( SQR(x) + SQR(y) + SQR(z) + SQR(w) ); if( !FLOAT_EQ( 1.0F, norm ) ) { return ; } //if LIMIT_RANGE(-1.0f, w, 1.0f); LIMIT_RANGE(-1.0f, x, 1.0f); LIMIT_RANGE(-1.0f, y, 1.0f); LIMIT_RANGE(-1.0f, z, 1.0f); } //Quaternion::Normalize
void C_Quaternion::Normalize(void) { float magn = sqrt(this->x * this->x + this->y * this->y + this->z * this->z + this->a * this->a); if(magn) { this->x /= magn; this->y /= magn; this->z /= magn; this->a /= magn; LIMIT_RANGE(-1.0 , this->x , 1.0); LIMIT_RANGE(-1.0 , this->y , 1.0); LIMIT_RANGE(-1.0 , this->z , 1.0); LIMIT_RANGE(-1.0 , this->a , 1.0); } }
long Settings::onChangeSetting(FXObject*o, FXSelector sel, void*p) { switch FXSELID(sel) { case ID_TOGGLE_SMART_HOME: { SmartHome = !SmartHome; break; } case ID_TOGGLE_WRAP_AWARE: { WrapAwareHomeEnd = !WrapAwareHomeEnd; break; } case ID_TOGGLE_USE_TABS: { FXSpinner*spin=(FXSpinner*)(((FXCheckButton*)o)->getUserData()); UseTabs = (bool)((FXival)p); if (UseTabs) { spin->disable(); spin->getNext()->disable(); spin->setTextColor(spin->getApp()->getBaseColor()); } else { spin->enable(); spin->getNext()->enable(); spin->setTextColor(spin->getApp()->getForeColor()); } break; } case ID_SET_BRACE_MATCHING: { BraceMatch = (FXival)p; LIMIT_RANGE(BraceMatch,BRACEMATCH_NONE,BRACEMATCH_AFTER); break; } case ID_TOGGLE_ASK_CLOSE_MULTI_MENU: { PromptCloseMultiMenu = !PromptCloseMultiMenu; break; } case ID_TOGGLE_ASK_CLOSE_MULTI_EXIT: { PromptCloseMultiExit = !PromptCloseMultiExit; break; } case ID_TOGGLE_WATCH_EXTERN: { WatchExternChanges = !WatchExternChanges; break; } case ID_TOGGLE_SMOOTH_SCROLL: { SmoothScroll = !SmoothScroll; break; } case ID_TOGGLE_SEARCH_VERBOSE: { SearchVerbose = !SearchVerbose; break; } case ID_TOGGLE_CARET_PAST_EOL: { CaretPastEOL = !CaretPastEOL; break; } case ID_TOGGLE_VIEW_WHITESPACE_EOL: { WhitespaceShowsEOL = !WhitespaceShowsEOL; break; } case ID_TOGGLE_ASCII_DEFAULT: { DefaultToAscii = !DefaultToAscii; break; } case ID_TOGGLE_SBCS_DEFAULT: { DefaultToSbcs = !DefaultToSbcs; break; } case ID_TOGGLE_WORD_WRAP: { WordWrap = !WordWrap; break; } case ID_TOGGLE_WRAP_TOOLBAR: { WrapToolbar = !WrapToolbar; break; } case ID_TOGGLE_AUTOSAVE: { FXWindow*w=(FXWindow*)o; w=(FXWindow*)w->getUserData(); Autosave = !Autosave; if (Autosave) { w->enable(); } else { w->disable(); } break; } case ID_SAVE_ON_FILTER_SEL: { SaveBeforeFilterSel = !SaveBeforeFilterSel; break; } case ID_SAVE_ON_INS_CMD: { SaveBeforeInsCmd = !SaveBeforeInsCmd; break; } case ID_SAVE_ON_EXEC_CMD: { SaveBeforeExecCmd = !SaveBeforeExecCmd; break; } case ID_CHOOSE_FONT: { EditorFontDlg dlg(((FXWindow*)o)->getShell()); dlg.setAscent(FontAscent); dlg.setDescent(FontDescent); #ifdef WIN32 // Windows font dialog is empty, unless setwidth is zero. FXushort setwidth=fontdesc.setwidth; fontdesc.setwidth=0; #endif SetDialogFromFont(dlg,fontdesc); if (dlg.execute(PLACEMENT_SCREEN)) { SetFontFromDialog(fontdesc,dlg); FontName=(FXchar*)(fontdesc.face); FontSize=fontdesc.size; FontAscent=dlg.getAscent(); FontDescent=dlg.getDescent(); } #ifdef WIN32 else { fontdesc.setwidth=setwidth; } #endif break; } case ID_SET_MAX_FILES: { FXTextField*tf=(FXTextField*)o; MaxFiles=FXIntVal(tf->getText(),10); LIMIT_RANGE(MaxFiles,1,999); char maxfiles[8]="\0\0\0\0\0\0\0"; snprintf(maxfiles, sizeof(maxfiles)-1, "%d", MaxFiles); tf->setText(maxfiles); break; } case ID_SET_TAB_WIDTH: { FXSpinner*spin=(FXSpinner*)o; TabWidth=spin->getValue(); LIMIT_RANGE(TabWidth,1,16); break; } case ID_SET_TAB_WIDTH_FOR_LANG: { FXSpinner*spin=(FXSpinner*)o; LangStyle*ls=(LangStyle*)spin->getUserData(); ls->tabwidth=spin->getValue(); LIMIT_RANGE(ls->tabwidth,0,16); break; } case ID_SET_INDENT_WIDTH: { FXSpinner*spin=(FXSpinner*)o; IndentWidth=spin->getValue(); LIMIT_RANGE(IndentWidth,1,16); break; } case ID_SET_CARET_WIDTH: { FXSpinner*spin=(FXSpinner*)o; CaretWidth=spin->getValue(); LIMIT_RANGE(CaretWidth,1,3); break; } case ID_SET_WHEEL_LINES: { FXSpinner*spin=(FXSpinner*)o; WheelLines=spin->getValue(); LIMIT_RANGE(WheelLines,1,32); break; } case ID_SET_TAB_TITLE_MAX_WIDTH: { FXSpinner*spin=(FXSpinner*)o; TabTitleMaxWidth=spin->getValue(); LIMIT_RANGE(TabTitleMaxWidth,0,ScreenWidth); } case ID_SET_SEARCH_WRAP: { SearchWrap=(FXival)p; LIMIT_RANGE(SearchWrap,SEARCH_WRAP_NEVER,SEARCH_WRAP_ASK); break; } case ID_SET_SEARCH_GUI: { SearchGui=(FXival)p; LIMIT_RANGE(SearchGui,SEARCH_GUI_ABOVE,SEARCH_GUI_FLOAT); break; } case ID_SET_AUTO_INDENT: { AutoIndent=(FXival)p; LIMIT_RANGE(AutoIndent,AUTO_INDENT_NONE,AUTO_INDENT_SMART); break; } case ID_SET_SPLIT_VIEW: { SplitView=(FXival)p; LIMIT_RANGE(SplitView,SPLIT_NONE,SPLIT_BESIDE); break; } case ID_SET_KEEP_FILE_FILTER: { KeepFileFilter=(FXival)p; LIMIT_RANGE(KeepFileFilter,REMEMBER_NEVER,REMEMBER_ALWAYS); break; } case ID_SET_RIGHT_EDGE: { FXSpinner*spin=(FXSpinner*)o; RightEdgeColumn=spin->getValue(); LIMIT_RANGE(RightEdgeColumn,1,1024); break; } case ID_SET_SHELL_CMD: { FXTextField*tf=(FXTextField*)o; ShellCommand=tf->getText().text(); break; } case ID_SET_AUTOSAVE_INT: { FXSpinner*spin=(FXSpinner*)o; AutosaveInterval=spin->getValue(); LIMIT_RANGE(AutosaveInterval,15,900); break; } case ID_SET_SEARCH_OPTS: { SearchOptions=(FXival)p; break; } case ID_SET_FILETYPES: { FXInputDialog*dlg=(FXInputDialog*)o; LangStyle* ls=(LangStyle*)dlg->getUserData(); if (ls) { if (ls->mask) { if (strcmp(ls->mask,dlg->getText().text())==0) { break; } if ( ls->mallocs & (1<<30) ) { free(ls->mask); } } ls->mask=strdup(dlg->getText().text()); } break; } case ID_SET_SHABANGS: { FXInputDialog*dlg=(FXInputDialog*)o; LangStyle* ls=(LangStyle*)dlg->getUserData(); if (ls) { if (ls->apps) { if (strcmp(ls->apps,dlg->getText().text())==0) { break; } if ( ls->mallocs & (1<<29) ) { free(ls->apps); } } ls->apps=strdup(dlg->getText().text()); } break; } case ID_SET_FILE_FORMAT: { DefaultFileFormat=(FXival)p; LIMIT_RANGE(DefaultFileFormat,0,2); break; } case ID_SET_TOOLBAR_BTN_SIZE: { ToolbarButtonSize=(FXival)p; LIMIT_RANGE(ToolbarButtonSize,0,2); break; } } return 1; }
Settings::Settings(FXMainWindow*w, const FXString &configdir, MenuMgr*mmgr):SettingsBase() { mnumgr=mmgr; FXString tmp; reg=&(w->getApp()->reg()); style_reg=new FXSettings(); app=w->getApp(); style_file=configdir+STYLE_FILE; if (use_xdg_config()) { style_file.append(".rc"); } #ifdef FOX_1_6 // Fox-1.6 will choke reading string entries > 2000 chars, so rewrite // the styles file, in case it was written by a newer version of Fox. if (FXStat::exists(style_file)) { FXFile style_fh(style_file,FXIO::Reading); if (style_fh.isOpen()) { FXString style_data('\0', style_fh.size()+1); style_fh.readBlock((char*)style_data.text(), style_fh.size()); style_fh.close(); FXint n=style_data.contains(ENDLINE); bool toolong=false; for (FXint i=0; i<=n; i++) { if (style_data.section(ENDLINE,i).length()>1952) { toolong=true; break; } } if (toolong && style_fh.open(style_file,FXIO::Writing)) { FXint eoln=strlen(ENDLINE); for (FXint i=0; i<=n; i++) { FXString line=style_data.section(ENDLINE,i); line.trunc(1952); if (strlen(line.text())) { style_fh.writeBlock(line.text(),line.length()); } style_fh.writeBlock(ENDLINE,eoln); } style_fh.close(); } } } #endif if ( (FXStat::exists(style_file)) && (!style_reg->parseFile(style_file, true))) { FXMessageBox::error(app,MBOX_OK, _("Configuration error"), "%s \n%s\n%s", _("Failed to read settings from"), style_file.text(), SystemErrorStr() ); } ReadInt(ShowStatusBar,true); ReadInt(ShowLineNumbers,false); ReadInt(ShowToolbar,true); ReadInt(ShowWhiteSpace,false); ReadInt(ShowOutputPane,false); bool InvertColors=false; ReadInt(InvertColors,false); ColorFuncs::InvertColors(InvertColors); ReadIntRng(SplitView,0,SPLIT_NONE,SPLIT_BESIDE); ReadInt(OutputPaneHeight,64); ReadInt(SmartHome,false); ReadInt(WrapAwareHomeEnd,false); ReadIntRng(BraceMatch,BRACEMATCH_EITHER,BRACEMATCH_NONE,BRACEMATCH_AFTER); ReadInt(UseTabs,true); ReadInt(CaretPastEOL,false); ReadIntRng(TabWidth,4,1,16); ReadIntRng(IndentWidth,TabWidth,1,16); ReadIntRng(CaretWidth,1,1,3); ReadIntRng(RightEdgeColumn,80,1,1024); ReadInt(ShowRightEdge,false); ReadInt(ShowIndentGuides,false); ReadInt(ShowCaretLine,true); ReadInt(SmoothScroll,true); ReadIntRng(WheelLines,3,1,32); ReadIntRng(SearchWrap,SEARCH_WRAP_ASK,SEARCH_WRAP_NEVER,SEARCH_WRAP_ASK); ReadIntRng(SearchGui,SEARCH_GUI_BELOW,SEARCH_GUI_ABOVE,SEARCH_GUI_FLOAT); ReadIntRng(AutoIndent,AUTO_INDENT_NONE,AUTO_INDENT_NONE,AUTO_INDENT_SMART); ReadInt(SearchVerbose,true); ReadInt(SearchOptions,0); ReadInt(ZoomFactor,0); ReadIntRng(MaxFiles,128,1,999); ReadInt(PromptCloseMultiMenu,true); ReadInt(PromptCloseMultiExit,true); ReadInt(WatchExternChanges,true); ReadInt(Autosave,false); ReadIntRng(AutosaveInterval,60,15,900); ReadInt(SaveBeforeFilterSel,false); ReadInt(SaveBeforeInsCmd,false); ReadInt(SaveBeforeExecCmd,true); ReadInt(WhitespaceShowsEOL,true); ReadIntRng(DefaultFileFormat,DEFAULT_EOL_FORMAT,0,2); ReadInt(DefaultToAscii,!LocaleIsUTF8()); ReadInt(DefaultToSbcs,true); ReadIntRng(KeepFileFilter,REMEMBER_NEVER,REMEMBER_NEVER,REMEMBER_ALWAYS); if (KeepFileFilter==REMEMBER_ALWAYS) { ReadInt(FileFilterIndex,0); } else { FileFilterIndex=0; } ReadInt(FileOpenMulti,false); ReadInt(WordWrap,false); ReadInt(WrapToolbar,true); ReadIntRng(ToolbarButtonSize,1,0,2);// 0=small; 1=medium; 2=large placement=reg->existingEntry(geom_sect,"Top")?PLACEMENT_DEFAULT:PLACEMENT_SCREEN; ReadInt(Left,0); ReadInt(Top,0); ReadInt(Width,0); ReadInt(Height,0); ScreenWidth=w->getApp()->getRootWindow()->getDefaultWidth(); ScreenHeight=w->getApp()->getRootWindow()->getDefaultHeight(); if ((Width==0)&&(Height==0)) { // First run, size based on screen dimensions Width=ScreenWidth*(4.0/5.0); Height=ScreenHeight*(3.0/4.0); LIMIT_RANGE(Width,600,Width); LIMIT_RANGE(Height,400,Height); } LIMIT_RANGE(Left,0,Left); LIMIT_RANGE(Top,0,Top); LIMIT_RANGE(Width,160,Width); LIMIT_RANGE(Height,120,Height); ReadInt(Maximize,false); ReadIntRng(TabTitleMaxWidth,ScreenWidth/6,0,ScreenWidth); reg->deleteSection("LastFocused"); ReadInt(FontSize,120); ReadIntRng(FontAscent,2,0,16); ReadIntRng(FontDescent,0,0,16); if (reg->existingEntry(edit_sect,"FontName")) { ReadStr(FontName,"Fixed [Misc]"); } else { FindFont(FontName); } tmp=reg->readStringEntry(view_sect,"DocTabPosition","T"); if (tmp.empty() || !strchr("TBLR",tmp.text()[0])) { DocTabPosition='T'; } else { DocTabPosition=tmp.text()[0]; } tmp=reg->readStringEntry(view_sect,"DocTabsPacked","A"); if (tmp=="0") { tmp="U"; } else if (tmp=="1") { tmp="P"; } if (tmp.empty() || !strchr("UPA",tmp.text()[0])) { DocTabsPacked='A'; } else { DocTabsPacked=tmp.text()[0]; } ReadStr(FileFilters, default_file_filters); FileFilters.substitute("|", "\n", true); ReadStr(ShellCommand,SHELL_COMMAND); ParseStyles(style_reg, global_sect, GlobalStyle); ParseStyle(style_reg, global_sect, &WhiteSpaceStyle); ParseStyle(style_reg, global_sect, &CaretLineStyle); ParseStyle(style_reg, global_sect, &RightMarginStyle); for (LangStyle*ls=languages; ls->name; ls++) { if (ls->words) { int i; for (i=0; ls->words[i]; i++) { char buf[256]; snprintf(buf,sizeof(buf)-1, "words_%d", i+1); tmp=style_reg->readStringEntry(ls->name,buf,ls->words[i]); SetKeywordList(ls,i,tmp); } } ParseStyles(style_reg, ls->name, ls->styles); tmp=style_reg->readStringEntry(ls->name,"FileMask",ls->mask?ls->mask:""); if ( (ls->mask && (strcmp(ls->mask,tmp.text())!=0))||((ls->mask==NULL)&&(!tmp.empty())) ) { ls->mask=strdup(tmp.text()); ls->mallocs |= LANGSTYLE_MASK_ALLOCD; } tmp=style_reg->readStringEntry(ls->name,"ShebangApps",ls->apps?ls->apps:""); if ( (ls->apps && (strcmp(ls->apps,tmp.text())!=0))||((ls->apps==NULL)&&(!tmp.empty())) ){ ls->apps=strdup(tmp.text()); ls->mallocs |= LANGSTYLE_APPS_ALLOCD; } ls->tabs=(TabPolicy)(style_reg->readIntEntry(ls->name,"TabPolicy", ls->tabs)); ls->tabwidth=style_reg->readIntEntry(ls->name,"TabWidth", 0); LIMIT_RANGE(ls->tabwidth,0,16); } styles=GlobalStyle; mnumgr->ReadMenuSpecs(reg,keys_sect); mnumgr->ReadToolbarButtons(reg,tbar_sect); mnumgr->ReadPopupMenu(reg,popup_sect); ReadErrorPatterns(reg); ReadSysIncPaths(reg); }