123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /**
- * fillbar.m
- *
- * Manages custom fillbars.
- *
- * @package com.winamp.maki.lib.community.fillbar
- * @author mpdeimos
- * @date 08/10/01
- * @version 1.0
- */
- #ifndef included
- #error This script can only be compiled as a #include
- #endif
- Class Layer FillBar;
- // {
- Member Map FillBar.fillmap;
- Member int FillBar.pos;
- Member boolean Fillbar.reverse;
- // User dragging stuff
- Member boolean Fillbar.dragable;
- Member boolean Fillbar.dragging;
- /**
- * constructor
- *
- * @param layer that should be handled like a fillbar
- * @param bitmapID that should be used as region map
- * @ret FillBar object
- */
- Function FillBar FillBar_construct(Layer l, String bitmapID);
- Function FillBar_setMap(FillBar fb, String bitmapID);
- /**
- * destructor, always call on script unloading
- *
- */
- Function FillBar_destruct(FillBar fb);
- /**
- * sets the region
- *
- * @param fillbar to act on
- * @param threshold of the map to generate a region
- */
- Function FillBar_setPosition(FillBar fb, int threshold);
- /**
- * called each time the users drags the fillbar
- *
- * @param The dragged FillBar
- * @param The alue the FillBar was dragged to.
- * @ret FALSE if you do not want to allow dragging.
- */
- Function boolean FillBar_onDrag(FillBar fb, int pos);
- /*
- * called each time the users ends dragging the fillbar
- *
- * @param The dragged FillBar
- * @param The alue the FillBar was dragged to.
- * @ret FALSE if you do not want to allow dragging.
- */
- Function boolean FillBar_onEndDrag(FillBar fb, int pos);
- /*
- * IMPLEMENTATION
- */
- FillBar FillBar_construct(Layer l, String bitmapID)
- {
- FillBar fb = l;
- fb.reverse = TRUE;
- fb.fillmap = new Map;
- fb.fillmap.loadMap(bitmapID);
- return fb;
- }
- FillBar_setMap(Fillbar fb, String bitmapID)
- {
- if (fb.fillmap != NULL)
- {
- delete fb.fillmap;
- }
-
- fb.fillmap = new Map;
- fb.fillmap.loadMap(bitmapID);
- }
- FillBar_destruct(FillBar fb)
- {
- Map tmp = fb.fillmap;
- delete tmp;
- }
- FillBar_setPosition(FillBar fb, int threshold)
- {
- fb.pos = threshold;
- fb.setRegionFromMap(fb.fillmap, threshold, fb.reverse);
- }
- // User dragging handles
- FillBar.onLeftButtonDown (int x, int y)
- {
- if (!FillBar.dragable)
- {
- return;
- }
-
- Fillbar.dragging = TRUE;
- }
- FillBar.onMouseMove (int x, int y)
- {
- if (!FillBar.dragable || !Fillbar.dragging)
- {
- return;
- }
- int mouseLeft = x - FillBar.getLeft();
- int mouseTop = y - Fillbar.getTop();
- if (!FillBar.fillMap.inRegion(mouseLeft, mouseTop))
- {
- return;
- }
-
- int position = FillBar.fillMap.getValue(mouseLeft, mouseTop);
- int update = FillBar_onDrag(FillBar, position);
-
- if (update)
- {
- FillBar_setPosition(FillBar, position);
- }
- }
-
- Fillbar.onLeftButtonUp (int x, int y)
- {
- if (!FillBar.dragable || !Fillbar.dragging)
- {
- return;
- }
- int mouseLeft = x - FillBar.getLeft();
- int mouseTop = y - Fillbar.getTop();
- int position = FillBar.fillMap.getValue(mouseLeft, mouseTop);
- if (!FillBar.fillMap.inRegion(mouseLeft, mouseTop))
- {
- position = fb.pos;
- }
- int update = FillBar_onEndDrag(FillBar, position);
-
- if (update)
- {
- FillBar_setPosition(FillBar, position);
- }
- Fillbar.dragging = FALSE;
- }
-
- // Callback Stubs
- boolean FillBar_onDrag(Fillbar fb, int pos) { return TRUE; }
- boolean FillBar_onEndDrag(Fillbar fb, int pos) { return TRUE; }
- // }
|