bool pawsControlWindow::PostSetup() { SetAlwaysOnTop(true); AddWindow( "InventoryWindow" , "InventoryButton" ); AddWindow( "ConfigWindow" , "OptionsButton" ); AddWindow( "SpellBookWindow" , "SpellBookButton" ); AddWindow( "AttackBookWindow" , "AttackButton" ); AddWindow( "InfoWindow" , "InfoButton" ); AddWindow( "HelpWindow" , "HelpButton" ); AddWindow( "ShortcutMenu" , "ShortcutButton" ); AddWindow( "BuddyWindow" , "BuddyButton" ); AddWindow( "GroupWindow" , "GroupButton" ); AddWindow( "PetitionWindow" , "PetitionButton" ); AddWindow( "ChatWindow" , "ChatButton" ); AddWindow( "SkillWindow" , "SkillsButton" ); AddWindow( "QuestNotebook" , "QuestButton" ); AddWindow( "GuildWindow" , "GuildButton" ); AddWindow( "ActiveMagicWindow" , "ActiveMagicButton" ); keyboard = csQueryRegistry<iKeyboardDriver> (PawsManager::GetSingleton().GetObjectRegistry()); //The quit button is a bit special //We need to manualy register it QuitIcon = new Icon; QuitIcon->window = NULL; QuitIcon->theirButton = (pawsButton*)FindWidget("QuitButton"); QuitIcon->orgRes = QuitIcon->theirButton->GetBackground(); QuitIcon->IsActive = false; QuitIcon->IsOver = false; buttons.Push(QuitIcon); csRef<iConfigManager> file = psengine->GetConfig(); int loadStyle = file->GetInt("PlaneShift.GUI.ControlWindow.CurrentStyle", 1); for (int i=0; i < loadStyle; i++) NextStyle(); // Switch to saved style buttonUp = FindWidget("ShowButtonUp"); buttonDown = FindWidget("ShowButtonDown"); return true; }
void pawsControlWindow::NextStyle() { // We load it each time to make the user able to change the style without the need to // restart the client //Increase style style++; csString filename; filename = PawsManager::GetSingleton().GetLocalization()->FindLocalizedFile("control_styles.xml"); if (!psengine->GetVFS()->Exists(filename.GetData())) { Error2( "Could not find XML: %s",filename.GetData()); return; } csRef<iDocument> doc = ParseFile(psengine->GetObjectRegistry(),filename.GetData()); if (!doc) { Error2("Error parsing file %s", filename.GetData()); return; } csString topNodestr("style"); topNodestr += style; csRef<iDocumentNode> root = doc->GetRoot(); if (!root) { Error2("No XML root in %s", filename.GetData()); return; } csRef<iDocumentNode> topNode = root->GetNode(topNodestr.GetData()); //If "style"+style doesn't exist, jump to start if (!topNode) { if (style == 1) //No styles at all :( return; style=0; NextStyle(); return; } csRef<iDocumentNodeIterator> iter = topNode->GetNodes(); //Loop through the XML int bwidth=52, bheight=52, mwidth=16, mheight=16; float xscale=1.0f, yscale=1.0f; // get the current width and height of the buttons (should be the same for all) pawsButton* btn = (pawsButton*)FindWidget("QuitButton"); int boldwidth = btn->ClipRect().Width(); int boldheight = btn->ClipRect().Height(); while ( iter->HasNext() ) { csRef<iDocumentNode> node = iter->Next(); if (!strcmp(node->GetValue(),"button")) { int x = GetActualWidth(node->GetAttributeValueAsInt("x")); int y = GetActualHeight(node->GetAttributeValueAsInt("y")); csString name = node->GetAttributeValue("name"); pawsWidget* wdg = FindWidget(name.GetData()); if (!wdg) { Error2("No such widget as %s!",name.GetData()); continue; } wdg->SetSize(bwidth, bheight); wdg->SetRelativeFramePos(x, y); } else if (!strcmp(node->GetValue(),"buttons")) { bwidth = GetActualWidth(node->GetAttributeValueAsInt("width")); bheight = GetActualHeight(node->GetAttributeValueAsInt("height")); mwidth = GetActualWidth(node->GetAttributeValueAsInt("hide_width")); mheight = GetActualHeight(node->GetAttributeValueAsInt("hide_height")); // get the multiplier for the button and the widget size if (boldwidth != 0 && boldheight != 0) { xscale = float(boldwidth) / float(bwidth); yscale = float(boldheight) / float(bheight); } } else if (!strcmp(node->GetValue(), "bar")) { orgw = GetActualWidth(node->GetAttributeValueAsInt("width")); orgh = GetActualWidth(node->GetAttributeValueAsInt("height")); SetRelativeFrameSize(orgw, orgh); min_width = GetActualWidth(node->GetAttributeValueAsInt("min_w")); min_height = GetActualWidth(node->GetAttributeValueAsInt("min_h")); alwaysResize = node->GetAttributeValueAsBool("always_resize", true); SetResizeShow(alwaysResize); } } /* Resize the widget according to the proportions of the previous style. * * When the new styles dimensions exceeds its max it will be downsized to fit. * See: pawsWidget::Resize(int deltaX, int deltaY, int flags) */ Resize( int(xscale*orgw-orgw), int(yscale*orgh-orgh), RESIZE_RIGHT | RESIZE_BOTTOM ); // Set the minimize buttons size pawsButton* minUp = (pawsButton*)FindWidget("ShowButtonUp"); minUp->SetSize(mwidth,mheight); pawsButton* minDown = (pawsButton*)FindWidget("ShowButtonDown"); minDown->SetSize(mwidth,mheight); }
bool pawsControlWindow::OnButtonPressed( int mouseButton, int keyModifier, pawsWidget* reporter ) { if(reporter->GetID() == CONTROL_MINIDOWN || reporter->GetID() == CONTROL_MINIUP) { if (mouseButton == csmbRight) { //If the user clicked on the right mouse button, switch to another style if ( !hidden ) //don't allow to change styles while the toolbar is closed NextStyle(); return true; } else if (mouseButton == csmbMiddle) { printf("Resetting toolbar to orginal size (%d,%d)\n",orgw,orgh); SetRelativeFrameSize(orgw,orgh); return true; } } switch ( reporter->GetID() ) { case CONTROL_MINIUP: { if ( !hidden ) Toggle(); return true; } case CONTROL_MINIDOWN: { if ( hidden ) Toggle(); return true; } case CONTROL_QUIT: { HandleQuit(); return true; } //////////////////////////////////////////////////////////////////// //Special cases that need more than the standard to open correctly //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // These two are from the confirm window buttons for quiting. //////////////////////////////////////////////////////////////////// case CONFIRM_YES: { psengine->QuitClient(); return true; } case CONFIRM_NO: { PawsManager::GetSingleton().SetModalWidget( 0 ); reporter->GetParent()->Hide(); return true; } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //Default handle for windows //////////////////////////////////////////////////////////////////// default: { pawsWidget* wdg = FindWidget(reporter->GetID()); if (!wdg) return false; pawsControlledWindow* wnd = FindWindowFromButton(wdg->GetName()); if (!wnd) return false; HandleWindow(wnd->GetName()); return true; } } return false; }
int main(int argc, char *argv[]) { FILE *f; struct groups_t g; struct styles_t s; struct pattern_group_t *groups; struct style_t *styles; struct pattern_t *patterns; int quiet = 0; int current_arg; s.first = NULL; g.first = NULL; if(argc < 2) { printf("Format: %s [-q[uiet]] <filename1> [filename2 ...]\n", argv[0]); return 1; } if(strncmp(argv[1],"-q",2) == 0) { quiet = 1; current_arg = 2; } else { current_arg = 1; } for(;current_arg<argc;current_arg++) { if((f = fopen(argv[current_arg],"r")) == NULL) { perror("Couldn't open file"); return 1; } ParsePatterns(f,&g,&s); fclose(f); if(!quiet) { printf("File: %s\n", argv[current_arg]); groups = FirstGroup(&g); printf("Group Data\n"); while(groups) { printf(" Group Name: %s\n",Group_GetName(groups)); patterns = Group_GetPatterns(groups); while(patterns) { printf(" Pattern Name: %s\n",Patt_GetName(patterns)); printf(" Style: %s\n",Patt_GetStyle(patterns)); printf(" Data: %s\n",Patt_GetData(patterns)); printf(" Height ratio: %1.2f\n",Patt_GetHR(patterns)); printf(" Dwell Ratio: %1.2f\n",Patt_GetDR(patterns)); printf(" Author: %s\n",Patt_GetAuthor(patterns)); patterns = NextPatt(patterns); } groups = NextGroup(groups); printf("\n"); }; printf("\n\n"); printf("Style Data\n"); styles = FirstStyle(&s); while(styles) { int i; printf(" Style Name: %s\n",Style_GetName(styles)); printf(" Length: %i\n",Style_GetLength(styles)); printf(" Data:\n"); for(i=0;i<(int)Style_GetLength(styles);i++) { if((i%4) == 0) { printf(" {"); } else if ((i%4) == 2) { printf("}{"); } printf(" %i",Style_GetData(styles)[i]); if ((i%4) == 0 || (i%4) == 2) { printf(", "); } else if ((i%4) == 3) { printf("}\n"); } } styles = NextStyle(styles); printf("\n"); } printf("\n\n"); } FreeGroups(&g); FreeStyles(&s); } return 0; }