void buildTrie(vector<string> & patterns , vector<vector<pair<char, int> > > &trie , vector<vector<pair<int, int> > > & qAcceptance) { //go through pattern by pattern for (int i = 0 , n = (int)patterns.size() ; i < n ; ++i) { insert_pattern(patterns[i], i+1, trie, qAcceptance); } }
void App::event_button(WPARAM wParam){ string name = ""; if(wParam>=1 && wParam<=Controls::geti()->controls.size()){ name = Controls::geti()->get_button_name(wParam); }else{ name = Controls::geti()->get_menu_name(wParam); } if(name.length()==0) return; if(name == "new"){ //nowy new_file(); }else if(name == "load"){ //wczytaj if(!Config::geti()->toolbar_show){ toolbar_switch(1); } string str2 = Controls::geti()->get_text("filename_edit"); if(str2.length()==0){ IO::geti()->echo("Podaj nazwê pliku."); }else{ open_chords_file(str2); } }else if(name == "save"){ //zapisz save_chords_file(); }else if(name == "analyze"){ //analizuj analyze(); }else if(name == "replace"){ //zamieñ if(!Config::geti()->toolbar_show){ toolbar_switch(1); return; } zamien(); }else if(name == "find"){ //znajdŸ if(!Config::geti()->toolbar_show){ toolbar_switch(1); return; } znajdz(); }else if(name == "undo"){ undo->revert(); }else if(name == "base"){ //baza akordów chordsbase_start(); }else if(name == "autoscroll"){ //autoscroll autoscroll_switch(); }else if(name == "reload"){ open_chords_file(Config::geti()->opened_file); }else if(name == "config"){ ShellExecute(0,"open",Config::geti()->config_filename.c_str(),"",0,SW_SHOW); }else if(name == "quick_replace"){ quick_replace(); }else if(name == "remove_chords"){ usun_akordy(); }else if(name == "remove_alt"){ usun_wersje(); }else if(name == "add_chord"){ dodaj_nawias(); }else if(name == "font++"){ change_font_size(+1); }else if(name == "font--"){ change_font_size(-1); }else if(name == "format_text"){ refresh_text(); }else if(name == "fullscreen"){ fullscreen_toggle(); }else if(name == "autoscroll_wait"){ autoscroll_on(); }else if(name == "autoscroll_nowait"){ autoscroll_nowait(); }else if(name == "autoscroll_off"){ autoscroll_off(); IO::geti()->echo("Autoscroll wy³¹czony"); }else if(name == "autoscroll_slower"){ autoscroll_nowait(+Config::geti()->autoscroll_interval*0.25); }else if(name == "autoscroll_faster"){ autoscroll_nowait(-Config::geti()->autoscroll_interval*0.2); }else if(name == "transpose+5"){ transpose(+5); }else if(name == "transpose++"){ transpose(+1); }else if(name == "transpose--"){ transpose(-1); }else if(name == "transpose-5"){ transpose(-5); }else if(name == "transpose0"){ transpose(-Config::geti()->transposed); }else if(name == "alt"){ dodaj_alternatywne(); }else if(name == "log"){ ShellExecute(0, "open", Config::geti()->log_filename.c_str(), "", 0, SW_SHOW); }else if(name == "associate_files"){ associate_files(); }else if(name == "help"){ show_help(); }else if(name == "info"){ stringstream ss; ss<<Config::geti()->program_name<<endl; ss<<"wersja "<<version<<endl; IO::geti()->message_box("O programie",ss.str()); }else if(name == "cmd_toggle"){ cmd_switch(); }else if(name == "toolbar_toggle"){ toolbar_switch(); }else if(name == "scroll_to_begin"){ set_scroll(0); }else if(name == "scroll_to_end"){ SendMessage(Controls::geti()->find("editor"), WM_VSCROLL, SB_BOTTOM, 0); }else if(name == "save_pattern"){ save_pattern(); }else if(name == "insert_pattern"){ insert_pattern(); }else if(name == "exit"){ DestroyWindow(main_window); }else{ IO::geti()->error("Zdarzenie nie zosta³o obs³u¿one: "+name); } }
LRESULT CALLBACK App::subclass_wndproc_new(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ //odnalezienie kontrolki Control* kontrolka = NULL; for(unsigned int i=0; i<Controls::geti()->controls.size(); i++){ if(Controls::geti()->controls.at(i)->handle == hwnd){ kontrolka = Controls::geti()->controls.at(i); break; } } if(kontrolka==NULL){ IO::geti()->error("Subclassing: Nie znaleziono kontrolki o podanym uchwycie"); return 0; } string nazwa = kontrolka->name; //globalne skróty klawiszowe if(message == WM_KEYDOWN){ if(wParam==VK_F1||wParam==VK_F2||wParam==VK_F3||wParam==VK_F5||wParam==VK_F6||wParam==VK_F7||wParam==VK_F8||wParam==VK_F9||wParam==VK_F10||wParam==VK_F11){ CallWindowProc(windowProc, hwnd, message, wParam, lParam); //przekazanie wy¿ej do mainwindow return 0; //przechwycenie } //wyjœcie z fullscreena if(wParam==VK_ESCAPE && Config::geti()->fullscreen_on){ CallWindowProc(windowProc, hwnd, message, wParam, lParam); //przekazanie wy¿ej do mainwindow return 0; //przechwycenie } //ctrl if(is_control_pressed()){ if(wParam=='S'||wParam=='F'||wParam=='N'||wParam=='B'||wParam==VK_ADD||wParam==VK_SUBTRACT||wParam==VK_LEFT||wParam==VK_RIGHT||wParam=='0'||wParam==VK_NUMPAD0||wParam==VK_OEM_3){ CallWindowProc(windowProc, hwnd, message, wParam, lParam); //przekazanie wy¿ej do mainwindow return 0; //przechwycenie } } } if(message == WM_SYSKEYDOWN){ if(wParam==VK_F10){ //zamiana WM_SYSKEYDOWN na WM_KEYDOWN subclass_wndproc_new(hwnd, WM_KEYDOWN, wParam, lParam); return 0; } } //globalne przechwycenie wygaszacza if(message == WM_SYSCOMMAND){ if(wParam == SC_SCREENSAVE){ CallWindowProc(windowProc, hwnd, message, wParam, lParam); //przekazanie wy¿ej do mainwindow return 0; //przechwycenie } } //nowe procedury kontrolek if(nazwa=="filename_edit"){ switch(message){ case WM_CHAR:{ if(wParam==VK_ESCAPE){ Controls::geti()->set_focus("editor"); return 0; }else if(wParam==VK_RETURN){ if(!Config::geti()->cmd_show){ cmd_switch(1); } Controls::geti()->set_focus("cmd"); Controls::geti()->select_all("cmd"); return 0; } }break; } } if(nazwa=="cmd"){ switch(message){ case WM_CHAR:{ if(wParam==VK_ESCAPE){ Controls::geti()->set_focus("editor"); return 0; }else if(wParam==VK_RETURN){ exec_cmd(); return 0; //przechwycenie } }break; case WM_KEYDOWN:{ if(wParam==VK_UP){ Controls::geti()->set_text("cmd", last_cmd); SendMessage(Controls::geti()->find("cmd"), EM_SETSEL, last_cmd.length(), last_cmd.length()); return 0; } if(wParam==VK_DOWN){ Controls::geti()->set_text("cmd", ""); return 0; } }break; } } if(nazwa=="editor"){ //edytor switch(message){ case WM_SYSKEYDOWN:{ if(wParam>='1' && wParam<='9'){ //zamiana WM_SYSKEYDOWN na WM_KEYDOWN subclass_wndproc_new(hwnd, WM_KEYDOWN, wParam, lParam); return 0; } }break; case WM_KEYDOWN:{ if(is_control_pressed()){ //ctrl if(wParam=='C'){ copy_text(); return 0; }else if(wParam=='A'){ select_all(); return 0; }else if(wParam=='Z'){ undo->revert(); return 0; }else if(wParam=='R'){ refresh_text(); return 0; }else if(wParam=='T'){ quick_replace(); return 0; }else if(wParam=='Q'){ usun_akordy(); return 0; }else if(wParam=='W'){ save_pattern(); return 0; }else if(wParam=='E'){ insert_pattern(); return 0; }else if(wParam=='D'){ dodaj_nawias(); return 0; }else if(wParam>='1' && wParam<='9'){ zapisz_tekst(wParam-'1'+1); return 0; } }else if(is_alt_pressed()){ //alt if(wParam>='1' && wParam<='9'){ wstaw_tekst(wParam-'1'+1); return 0; } } }break; case WM_CHAR:{ //dla ka¿dego znaku (bez controla) if(!is_control_pressed()){ undo->save(); } //undo->save(); if(wParam == ']'){ string add_text = "]"; SendMessage(Controls::geti()->find("editor"), EM_REPLACESEL, 0, (LPARAM)add_text.c_str()); //wstawienie znaku refresh_text(); //odœwie¿enie tekstu //zmiana koloru po nawiasie na kolor tekstu CHARFORMAT cf_text; cf_text.cbSize = sizeof(cf_text); SendMessage(Controls::geti()->find("editor"), EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf_text); //kolor tekstu + brak pogrubienia cf_text.dwMask = CFM_COLOR | CFM_BOLD; cf_text.crTextColor = RGB(Config::i()->color_text[0], Config::i()->color_text[1], Config::i()->color_text[2]); cf_text.dwEffects = 0; SendMessage(Controls::geti()->find("editor"), EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf_text); return 0; } }break; case WM_MOUSEWHEEL:{ int zdelta = GET_WHEEL_DELTA_WPARAM(wParam); if(LOWORD(wParam)==MK_CONTROL){ //z controlem //zmiana czcionki if(zdelta>=0){ change_font_size(+1); }else{ change_font_size(-1); } return 0; }else{ //scrollowanie edytora int scroll_step = Config::geti()->editor_fontsize + 2; if(zdelta>=0){ change_scroll(-scroll_step); }else{ change_scroll(+scroll_step); } return 0; } }break; } } if(nazwa=="find_edit"){ //szukany ci¹g znaków switch(message){ case WM_SETFOCUS:{ if(Controls::i()->get_text("find_edit")==Config::i()->find_edit_placeholder){ Controls::i()->set_text("find_edit", ""); } IO::geti()->echo("(Wpisz szukany ci¹g znaków, Enter - szukaj)"); }break; case WM_KILLFOCUS:{ if(Controls::i()->get_text("find_edit").length()==0){ Controls::i()->set_text("find_edit", Config::i()->find_edit_placeholder); } }break; case WM_CHAR:{ if(wParam==VK_RETURN){ znajdz(); return 0; } if(wParam==VK_TAB){ Controls::geti()->set_focus("replace_edit"); return 0; } }break; } } if(nazwa=="replace_edit"){ //tekst do zamiany switch(message){ case WM_SETFOCUS:{ if(Controls::i()->get_text("replace_edit")==Config::i()->replace_edit_placeholder){ Controls::i()->set_text("replace_edit", ""); } IO::geti()->echo("(Wpisz tekst do zamiany, Enter - zamieñ w zaznaczeniu lub ca³ym pliku)"); }break; case WM_KILLFOCUS:{ if(Controls::i()->get_text("replace_edit").length()==0){ Controls::i()->set_text("replace_edit", Config::i()->replace_edit_placeholder); } }break; case WM_CHAR:{ if(wParam==VK_RETURN){ zamien(); return 0; } if(wParam==VK_TAB){ Controls::geti()->set_focus("find_edit"); return 0; } }break; } } if(nazwa=="autoscroll_interval"){ //autoscroll_interval switch(message){ case WM_SETFOCUS:{ IO::geti()->echo("(Czas miêdzy kolejnymi przebiegami autoscrolla - wyra¿ony w milisekundach)"); }break; case WM_CHAR:{ if(wParam==VK_RETURN){ autoscroll_nowait(0); return 0; } }break; } } if(nazwa=="autoscroll_wait"){ //autoscroll_wait switch(message){ case WM_SETFOCUS:{ IO::geti()->echo("(Czas opóŸnienia przed autoscrollem - wyra¿ony w sekundach)"); }break; case WM_CHAR:{ if(wParam==VK_RETURN){ autoscroll_on(); return 0; } }break; } } return CallWindowProc(kontrolka->wndproc_old, hwnd, message, wParam, lParam); }
int main(void) { lcd.clearMarkers(); //init analog if needed init_analog(); srand(adc_read(0)); //pin 0 on portb output. //led stays on if iterations between fields are the same (same number of cells) DDRB |= _BV(PB0); //clear the buffer. clearArray(buffer); //if house define insert that. #ifdef PATTERN insert_pattern(field, Glider, 0,0); #endif //else random field. #ifdef RANDOM createRandomField(field); #endif //set contrast. lcd.setContrast(17); //make sure to start at location 0,0 lcd.setCursor(0,0); //position is field size, I refresh the screen Backwards. position = fieldSize; while(position--) { //display field with current position showField(field, fieldSize-position); //here the rules of the game of life are checked. //if a position has a cell (1), //then look how many around, //if 2 or 3 around it lives, else it dies. //if(field[position]) //{ // if(totalAround(field, position)==surviveAbility) // { // buffer[position]=1; // } // else if(totalAround(field, position)==surviveAbility+1) // { // buffer[position]=1; // } // else // { // buffer[position]=0; // } //} //else //{ //but if a position in the field is empty //and it has 3 around, that position becomes alife. // if(totalAround(field, position)==reproductiveNumber) // { // buffer[position] = 1; // } // else // { // buffer[position] = 0; // } //} //position keeps position in the field array, //and at the same time drawing location on //screen. if(position == 0) { //insert changes into the field. copy_buffer(buffer, field); //reset position to 0 position = fieldSize; //set frame rate with a blocking delay.. delay(adc_read(1)); //check wether we are in a steady state or just still evolving. currentState = checkField(field); //set contrast with pot meter on analog pin 1 (not 0) lcd.setContrast(32/2); //change field if field the same a while, or iterations goes above a certain number which meens it's probaly in a loop //check if button is pressed and create a new field. if(changeCount == holdingNumber || (iterations > 1000) || (PINB & (1<<PB2))) { //reset changeCount changeCount = 0; //reset iteration count. iterations = 0; //create a random playing field. #ifdef PATTERN insert_pattern(field, Glider, 0,0); #endif //createRandomField(field); //put a pattern we created onto the field. //insert_field(stable, field); } //if the field states stay the same. else if(currentState == previousState) { PORTB |= (1<<PB0); changeCount++; } //if the field states are different. else { PORTB &= ~(1<<PB0); previousState = currentState; //that is why setting it to zero. iterations++; //changeCount shouldn't change if the inbetween states happen te be the same. changeCount = 0; } //set location and nicely print something. lcd.setCursor(0,5); writeFormated(iterations,changeCount,"Game of Life:"); } } return 0; }