bool TrackBar::OnEventKeyboard(Event event,WPARAM wparam,LPARAM lparam) { if(!GetVisible() || !GetEnabled()) return false; switch(event) { case EventKeyDown: if(wparam == VK_DOWN || wparam == VK_LEFT) { if(GetTrackValue()) SetTrackValue(GetTrackValue() - 1); if(GetParent()) GetParent()->OnEvent(EventChildCommand,ControlEventTrackChange,(LPARAM)this); return true; } if(wparam == VK_UP || wparam == VK_RIGHT) { if(GetTrackValue() < GetTrackRange()) SetTrackValue(GetTrackValue() + 1); if(GetParent()) GetParent()->OnEvent(EventChildCommand,ControlEventTrackChange,(LPARAM)this); return true; } if(wparam == VK_HOME) { SetTrackValue(0); if(GetParent()) GetParent()->OnEvent(EventChildCommand,ControlEventTrackChange,(LPARAM)this); return true; } if(wparam == VK_END) { SetTrackValue(GetTrackRange()); if(GetParent()) GetParent()->OnEvent(EventChildCommand,ControlEventTrackChange,(LPARAM)this); return true; } break; } return Control::OnEventKeyboard(event,wparam,lparam); }
Rect TrackBar::GetTrackBox(void) const { Rect box = GetBoundingBox(); Size size(8,box.GetHeight()); return Rect(Point(box.left + box.GetWidth() * GetTrackValue() / GetTrackRange() - size.cx / 2,box.top + box.GetHeight() / 2 - size.cy / 2 + 2),size); }
bool TrackBar::OnRender(void) { if(!GetVisible()) return false; Rect box = GetBoundingBox(); GetKernel()->GetUserInterface()->DrawTrackBar(box,GetTrackBox(),GetTrackRange(),GetTrackValue(),false,GetEnabled(),GetFocused()); return Control::OnRender(); }
int ReadGPX(const char* File, struct GPSTrack* Track) { /* Init the libxml library. Also checks version. */ LIBXML_TEST_VERSION xmlDocPtr GPXData; /* Read the GPX data from file. */ GPXData = xmlParseFile(File); if (GPXData == NULL) { fprintf(stderr, _("Failed to parse GPX data from %s.\n"), File); return 0; } /* Now grab the "root" node. */ xmlNodePtr GPXRoot; GPXRoot = xmlDocGetRootElement(GPXData); if (GPXRoot == NULL) { fprintf(stderr, _("GPX file has no root. Not healthy.\n")); xmlFreeDoc(GPXData); xmlCleanupParser(); return 0; } /* Check that this is indeed a GPX - the root node * should be "gpx". */ if (strcmp((const char *)GPXRoot->name, "gpx") == 0) { /* Ok, it is a GPX file. */ } else { /* Not valid. */ fprintf(stderr, _("Invalid GPX file.\n")); xmlFreeDoc(GPXData); xmlCleanupParser(); return 0; } /* Now comes the messy part... walking the tree to find * what we want. * I've chosen to do it with two functions, one of which * is recursive, rather than a clever inside-this-function * walk the tree thing. * * We start by calling the recursive function to look for * <trkseg> tags, and then that function calls another * when it has found one... this sub function then * hauls out the <trkpt> tags with the actual data. * Messy, convoluted, but it seems to work... */ /* As to where to store the data? Again, its messy. * We maintain two global vars, FirstPoint and LastPoint. * FirstPoint points to the first GPSPoint done, and * LastPoint is the last point done, used for the next * point... we use this to build a singly-linked list. */ /* (I think I'll just be grateful for the work that libxml * puts in for me... imagine having to write an XML parser! * Nasty.) */ /* Before we go into this function, we also setlocale to "C". * The GPX def indicates that the decimal separator should be * ".", but certain locales specify otherwise. Which has caused issues. * So we set the locale for this function, and then revert it. */ FirstPoint = NULL; LastPoint = NULL; char* OldLocale = setlocale(LC_NUMERIC, "C"); FindTrackSeg(GPXRoot); setlocale(LC_NUMERIC, OldLocale); /* Clean up stuff for the XML library. */ xmlFreeDoc(GPXData); xmlCleanupParser(); Track->Points = FirstPoint; /* Find the time range for this track */ GetTrackRange(Track); return 1; }
bool TrackBar::OnEventMouse(Event event,WPARAM wparam,LPARAM lparam) { if(!GetVisible() || !GetEnabled()) return false; switch(event) { case EventLeftButtonDown: if(PointInTrack(*(Point*)wparam)) { if(!GetFocused()) Focus(); mTracking = true; mTrackingValue = mValue; mTrackingPosition = ((Point*)wparam)->x - GetTrackBox().GetCenter().x; SetCapture(GetKernel()->GetWindowHandle()); return true; } if(PointIn(*(Point*)wparam)) { if(!GetFocused()) Focus(); if(((Point*)wparam)->x > GetTrackBox().GetCenter().x) { if(GetTrackValue() < GetTrackRange()) SetTrackValue(GetTrackValue() + 1); } else { if(GetTrackValue()) SetTrackValue(GetTrackValue() - 1); } return true; } break; case EventLeftButtonUp: if(mTracking) { mTracking = false; ReleaseCapture(); return true; } break; case EventMouseMove: if(mTracking) { Point delta = *(Point*)wparam; delta.x -= GetScreenPosition().x + mTrackingPosition; float val = (float)GetBoundingBox().GetWidth() / (float)GetTrackRange(); if((float)delta.x / val > (float)GetTrackRange()) SetTrackValue(GetTrackRange()); else if((float)delta.x / val < 0.0f) SetTrackValue(0); else SetTrackValue((float)delta.x / val); if(GetParent()) GetParent()->OnEvent(EventChildCommand,ControlEventTrackChange,(LPARAM)this); } break; } return Control::OnEventMouse(event,wparam,lparam); }