| 1 | /*************************************************************************** |
| 2 | horizontal.cpp - description |
| 3 | ------------------- |
| 4 | begin : Thu Aug 17 2000 |
| 5 | copyright : (C) 2000 by Waldemar Baraldi |
| 6 | email : [email protected] |
| 7 | ***************************************************************************/ |
| 8 | |
| 9 | /*************************************************************************** |
| 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or modify * |
| 12 | * it under the terms of the GNU General Public License as published by * |
| 13 | * the Free Software Foundation; either version 2 of the License, or * |
| 14 | * (at your option) any later version. * |
| 15 | * * |
| 16 | ***************************************************************************/ |
| 17 | |
| 18 | #include "horizontal.h" |
| 19 | #include "pointerhorizontal.h" |
| 20 | |
| 21 | Horizontal::Horizontal():Pipe(){ |
| 22 | p=new PointerHorizontal(); |
| 23 | } |
| 24 | |
| 25 | Horizontal::~Horizontal(){ |
| 26 | delete p; |
| 27 | } |
| 28 | |
| 29 | bool Horizontal::hasConnection(CardinalPoint con){ |
| 30 | return ((con==West) || (con==East)); |
| 31 | } |
| 32 | |
| 33 | CardinalPoint Horizontal::getOutput(CardinalPoint input){ |
| 34 | if (input==ro) return Void; |
| 35 | switch (input){ |
| 36 | case West: return East; |
| 37 | case East:return West; |
| 38 | default:return Void; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | void Horizontal::restrictAsOutput(CardinalPoint con){ |
| 43 | if (con==East || con==West) ro=con; |
| 44 | } |
| 45 | |
| 46 | bool Horizontal::isRestrictedAsOutput(CardinalPoint con){ |
| 47 | return (con==ro); |
| 48 | } |
| 49 | |
| 50 | void Horizontal::incFullLevel(CardinalPoint input,unsigned int amount){ |
| 51 | if (input==West || input==East) |
| 52 | if ((used_input==Void || used_input==input) && input!=ro){ |
| 53 | full_level+=amount; |
| 54 | used_input=input; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | int Horizontal::getFullLevel(CardinalPoint input){ |
| 59 | if (input==used_input) |
| 60 | return full_level; |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | Pointer * Horizontal::getPointer(){ |
| 65 | return p; |
| 66 | } |
| 67 | |
| 68 | void Horizontal::paint(VideoManager * vm){ |
| 69 | Image * ima; |
| 70 | if (fixed) |
| 71 | ima=(vm->getImageManager())->getImage(new Str("horizontal_b.png")); |
| 72 | else |
| 73 | ima=(vm->getImageManager())->getImage(new Str("horizontal.png")); |
| 74 | vm->blit(ima, x, y); |
| 75 | |
| 76 | if (ro!=Void) paintRestriction(vm, ro); |
| 77 | |
| 78 | paintFlow(vm); |
| 79 | } |
| 80 | |
| 81 | void Horizontal::paintFlow(VideoManager * vm){ |
| 82 | |
| 83 | if (full_level>0){ |
| 84 | Image * aux=(vm->getImageManager())->getImage(new Str("flow.png")); |
| 85 | int yof=y+(PipeHeight-aux->height())/2; |
| 86 | int total,f; |
| 87 | vm->setClipping(x, y, PipeWidth, PipeHeight); |
| 88 | vm->enableClipping(true); |
| 89 | if (used_input==West){ |
| 90 | total=x-aux->width()/2; |
| 91 | f=1; |
| 92 | } |
| 93 | else{ |
| 94 | total=x+PipeWidth-aux->width()/2; |
| 95 | f=-1; |
| 96 | } |
| 97 | for (int i=0; i<full_level+2*Gran;i+=Gran) |
| 98 | vm->blit(aux, (int)(total+f*(float)i/(float)full()*(float)PipeWidth), yof); |
| 99 | vm->enableClipping(false); |
| 100 | } |
| 101 | if (bonus!=NormalBonus) paintBonus(vm, bonus); |
| 102 | } |
| 103 |